You could try a bootloader (like GRUB) and not have to worry about booting from any device.
Faizan wrote:
How does a bootloader (residing on the bootsector of a boot device, such as a floppy disk) locate or find the kernel.bin? In simple words, how does the bootloader passes its control to a file (like loader.bin or kernel.bin) which is actually located on a normal floppy disk?
Can someone please show me the snippet code of any bootloader which locates the kernel.bin and passes control to it?
Thanks and regards,
Faizan
What a bootloader does is read a file from some device (floppy/hard disk etc.) into memory and then pass control over to the memory address where the file is loaded.
You may use a formatted floppy (i.e. one with a file system, btw is that what you mean by 'normal'?) for e.g. a FAT12 formatted floppy or just use a floppy where you directly write your kernel/secondary loader file to specific sectors on the disk (using rawrite, partcopy etc.).
Either way your system BIOS reads the first sector of the disk and loads the contents of the first sector from the disk to memory address 0x7C00 (this can actually be adress 0x07C0:0000 or 0x0000:0x7C00 but thats another story). Your primary stage boot-loader should thus be located on the first sector (this gives you 512 bytes for the primary stage) of the disk.
Now if you use a floppy where you know on which sectors the file is located you just have to read in the correct sectors from disk using the BIOS interrupts (INT 0x13). So all your primary loader should do is be able to read in the other sectors where your kernel or secondary stage loader is located.
If you use a FAT12 floppy things get more fun
(I have a diagram of the layout of a FAT12 floppy somewhere else in this board... let me check....
yeah its here. please refer to it). You have to read in the FAT (File Allocation Table), Root Directory(RD) etc. after calclulating on whcih sectors they are located. You then have to search the RD for the file (whose filename you know) and then locate on which sectors the file is present (which may or may not be contiguous on disk). At this point you know on which sectors your file is present and what you have to do is read those sectors in to some memory location and pass control over to that location.
My own bootloader (2 stage) is available
here. I have an algorithm
here explaining how a bootloader reads a file from a FAT12 floppy. You may find them useful. I've also attached the bootloader here.
If you find writing a bootloader too troublesome just forget it and try something like GRUB to boot your kernel.