Page 1 of 1

Strange Booting Problem

Posted: Wed May 28, 2008 12:19 pm
by crbenesch
I have a very strange problem with booting. I've been developing thus far using bochs / vmware, but I decided to try it on a real PC. Unfortunately the only one with a working floppy drive is my laptop. I have a two stage bootloader. The first stage loads a file named loader.bin from the floppy using the FAT12 filesystem. That works fine. Then loader.bin, which is in the low memory area (0x500) loads another file KERNEL.BIN which has some RM code at the beginning for switching video modes, and is followed by the ELF file for the kernel written in C. It sets up PMode just fine, jumps into it, relocates the ELF up into high memory (0x100000) then calls it based off of the entry point in the ELF image.

Interrupts are disabled, the stack is way up high (0x90000) and I even do a push dword 2 popfd to clear all the flags before calling the kernel's entry point. I changed the kernel I've been working on for the last 2 weeks to just one that writes 0x1f20 to the screen at 0xb8000 2000 times.

Code: Select all

void _start()
{
   short *vm = (short *)0xb8000;
   int i;

   /* Clear the screen */
   for (i=0; i < 2000; i++) vm[i] = 0x1f20;
   while(1);
}
The above is literally my "kernel" code. Thus far, everything has worked in Bochs and even VMWare, but when I try it on a real PC (or laptop) it actually enters the kernel and fills up most of the screen with blue, hangs, then the PC reboots.

I've tried it on more than one PC by writing a CDROM with a floppy image and an emulator. Exactly the same thing. It must be an interrupt somewhere , but where? What would cause it? Has anyone else experienced this problem?

Posted: Wed May 28, 2008 1:47 pm
by jinksys
I put your kernel code in the place of mine and booted it on a real pc and vmware and both acted normally. They filled the screen with blue and did not reboot.

Seems your bootloader code is suspect. Would be helpful if you posted it.

Posted: Wed May 28, 2008 1:59 pm
by crbenesch
jinksys wrote:I put your kernel code in the place of mine and booted it on a real pc and vmware and both acted normally. They filled the screen with blue and did not reboot.

Seems your bootloader code is suspect. Would be helpful if you posted it.
Certainly, I will attach it as a file. Now keep in mind this code is very much under investigation and as such has bad formatting and is incorrectly documented in places. Basically it starts to load the image file at 0xfe00 by using es:bx as its destination, and the code orignally read the sector then added 0x200 to bx. (you can tell I've spent way to much time on this, I'm thinking in hex), but I changed it to increment es by 0x20 instead and leave bx cleared.

Maybe its a stray hardware interrupt? I dont know at this point.

Posted: Wed May 28, 2008 7:58 pm
by jinksys
Could you post your gdtnasm.inc?

Posted: Wed May 28, 2008 8:35 pm
by crbenesch
jinksys wrote:Could you post your gdtnasm.inc?
Oh, sorry I thought you were just looking at it. I guess you dont see anything obviously wrong either, huh?

Posted: Fri May 30, 2008 6:32 pm
by Ryu
I know this is an indirect way at hacking to your problem, but you should handle exception handlers like general protection faults at the minimum so that problems like this can be debugged. Its a lot easier knowing the error code.