Page 1 of 1

Bootloader doesn't load a kernel bigger than 512 bytes.

Posted: Mon Sep 07, 2015 11:26 am
by Kirdow
Sorry if this is already asked/answered on here or somewhere else. I've searched and couldn't find a good answer so I make this post.

NOTE: I will not use GRUB bootloader or any other premade bootloader. I want to code both the bootloader and the kernel from scratch.

So, I posted a question recently where I had a problem with saving my kernel to the second sector of the first track. now I managed to do that, and my kernel has been working perfectly fine. I'll point out that I have a boot.asm/boot.bin and a kernel.asm/kernel.bin which gets assembled using 'nasm boot.asm -f bin -o boot.bin' and the same for the kernel. at the end of the boot.asm file I have

Code: Select all

times 510-($-$$) db 0
dw 0xAA55
and at the end of the kernel (which is in only 1 sector) I have

Code: Select all

times 512-($-$$) db 0
Now when the kernel grew bigger I wanted to make the kernel have 4096 bytes size instead of 512.
so I changed the end of the kernel to

Code: Select all

times 4096-($-$$) db 0
When I then move the boot.bin and the kernel.bin to the floppy disk I do
partcopy boot.bin 0 200 -f0
partcopy kernel.bin 0 1000 -f0 200
I code the OS on WindowsXP 32-bit using VirtualBox and the floppy disk is a virtual floppy disk that I have inputted to VirtualBox WindowsXP. so when I copied it into the floppy disk I went to my real OS (Windows 10) to check the .img file (the floppy) to see if it was changed (cheaty cheaty :wink: ) and it was.

Now to the part where I run my OS. I followed this stackoverflow tutorial/thread and it all worked during the time where the kernel was 512 bytes. and now when I moved to 4096 bytes, it somehow doesn't work anymore. And it's not that I've forgot to load it all. on the int 13h/ah=02h, there is an 'al' register saying how many sectors should get loaded. I've set it to 8 because 512 (length of 1 sector) * 8 (new value for 'al' register) = 4096 (kernel size). it all loads fine, no problem there. but the problem comes when I jump to the kernel. Nothing happens atall. in the kernel I have a message to print "Welcome to my OS" which ran fine when it was 512 bytes. but now with 4096 bytes, not atall. And I've double checked, the RAM position of the kernel is correct.

I don't know anymore details to point out. If anyone has questions and wanna help me. please do!

Re: Bootloader doesn't load a kernel bigger than 512 bytes.

Posted: Mon Sep 07, 2015 11:40 am
by BASICFreak
mov al, 1 ; read 1 sector
^ That's your issue

V Here is how to use int 13h (function 02h)

http://www.ctyme.com/intr/rb-0607.htm

Re: Bootloader doesn't load a kernel bigger than 512 bytes.

Posted: Mon Sep 07, 2015 11:47 am
by Kirdow
Ok... I solved it. at the point where I get the value for the al register. I call a function to calculate how many sectors I need (function called get_sectors). that sector changes some values, and I forgot to add push and pop to that function, so some of the values for int 13h/ah=02h got changed without me knowing. I added the push and pop to get_sectors and.... now it works....

Like most of the times (most, not all) when I have a problem. I find out the cause of the problem right after I post a forum post. but fun thing is that if I wouldn't post a question about it, I wouldn't figure it out. so this post was actually good anyway :P
^ That's your issue

V Here is how to use int 13h (function 02h)
naah, in this case it wasn't. I had al assigned right before doing int 0x13, and that was made by a function, which I forgot to add push and pop to. which then caused some important registers for int 13h to get changed to other values (see above). no damage done tho luckly and I got it working.

Re: Bootloader doesn't load a kernel bigger than 512 bytes.

Posted: Mon Sep 07, 2015 11:55 am
by BASICFreak
And I didn't read the last two sentences of your post to see you have changed al...

You really should be using a file system of some sort, you will likely regret it soon if you don't.

The stack and ASM... a fun combo to debug...





EDIT: FAT12 (at least on FD) does not allow for reserved sectors (and the disk will fail to read on windows and *nix)

Re: Bootloader doesn't load a kernel bigger than 512 bytes.

Posted: Tue Sep 15, 2015 11:55 am
by bombem
Maybe you should consider using cd instead of floppy.
El torito & iso9660 are pretty basic.
If I remember correctly after sector 0x14 you can put your data/code wherever you like.
and reading is simple (use int 0x13).