Anyone tried to code their own bootloader ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Coldberg
Posts: 8
Joined: Fri Apr 25, 2008 2:03 pm

Anyone tried to code their own bootloader ?

Post by Coldberg »

I see alot of people here just use GRUB , i'm curious though has anyone ever tried to write their own non-trivial bootloader ? I'm currently trying to do so.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Its not uncommon really. There's even a tutorial on it on the wiki (Babystep)
My bootloader can be found on my homepage (see signature)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
octavio
Member
Member
Posts: 94
Joined: Wed Oct 25, 2006 5:12 am
Location: Barcelona España
Contact:

Re: Anyone tried to code their own bootloader ?

Post by octavio »

Coldberg wrote:I see alot of people here just use GRUB , i'm curious though has anyone ever tried to write their own non-trivial bootloader ? I'm currently trying to do so.
I wrote many bootloaders and many other assembly programmers write their own bootloaders too.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post by suthers »

I wrote my own bootloader, but mine was pretty simple, it just enables A20, loads a gdt, reads all the floppy from which it booted and the jumps to it.
Nothing more than i needed for it to work at the begining.
The only reason I wrote though is because I hate using anybodies else's code or binaries and i also felt that long term it would be better because i would have a bit more control.
Jules
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Post by Ready4Dis »

Many write their own bootloaders, many want to just get on with programming their kernel. I chose to write my own, and I use what most would call 'unconventional' tools (like djgpp instead of cygwin and a cross compiler, I use coff rather than elf like most others use, etc). I also wrote my own MBR that allows me to boot different partitions without a bootsector being the wiser (easily allows me to multi-boot windows, dos, my os, linux, and I use the standard partition table format so it's recognized by windows, linux, etc) in the 510 bytes i'm alloted, without a fancy/large graphical boot loader. I have multiple version of my bootloader depending on the device and file system, i currently have them for fat12/16/32 for floppy/hd (including usb drives if the bios supports them properly). I also wrote my own fat formatting utilities, as well as partitioning software. I like writing stuff myself, I use very little pre-made utlities (outside of the compilers, I even wrote my own linker for coff files so I can relocate and link them in my kernel). I haven't written my own compiler or assembler though, I will probably just port those over ;).
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

There was a poll on here a while back -- asking how many people use GRUB vs. writing their own bootloader. It turned out that a slight majority wrote their own. It's mostly pretty easy -- just gathering all the useful info from the BIOS, before the BIOS stops running (when you enter pmode) -- and parsing your supported filesystem to find/load the kernel image. All the while dealing with the limitations of realmode segmentation. :roll:
Then storing all that nice info in temporary tables for your kernel to retrieve.

Just make sure you limit your memory usage to 0x500 - 0x7ffff in realmode. That is the one thing that really doesn't get explained clearly enough.
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

I too have written several bootloaders. My main system's bootloader is fairly complex as it has alot of support to both a) insure the operating system itself is hardware independent, and b) contains all boot-time information and mode to start in. The bootloader contains its own minidrivers that are used to parse and load the kernel from 32bit pmode--without the Bios.

I never used GRUB for portability and security purposes. The kernel itself is hardware independent as it relies on other drivers that were pre-loaded by the bootloader to load its own kernel mode drivers.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Theres "bootprog" as a good example http://alexfru.chat.ru/epm.html#bootprog
But there again, DexOS could be used as a bootloader for other OS's, as it as most of what's in GRUB, but is only 50k insize.
User avatar
edfed
Member
Member
Posts: 42
Joined: Wed Apr 09, 2008 5:44 pm
Location: Mars

Post by edfed »

i currentlly write a new version of my bootloader.

i is able to load a file from sector 2, and restart from an other drive.

i'll put an hidden menu ( press ctrl) to choose the drive.
it fits in only 160 bytes, i have approximatelly 200 others bvytes for the hidden menu. and bug fixes :)
welcome in my dream.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

I have written my own bootloader as well.

yep... that's all i have to say.
zerosum
Member
Member
Posts: 63
Joined: Wed Apr 09, 2008 6:57 pm

Post by zerosum »

I wrote a crap one. Now I use GRUB :-)
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

I have gone the other way - I was using GRUB (with an intermediate stage for enabling VESA video, switching to long mode and it had a debug command line console and could jump straight to a main() function without an assembly stub), but I have now switched to writing my own (in early stages).

My aim is to write a boot loader which offers an OS selection (like GRUB), has the same debug console as my first version and will also supply the kernel with information on installed devices (PCI configuration space and so on....). The aim is to get a lot of this 'run once' stuff out of my kernel.

The main difference between my 'second stage loader' which used GRUB and the new version, is that the original just used v86 for VESA switching, whereas the current version returns to real mode for using BIOS ints (so it can use BIOS int 0x13).

Cheers,
Adam
Coldberg
Posts: 8
Joined: Fri Apr 25, 2008 2:03 pm

Post by Coldberg »

Wow awesome :) anyone ever tried PXE ?
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Post by Ready4Dis »

Coldberg wrote:Wow awesome :) anyone ever tried PXE ?
No, but I have been wanting to try it out, seems like a much simpler way to test, rather then rebooting the dev machine, or copying it to disk all the time ;). Just setup a server on my local network, update my kernel, and reboot the test machine. It's great too, because you can test it out on however many computers you want by just booting them on the network and booting from network :). No need to worry about which computer has a floppy disk, etc.
Coldberg
Posts: 8
Joined: Fri Apr 25, 2008 2:03 pm

Post by Coldberg »

I'm working on implementing a PXE bootloader atm , so far so good , all i really need is a test machine or a netcard with PXE enabled. so far i was only been able to test on VMWare
Post Reply