0N/A/*
2119N/A * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "runtime/os.hpp"
1879N/A#include "vm_version_sparc.hpp"
0N/A
641N/A# include <sys/auxv.h>
641N/A# include <sys/auxv_SPARC.h>
0N/A# include <sys/systeminfo.h>
1968N/A# include <kstat.h>
0N/A
641N/A// We need to keep these here as long as we have to build on Solaris
641N/A// versions before 10.
641N/A#ifndef SI_ARCHITECTURE_32
641N/A#define SI_ARCHITECTURE_32 516 /* basic 32-bit SI_ARCHITECTURE */
641N/A#endif
641N/A
641N/A#ifndef SI_ARCHITECTURE_64
641N/A#define SI_ARCHITECTURE_64 517 /* basic 64-bit SI_ARCHITECTURE */
641N/A#endif
641N/A
641N/Astatic void do_sysinfo(int si, const char* string, int* features, int mask) {
641N/A char tmp;
641N/A size_t bufsize = sysinfo(si, &tmp, 1);
641N/A
641N/A // All SI defines used below must be supported.
641N/A guarantee(bufsize != -1, "must be supported");
641N/A
641N/A char* buf = (char*) malloc(bufsize);
641N/A
641N/A if (buf == NULL)
641N/A return;
641N/A
641N/A if (sysinfo(si, buf, bufsize) == bufsize) {
641N/A // Compare the string.
641N/A if (strcmp(buf, string) == 0) {
641N/A *features |= mask;
641N/A }
641N/A }
641N/A
641N/A free(buf);
641N/A}
641N/A
0N/Aint VM_Version::platform_features(int features) {
641N/A // getisax(2), SI_ARCHITECTURE_32, and SI_ARCHITECTURE_64 are
641N/A // supported on Solaris 10 and later.
641N/A if (os::Solaris::supports_getisax()) {
0N/A
641N/A // Check 32-bit architecture.
641N/A do_sysinfo(SI_ARCHITECTURE_32, "sparc", &features, v8_instructions_m);
641N/A
641N/A // Check 64-bit architecture.
641N/A do_sysinfo(SI_ARCHITECTURE_64, "sparcv9", &features, generic_v9_m);
641N/A
641N/A // Extract valid instruction set extensions.
641N/A uint_t av;
641N/A uint_t avn = os::Solaris::getisax(&av, 1);
641N/A assert(avn == 1, "should only return one av");
0N/A
1834N/A#ifndef PRODUCT
1834N/A if (PrintMiscellaneous && Verbose)
1834N/A tty->print_cr("getisax(2) returned: " PTR32_FORMAT, av);
1834N/A#endif
1834N/A
641N/A if (av & AV_SPARC_MUL32) features |= hardware_mul32_m;
641N/A if (av & AV_SPARC_DIV32) features |= hardware_div32_m;
641N/A if (av & AV_SPARC_FSMULD) features |= hardware_fsmuld_m;
641N/A if (av & AV_SPARC_V8PLUS) features |= v9_instructions_m;
643N/A if (av & AV_SPARC_POPC) features |= hardware_popc_m;
641N/A if (av & AV_SPARC_VIS) features |= vis1_instructions_m;
641N/A if (av & AV_SPARC_VIS2) features |= vis2_instructions_m;
1834N/A
1834N/A // Next values are not defined before Solaris 10
1834N/A // but Solaris 8 is used for jdk6 update builds.
1834N/A#ifndef AV_SPARC_ASI_BLK_INIT
1834N/A#define AV_SPARC_ASI_BLK_INIT 0x0080 /* ASI_BLK_INIT_xxx ASI */
1834N/A#endif
1968N/A if (av & AV_SPARC_ASI_BLK_INIT) features |= blk_init_instructions_m;
1968N/A
1834N/A#ifndef AV_SPARC_FMAF
1968N/A#define AV_SPARC_FMAF 0x0100 /* Fused Multiply-Add */
1834N/A#endif
1834N/A if (av & AV_SPARC_FMAF) features |= fmaf_instructions_m;
1968N/A
1968N/A#ifndef AV_SPARC_FMAU
1968N/A#define AV_SPARC_FMAU 0x0200 /* Unfused Multiply-Add */
1968N/A#endif
1968N/A if (av & AV_SPARC_FMAU) features |= fmau_instructions_m;
1968N/A
1968N/A#ifndef AV_SPARC_VIS3
1968N/A#define AV_SPARC_VIS3 0x0400 /* VIS3 instruction set extensions */
1968N/A#endif
1968N/A if (av & AV_SPARC_VIS3) features |= vis3_instructions_m;
1968N/A
2664N/A#ifndef AV_SPARC_CBCOND
2664N/A#define AV_SPARC_CBCOND 0x10000000 /* compare and branch instrs supported */
2664N/A#endif
2664N/A if (av & AV_SPARC_CBCOND) features |= cbcond_instructions_m;
2664N/A
641N/A } else {
641N/A // getisax(2) failed, use the old legacy code.
641N/A#ifndef PRODUCT
641N/A if (PrintMiscellaneous && Verbose)
1834N/A tty->print_cr("getisax(2) is not supported.");
641N/A#endif
641N/A
641N/A char tmp;
641N/A size_t bufsize = sysinfo(SI_ISALIST, &tmp, 1);
641N/A char* buf = (char*) malloc(bufsize);
0N/A
641N/A if (buf != NULL) {
641N/A if (sysinfo(SI_ISALIST, buf, bufsize) == bufsize) {
641N/A // Figure out what kind of sparc we have
641N/A char *sparc_string = strstr(buf, "sparc");
641N/A if (sparc_string != NULL) { features |= v8_instructions_m;
641N/A if (sparc_string[5] == 'v') {
641N/A if (sparc_string[6] == '8') {
641N/A if (sparc_string[7] == '-') { features |= hardware_mul32_m;
641N/A features |= hardware_div32_m;
641N/A } else if (sparc_string[7] == 'p') features |= generic_v9_m;
641N/A else features |= generic_v8_m;
641N/A } else if (sparc_string[6] == '9') features |= generic_v9_m;
641N/A }
641N/A }
641N/A
641N/A // Check for visualization instructions
641N/A char *vis = strstr(buf, "vis");
641N/A if (vis != NULL) { features |= vis1_instructions_m;
641N/A if (vis[3] == '2') features |= vis2_instructions_m;
0N/A }
0N/A }
641N/A free(buf);
0N/A }
0N/A }
0N/A
641N/A // Determine the machine type.
641N/A do_sysinfo(SI_MACHINE, "sun4v", &features, sun4v_m);
0N/A
1968N/A {
1968N/A // Using kstat to determine the machine type.
1968N/A kstat_ctl_t* kc = kstat_open();
1968N/A kstat_t* ksp = kstat_lookup(kc, (char*)"cpu_info", -1, NULL);
1968N/A const char* implementation = "UNKNOWN";
1968N/A if (ksp != NULL) {
1968N/A if (kstat_read(kc, ksp, NULL) != -1 && ksp->ks_data != NULL) {
1968N/A kstat_named_t* knm = (kstat_named_t *)ksp->ks_data;
1968N/A for (int i = 0; i < ksp->ks_ndata; i++) {
1968N/A if (strcmp((const char*)&(knm[i].name),"implementation") == 0) {
1968N/A#ifndef KSTAT_DATA_STRING
1968N/A#define KSTAT_DATA_STRING 9
1968N/A#endif
1968N/A if (knm[i].data_type == KSTAT_DATA_CHAR) {
1968N/A // VM is running on Solaris 8 which does not have value.str.
1968N/A implementation = &(knm[i].value.c[0]);
1968N/A } else if (knm[i].data_type == KSTAT_DATA_STRING) {
1968N/A // VM is running on Solaris 10.
1968N/A#ifndef KSTAT_NAMED_STR_PTR
1968N/A // Solaris 8 was used to build VM, define the structure it misses.
1968N/A struct str_t {
1968N/A union {
1968N/A char *ptr; /* NULL-term string */
1968N/A char __pad[8]; /* 64-bit padding */
1968N/A } addr;
1968N/A uint32_t len; /* # bytes for strlen + '\0' */
1968N/A };
1968N/A#define KSTAT_NAMED_STR_PTR(knptr) (( (str_t*)&((knptr)->value) )->addr.ptr)
1968N/A#endif
1968N/A implementation = KSTAT_NAMED_STR_PTR(&knm[i]);
1968N/A }
1968N/A#ifndef PRODUCT
1968N/A if (PrintMiscellaneous && Verbose) {
1968N/A tty->print_cr("cpu_info.implementation: %s", implementation);
1968N/A }
1968N/A#endif
2119N/A // Convert to UPPER case before compare.
2119N/A char* impl = strdup(implementation);
2119N/A
2119N/A for (int i = 0; impl[i] != 0; i++)
2119N/A impl[i] = (char)toupper((uint)impl[i]);
2119N/A if (strstr(impl, "SPARC64") != NULL) {
1968N/A features |= sparc64_family_m;
3935N/A } else if (strstr(impl, "SPARC-M") != NULL) {
3935N/A // M-series SPARC is based on T-series.
3935N/A features |= (M_family_m | T_family_m);
2119N/A } else if (strstr(impl, "SPARC-T") != NULL) {
1968N/A features |= T_family_m;
2119N/A if (strstr(impl, "SPARC-T1") != NULL) {
1968N/A features |= T1_model_m;
1968N/A }
2119N/A } else {
3935N/A if (strstr(impl, "SPARC") == NULL) {
3935N/A#ifndef PRODUCT
3935N/A // kstat on Solaris 8 virtual machines (branded zones)
3935N/A // returns "(unsupported)" implementation.
3935N/A warning("kstat cpu_info implementation = '%s', should contain SPARC", impl);
3935N/A#endif
3935N/A implementation = "SPARC";
3935N/A }
1968N/A }
2119N/A free((void*)impl);
1968N/A break;
1968N/A }
1968N/A } // for(
1968N/A }
1968N/A }
1968N/A assert(strcmp(implementation, "UNKNOWN") != 0,
1968N/A "unknown cpu info (changed kstat interface?)");
1968N/A kstat_close(kc);
1968N/A }
1968N/A
0N/A return features;
0N/A}