Unformatted text preview:

The x86 Feature FlagsSome features of interestQuotationThe CPUID instructionAn example using CPUIDCPU feature informationRegister EDXRegister ECXAMD’s extensionsThe 64-bit feature?Intel’s extended features bitsThe ‘asm’ constructgcc/g++ extensionsLocal variablesSlide 16Example from ‘usecpuid.cpp’Slide 18The processor’s ‘brand string’Getting the brand stringIn-class exercise #1In-class exercise #2The x86 Feature FlagsOn using the CPUID instruction for processor identification and feature determinationSome features of interest•In our course we focus on EM64T and VT•A majority of x86 processors today do not support either of these features (e.g., our classroom and Lab machines lack them)•But machines with Intel’s newest CPUs, such as Core-2 Duo and Pentium-D 9xx, do have both of these capabilities built-in •Software needs to detect these features (or risk crashing in case they’re missing)QuotationNOTESoftware must confirm that a processor feature is presentusing feature flags returned by CPUID prior to using the feature.Software should not depend on future offerings retaining all features. IA-32 Intel Architecture Software Developer’s Manual, volume 2A, page 3-165The CPUID instruction•It exists if bit #21 in the EFLAGS register (the ID-bit) can be ‘toggled’ by software•It can be executed in any processor mode and at any of processor’s privilege-levels•It returns two categories of information:–Basic processor functions–Extended processor functions •It’s documented online (see class website)An example using CPUID•Here is a code-fragment that uses CPUID to obtain basic processor information:.section .datavid: .asciz “xxxxxxxxxxxx” # Vendor Identification String.section .text# Using CPUID to obtain the processor’s Vendor Identification Stringxor %eax, %eax # setup 0 as input-value cpuid # then execute CPUIDmov %ebx, vid+0 # save bytes 0..3 mov %edx, vid+4 # save bytes 4..7mov %ecx, vid+8 # save bytes 8..11CPU feature information•You can execute CPUID with input-value 1 to get some processor feature information (as well as processor-version information)•The feature information is returned in the EDX and ECX registers, with individual bit-settings indicating whether or not specific features are present in the processor•These bits are documented in volume 2ARegister EDX RHTMMXRPSNMTRRRPAEPSEFPU 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0Legend (partial): HT = Hyperthreading Technology (1=yes, 0=no) MMX = MultiMedia eXtensions (1=yes, 0=no)PSN = Processor Serial Number (1=yes, 0=no)MTRR = Memory Type-Range Registers (1=yes, 0=no)PAE = Page-Address Extensions (1=yes, 0=no)PSE = Page-Size Extensions (1=yes, 0=no)FPU = Floating-Point Unit on-chip (1=yes, 0=no)R= Intel ‘reserved’ bitRegister ECXR R R R R R R R R R R R R R R R R R R R R RVMXR R 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0R= Intel ‘reserved’ bitLegend (partial):VMX = Virtualization Technology eXtensions (1=yes, 0=no)AMD’s extensions •The Advanced Micro Devices corporation pioneered the 64-bit architectural design in their x86 processors (e.g., Athlon/Opteron)•They implemented some extended input-values for their CPUID instruction, and to be ‘compatible’ Intel has followed suit•These extended input-values represent negative integers (in two’s complement)New example using CPUID•Here is a code-fragment that uses CPUID to get the highest extended function input-value that the processor understands:.section .datahighin: .int 0 # for highest CPUID input-value.section .text# Using CPUID to obtain the processor’s highest valid CPUID input-valuemov $0x80000000, %eax # setup the input-value cpuid # then execute CPUIDmov %eax, highin # save theThe 64-bit feature?•AMD uses CPUID input-value 0x80000001 for obtaining their ‘extended features’ bits, returned in the ECX and EDX registers, so Intel processors follow this convention, too.section .dataext_features: .space 8 # for extended features bits.section .textmov $0x80000001, %eax # setup input-value in EAXcpuid # then execute CPUIDmov %edx, ext_features+0 # save feature-bits from EDXmov %ecx, ext_features+4 # save feature-bits from ECXIntel’s extended features bitsR R R R R R R R R R R R R R R R R R R R R R R R R R R R R R RLSF 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0R REM64TR R R R R R R RXDR R R R R R R RSYSCALLR R R R R R R R R R R 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0ECX =EDX =R= Intel ‘reserved’ bitLegend:EM64T = Extended Memory 64-bit Technology (1=yes, 0=no)XD = eXecute Disable paging-bit implemented (1=yes, 0=no)SYSCALL = fast SYSCALL / SYSRET (64-bit mode) (1=yes, 0=no)LSF = LAHF / SAHF implemented in 64-bit mode (1=yes, 0=no)The ‘asm’ construct•When using C/C++ for systems programs, we sometimes need to employ processor-specific instructions (e.g., to access CPU registers or the current stack area)•Because our high-level languages strive for ‘portability’ across different hardware platforms, these languages don’t provide direct access to CPU registers or stackgcc/g++ extensions•The GNU compilers support an extension to the language which allows us to insert assembler code into our instruction-stream•Operands in registers or global variables can directly appear in assembly language, like this (as can immediate operands):int count = 4; // global variableasm(“ mov count , %eax “); asm(“ imul $5, %eax, %ecx “);Local variables•Variables defined as local to a function are more awkward to reference by name with the ‘asm’ construct, because they reside on the stack and require the generation of offsets from the %ebp register-contents•A special syntax is available for handling such situations in a manner that gcc/g++ can decipherTemplate•The general construct-format is as follows:asm( instruction-sequence: output-operand(s): input-operand(s): clobber-list );Example from ‘usecpuid.cpp’{int regEBX, regECX, regEDX; //


View Full Document

USF CS 686 - The x86 Feature Flags

Documents in this Course
Load more
Download The x86 Feature Flags
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The x86 Feature Flags and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The x86 Feature Flags 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?