Write your OWN OPERATING SYSTEM TUTORAL (6)

zhaozj2021-02-08  213

Lesson 6: boot loading

Everything we've done so far has been placed entirely inside the boot sector. We can not make our operating system very big at all if it is to fit in one sector. We need a way of expanding. We will do this by making a boot program that simply loads an executable file off the disk and begins executing it. This is called a boot loader. This file loaded off the disk can be as big as we want, since it will not be constrained to one sector.

This is more difficult than anything else we've done so far. It might be a good idea, now, to locate a reference on the FAT file system (or the file system of your choice, but I will be assuming the use of the Fat System. I Will Give a brief overview of the boot loading process.

A Floppy Disk Contains, In This Order, The Firl We Have Beot Record (The File Allocation Table (Fat), The File Allocation Table (FAT), The Root Directory, And The Data ContaIn The Files On The DiS. hard disk is more complicated. It has a Master Boot Record and multiple partitions.) Suppose we write an operating system, compile / assemble it to a file named lOADER.BIN, and place it on the disk. The boot loader will load it as Follows.

The DOS Boot Record (DBR) is read to determine the size of the DBR, FAT, and Root Directory. The location of each on the disk is then determined. The Root Directory is read in to memory. The Root Directory is searched for the file name lOADER.BIN. If found, we can look in the directory entry to find out which is the file's first cluster (file allocation unit). If not found, we give an error message. The File Allocation Table is read off the disk in to memory. Starting with the file's first cluster, we use the FAT to locate all the clusters belonging to the file. We read them all off the disk into memory at a specific location. We jump to that location to begin execution of the operating system.All of the reading from the disk will be done using calls to BIOS. If you feel adventurous, use a reference of BIOS functions to learn how to read sectors from the disk and try writing your own boot loader. Otherwise, I have provided A Slightly Modified Version of John S. Fine's Fat12 Boots trap loader. If you can find a copy of his utility "partcopy," then use his compiling and installing instructions (and let me know where to find it). Otherwise, copy the boot loader to the floppy disk using the same method we have Used in the previous lessons.

There are many user-adjustable settings in John Fine's bootstrap loader. His loader assumes the use of a FAT12 file system (the system that is used on floppy disks). For another system, you will need to use a different loader. Things you can ....................... ..

By default, the loader loads a file named LOADER.BIN in the root directory (if one exists) into memory starting at address 0x1000: 0000 (This is adjustable by the% define IMAGE_SEG) Thus you can compile / assemble an operating system.. and copy it to the floppy disk as a file named LOADER.BIN.As an example, we will take the Hello, World operating system from Lesson 4 and run it with our boot loader. We can not use the exact same source file from Lesson 4 ., however We need to make a few changes First, we need to take into account that this file will now be loaded into a different location in memory. (0x1000: 0000 instead of 0000: 7C00), and, secondly, we can get Rid of the dos boot record data.

We can start the code by setting up the data and stack segments and the stack pointer. We will do this as shown below. The current code segment is in the CS register, and the static data assembled into the executable is here, so we will .

MOV AX, CS; Get The Current Segment

MOV DS, AX; The Data IS in this segment

CLI; Disable Interrupts While Changing Stack

Mov SS, AX; We'll Use this Segment for the Stack TOO

MOV SP, 0xFFFE; Start The Stack At The Top of The Segment

Sti; Reenable Interrupts

Finally, we can get rid of some lines at the bottom of the source code that adds the boot sector signature and the check to make sure the file is exactly 1 sector long. All of the other code should look familiar. The resulting file can be Downloaded Here: Lesson6.asm.

Assemble this file and copy it to your disk using the folloading commands.nasmw lesson6.asm -o less.bin

Copy Lesson6.bin A: /Loader.bin

Then, assuming you have already installed the boot loader, you can go ahead and boot with the disk. Once you have this working, feel free to modify any other programs you have written in previous lessons, so that you can try loading them with this Boot Loader. Most of The Following Lessons Will Assume That You Will Be Using this Boot Loader (or Other Boot Loader of Your Choice) To load your operation system file (s).

Now We can make our operation system larger Than A Single Seig.

转载请注明原文地址:https://www.9cbs.com/read-3176.html

New Post(0)