Getting Started (double entendre!)
Posted: Thu May 10, 2007 12:19 am
Haha, witty title (I thought so)
er, anyway, I have a lot to say/ask, so I'll divide things up:
Background
I've held back the urge to dive into OS development to let myself just read and absorb information, but now I think I'm ready to start.
I think I'll eventually just use Grub or something as my bootloader, however I've decided that I want to make one just for the understanding.
I've seen countless "Hello, World!" example bootloaders and have written a few small things to test ideas or answer things i wasn't sure about while reading, so I'm quite familiar with how everything works at this point - I used documentation on the keyboard controller to write something to enable A20 (the standard method and also one that supports the method by the HP Vectra chipset).
Some Design
I've chosen EXT2 as my main File System at least for now. I think I have EXT2 documentation burned on the back of my eyes. I created a drive image file, formatted it to EXT2, mounted it, played around, unmounted it. I then opened it up with a Hex Editor and found my way around - so I know that I fully understand how EXT2 works now, or at least enough to read.
I'm not going to worry about partition tables because, supposing I don't end up using Grub to load my kernel, I could use Grub to chainload my bootloader - so the bootloader is meant to be stored in the first 512 bytes of the partition (which, according to some documents I've read, is the main idea, though not necessarily followed).
However, when I look over what I think I need, I'm not sure I can get it to fit in 510 bytes!
So, make a second stage, right? yes, but supposing I want to do a double-stage bootloader, the first stage must...
Now, from what I've been reading, BIOS calls won't necessarily work, right? Some implement the extensions to interrupt 0x13 that allow LBA mode, but usually that implementation is added by MS or IBM code, correct? So I can't rely on the BIOS.
I know how to check if LBA48 is supported, and I know how to read in LBA mode using PIO (both 28-bit and 48-bit).
I know how to navigate the file system, and I know how to copy data to a certain point in memory and run it.
I think I can figure out how to detect which drive, and which partition this bootloader was loaded from, but I can already see that being a good-sized chunk of code (at least when you consider the 510 byte limitation)!
Also, what if the bootloader happens to be on a CD or floppy disk? I haven't really found any clear documentation - can I access these devices using LBA28? Or is that yet another method that needs to be included in this small space?
A lot of bootloader examples say that the "drive number" is stored in DL. They say 0x00=Floppy, and 0x80=Hard Drive, right? But doesn't the BIOS check each drive until it finds a bootable one? What if that drive is the slave drive of the second IDE channel? DL=0x80 still? How do INT 0x13 calls know what you mean when you say 0x80 at this point? What about the CD drive? or a USB drive?
Also, I thought I read somewhere that another register would be set to the partition that was booted from. Is this true? I can't find the document to verify... If it is, what is the value of that register when the drive is not partitioned??
Also, many computers are coming with SATA drives rather than the ATA/133 drives. Is this a transparent change to the programmer? (oh please say yes)
Finally, can someone please point me in the direction of something that explains what is where in memory when the computer boots? I know the IDT is... somewhere, and then there's video memory... somewhere else... basically I need to know where i can load temporary values, and the second stage of my bootloader without messing something else up (also, it seems like the first 640 kbytes of memory are useable - why don't any examples seem to use that??)!
I figured I'd post all these questions and see what other people say before I start, so I don't head down the wrong path.
Thank you for any help!
er, anyway, I have a lot to say/ask, so I'll divide things up:
Background
I've held back the urge to dive into OS development to let myself just read and absorb information, but now I think I'm ready to start.
I think I'll eventually just use Grub or something as my bootloader, however I've decided that I want to make one just for the understanding.
I've seen countless "Hello, World!" example bootloaders and have written a few small things to test ideas or answer things i wasn't sure about while reading, so I'm quite familiar with how everything works at this point - I used documentation on the keyboard controller to write something to enable A20 (the standard method and also one that supports the method by the HP Vectra chipset).
Some Design
I've chosen EXT2 as my main File System at least for now. I think I have EXT2 documentation burned on the back of my eyes. I created a drive image file, formatted it to EXT2, mounted it, played around, unmounted it. I then opened it up with a Hex Editor and found my way around - so I know that I fully understand how EXT2 works now, or at least enough to read.
I'm not going to worry about partition tables because, supposing I don't end up using Grub to load my kernel, I could use Grub to chainload my bootloader - so the bootloader is meant to be stored in the first 512 bytes of the partition (which, according to some documents I've read, is the main idea, though not necessarily followed).
However, when I look over what I think I need, I'm not sure I can get it to fit in 510 bytes!
So, make a second stage, right? yes, but supposing I want to do a double-stage bootloader, the first stage must...
- Figure out what physical drive it is on
Figure out what partition it is on (if the drive is partitioned)
Figure out if LBA48 is supported (worst-case scenario, the second stage is stored near the end of a huge drive! it could happen...)- If not, fall back to LBA28 (should be supported on most modern hardware and virtual machines, right?)
Copy the data for the second stage to some part of memory and jump to it
Now, from what I've been reading, BIOS calls won't necessarily work, right? Some implement the extensions to interrupt 0x13 that allow LBA mode, but usually that implementation is added by MS or IBM code, correct? So I can't rely on the BIOS.
I know how to check if LBA48 is supported, and I know how to read in LBA mode using PIO (both 28-bit and 48-bit).
I know how to navigate the file system, and I know how to copy data to a certain point in memory and run it.
I think I can figure out how to detect which drive, and which partition this bootloader was loaded from, but I can already see that being a good-sized chunk of code (at least when you consider the 510 byte limitation)!
Also, what if the bootloader happens to be on a CD or floppy disk? I haven't really found any clear documentation - can I access these devices using LBA28? Or is that yet another method that needs to be included in this small space?
A lot of bootloader examples say that the "drive number" is stored in DL. They say 0x00=Floppy, and 0x80=Hard Drive, right? But doesn't the BIOS check each drive until it finds a bootable one? What if that drive is the slave drive of the second IDE channel? DL=0x80 still? How do INT 0x13 calls know what you mean when you say 0x80 at this point? What about the CD drive? or a USB drive?
Also, I thought I read somewhere that another register would be set to the partition that was booted from. Is this true? I can't find the document to verify... If it is, what is the value of that register when the drive is not partitioned??
Also, many computers are coming with SATA drives rather than the ATA/133 drives. Is this a transparent change to the programmer? (oh please say yes)
Finally, can someone please point me in the direction of something that explains what is where in memory when the computer boots? I know the IDT is... somewhere, and then there's video memory... somewhere else... basically I need to know where i can load temporary values, and the second stage of my bootloader without messing something else up (also, it seems like the first 640 kbytes of memory are useable - why don't any examples seem to use that??)!
I figured I'd post all these questions and see what other people say before I start, so I don't head down the wrong path.
Thank you for any help!