Write Your Own Operating System Tutorial(6)

    技术2022-05-11  143

    Lesson 6: Boot Loader

    Everything we’ve done so far has been placed entirely inside the boot sector.  We can’t 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 DOS Boot Record (the first sector we have been working with), the File Allocation Table (FAT), the Root Directory, and then the data contained in the files on the disk.  (A 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 bootstrap 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 adjust are the locations where the operating system and various FAT data structures will be loaded into memory.  You can also adjust the filename (of the operating system) that the loader loads.

    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

    转载请注明原文地址: https://ibbs.8miu.com/read-4920.html

    最新回复(0)