src/cpu/x86/vm/vm_version_x86.cpp

Print this page
rev 3111 : imported patch osx-threadid
   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  48 int VM_Version::_cpuFeatures;
  49 const char*           VM_Version::_features_str = "";
  50 VM_Version::CpuidInfo VM_Version::_cpuid_info   = { 0, };
  51 
  52 static BufferBlob* stub_blob;
  53 static const int stub_size = 550;
  54 
  55 extern "C" {
  56   typedef void (*getPsrInfo_stub_t)(void*);
  57 }
  58 static getPsrInfo_stub_t getPsrInfo_stub = NULL;
  59 
  60 
  61 class VM_Version_StubGenerator: public StubCodeGenerator {
  62  public:
  63 
  64   VM_Version_StubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
  65 
  66   address generate_getPsrInfo() {
  67     // Flags to test CPU type.
  68     const uint32_t EFL_AC           = 0x40000;
  69     const uint32_t EFL_ID           = 0x200000;
  70     // Values for when we don't have a CPUID instruction.
  71     const int      CPU_FAMILY_SHIFT = 8;
  72     const uint32_t CPU_FAMILY_386   = (3 << CPU_FAMILY_SHIFT);
  73     const uint32_t CPU_FAMILY_486   = (4 << CPU_FAMILY_SHIFT);
  74 
  75     Label detect_486, cpu486, detect_586, std_cpuid1, std_cpuid4;
  76     Label sef_cpuid, ext_cpuid, ext_cpuid1, ext_cpuid5, ext_cpuid7, done;
  77 
  78     StubCodeMark mark(this, "VM_Version", "getPsrInfo_stub");
  79 #   define __ _masm->
  80 
  81     address start = __ pc();
  82 
  83     //
  84     // void getPsrInfo(VM_Version::CpuidInfo* cpuid_info);
  85     //
  86     // LP64: rcx and rdx are first and second argument registers on windows
  87 
  88     __ push(rbp);
  89 #ifdef _LP64
  90     __ mov(rbp, c_rarg0); // cpuid_info address
  91 #else
  92     __ movptr(rbp, Address(rsp, 8)); // cpuid_info address
  93 #endif
  94     __ push(rbx);
  95     __ push(rsi);
  96     __ pushf();          // preserve rbx, and flags
  97     __ pop(rax);
  98     __ push(rax);
  99     __ mov(rcx, rax);
 100     //
 101     // if we are unable to change the AC flag, we have a 386
 102     //
 103     __ xorl(rax, EFL_AC);
 104     __ push(rax);
 105     __ popf();
 106     __ pushf();
 107     __ pop(rax);
 108     __ cmpptr(rax, rcx);
 109     __ jccb(Assembler::notEqual, detect_486);
 110 
 111     __ movl(rax, CPU_FAMILY_386);
 112     __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
 113     __ jmp(done);
 114 
 115     //
 116     // If we are unable to change the ID flag, we have a 486 which does
 117     // not support the "cpuid" instruction.
 118     //
 119     __ bind(detect_486);
 120     __ mov(rax, rcx);
 121     __ xorl(rax, EFL_ID);
 122     __ push(rax);
 123     __ popf();
 124     __ pushf();
 125     __ pop(rax);
 126     __ cmpptr(rcx, rax);
 127     __ jccb(Assembler::notEqual, detect_586);
 128 
 129     __ bind(cpu486);
 130     __ movl(rax, CPU_FAMILY_486);
 131     __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
 132     __ jmp(done);
 133 
 134     //
 135     // At this point, we have a chip which supports the "cpuid" instruction
 136     //
 137     __ bind(detect_586);
 138     __ xorl(rax, rax);
 139     __ cpuid();
 140     __ orl(rax, rax);
 141     __ jcc(Assembler::equal, cpu486);   // if cpuid doesn't support an input


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  48 int VM_Version::_cpuFeatures;
  49 const char*           VM_Version::_features_str = "";
  50 VM_Version::CpuidInfo VM_Version::_cpuid_info   = { 0, };
  51 
  52 static BufferBlob* stub_blob;
  53 static const int stub_size = 550;
  54 
  55 extern "C" {
  56   typedef void (*getPsrInfo_stub_t)(void*);
  57 }
  58 static getPsrInfo_stub_t getPsrInfo_stub = NULL;
  59 
  60 
  61 class VM_Version_StubGenerator: public StubCodeGenerator {
  62  public:
  63 
  64   VM_Version_StubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
  65 
  66   address generate_getPsrInfo() {
  67     // Flags to test CPU type.
  68     const uint32_t HS_EFL_AC           = 0x40000;
  69     const uint32_t HS_EFL_ID           = 0x200000;
  70     // Values for when we don't have a CPUID instruction.
  71     const int      CPU_FAMILY_SHIFT = 8;
  72     const uint32_t CPU_FAMILY_386   = (3 << CPU_FAMILY_SHIFT);
  73     const uint32_t CPU_FAMILY_486   = (4 << CPU_FAMILY_SHIFT);
  74 
  75     Label detect_486, cpu486, detect_586, std_cpuid1, std_cpuid4;
  76     Label sef_cpuid, ext_cpuid, ext_cpuid1, ext_cpuid5, ext_cpuid7, done;
  77 
  78     StubCodeMark mark(this, "VM_Version", "getPsrInfo_stub");
  79 #   define __ _masm->
  80 
  81     address start = __ pc();
  82 
  83     //
  84     // void getPsrInfo(VM_Version::CpuidInfo* cpuid_info);
  85     //
  86     // LP64: rcx and rdx are first and second argument registers on windows
  87 
  88     __ push(rbp);
  89 #ifdef _LP64
  90     __ mov(rbp, c_rarg0); // cpuid_info address
  91 #else
  92     __ movptr(rbp, Address(rsp, 8)); // cpuid_info address
  93 #endif
  94     __ push(rbx);
  95     __ push(rsi);
  96     __ pushf();          // preserve rbx, and flags
  97     __ pop(rax);
  98     __ push(rax);
  99     __ mov(rcx, rax);
 100     //
 101     // if we are unable to change the AC flag, we have a 386
 102     //
 103     __ xorl(rax, HS_EFL_AC);
 104     __ push(rax);
 105     __ popf();
 106     __ pushf();
 107     __ pop(rax);
 108     __ cmpptr(rax, rcx);
 109     __ jccb(Assembler::notEqual, detect_486);
 110 
 111     __ movl(rax, CPU_FAMILY_386);
 112     __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
 113     __ jmp(done);
 114 
 115     //
 116     // If we are unable to change the ID flag, we have a 486 which does
 117     // not support the "cpuid" instruction.
 118     //
 119     __ bind(detect_486);
 120     __ mov(rax, rcx);
 121     __ xorl(rax, HS_EFL_ID);
 122     __ push(rax);
 123     __ popf();
 124     __ pushf();
 125     __ pop(rax);
 126     __ cmpptr(rcx, rax);
 127     __ jccb(Assembler::notEqual, detect_586);
 128 
 129     __ bind(cpu486);
 130     __ movl(rax, CPU_FAMILY_486);
 131     __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
 132     __ jmp(done);
 133 
 134     //
 135     // At this point, we have a chip which supports the "cpuid" instruction
 136     //
 137     __ bind(detect_586);
 138     __ xorl(rax, rax);
 139     __ cpuid();
 140     __ orl(rax, rax);
 141     __ jcc(Assembler::equal, cpu486);   // if cpuid doesn't support an input