Real PC crash [solved]
Real PC crash [solved]
I have tried different times my os in both Virtual Box and Qemu. But now, if i try to boot it to my computer (a pentium 4 with 512mb of ram) it crasches. It loads grub, i choose to boot my os and then the pc restart. Any suggest??
Last edited by Srowen on Wed Aug 26, 2009 1:21 am, edited 1 time in total.
Re: Real PC crash
Just have your system display information. It will give you some idea of how far it gets before it crashes, and try to narrow it down until you know where it fails at. Its what I do in these situations.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Real PC crash
Something in your PC that's different than an emulated box isn't happy with your code or vice versa, creating a triple fault. To quote Brian Kernighan:
[quote="K, from "Unix for Beginners""]The most effective debugging tool is still careful thought, coupled with judiciously placed print statements.[/quote]
[quote="K, from "Unix for Beginners""]The most effective debugging tool is still careful thought, coupled with judiciously placed print statements.[/quote]
Re: Real PC crash
[/quote]Troy Martin wrote:Something in your PC that's different than an emulated box isn't happy with your code or vice versa, creating a triple fault. To quote Brian Kernighan:
[quote="K, from "Unix for Beginners""]The most effective debugging tool is still careful thought, coupled with judiciously placed print statements.
QFT! Excellent quote.
OP: one of the top reasons that an OS works great in an emulator then fails on real hardware is due to initialized memory (zero'd memory). When some of your code expects an array to be zero'd or something like that, bad things happen.
But like TroyMartin said, lots of printf() statements and/or some keyboard-enabled stepping would help.
Website: https://joscor.com
- gravaera
- Member
- Posts: 737
- Joined: Tue Jun 02, 2009 4:35 pm
- Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.
Re: Real PC crash
As an added bit to the debugging methodology tip: I sometimes also find infinite loops to be helpful.
e.g:
I need to know exactly which point in a function an undefined/unexpected behaviour occurs, etc. I placean infinite loop in a narrow area where I KNOW the error is occurring, and keep recompiling and relocating my infinite loop until I get the exact point of deviation.
Works great when the error you're trying to track is causing a triple fault, and you can't quite manage to read the printed bits before you get a reset.
e.g:
I need to know exactly which point in a function an undefined/unexpected behaviour occurs, etc. I placean infinite loop in a narrow area where I KNOW the error is occurring, and keep recompiling and relocating my infinite loop until I get the exact point of deviation.
Works great when the error you're trying to track is causing a triple fault, and you can't quite manage to read the printed bits before you get a reset.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Real PC crash
Another good idea: make some basic exception handlers for at least exception 0, 6, and 13. 14 as well if you have paging.
Re: Real PC crash
ok i found where my pc reset.. it has some problem when i try to enable paging.. maybe there something wrong here:
any suggestions?
(I've checked the mapping of the kernel and it sould be ok..it crash while i try to enable paging only)
Code: Select all
asm volatile("mov %0, %%eax":: "r"(address));
asm volatile("mov %eax, %cr3");
unit_32b cr0;
asm volatile("mov %cr0, %eax");
asm volatile("mov %%eax, %0": "=r"(cr0));
cr0 |= 0x80000000; // Enable paging!
asm volatile("mov %0, %%eax":: "r"(cr0));
asm volatile("mov %eax, %cr0");
(I've checked the mapping of the kernel and it sould be ok..it crash while i try to enable paging only)
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Real PC crash
The biggest difference (from a non-device standpoint) between a real machine and an emulator is that an emulator zeroes out all memory before running. If the area of memory you are using for paging structures is not part of .bss (which would be cleared by the bootloader, usually), you have to clear it first.
Re: Real PC crash
but the problem is that i've done it.. i'll check this another time..maybe i haven't see something..NickJohnson wrote:The biggest difference (from a non-device standpoint) between a real machine and an emulator is that an emulator zeroes out all memory before running. If the area of memory you are using for paging structures is not part of .bss (which would be cleared by the bootloader, usually), you have to clear it first.
Re: Real PC crash
Erm, you really don't see the problem there? There's some big ones, so let's tear this apart.Srowen wrote:ok i found where my pc reset.. it has some problem when i try to enable paging.. maybe there something wrong here:
any suggestions?Code: Select all
asm volatile("mov %0, %%eax":: "r"(address)); asm volatile("mov %eax, %cr3"); unit_32b cr0; asm volatile("mov %cr0, %eax"); asm volatile("mov %%eax, %0": "=r"(cr0)); cr0 |= 0x80000000; // Enable paging! asm volatile("mov %0, %%eax":: "r"(cr0)); asm volatile("mov %eax, %cr0");
(I've checked the mapping of the kernel and it sould be ok..it crash while i try to enable paging only)
Code: Select all
asm volatile("mov %0, %%eax":: "r"(address));
asm volatile("mov %eax, %cr3");
Code: Select all
asm volatile ( "mov %0, %%cr3" :: "r"(address) : "cr3" );
Code: Select all
unit_32b cr0;
asm volatile("mov %cr0, %eax");
asm volatile("mov %%eax, %0": "=r"(cr0));
cr0 |= 0x80000000; // Enable paging!
asm volatile("mov %0, %%eax":: "r"(cr0));
asm volatile("mov %eax, %cr0");
Code: Select all
uint_32b cr0;
asm volatile ( "mov %%cr0, %0" : "=r"(cr0) );
cr0 |= 0x80000000;
asm volatile ( "mov %0, %%cr0" : /* no outputs */ : "r"(cr0) );
Code: Select all
uint_32b cr0;
asm volatile (
"movl %%cr0, %%eax\n\t"
"orl %%eax, $0x80000000\n\t"
"movl %%eax, %%cr0"
: /* no outputs */ : "a"(cr0) : "memory" );
One caveat to the above code: cr0 isn't listed as an output in any way shape or form, so don't expect to be able to update it and have it contain what you think is the correct value.
Re: Real PC crash
i've tried your code but the gcc give me some error in the ASM line... i correct then and i have this code:
but i crash as before and the virtual box is still running..
Code: Select all
asm volatile( "mov %0, %%cr3" :: "r"(adress));
asm volatile("movl %cr0, %eax\n\t orl $0x80000000, %eax\n\t movl %eax, %cr0");
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Real PC crash
Are you sure the source of the crash is here, exactly? Is it somewhere after enabling paging (say, printing a string to the screen) rather than this function exactly?but i crash as before and the virtual box is still running..
Are you depending on uninitialised memory being zero anywhere? Have you mapped the text framebuffer (0xB8000) in your paging code? Have you mapped the stack in your paging code?
Re: Real PC crash
last test... i've upload the img file of my os and also the binary so if someone wants to try on his pc...
the img file:
http://www.easy-share.com/1907476159/immagine.img
the bin file:
http://www.easy-share.com/1907476161/oxygen.bin
(if you try the img file, you have to choose Oxygen in the grub menu..)
thanks to everyone that help me..
the img file:
http://www.easy-share.com/1907476159/immagine.img
the bin file:
http://www.easy-share.com/1907476161/oxygen.bin
(if you try the img file, you have to choose Oxygen in the grub menu..)
thanks to everyone that help me..
Re: Real PC crash
yes i'm sure.. i've mapped all the memory for the os.. and if i comment only this function the os run, without paging, but run.. and i also think that if i have a problem in mapping some parts of memory i shoud notice it also in the virtual machine..pcmattman wrote:Are you sure the source of the crash is here, exactly? Is it somewhere after enabling paging (say, printing a string to the screen) rather than this function exactly?but i crash as before and the virtual box is still running..
Are you depending on uninitialised memory being zero anywhere? Have you mapped the text framebuffer (0xB8000) in your paging code? Have you mapped the stack in your paging code?
and it isn't a problem in the interrupt because i tried to disable them and it crashes the same.. i'm desperate..
Re: Real PC crash
Hm, the image file runs fine for me in bochs and VPC...
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}