CPUID Question

Programming, for all ages and all languages.
Post Reply
nikito
Member
Member
Posts: 42
Joined: Thu Jul 15, 2010 7:16 pm

CPUID Question

Post by nikito »

Hi!

Code: Select all

mov EAX, 80000008h
cpuid
;AL = 160+ decimal
;AH = 160+ decimal
;Then I invoke again the same command...
mov EAX, 80000008h
cpuid
;AL = 36 decimal
;AH = 48 decimal
;This looks more appropriate result
BTW. Now I call CPUID one time before truly use it and all seems to works.
But I wish to know why this happen.

Thanks!
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: CPUID Question

Post by xenos »

Which type of CPU do you use to run that piece of code? Have you checked that EAX = 0x80000008 is supported by using EAX = 0x80000000 before?
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
nikito
Member
Member
Posts: 42
Joined: Thu Jul 15, 2010 7:16 pm

Re: CPUID Question

Post by nikito »

The CPU supports all the CPUID instructions I have tried, but in the second time, not the first.
I guess it is due a thing that I do not understand at all, an thing called "serializing instructions".
CPUID can be executed at any privilege level to serialize instruction execution. Serializing instruction execution guarantees that any modifications to flags, registers, and memory for previous instructions are completed before the next instruction is fetched and executed.
:roll: ?????
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: CPUID Question

Post by Brendan »

Hi,
nikito wrote:The CPU supports all the CPUID instructions I have tried, but in the second time, not the first.
In that case it's likely to be a problem elsewhere (e.g. in the code you're using to display the values returned by CPUID, rather than in the code to use CPUID or in the CPU itself).
nikito wrote:I guess it is due a thing that I do not understand at all, an thing called "serializing instructions".
CPUID can be executed at any privilege level to serialize instruction execution. Serializing instruction execution guarantees that any modifications to flags, registers, and memory for previous instructions are completed before the next instruction is fetched and executed.
Short answer: This isn't the problem.

Long answer: The CPU pretends that things are done in order (even when they aren't). In most cases it makes no difference (except performance) if the CPU is creating the illusion of "everything in order" or if the CPU is actually doing things in order. In very rare situations (typically involving profiling and/or multi-CPU synchronisation that relies on memory ordering and not something more robust like LOCK) it might matter, and for these (extremely rare) situations there's serialising instructions (and the MFENCE/SFENCE/LFENCE instructions). Simply using CPUID (like you are) isn't one of these extremely rare situations, and doesn't require serialisation. The CPUID instruction is one of the serialising instructions, but this is just coincidence.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
nikito
Member
Member
Posts: 42
Joined: Thu Jul 15, 2010 7:16 pm

Re: CPUID Question

Post by nikito »

Hi Brendan!
Thanks to the raply.

I have not problem with the ways that I'm printing the values. But I had an idea: I touch in a part of the code the EBP register and do not restore it. Can be this an reason to the problem?

Sorry I am new in ASM.(but have much interest in learn it)

Bye!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: CPUID Question

Post by Combuster »

EBP has a special meaning in higher level languages. At the end of a function call, EBP must have the same value as before.
"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 ]
nikito
Member
Member
Posts: 42
Joined: Thu Jul 15, 2010 7:16 pm

Re: CPUID Question

Post by nikito »

Thanks for the valuable info!

BTW. Will let this CPUID curiosity apart because have greater problems right now.
I have just crashed all the system and the hypervisor while trying to enable SSE.
Have set the cr0 & cr4 registers as shown in chapter 13 Intel manual volume 3A, and execute an movq ...... and crashed totally. I'm now reinstalling windows.
](*,)

No matter no matter ..... ¬¬


PD: OK Guys. I really sorry for the senseless thread. There apparently was a problem with the system. Have just now reinstalled all and work fine. I call only one time the CPUID and seems to work fine. Then execute too movq xmm*.... and no blue screens.

Next time if something weird happen, I will considerate an problem in the system.

Thanks to all.

Bye!

Niki
Post Reply