Intrinsic functions

I brought this up a few weeks ago because it looked like I would need to
acquire the CPUID while in the kernel. I dropped it when it looked like that
function was returning to usermode. However, it’s now back in the kernel and
I’ve re-read the original posts.

I find __cpuid() is indeed an intrinsic and is defined in intrin.h. However,
intrin.h is not a header file in any of the current WinDDK include
directories, nor is __cpuid() used by any source files in the DDK. I did
find __readPmc(), __rdTsc, and __getReg(). GetReg looks to be IA64 specific.
I don’t deny that __cpuid is an intrinsic and should therefore simply work
once called. The problem is what header file to include from what path, and
what switches should be set? As a sledge hammer effort I simply moved
anything ending in intrin.h into my build space and watched everything
meltdown into a pile of molten errors.

So, has anyone used cupid in the kernel and if so can you detail how you did
it? I’m not quite ready to go back to my client and say it can’t be done in
the kernel.

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

Gary G. Little wrote:

I brought this up a few weeks ago because it looked like I would need to
acquire the CPUID while in the kernel. I dropped it when it looked like that
function was returning to usermode. However, it’s now back in the kernel and
I’ve re-read the original posts.

I find __cpuid() is indeed an intrinsic and is defined in intrin.h. However,
intrin.h is not a header file in any of the current WinDDK include
directories, nor is __cpuid() used by any source files in the DDK.
So, has anyone used cupid in the kernel and if so can you detail how you did
it? I’m not quite ready to go back to my client and say it can’t be done in
the kernel.

Kernel vs user does not play a role in this. It’s a compiler
intrinsic! The compiler neither knows nor cares how the code will be used.

Put this in one of your own headers:
void __cpuid( int a[4], int b );

Now you can call this wherever you want:
int cpu[4];
__cpuid(x, 0);


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

“Gary G. Little” wrote in message
news:xxxxx@ntdev…
> So, has anyone used cupid in the kernel and if so can you detail how you
> did
> it? I’m not quite ready to go back to my client and say it can’t be done
> in
> the kernel.

I just copied the function prototype into a header file, worked fine.

-scott


Scott Noone
Consulting Associate
OSR Open Systems Resources, Inc.
http://www.osronline.com

“Gary G. Little” wrote in message
news:xxxxx@ntdev…
> I brought this up a few weeks ago because it looked like I would need to
> acquire the CPUID while in the kernel. I dropped it when it looked like
> that
> function was returning to usermode. However, it’s now back in the kernel
> and
> I’ve re-read the original posts.
>
> I find __cpuid() is indeed an intrinsic and is defined in intrin.h.
> However,
> intrin.h is not a header file in any of the current WinDDK include
> directories, nor is__cpuid() used by any source files in the DDK. I did
> find __readPmc(),__rdTsc, and __getReg(). GetReg looks to be IA64
> specific.
> I don’t deny that__cpuid is an intrinsic and should therefore simply work
> once called. The problem is what header file to include from what path,
> and
> what switches should be set? As a sledge hammer effort I simply moved
> anything ending in intrin.h into my build space and watched everything
> meltdown into a pile of molten errors.
>
> So, has anyone used cupid in the kernel and if so can you detail how you
> did
> it? I’m not quite ready to go back to my client and say it can’t be done
> in
> the kernel.
>
> Gary G. Little
> H (952) 223-1349
> C (952) 454-4629
> xxxxx@comcast.net
>
>
>
>

Searching our source tree doesn’t yield any prototype for __cpuid, so I figure something that we #include <> must contain the definition - although searching through the DDK inc doesn’t come up with anything either - so I’m somewhat at a loss.

Scott, Tim

Thanks. That did it. I added the prototype and it worked, though since I use
the /Tp compile switch for C++, I also had to externalize it to “C”.

Thanks again.

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Thursday, September 16, 2010 1:14 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Intrinsic functions

Gary G. Little wrote:

I brought this up a few weeks ago because it looked like I would need
to acquire the CPUID while in the kernel. I dropped it when it looked
like that function was returning to usermode. However, it’s now back
in the kernel and I’ve re-read the original posts.

I find __cpuid() is indeed an intrinsic and is defined in intrin.h.
However, intrin.h is not a header file in any of the current WinDDK
include directories, nor is __cpuid() used by any source files in the DDK.
So, has anyone used cupid in the kernel and if so can you detail how
you did it? I’m not quite ready to go back to my client and say it
can’t be done in the kernel.

Kernel vs user does not play a role in this. It’s a compiler intrinsic!
The compiler neither knows nor cares how the code will be used.

Put this in one of your own headers:
void __cpuid( int a[4], int b );

Now you can call this wherever you want:
int cpu[4];
__cpuid(x, 0);


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I’m not sure if it applies here, but there intrinsic-ish functions that are
more or less part of the compiler but one can still replace. The example
that comes to mind are the functions that are used to implement RTTI. If
one defines them (they start with ‘RT,’ but that’s about all I remember this
far out), they replace the normal ones.

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@oracle.com
Sent: Thursday, September 16, 2010 3:04 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Intrinsic functions

Searching our source tree doesn’t yield any prototype for __cpuid, so I
figure something that we #include <> must contain the definition - although
searching through the DDK inc doesn’t come up with anything either - so I’m
somewhat at a loss.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> once called. The problem is what header file to include from what path, and

what switches should be set?

Maybe it works without any header files?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Like Tim continued to smote into my cranium, it’s a COMPILER intrinsic, but
to include the prototype in a C++ compile you must externalize (extern “C”).
You may or may not need the #pragma intrinsic(__cpuid) I added it just to
be safe.

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@oracle.com
Sent: Thursday, September 16, 2010 2:04 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Intrinsic functions

Searching our source tree doesn’t yield any prototype for __cpuid, so I
figure something that we #include <> must contain the definition - although
searching through the DDK inc doesn’t come up with anything either - so I’m
somewhat at a loss.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

It seems that the compiler now recognizes at least some intrinsics without any declaration.

IIRC, once it was nesessary to provide the prototype of the intrinsic, and declare it with #pragma intrinsic (like __rdtsc is defined in ntddk.h).

– pa

Correction: declaration of __cpuid is not needed *in plain C mode*.
As Mr. Little wrote, __cpuid still requires the prototype in c++ mode.

(the more artificial intelligence we have, the more likely it will get obvious things wrong?)
– pa