CPUID somehow seems to crash the computer.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
DennisCGc

CPUID somehow seems to crash the computer.

Post 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 ::) )
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:CPUID somehow seems to crash the computer.

Post 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) ...
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:CPUID somehow seems to crash the computer.

Post by bubach »

Just so you'll know, he is using NASM, so the "compiler" won't excpect anything..
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
DennisCGc

Re:CPUID somehow seems to crash the computer.

Post 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.
Post Reply