Not sure how correct my bootloader code is.
Posted: Mon Feb 27, 2012 3:00 pm
I've (partially) written the first stage of a bootloader which, hopefully, will load 32 kiB from either a floppy disk (using CHS) or the bootable partition of a hard disk (using CHS or LBA), then parse that 32 kiB as an ELF executable, and then jump to its entry function. The ELF executable will be my second stage.
The thing is, I'm not entirely sure if my code is correct. The main things I'm concerned about are:
1. The code for parsing the partition table ("dap" is a Data Address Packet, 0x0c is the offset into a partition table entry for the LBA of the partition's first sector).
2. The LBA code
3. The ELF parser. I haven't written this yet, but I only have 192 bytes left in my boot sector to write it with. I might be able to do a super rudimentary ELF parser in 192 bytes; plus, I have some duplicated code that I could probably un-duplicate if I really tried, so I could probably get more space. If I can't write an ELF parser with however much space I can get, then I'll just have to have three stages rather than two.
And if anyone is feeling super generous with their time: Full code (X11 licensed).
I'm aware that the code is not perfect or anything; this is a first draft (I just spent the last 3 or so hours writing it) which needs a lot of cleaning up. Hopefully the comments are helpful and not excessive (and not indicative of my relative lack of experience with assembly). I want to get it working before I try making it pretty.
Thanks.
[edit 1] I've noticed a few comments that say "parse" where they should say "loaded"; it's because I had a function called "loaded" which I renamed "parse" using find-and-replace-all... I forgot it includes comments
[edit 2] Also, just in case anyone is in any way interested in the name ("Schwann") it's a reference to Schwann cells which, among other things, are responsible for the myelin sheath that surrounds neurons in the peripheral nervous system of animals. Since my kernel is called Myelin*, I thought of calling the bootloader Myelinator (the process of myelin production being "myelination"), but that was too long, so I decided to name it Schwann after the cells that perform myelination.
* the rationale behind that name is simpler - I heard the word in biology and I thought it was an auditorily (like aesthetically, but for sounds) pleasing word (maybe because it rhymes with violin).
The thing is, I'm not entirely sure if my code is correct. The main things I'm concerned about are:
1. The code for parsing the partition table ("dap" is a Data Address Packet, 0x0c is the offset into a partition table entry for the LBA of the partition's first sector).
2. The LBA code
3. The ELF parser. I haven't written this yet, but I only have 192 bytes left in my boot sector to write it with. I might be able to do a super rudimentary ELF parser in 192 bytes; plus, I have some duplicated code that I could probably un-duplicate if I really tried, so I could probably get more space. If I can't write an ELF parser with however much space I can get, then I'll just have to have three stages rather than two.
And if anyone is feeling super generous with their time: Full code (X11 licensed).
I'm aware that the code is not perfect or anything; this is a first draft (I just spent the last 3 or so hours writing it) which needs a lot of cleaning up. Hopefully the comments are helpful and not excessive (and not indicative of my relative lack of experience with assembly). I want to get it working before I try making it pretty.
Thanks.
[edit 1] I've noticed a few comments that say "parse" where they should say "loaded"; it's because I had a function called "loaded" which I renamed "parse" using find-and-replace-all... I forgot it includes comments
[edit 2] Also, just in case anyone is in any way interested in the name ("Schwann") it's a reference to Schwann cells which, among other things, are responsible for the myelin sheath that surrounds neurons in the peripheral nervous system of animals. Since my kernel is called Myelin*, I thought of calling the bootloader Myelinator (the process of myelin production being "myelination"), but that was too long, so I decided to name it Schwann after the cells that perform myelination.
* the rationale behind that name is simpler - I heard the word in biology and I thought it was an auditorily (like aesthetically, but for sounds) pleasing word (maybe because it rhymes with violin).