Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Crispy

help with a little piece of assembly code

This topic is 5595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I don''t know much Assembly, but I occasionally try to write little stuff (like this) for fun. Here''s a piece I can''t understand. I copied the instructions from here. Mind you, I don''t understand them at all well.
  
;execute CPUID with EAX=0xc0000000
;
;check if EAX=0xc0000000; if not - you are not being fooled, the
;CPU is not IDT
;
;if EAX==0xc0000000 - change bit 14 of FCR2 (MSR#108h) to 0
;
;Execute CPUID 0 and 1 again, this time you will get true Vendor
;info, but family/model/stepping will still be the same as before
;
;and now my part :) :

  mov eax, c0000000h
  cpuid
  cmp eax, c0000000h
  jne elsewhere
  or fcr2, 2000h  ;ok - what is FCR2 - I mean I looked it up, but
                  ;I still don''t know what it really is...
  mov     ?, 0    ;what is the difference between cpuid 0 and
                  ;cpuid 1 - what do I have to set to select
                  ;either of them?
  cpuid
  mov     ?, 1
  cpuid

  ;finally - where is the vendor string stored at this point and how do I 
  ;retrieve it?
  
I''d appreciate if someone helped me finish this piece of code as I''m not very fond of the language and reading books on it doesn''t count as "fun time" for me - bu certain things I see no way around in. Thanks in advance, Crispy

Share this post


Link to post
Share on other sites
Advertisement
That page explains everything you''ll need. FCR2 is a model specific register (0x108); the individual CPUID functions are selected by setting eax to some value; CPUID function 1 returns VendorID in the ebx,edx,ecx regs.

Slapped together code:


mov eax, 0xc0000000
mov esi, eax
xor eax, eax
cpuid
cmp eax, esi
jne .not_idt

; clear fcr2[14]
mov ecx, 0x108 ; fcr2
rdmsr
and eax, ~(1 << 14)
wrmsr

.not_idt:

xor eax, eax
cpuid

; < (ebx,edx,ecx) = VendorID


HTH
Jan

Share this post


Link to post
Share on other sites
A couple of things I don''t understand:

1) my TASM gives me an "Illegal instruction for currently selected processor(s)" error at compile time on rdmsr and wrmsr. It used to give the same error on other things, too, but I provided a P585 instruction (?) somewhere and they went away. What do I have to do to enable these two instructions?

2) what does the last line ( < (ebx,edx,ecx) = VendorID ) mean?

Thanks,
Crispy

Share this post


Link to post
Share on other sites
1) No idea (I use a real assembler ) If nothing else, you can hand-code the opcodes: 0f 32 and 0f 30.
2) that means that the code outputs the 12 char vendor id (stored in the 3 registers ebx,edx,ecx)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!