Page 1 of 1

CPUID faiilure

Posted: Mon Jan 14, 2013 6:49 am
by TightCoderEx
PROBLEM SOLVED:

Not exactly, but I do know it's CPUID that is causing the problem. Maybe I have to check bit 21 in EFLAGS first to see if instruction is even supported in legacy mode with this processor

Machine: Intel Q6600 Quad core running Ubuntu 12.04 LTS 3.0 gig memory. Emulator qemu

Having just begun programming at this level, meaning BOOT, BIOS and ultimately kernel development, but no stranger to assembly, I haven't yet amassed the resources yet to drill into my code to see what's going on. Hencse this question. I hammered together a small test bed elf64 that is identical to snippet addresses 19H - 36H and the result was exactly as expected. Even this MBR works the way it is supposed to and drops into second stage @ 42H when 19H - 37H are omitted.

I have three drives on my computer and /dev/sda is what I use to emulate real life senarios. Otherwise qemu and as I have to invoke it kvm -hda boot do not have similar behaviours. I've even qualified the emulator with -cpu 486, -cpu kvm64, with no change. Can anyone shed some light on why this snippet does not think I have 64 bits, when a elf64 app in gdb works just fine with the exact same code.

It seems as though this legacy mode and 32 bit code just don't like one another.

Code: Select all

ADDR
--------------------------------------------
 00      FA                cli
 01      31C0              xor ax,ax
 03      8ED0              mov ss,ax
 05      BC007C            mov sp,0x7c00
 08      8ED8              mov ds,ax
 0A      8EC0              mov es,ax
 0C      FB                sti

 0D      B80300            mov ax,0x3
 10      CD10              int 0x10

 12      BEF07C            mov si,0x7cf0
 15      E86000            call word 0x78
 18      56                push si

 19      66B800000080      mov eax,0x80000000
 1F      6650              push eax
 21      0FA2              cpuid
 23      6659              pop ecx
 25      6639C8            cmp eax,ecx
 28      761D              jna 0x47
 2A      B101              mov cl,0x1
 2C      6689C8            mov eax,ecx
 2F      0FA2              cpuid
 31      660FBAE21D        bt edx,0x1d
 36      730F              jnc 0x47

 38      BEE07C            mov si,0x7ce0
 3B      B80042            mov ax,0x4200
 3E      CD13              int 0x13
 40      7205              jc 0x47

 42      EA00000001        jmp word 0x100:0x0

 47      5E                pop si
 48      E82D00            call word 0x78
 4B      31C0              xor ax,ax
 4D      CD16              int 0x16
 4F      CD19              int 0x19
 51
As this is my first post, I've chosen this format as a copy of the source code tabulates pretty strange in any manner I try to massage the text to either eliminate tabs or change to a different indentation methods. Maybe there is a better method of posting snippets.

Re: CPUID faiilure

Posted: Mon Jan 14, 2013 7:02 am
by iansjack
I'm not quite sure that I understand your question, but shouldn't you be using "qemu-system-x86_64" if you want to emulate an x86_64 processor?

Re: CPUID faiilure

Posted: Mon Jan 14, 2013 7:28 am
by TightCoderEx
iansjack wrote:I'm not quite sure that I understand your question
Why does the code 19H - 38H fail, when I have a 64 bit CPU and my test app works when compiled with elf64.
iansjack wrote:but shouldn't you be using "qemu-system-x86_64" if you want to emulate an x86_64 processor?
In my case it wants to call it "kvm" and it seems to work alright. When I copy this code to my test disk dd if=boot of=/dev/sda this code still fails and not only that, but my login text doesn't even show, whereas it does in qemu aka kvm.

Re: CPUID faiilure

Posted: Mon Jan 14, 2013 9:15 am
by iansjack
Why does the code 19H - 38H fail
I'm sorry, but that's not a very meaningful statement. What do you mean by "fail" Do you get an exception; if so what exception? Or does it just not do what you expect it to do? If the latter, what does it not do that you expect it to?

Re: CPUID faiilure

Posted: Mon Jan 14, 2013 10:05 am
by Combuster
Did you have to add the colours and huge fonts? I hope you're not as ignorant of the actual problem as you just proved to be of the forum rules (tip: read them). :shock:

Re: CPUID faiilure

Posted: Mon Jan 14, 2013 10:37 am
by TightCoderEx
I've determined the problem is at 21H, but because I don't have the ability or code devised to see registers I can't determine what an appropriate workaround would be. Excerpt from Software Developers Manual (pg. 804)

On Intel 64 processors, CPUID clears the high 32 bits of the RAX/RBX/RCX/RDX registers in all modes.

It would seem in legacy mode changes other registers too. Thanks for the input, but unless you have a way of telling what the contents of registers are @ 23H, susequent dialoge won't solve the problem.

Re: CPUID faiilure

Posted: Mon Jan 14, 2013 10:51 am
by iansjack
Until you tell us what your problem is, I think you are correct. No point in further dialogue.