[ Home ]  



Building a Kernel, by Sohail Qayum Malik<sqm@cyberian.pk>

Last updated :- 01/03/2012

This project has been moved, here


The basic objective of all this exercise is to learn, get some experience. Put together some pieces of code which behave or work like an OS(Kernel)....

I'm working on the code, actually I want a bootstrap code which understands the FAT12 file-system and uses this structure to load the secondry boot programms and then the ELF file loader.
At the moment I'm more interested in developing tools, tools which will help me to copy the bootstrap code in the boot sector and update different constant of the bootstrap code and in between those two boundries do other related stuff....
The tool which I'm at the moment working on is called, maker.exe .

When computer boots it reads the content of the bootsector, in this case its the file bootblok.img. The file bootblok.img knows where in the disk the reserved sectors are, these reserved sectors have the cylinder, sector and head number of each sector which stores the content of the file boot.img. The file bootblok.img reads the file boot.img and then execution begins at file boot.img. The file boot.img has a read only FAT12 driver which can be called as a normal function by giving it the name of the file and far address of the area where to store the read file etc... so this FAT12 driver is a mechanism to load the other parts of the OS in the memory.

The tool maker.exe copies the content of the file bootblok.img in the bootsector. It finds all the sectors of the file boot.img. It finds n number of free contiguous sectors, it marks them as reserved and put the sector numbers in the form of cylinder number, sector number and head number as a three byte entity in the reserved sectors then after this it updates the addresses of these reserved sectors in the file bootblok.img....

The source code of maker.exe
  maker.h  
  maker.c  
  lib.asm  

  Makefile  

After compiling the tool use the option --help to find out about the options available with the maker.exe.


Compiler and Assembler being used....
C compilor is Turbo C for DOS. The assemblers are NASM for DOS and MASM for DOS.

Source Code files of the Bootstrap

  bootblok.asm  
  boot.asm  

  Makefile  

How to build and run the above code....
Compile the files BOOTBLOK.ASM and BOOT.ASM, you'll get the files BOOTBLOK.IMG and BOOT.IMG.
Take a formatted DOS disk, put it in the drive A .
In order to change the partition information of this drive use the tool readmbr.exe with "w" option.
Copy the file BOOT.IMG to disk in the drive A .
Now rerun the tool readmbr.exe this time without the "w" option. The file block.bin will be created.
Use the tool encode.exe to copy the files BOOTBLOK.IMG and block.bin to the disk in drive A .

Source Code files of the tools for my own OS

I've written three tools, they are in C & Assembly....

 readmbr.exe 
  It rewrites the partition information after changing some values of it, like increasing the size of the reserved area, decreasing the number of FAT's to one from two. It also reads the FAT and root directory to find the file BOOT.IMG, if the file is found in the root directory then it gets the sector numbers of the sectors allocated to it and writes them in the CHS format in the file block.bin.

  mbr.h  
  readmbr.c  
  libmbr.asm  

  Makefile  

 encode.exe 
  It writes the file BOOTBLOK.IMG in the bootsector and the contents of the file block.bin in the sector right after the bootsector.

  encode.h  
  encode.c  
  libmbr.asm  

  Makefile  

 read.exe 
  This tool will read the file block.bin get all the sector numbers from it and then tries to read the respective sector from the drive A: and when the sector is read put its contents on the screen. This is actually a verification tool to be certain that the file block.bin is complete and accurate.

  main.h  
  main.c  
  rws.s  

  Makefile  

 Save your MBR 
  



Link/s to the free C compilor/s for DOS

  Borland Turbo C/C++  
  Modern Digital Mars C compilor  

Link/s to the free Assembler/s for DOS

Link/s to D language

  D language  
  Froming an echo request(ping) and processing reply using D language.   
  Froming an address-mask request and processing reply using D language.