MS Boot loader

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.
Post Reply
kan
Posts: 19
Joined: Sat Jan 22, 2005 12:00 am
Location: India

MS Boot loader

Post by kan »

hi,
i am trying to load my small C Kernel using DOS bootloader. According to what i know DOS bootloader first tries to load io.sys and starts executing it.
So now if i replace io.sys with my Kernel, eventually i would be loading my kernel at boot time!
so i want to know at what memory location does DOS bootloader load io.sys so that i can give that mem location to gcc at compile time.

gcc -ffreestanding example.c -Ttext MEM_LOCATION -nostdlib -oformat=elf32-i386 -o example
Nothings Impossible :)
User avatar
smiddy
Member
Member
Posts: 127
Joined: Sun Oct 24, 2004 11:00 pm
Location: In my cube, like a good leming. ;-)

Re: MS Boot loader

Post by smiddy »

I think it really depends on your version of DOS. There is PC-DOS from IBM, and MS-DOS from Microsoft. Then there are the variants, DR-DOS, FreeDOS, etcetera. Depending on your variant, and version number will depend on where the IO.SYS (or whatever the OS uses, it may not always be IO.SYS) is loaded for execution. You may have to dissassemble your boot sector in order to make that determination. You should be able to do this with DEBUG fairly easily. In that look for INT 13h and the segment-offset of the initial loading routine. Also, look for either a FAR call to a specific segment-offset or a push of two words onto the stack with a RETF.

I hope this gets you in the ball park...happy coding! :D
-smiddy
rexlunae
Member
Member
Posts: 134
Joined: Sun Oct 24, 2004 11:00 pm
Location: North Dakota, where the buffalo roam

Re: MS Boot loader

Post by rexlunae »

kan wrote:So now if i replace io.sys with my Kernel, eventually i would be loading my kernel at boot time!
...
gcc -ffreestanding example.c -Ttext MEM_LOCATION -nostdlib -oformat=elf32-i386 -o example
No. There are at least 4 big problems with attempting to use DOS's bootloader here.

1. DOS is 16-bit and real mode, so that is how the DOS kernel is loaded. Your kernel is almost certainly 32-bit protected mode.

2. DOS does not use ELF, so your binary is going to be in the wrong format to be loaded by DOS.

3. Because the DOS bootloader is designed to load DOS, the mechanism is not documented and there is no way to be certain that a kernel that you produce will work correctly.

4. Because DOS is not free, if you rely on it to load your kernel, anyone wanting to use your OS will need to purchase a copy of DOS.

I recommend looking into GNU/GRUB as a bootloader. It is designed to boot multiple kernels, and it supports protected mode and ELF format.
Last edited by rexlunae on Thu Jun 23, 2005 11:00 pm, edited 2 times in total.
Post Reply