OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:40 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Wiki: CPUID
PostPosted: Wed Jan 14, 2009 10:51 pm 
Offline
Member
Member

Joined: Wed Feb 27, 2008 12:40 am
Posts: 162
I've added a routine to the article that checks that the CPUID instruction is supported.

I am fairly confident that it is correct, but if someone could take a look and double check, I'd
appreciate it.


Top
 Profile  
 
 Post subject: Re: Wiki: CPUID
PostPosted: Sat Jan 17, 2015 8:21 pm 
Offline

Joined: Mon Mar 31, 2014 8:26 pm
Posts: 7
Hangin10 wrote:
I've added a routine to the article that checks that the CPUID instruction is supported.

I am fairly confident that it is correct, but if someone could take a look and double check, I'd
appreciate it.


I believe this is the code in question:

Code:
; returns 1 if CPUID is supported, 0 otherwise (ZF is also set accordingly)
pushfd ; get
pop eax
mov ecx, eax ; save
xor eax, 0x200000 ; flip
push eax ; set
popfd
pushfd ; and test
pop eax
xor eax, ecx ; mask changed bits
shr eax, 21 ; move bit 21 to bit 0
and eax, 1 ; and mask others
push ecx
popfd ; restore original flags
ret


Forgive my ignorance. How is this called from C?

I don't see much reference to it in the forums or general googling, so I'm guessing that people just assume their CPU is CPUID capable.

Thank you.


Top
 Profile  
 
 Post subject: Re: Wiki: CPUID
PostPosted: Sun Jan 18, 2015 2:28 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Quote:
How is this called from C?
This code follows the i386 system V ABI. That means you just give it a name and declare it as (extern "C") int isCPUIDsupported(); like you would for any function call in a different object file.

Quote:
people just assume their CPU is CPUID capable.
More likely, they're not using it in the first place.

Quote:
ZF is also set accordingly
Considering the last two instructions are POPFD; RET; I call all flags preserved instead. :wink:

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Wiki: CPUID
PostPosted: Sun Jan 18, 2015 4:55 am 
Online
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Combuster wrote:
Quote:
ZF is also set accordingly
Considering the last two instructions are POPFD; RET; I call all flags preserved instead. :wink:

But isn't the POPFD restoring the flags as pushed earlier in the routine (by PUSH ECX), not as originally set?


Top
 Profile  
 
 Post subject: Re: Wiki: CPUID
PostPosted: Sun Jan 18, 2015 4:03 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Find the only assignment to ECX :wink:

Meanwhile, Brendan demonstrated a much shorter version.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group