Sunday, June 14, 2009

How to write your Operating System


I was just thinking of sharing my experience of Operating System implementation. So here it is. here i will tell you the steps to implement your Operating System from scratch.

It will be a small kernel implementation. It will boot and you can run small programs on it. This kernel will run on intel x86 machine.


. DJGPP compiler.
. Virtual machine, I will use Bochs.


we will start from a main function. This function will be called when our operating system starts.
In this function you will disable interrupts.
In this function you will initialize the PIC to make first IRQ aligned with int 30 so that it does not mix up with int 1,2 and onwards.

now you are setup. you can check and execute any helloworld programs here.

you are ready to move to the next steps.

Memory Initialization:

When you boot using the grub loader you will be given the start and end address of your kernel.
Now here you have to implement the memory management. first you have to mark all the memory frames as not used. you will use 1 bit per each frame. Allocate byte array equal to:

size = memory /(4096*8)

where 4096 is page size.

This is your frame state array. initialize it with 0 which means all your memory is free. Now mark the frames that fall in your kernel start and end address equal to one to keep record that these frames are already used.

to be continued..

1 comment:

  1. Com'on man complete it, its so interesting