Page 1 of 1

CPUID Question

Posted: Sat Jul 17, 2010 4:07 pm
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!

Re: CPUID Question

Posted: Sun Jul 18, 2010 1:13 am
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?

Re: CPUID Question

Posted: Sun Jul 18, 2010 4:48 am
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: ?????

Re: CPUID Question

Posted: Sun Jul 18, 2010 5:18 am
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

Re: CPUID Question

Posted: Sun Jul 18, 2010 10:21 pm
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!

Re: CPUID Question

Posted: Mon Jul 19, 2010 4:25 am
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.

Re: CPUID Question

Posted: Mon Jul 19, 2010 5:02 am
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