Strange Booting Problem

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
User avatar
crbenesch
Posts: 13
Joined: Wed May 28, 2008 9:23 am
Location: Maricopa, AZ USA
Contact:

Strange Booting Problem

Post 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?
~~~~~~~~~~~~~~~~~~~~~
Chris Benesch
CRIBIX
http://www.maricopacomputer.com/cribix/
User avatar
jinksys
Posts: 20
Joined: Tue May 20, 2008 4:52 pm
Location: St Louis, Missouri, USA

Post 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.
User avatar
crbenesch
Posts: 13
Joined: Wed May 28, 2008 9:23 am
Location: Maricopa, AZ USA
Contact:

Post 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.
Attachments
loader.asm
Second stage loader, where the error is more than likely happening
(13.48 KiB) Downloaded 28 times
boot.asm
The bootsector code which loads loader.bin (compiled from loader.asm). I doubt the problem is in here, but just in case.
(8.63 KiB) Downloaded 37 times
~~~~~~~~~~~~~~~~~~~~~
Chris Benesch
CRIBIX
http://www.maricopacomputer.com/cribix/
User avatar
jinksys
Posts: 20
Joined: Tue May 20, 2008 4:52 pm
Location: St Louis, Missouri, USA

Post by jinksys »

Could you post your gdtnasm.inc?
User avatar
crbenesch
Posts: 13
Joined: Wed May 28, 2008 9:23 am
Location: Maricopa, AZ USA
Contact:

Post 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?
Attachments
gdtnasm.asm
The inculde file for easily setting up descriptors. Just rename to gdtnasm.inc
(3.79 KiB) Downloaded 24 times
~~~~~~~~~~~~~~~~~~~~~
Chris Benesch
CRIBIX
http://www.maricopacomputer.com/cribix/
User avatar
Ryu
Posts: 13
Joined: Sun Dec 03, 2006 8:58 am

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