Dear all:
May I ask that
how can kernel mode driver get the CPUID in 64bit plateform (IA64,AMD64) ?
Best Regards
Dear all:
May I ask that
how can kernel mode driver get the CPUID in 64bit plateform (IA64,AMD64) ?
Best Regards
Hi Alan,
This is a late answer, but I haven't seen another one, so I hope this is of
some help.
I'm not sure exactly what you're asking for (nor what you're trying to
achive), but I can answer on the AMD64 "technical" side: The CPUID
instruction is available in user and kernel mode of the processor, so
kernel mode drivers can execute the instruction.
I don't know if there is a generic interface to get the CPUID information
or not, but I suspect there is at least an intrinsic function to get the
CPUID data from a generic AMD64, but I can't find one in the DDK docs from
13th of Aug. 2003 that I'm using for my work. If there isn't a function to
do it, you may have to write a tiny assembler function to read out the
values and store them away and call this from your c/c++ code.
However, there is this function in the OS: ExIsProcessorFeaturePresent,
which seems to do several of the CPUID related functions, and is also safer
to use.
Please note that using CPUID to find features of a processor should be done
in a manner that uses the FEATURES bits, not relying on the CPUID
model/family/revision data, as it's a common cause for concern when new
features are introduced in a competing product, i.e. AMD introducing SSE or
SSE2 and the code checking only for Intel products when deciding to look
for SSE instructions.
A third way, that works for most things is to do a "try/catch" block around
instructions, and then find out which works. Just try from the oldest to
newest technology, setting a variable for each functionality that works.
That is, of course, if you actually want to use this for finding the
features of the processor, if you just want to find which revision of
silicon it is, or something similar, then you need the CPUID
instruction....
Mats
xxxxx@lists.osr.com wrote on 08/23/2004 07:03:00 AM:
Dear all:
May I ask that
how can kernel mode driver get the CPUID in 64bit plateform (IA64,AMD64)
?Best Regards
Questions? First check the Kernel Driver FAQ at http://www.
osronline.com/article.cfm?id=256You are currently subscribed to ntdev as: unknown lmsubst tag argument:
''
To unsubscribe send a blank email to xxxxx@lists.osr.com
ForwardSourceID:NT00001DA6
Dear Mats:
Thank's very much!
-----Original Message-----
From: Mats PETERSSON [mailto:xxxxx@3dlabs.com]
Sent: Tuesday, August 31, 2004 6:32 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] cpuid ?
Hi Alan,
This is a late answer, but I haven't seen another one, so I hope this is of
some help.
I'm not sure exactly what you're asking for (nor what you're trying to
achive), but I can answer on the AMD64 "technical" side: The CPUID
instruction is available in user and kernel mode of the processor, so
kernel mode drivers can execute the instruction.
I don't know if there is a generic interface to get the CPUID information
or not, but I suspect there is at least an intrinsic function to get the
CPUID data from a generic AMD64, but I can't find one in the DDK docs from
13th of Aug. 2003 that I'm using for my work. If there isn't a function to
do it, you may have to write a tiny assembler function to read out the
values and store them away and call this from your c/c++ code.
However, there is this function in the OS: ExIsProcessorFeaturePresent,
which seems to do several of the CPUID related functions, and is also safer
to use.
Please note that using CPUID to find features of a processor should be done
in a manner that uses the FEATURES bits, not relying on the CPUID
model/family/revision data, as it's a common cause for concern when new
features are introduced in a competing product, i.e. AMD introducing SSE or
SSE2 and the code checking only for Intel products when deciding to look
for SSE instructions.
A third way, that works for most things is to do a "try/catch" block around
instructions, and then find out which works. Just try from the oldest to
newest technology, setting a variable for each functionality that works.
That is, of course, if you actually want to use this for finding the
features of the processor, if you just want to find which revision of
silicon it is, or something similar, then you need the CPUID
instruction....
Mats
xxxxx@lists.osr.com wrote on 08/23/2004 07:03:00 AM:
Dear all:
May I ask that
how can kernel mode driver get the CPUID in 64bit plateform (IA64,AMD64)
?Best Regards
Questions? First check the Kernel Driver FAQ at http://www.
osronline.com/article.cfm?id=256You are currently subscribed to ntdev as: unknown lmsubst tag argument:
''
To unsubscribe send a blank email to xxxxx@lists.osr.com
ForwardSourceID:NT00001DA6
Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@xgitech.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
Dear Mats:
you may have to write a tiny assembler function to read out the
values and store them away and call this from your c/c++ code.
A little bit confuse, How can I write the assembly codes in kernel driver ?
Best Regards,
Alan
Hi Alan,
Dear Mats:
> you may have to write a tiny assembler function to read out the
> values and store them away and call this from your c/c++ code.A little bit confuse, How can I write the assembly codes in kernel driver
?
If you create a directory called i386 or AMD64 for instance, then a file
called xxx.asm, and add that to your SOURCES file as I386_SOURCES or
AMD64_SOURCES, it will automatically be assembled into an object file for
the relevant architecture. Of course, AMD64_SOURCES is only built if you
build for AMD64, I386_SOURCES only for I386, etc. \
Of course, for I386, you can write it as inline assembler, just like any
other 32-bit Windows C/C++ code.
Now, the next question will probably be about the calling convention and
how to write the actual code, so here’s a little snipped that may do what
you want…
FILE “cpuid.h”:
struct CPUIDVALS
{
unsigned long a, b, c, d;
};
extern void GetCPUID(unsigned long id, struct CPUIDVALS *vals);
EOF.
FILE “cpuid.asm”:
PUBLIC GetCPUID
.CODE
GetCPUID PROC NEAR
mov r8, rdx ; Save rdx in a register that isn’t used by
the function.
mov r9, rbx ; Save rbx (it’s to be preserved by the
called function if modified, and CPUID instruction sets it).
mov eax, ecx ; Set up for reading the CPUID.
cpuid ; Do it…
mov dword ptr [r8], eax
mov dword ptr [r8+4], ebx
mov dword ptr [r8+8], ecx
mov dword ptr [r8+12], edx
mov rbx, r9
ret
GetCPUID ENDP
Hope this helps.
Note that I haven’t actually tested this code, and it may not work
immediately, but I think you get the idea. If you search in the DDK Help
file for “Calling convention AMD”, you’ll find an index for instance for
“Register usage” which can be helpful for writing assembler code.
Of course, using assembler code in a driver (or any other product) makes it
much less portable, and increases maintenance, so using other methods are
encouraged…
–
Mats
Best Regards,
Alan