[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
bootup

BOOTLOADERS

[1]. What is a bootloader ?


Bootloader is a program that runs just before an Operating System really starts it work. Infact it is the one that loads the Kernel of the Operating System. When the system is started, program execution begins at 0FFFF0H. This address corresponds to ROM and usually contains a jump instruction to system test code and the ROM bootstrap routine. The ROM bootstrap routine loads the disk bootstrap routine into memory. This disk bootstrap routine is the bootloader that is the focus of our discussion in this article. If you want to understand how an Operating System gets loaded into memory a good place to start is with MS-DOS. MS-DOS Loading Process



[2]. Where does a bootloader reside ?


Now where does ROM bootstrap routine finds the disk bootstrap routine or the bootloader ? Now here there are two cases. Let's take a simple one for better understanding. It is a code fragment located in the first sector of the bootloader which is also known as boot sector. This fragment of code can be atmost 512 bytes. The important thing here is that the last two bytes must be 0xAA55. This is called boot signature without which your floppy would not be considered as bootable by the BIOS. This code is loaded into memory. (Where in Memory ? )



[3]. What if the size of my bootloader is more than 512 bytes ?


Simple. Before ending your code make it load file which contains remaining of the code to continue execution. Well all this would require a more complicated code which will include the code for loading a file into memory and executing it. Remember all this code should fit into a 512 byte block ( including the boot signature ofcourse ).



[2]. How do i copy the compiled file onto the first sector ?


This is a tricky part. You will have to carefully select your assembler. An assembler which is capable of producing flat binaries. Now TASM wont be able to do that. For this purpose you will have to download NASM i.e Netwide Assembler which is available for free. Flat binaries are required because we have just started our pc and at this point of time it is nothing but a useless bulk of chips. It knows nothing. We have to program everything in it.

Now write your bootloader in assembly and then compile it to produce flat binary. Now the problem of copying the binary into the first sector. How would i do that ? Well a good C programmer knows ( i hope ) the way to copy a file to any part of floppy disk. The fact is we all are programmers and being a programmer we all are lazy. I'm too lazy to explain this stuff. Well we have a shorter way out ( jugaad ). Use the tool debug that MS-DOS provides. Say you compiled the file as BootLDR.com so do as following

[font = courier] C:\MYOS>debug BOOTLDR.COM

Now you will enter into a strange zone with a strange looking prompt -
type here

-W 100 0 0 1

and press enter (do i need to say this ?)

-Q
C:\MYOS>

[/font] Whoa ! something happened and the code got copied into the bootsector. Cool isnt it ? Now you can put your floppy into the drive and restart and your bootloader program will run automatically.



Note : Unix users can copy the boot image to the boot sector of the floppy disk using the following command



dd if=boot.bin bs=512 count=1 of=/dev/fd0



[4]. Now Where ?
You have writtern the bootloader. What a hectic job that was ! You now know how is it to work with assembly language. If you are to make a complete 32-bit operting system in assembly alone i'm sure by the time you finish your coding you will have too few ugly hairs hanging down your heads. But there are people who have made their own (almost) complete OS in assembly. I'm also working on an OPerating System project ( Yes ! fully in Assembly ) and i often find myself banging my head on the keyboard and the like. Well if you want the easy way out or if you care your keyboard is not banged upon you can use 32 bit C/C++ compiler. But be Careful. There are number of issues left to explore. Explore it yourself. Believe me it's a lot fun. So Explore and HAPPY CODING !!

You can contact me on - rahulbhamre@hotmail.com

last edited (January 5, 2003) by rahul_d_geek, Number of views: 4335, Current Rev: 1

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.