Page 2 of 3
Posted: Sun Apr 27, 2008 10:38 am
by AJ
Coldberg wrote:Wow awesome

anyone ever tried PXE ?
It's on the massive todo list

Re: Anyone tried to code their own bootloader ?
Posted: Tue Jul 15, 2008 10:18 am
by indiocolifa
I'm developing FAT12/FAT16/FAT32 code in my assembler bootloader stage 2. My question is how do you load your kernel after setting up a proper environment (A20/PMode/HW detection,etc). My kernel executable will be ELF, so I must write a minimal ELF loader that's it?
Re: Anyone tried to code their own bootloader ?
Posted: Tue Jul 15, 2008 1:03 pm
by AJ
Yes - pretty much. My stage 2 switches between PMode and RMode so that in effect it supports any device which is bootable by the BIOS, without coding separate drivers for PATA/FDD/SATA/ATAPI etc...
Cheers,
Adam
Re: Anyone tried to code their own bootloader ?
Posted: Tue Jul 15, 2008 5:49 pm
by Telgin
I'm in the process of writing one for my OS at the moment, actually.
Probably not the best project to learn x86 assembly on, that's for sure, but I've managed to get by so far. Having experience with MIPS assembly helps a little.
I've probably done plenty wrong in the code, but in 512 bytes I managed to get enough system information to load a second stage boot loader from an image of the filesystem I developed for my OS. I'm currently writing the second stage in real mode assembly as well, with the goal of it being able to load boot-time drivers (which I have certainly not written yet nor would the kernel actualyl look for such a thing for quite some time in the future) as well as the kernel before setting the requested VBE video mode and entering protected (64-bit) mode.
So far all it does is actually start the second stage and read a data table set up by the first stage to get drive geometry and volume information without having to do the BIOS call or file system parsing again.
Also, can I ask why using memory above 0x7FFF is bad? I'm pretty certain that my first stage loaded something starting at 0x8000 without any trouble, and that should be only half of the addressable memory. I'm concerned now though, it sounds like I've done something stupid that I shouldn't have... all of the intricacies of real mode x86 can be a little tiring.
Re: Anyone tried to code their own bootloader ?
Posted: Tue Jul 15, 2008 7:24 pm
by bewing
You may have dropped an 'F' or '0' when you were being told what was bad. 0x8000 is fine. 0x80000 (=512K) is bad -- unless you use INT12h to make sure that you have some available memory between 0x80000 and 0xA0000.
Re: Anyone tried to code their own bootloader ?
Posted: Wed Jul 16, 2008 10:38 am
by indiocolifa
I'm thinking of my "ELF" kernel decision... mmm.. Do I need the kernel to be in an executable format such as ELF? I don't know if there is an advantage of using that at this point, may be it's better to output a flat binary C kernel and load it at the physical address I want (2 MB).
Re: Anyone tried to code their own bootloader ?
Posted: Fri Jul 18, 2008 6:47 pm
by Telgin
bewing wrote:You may have dropped an 'F' or '0' when you were being told what was bad. 0x8000 is fine. 0x80000 (=512K) is bad -- unless you use INT12h to make sure that you have some available memory between 0x80000 and 0xA0000.
That's reassuring. Thought I wasn't crazy.
I'm thinking of my "ELF" kernel decision... mmm.. Do I need the kernel to be in an executable format such as ELF? I don't know if there is an advantage of using that at this point, may be it's better to output a flat binary C kernel and load it at the physical address I want (2 MB).
Unless you need to take advantage of something offered by an executable format such as exporting functions or code relocation. I suppose if you know where the code is going to be in memory and originate it there from the assembler, it should work fine.
Re: Anyone tried to code their own bootloader ?
Posted: Sat Jul 19, 2008 2:01 am
by AJ
Another good reason to use ELF is size on disk - especially if you have a large BSS. Also, where a flat binary has to pad between aligned sections an ELF simply specifies the "memsz" of a given section.
For example, if your code section ends at 0x1001 and your sections are all page aligned, your data section may start at 0x2000. In a flat binary, 0x1002-0x1FFF will be zero-padding. In an elf, you do not have 0x0FFD bytes of superfluous data sitting on disk (which has to be loaded via a slow disk driver, rather than quickly set in memory).
Cheers,
Adam
Re: Anyone tried to code their own bootloader ?
Posted: Sat Jul 19, 2008 2:07 am
by inflater
In the "PortixOS 0.4" days I've used a small bootloader that would set unreal mode, since I couldn't do that in inline assembly of Borland pascal. It could be done using external compilation (TASM etc) and then linkage to the whole kernel, but I've used this method only for loading fonts.

Re: Anyone tried to code their own bootloader ?
Posted: Sun Jul 20, 2008 12:34 pm
by Troy Martin
I'm using one based off of the MikeOS bootloader for my OS (which is based off of MikeOS as well

).
I mainly write my own. The last OS project I did didn't get too far, and I don't have anything but the bootloader anymore.
Re: Anyone tried to code their own bootloader ?
Posted: Tue Jul 22, 2008 12:11 am
by naiksidd_85
I started writing bootloader, but with my knowledge and the requirement it started becoming complex and time consuming.
So i started using GRUB insted.
But yes this on my list once am through with some basic things.
may be the next version.. (as if I am going to publish any

)
Re: Anyone tried to code their own bootloader ?
Posted: Thu Jul 24, 2008 3:47 am
by AndrewAPrice
I want to know what happened to that guy who was writing his boot loader in C. I'd like to see his code (but I think his OS was closed source), and know if he was successful or not.
Re: Anyone tried to code their own bootloader ?
Posted: Thu Jul 24, 2008 1:40 pm
by inflater
Anyways I think a bootloader in C is possible (but not
entirely in C though.) Just create a working C kernel with basic screen and disk I/O functions and voila.

Re: Anyone tried to code their own bootloader ?
Posted: Thu Jul 24, 2008 6:45 pm
by Masterkiller
I'm using my own bootloader since CD structure is a little bit different. It loads only binary files, but I'm currently working on parsing .ini files.
I'm still confused in what to do then. The GRUB finished loading of the image in protected-mode. I suppose it doesn't load any drivers. Then kernel must start the system in protected mode and load the drivers from disk (cd-rom in my case). How could kernel do that without cd-rom driver? So do I must first load the cdrom driver then the kernel or I should write a function for switching back to real-mode and use the BIOS functions.
Re: Anyone tried to code their own bootloader ?
Posted: Fri Jul 25, 2008 12:14 am
by Brendan
Hi,
Masterkiller wrote:The GRUB finished loading of the image in protected-mode. I suppose it doesn't load any drivers. Then kernel must start the system in protected mode and load the drivers from disk (cd-rom in my case). How could kernel do that without cd-rom driver? So do I must first load the cdrom driver then the kernel or I should write a function for switching back to real-mode and use the BIOS functions.
Don't let the terminology used in the GRUB/multi-boot documentation confuse you. GRUB loads a file that it tries to execute (that they call "the kernel") and (optionally) several other files. There's no reason why the initial executable file can't be something like a second stage, and no reason why the other files can't be kernel/s, device drivers and/or a boot image (containing lots of stuff).
Also note that the multi-boot specification clearly states that the boot loader (GRUB) must leave the "boot environment" in a working state, which means you can disable protected mode (return to real mode) and use the BIOS, etc (then enable protected mode again when you actually want protected mode). Basically the multi-boot specification doesn't allow a boot loader (e.g. GRUB) to stuff up things like the BIOS's IVT, data area, extended data area, PIC settings, etc.
Cheers,
Brendan