COS 318 : Operating system
Fall 2002, Princeton University Project 2: Bootup Mechanism |
This project involves writing the bootup code for a simple operating system that we will be developing for the rest of the semester. In this project, the bootup code will be in the so called real mode (instead of protected mode).
A PC can be booted up in two modes: cold boot or warm boot. Cold boot means you power down and power up the machine by pressing the power button of a PC. Warm boot means that you press <ctrl><alt><del> keys together. Either way, the PC will reset the processor and run a piece of code in the BIOS to try to read the first sector from the floppy drive if a diskette is in the drive, otherwise, it will try to read a sector from the hard disk drive. Once this sector is read in, the CPU will jump to the beginning of the loaded code.
Your job in this project is to implement two programs: bootblock.s and createimage.c. The bootblock.s is the boot code that resides on the boot sector and its responsibility is to load the rest of the operating system image from other sectors to the memory. The createimage code is a tool (in this case a Linux tool) to create a bootable operating system image including the bootblock and the rest of the operating system.
The "bootblock" and "createimage" from this assignment will be used throughout the semester.
You should use the code available in /u/cs318/1_pre/ as a starting point for your project. We provide you with five files:
The bootblock gets loaded at 0x07c0:0000. Your bootblock should load the OS starting at 0x0000:1000. In real mode, you have 640 KBytes starting at 0x0000:0000. The low memory area has some system data like the interrupt vectors and BIOS data. So, to avoid overwriting them, you should only use memory above 0x0000:1000 for this assignment.
To design and implement this, you need to learn about x86 architecture, CPU resets and how to read a sector from the floppy drive with BIOS (described below). We have provided you with a trivial and useless kernel (kernel.s) to test whether your implementation works.
Note: You can assume that the entire OS is less or equal to 36 sectors for this project.
Useful information:
man -M /u/cs318/man createimage
Please ignore the "-vm" option for this project.
You should be aware that two adjacent segments in an executable file may not be contiguous when they are loaded into memory, you should pad before each segment. When copying segments from executable files into image file, you should pad after each segment to make sure that its length can be divided by 512 bytes. The length of a segment in executable file may expand when loaded into memory.
You should read:
Submitting Programming Assignments
Submit your final solution electronically using the following command:
/u/cs318/bin/318submit 2 README Makefile bootblock.s createimage.c
The submit command copies your files to the directory /u/cs318/submit/UserLogin/number and lists all the files that you have submitted for assignment number. UserLogin is your user account name. If you execute submit after the project deadline, your files are placed in directory number_late. You can run submit more than once, and you can submit partial lists of files.
Each group needs to submit only one copy. This means that only
one of you needs to submit.
So, the following code sequence writes the character 'K' (ascii 0x4b)
to the top left corner of the screen.
movw 0xb800,%bx
movw %bx,%es
movw $0x074b,%es:(0x0)
This code sequence is very useful for debugging.
Called with:
ah = 2
al = number of sectors to read, 1 to 36
ch = track number, 0 to 79
cl = sector number, 1 to 36
dh = head number, 0 or 1
dl = drive number, 0 to 3
es:bx = pointer where to place information read from diskette
Returns:
ah = return status (0 if successful)
al = number of sectors read
carry = 0 successful, = 1 if error occurred
Called with:
ah = 0x0e
al = character to write
bh = active page number (Use 0x00)
bl = foreground color (graphics mode only) (Use 0x02)
Returns:
character displayed
CS318 Staff