For a long time I was trying to find a basic code which could boot in my virtual machine. Finally I could get my hands on interesting resources which helped me in writing my first kernel. (Mostly copy paste job).
1. 'How to write a simple OS' prvides with a very basic implementation of the booting script (in X86 assembly). Using the NASM assembler and Qemu emulator, we can build a kernel which writes 'Hello World!!!' on the screen. A small step for a programmer, a big one for me.
Next, the same page also provides with a mechanism of write into a floppy and also a CD. You can boot from this CD and print 'Hello World' on the screen. Except for the change that I had to add the following options '-no-emul-boot -boot-load-size 4' for converting it to CD.
However the catch here is that since the compilation is in binary, we cannot call a function from another file. And just changing the output of NASM to aout/elf does not work because the boot loader cannot understand the format (because it expects certain things at certain location in the file which does not happen with elf/aout format).
2. In order to use multi file code, the 'Bare-Bones' kernel is a resource which I succedded in replicating on my VM. This page gives excellent summary of what goes wrong and example code. I could boot this kernel by just copy pasting the code.
Again, the boot loader is written in assembly which is compiled by NASM. However the main difference is that, this assembly code then calls a function which can be written in C in a different file. Linker file is also provided which tells the compiler to prepare the binary with different sections at particular locations in the file.
The required instructions to prepare a GRUB file is also provided which can be written into a floppy and booted using Qemu.
To make a bootable CD, some further work is required as given here.
As an output, I could make a bootable CD which prints 'A' on the screen. :)
Further work:
To write the functions for interrupts and memory management as explained here.
Thursday, January 12, 2012
Subscribe to:
Comments (Atom)