Wed, 11 Mar 2009 14:16:13 -0700
6812587: Use auxv to determine SPARC hardware features on Solaris
Summary: A similar function to getisax(2) should be used to determine all possible instruction set extensions.
Reviewed-by: never, kvn
duke@435 | 1 | /* |
twisti@1076 | 2 | * Copyright 2006-2009 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_vm_version_solaris_sparc.cpp.incl" |
duke@435 | 27 | |
twisti@1076 | 28 | # include <sys/auxv.h> |
twisti@1076 | 29 | # include <sys/auxv_SPARC.h> |
duke@435 | 30 | # include <sys/systeminfo.h> |
duke@435 | 31 | |
twisti@1076 | 32 | // We need to keep these here as long as we have to build on Solaris |
twisti@1076 | 33 | // versions before 10. |
twisti@1076 | 34 | #ifndef SI_ARCHITECTURE_32 |
twisti@1076 | 35 | #define SI_ARCHITECTURE_32 516 /* basic 32-bit SI_ARCHITECTURE */ |
twisti@1076 | 36 | #endif |
twisti@1076 | 37 | |
twisti@1076 | 38 | #ifndef SI_ARCHITECTURE_64 |
twisti@1076 | 39 | #define SI_ARCHITECTURE_64 517 /* basic 64-bit SI_ARCHITECTURE */ |
twisti@1076 | 40 | #endif |
twisti@1076 | 41 | |
twisti@1076 | 42 | static void do_sysinfo(int si, const char* string, int* features, int mask) { |
twisti@1076 | 43 | char tmp; |
twisti@1076 | 44 | size_t bufsize = sysinfo(si, &tmp, 1); |
twisti@1076 | 45 | |
twisti@1076 | 46 | // All SI defines used below must be supported. |
twisti@1076 | 47 | guarantee(bufsize != -1, "must be supported"); |
twisti@1076 | 48 | |
twisti@1076 | 49 | char* buf = (char*) malloc(bufsize); |
twisti@1076 | 50 | |
twisti@1076 | 51 | if (buf == NULL) |
twisti@1076 | 52 | return; |
twisti@1076 | 53 | |
twisti@1076 | 54 | if (sysinfo(si, buf, bufsize) == bufsize) { |
twisti@1076 | 55 | // Compare the string. |
twisti@1076 | 56 | if (strcmp(buf, string) == 0) { |
twisti@1076 | 57 | *features |= mask; |
twisti@1076 | 58 | } |
twisti@1076 | 59 | } |
twisti@1076 | 60 | |
twisti@1076 | 61 | free(buf); |
twisti@1076 | 62 | } |
twisti@1076 | 63 | |
duke@435 | 64 | int VM_Version::platform_features(int features) { |
twisti@1076 | 65 | // getisax(2), SI_ARCHITECTURE_32, and SI_ARCHITECTURE_64 are |
twisti@1076 | 66 | // supported on Solaris 10 and later. |
twisti@1076 | 67 | if (os::Solaris::supports_getisax()) { |
twisti@1076 | 68 | #ifndef PRODUCT |
twisti@1076 | 69 | if (PrintMiscellaneous && Verbose) |
twisti@1076 | 70 | tty->print_cr("getisax(2) supported."); |
twisti@1076 | 71 | #endif |
duke@435 | 72 | |
twisti@1076 | 73 | // Check 32-bit architecture. |
twisti@1076 | 74 | do_sysinfo(SI_ARCHITECTURE_32, "sparc", &features, v8_instructions_m); |
duke@435 | 75 | |
twisti@1076 | 76 | // Check 64-bit architecture. |
twisti@1076 | 77 | do_sysinfo(SI_ARCHITECTURE_64, "sparcv9", &features, generic_v9_m); |
duke@435 | 78 | |
twisti@1076 | 79 | // Extract valid instruction set extensions. |
twisti@1076 | 80 | uint_t av; |
twisti@1076 | 81 | uint_t avn = os::Solaris::getisax(&av, 1); |
twisti@1076 | 82 | assert(avn == 1, "should only return one av"); |
twisti@1076 | 83 | |
twisti@1076 | 84 | if (av & AV_SPARC_MUL32) features |= hardware_mul32_m; |
twisti@1076 | 85 | if (av & AV_SPARC_DIV32) features |= hardware_div32_m; |
twisti@1076 | 86 | if (av & AV_SPARC_FSMULD) features |= hardware_fsmuld_m; |
twisti@1076 | 87 | if (av & AV_SPARC_V8PLUS) features |= v9_instructions_m; |
twisti@1076 | 88 | if (av & AV_SPARC_VIS) features |= vis1_instructions_m; |
twisti@1076 | 89 | if (av & AV_SPARC_VIS2) features |= vis2_instructions_m; |
twisti@1076 | 90 | } else { |
twisti@1076 | 91 | // getisax(2) failed, use the old legacy code. |
twisti@1076 | 92 | #ifndef PRODUCT |
twisti@1076 | 93 | if (PrintMiscellaneous && Verbose) |
twisti@1076 | 94 | tty->print_cr("getisax(2) not supported."); |
twisti@1076 | 95 | #endif |
twisti@1076 | 96 | |
twisti@1076 | 97 | char tmp; |
twisti@1076 | 98 | size_t bufsize = sysinfo(SI_ISALIST, &tmp, 1); |
twisti@1076 | 99 | char* buf = (char*) malloc(bufsize); |
twisti@1076 | 100 | |
twisti@1076 | 101 | if (buf != NULL) { |
twisti@1076 | 102 | if (sysinfo(SI_ISALIST, buf, bufsize) == bufsize) { |
twisti@1076 | 103 | // Figure out what kind of sparc we have |
twisti@1076 | 104 | char *sparc_string = strstr(buf, "sparc"); |
twisti@1076 | 105 | if (sparc_string != NULL) { features |= v8_instructions_m; |
twisti@1076 | 106 | if (sparc_string[5] == 'v') { |
twisti@1076 | 107 | if (sparc_string[6] == '8') { |
twisti@1076 | 108 | if (sparc_string[7] == '-') { features |= hardware_mul32_m; |
twisti@1076 | 109 | features |= hardware_div32_m; |
twisti@1076 | 110 | } else if (sparc_string[7] == 'p') features |= generic_v9_m; |
twisti@1076 | 111 | else features |= generic_v8_m; |
twisti@1076 | 112 | } else if (sparc_string[6] == '9') features |= generic_v9_m; |
twisti@1076 | 113 | } |
twisti@1076 | 114 | } |
twisti@1076 | 115 | |
twisti@1076 | 116 | // Check for visualization instructions |
twisti@1076 | 117 | char *vis = strstr(buf, "vis"); |
twisti@1076 | 118 | if (vis != NULL) { features |= vis1_instructions_m; |
twisti@1076 | 119 | if (vis[3] == '2') features |= vis2_instructions_m; |
duke@435 | 120 | } |
duke@435 | 121 | } |
twisti@1076 | 122 | free(buf); |
duke@435 | 123 | } |
duke@435 | 124 | } |
duke@435 | 125 | |
twisti@1076 | 126 | // Determine the machine type. |
twisti@1076 | 127 | do_sysinfo(SI_MACHINE, "sun4v", &features, sun4v_m); |
duke@435 | 128 | |
duke@435 | 129 | return features; |
duke@435 | 130 | } |