Page 1 of 1

Boot Loader Issues

Posted: Thu May 27, 2010 4:09 am
by montrom
Hi, I'm having several issues with my new boot loader code. I am trying to load my kernel from floppy disk, but when I jump to where I loaded it in memory, the CPU triple faults.

Here is the flow of my second stage loader with the relevant code:
  • org 0x2000
  • make stack
  • A20/GDT Stuff
  • Enter Unreal Mode
  • Read Floppy starting at sector 0x90 till n sectors
  • [code] ;disk buffer mov ax, 0x1000 mov es, ax xor bx, bx mov ax, 0x90 ;starting sector, temp, will locate actual sector via code eventually .loop: pusha call linear_to_chs call kread_cylinder popa add ax, 18 pusha xor dx, dx test dx, dx jnz .no_marker .no_marker: popa push ds push es pushad mov cx, 0 mov es, cx mov ds, cx mov edi, 0x100000 sub eax, 18 shl eax, 9 add edi, eax mov esi, 0x10000 mov ecx, (512*18)/4 a32 rep movsd popad pop es pop ds cmp ax, ((0x400*24)/0x200) + 0x91 ; temp calc, will have actual size eventually jl .loop [CODE SNIPPED] [/code]
  • Jump to Protected Mode & Start Kernel
  • [code] cli mov eax, cr0 or al, 1 mov cr0, eax jmp 0x8: _protected ; switch to 32 bits [BITS 32] _protected: mov ax, 0x10 mov ds, ax mov es, ax mov ss, ax mov fs, ax mov gs, ax mov esp, 0x200000 - 16 call 0x100000 ; start kernel [/code]
And, like I said, it fails every time. I have tried this at least 9 different ways and I am completely stumped. Any ideas?

Re: Boot Loader Issues

Posted: Thu May 27, 2010 5:48 am
by Nugget
Hi montrom,

Sounds like your kernel isn't getting loaded properly so there isn't code at 0x100000. I'd single-step your code through the Bochs debugger to make sure that the data you are reading from the floppy is ending up at the correct memory locations.

Another debug approach is to print some characters to the screen to show you exactly where your code is getting to. You can either use the BIOS print routines or just write directly to screen memory at 0xB8000. (See wiki for more details: http://wiki.osdev.org/Printing_to_Screen). Write a little routine that prints the value at a given memory location and use that to check that your kernel is being loaded correctly.

You'll need to determine exactly which line is generating the fault, and you'll need to determine exactly which byte of data is written to each memory location.

Are you sure that the first byte of your kernel is an instruction and not some ELF header?

Use your ingenuity. Don't give up. Good luck!

Re: Boot Loader Issues

Posted: Fri May 28, 2010 4:13 am
by montrom
Hi, Nugget. Thank you for that boost of confidence, I definitely needed that. Thanks again for that. :)

As far as the code is going, it's coming along now, I am finally making progress again. As soon as I read your reply, I went back to my code and began looking at it very critically and from doing that, I discovered two things:

1. My linear_to_chs routine was failing. I fixed that. It works as expected now.
2. Each new read overwrites the last. I verified this by reading the buffer after it was stored and I noticed that I was reading the beginning of the last cylinder I read.

So, indeed, my kernel was not loaded correctly. And, since you asked, I am loading a flat binary file, thank God. :)

Best Regards

P.s. Welcome to the forum. :D

Re: Boot Loader Issues

Posted: Fri May 28, 2010 2:06 pm
by Nugget
Excellent! :D
P.s. Welcome to the forum. :D
Thank you.

Re: Boot Loader Issues

Posted: Tue Jun 08, 2010 12:12 am
by Developer
Hi montrom,

I recommend you do NOT call the actual memory address.
Instead, declare extern keyword in the ASM code on top,
and then call main(); directly.

I hope this helps...

Have a great day...