Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

Intrinsic functions

Gary_Little-3Gary_Little-3 Member Posts: 1,208
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

Comments

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 12,914
    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.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,096
    "Gary G. Little" <xxxxx@comcast.net> 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" <xxxxx@comcast.net> 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
    >
    >
    >
    >

    -scott
    OSR

  • Steve_ProchniakSteve_Prochniak Member Posts: 100
    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.
  • Gary_Little-3Gary_Little-3 Member Posts: 1,208
    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
  • mmmm Member - All Emails Posts: 1,409
    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
  • Maxim_S._ShatskihMaxim_S._Shatskih Member Posts: 10,396
    > 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
  • Gary_Little-3Gary_Little-3 Member Posts: 1,208
    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
  • Pavel_APavel_A Member Posts: 2,659
    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
  • Pavel_APavel_A Member Posts: 2,659
    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
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Writing WDF Drivers 25 Feb 2019 OSR Seminar Space
Developing Minifilters 8 April 2019 OSR Seminar Space