Page 1 of 1
Where and how to save kernel
Posted: Sun Sep 06, 2015 2:32 pm
by Kirdow
My first "versions" of my OS has the bootloader and kernel on the same sector (first sector). now I tried to assemble with NASM and got something like TIMES negative -5. I know that it means my bootloader is 517 bytes and it has to be 512 bytes. So I thought I check the wiki to see how I can solve it. Somewhere it said that the bootloader should load the kernel into memory from outside the first sector and then run the kernel. But a newbie like me thought of this. How do I save the kernel somewhere else and how do I load it from the bootloader?
I'm using VirtualBox running Windows XP 32-bit. I have a virtual floppy (1.44MB) inserted into VirtualBox and runs my OS by restarting and selecting the floppy in BIOS. I also doesn't have partcopy so I've used the following to write the bootloader to the floppy:
debug boot.bin
-W 100 0 0 1
-Q
Now I wonder. if I want to write the kernel somewhere else on the floppy (aka not on the first sector) and then load it in the bootloader. What do I have to do?
Re: Where and how to save kernel
Posted: Sun Sep 06, 2015 3:50 pm
by madanra
Have a look at
Bootloader. If you want to get on with writing your kernel, and don't care about the bootloader that much, GRUB may well be a good option.
Re: Where and how to save kernel
Posted: Sun Sep 06, 2015 3:59 pm
by SpyderTL
I don't know about debug, but I can help with the boot loader.
The BIOS will automatically load the first block from the floppy drive to system memory at address 7c00. The code that you place in that block is responsible for loading the rest of your operating system. The easiest way is to call interrupt 0x13, and let the BIOS deal with all of the details of the hardware. Before calling the interrupt, set AH to 0x02, and set AL to the number of sectors you need to read. Set CH to the starting track number (starting at 0), CL to the sector number (starting at 1), and DH to the head number (starting at 0). Set DL to the drive number that is passed in to your boot loader by the BIOS in DL. Set ES to the destination memory page, and set BX to the destination address on that page.
So if you wanted to copy the 512 byte block directly after the boot loader block zero to the memory address directly after the boot loader in system memory, use AL = 1, CH = 0, CL = 2, DH = 0, and leave DL set to whatever it was set to when your boot loader started. Set ES = 0, and BX = 0x7e00. This will cause the data in memory to match the first two blocks on the floppy drive exactly.
Let us know how it goes, and if you have any other questions.
Re: Where and how to save kernel
Posted: Sun Sep 06, 2015 11:25 pm
by Kirdow
Yeah, so far I'm good, load the sector I want to load with int 0x13, but that's not the problem, loading with int 0x13, the problem is when I develop it, and want to save it to the floppy. I have a boot.bin and a kernel.bin. then I have a floppy in the A drive. I know how to get the bootloader to the first sector. but how do I get the kernel to save somewhere else? (I would love some "code", not just "save it using this at this").
EDIT: Let me also point out that I want to code my own Bootloader and Kernel at this point. so no GRUB for me.
Re: Where and how to save kernel
Posted: Mon Sep 07, 2015 1:20 am
by Kevin
If you think you have the necessary knowledge to write a bootloader (I doubt it), you should be able to figure out by yourself how to copy the kernel binary to the second sector. There is more than one solution for it, so finding one shouldn't be that hard. If you can't, maybe a bootloader isn't for you yet.
Re: Where and how to save kernel
Posted: Mon Sep 07, 2015 1:29 am
by Techel
If you know how to copy the bootloader to sector 1, you should also know how to copy your next stage to sector 2 and further
Re: Where and how to save kernel
Posted: Mon Sep 07, 2015 3:13 am
by Kirdow
I acually found it out myself, searched on google and actually found one I didn't find yesterday. So. something with windows 32-bit debug command can only read/write to first sector for some reason. atleast what I tried. And the partcopy link on the wiki was broken so I thought there were no more. But now I tried searching again and finally found a working copy of partcopy. and partcopy was so much easier. So blame debug command for being crappy
. So, I finally got it working. Thanks for giving time to help
Re: Where and how to save kernel
Posted: Mon Sep 07, 2015 5:42 pm
by azblue
You can run a "real" OS in Virtual Box, compile your code in Virtual Box, and then save it to your floppy as if it were a normal disk.
Then you install your bootsector, which, if it can read FAT12, can then load your kernel.
Or you can write custom code that copies your bootsector, formats the disk, and loads your kernel and other files (that's what I did).
Or you can copy your kernel at some "hard-coded" location; it's easy, but lazy, and if you want to write your own bootloader you'll want to properly read a file system (something you'll need to do eventually anyway).