Page 1 of 1

CPUID somehow seems to crash the computer.

Posted: Tue May 10, 2005 8:44 am
by DennisCGc
Hi,

After doing some code on my "better" MM design, I now have a problem.
Let me try to explain it:

First, when the loading is done and the protected mode is properly setup, it calls mem_init.
Mem_init is responsible setting the pages up and maps the kernel to 0xC0000000.

Everything went fine until I issued the CPUID command like this after mem_init:

Code: Select all

xor  eax,eax
cpuid
Then somehow the computer crashes. Bochs "restarts" immediatly. Before asking this question immediatly (the problem is already a "few days old") I did some testing.
First I put it before call mem_init. Which surprisingly works then.
So the problem is in the routine itself. So I put there a cpuid command. Putting it after the pages setup (I mean; page directory and page tables) works okay. But when putting it after the setup of 0xC0000000 (e.g.: writing to 0xC00 and setting up some page tables) it crashes. (when doing that I got a 286 JUMP to busy TSS not supported; which is b*llshit IMO, I don't do any jumping or such :-\ ).

So, IMO, there was one logical explanation; kernel overwrite. BUT, 0xC00 and where the pages are created DO NOT overwrite the kernel.

So, my question is (and if you can understand my crappy English), how is this caused ?
Of course, I could put CPUID before mem_init, but that's just "running away from the problems", which I won't do.

And yes, I already used BOCHS debugger, but it does not report anything useful IMO. (it just continues after the command, but the printing routine doesn't seem to end, which is weird).

Hopefully someone can help me with this frustrating problem.

TIA,

DennisCGc.

PS. if you need mem_init somehow, please request it here :). I'm very cautious of putting my source online. (that's just me ::) )

Re:CPUID somehow seems to crash the computer.

Posted: Tue May 10, 2005 10:51 am
by Pype.Clicker
i'd try to have a trace of bochs execution, if i were you. It obviously seems that - for unknown reasons - your bochs is not exactly executing expected instructions...

btw, keep in mind that cpuid trashes virtually all the registers, so if you don't take care, you could also trash registers that the compiler assumes preserved, heading to GreatHavoc(tm) ...

Re:CPUID somehow seems to crash the computer.

Posted: Tue May 10, 2005 11:41 am
by bubach
Just so you'll know, he is using NASM, so the "compiler" won't excpect anything..

Re:CPUID somehow seems to crash the computer.

Posted: Wed May 11, 2005 12:17 am
by DennisCGc
Hi,

I solved it thanks to Pype.

I just did some coding yesterday, and I found that CPUID is not the actual cause for it. Because when I called an "empty" routine it did work.

Code: Select all

nop
nop
nop
ret
But, just for experimenting with it, I put a pushad and pushfd before the actual command.
And of course a popfd and popad. And that worked.

Thanks for the information, I think it's my "write" routine. Have to take a look at it. (Although it's weird IMO).

DennisCGc.