Page 1 of 1
MS Boot loader
Posted: Wed Jun 22, 2005 11:00 pm
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
Re: MS Boot loader
Posted: Wed Jun 22, 2005 11:00 pm
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!

Re: MS Boot loader
Posted: Thu Jun 23, 2005 11:00 pm
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.