|
COS 318 : Operating
system
Fall 2001, Princeton University
Project 2: Bootup Mechanism
|
Important
dates:
Question
& Answer (Design review): week of October 8
Due
: 11:59 PM Tuesday, October 16
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:
-
Makefile: A makefile for you to compile with the right options.
-
bootblock.s: A template for you to write the bootup code.
-
createimage.c: A template for you to write a Linux tool to create
a bootable operating system image on a floppy diskette.
-
createimage.given: An executable Linux tool for you to test your
bootblock.s
code and validate your createimage.c.
-
kernel.s: A minimal kernel to test your bootup code and your tool.
Since our entire project will be using the floppy
drive, please do not read/modify the hard disk.
Detailed requirements/hints for bootblock.s
This file should contain the code that will be written
on the boot sector of the floppy disk. This has to be written in x86 assembly
and shouldn't exceed 512 bytes (1 sector). This code will be responsible
for loading in the rest of the operating system, setting up a stack for
the kernel and then invoking it. You are required to handle kernels of
size up to 36 sectors. You will get extra credit if your bootblock
can handle sizes greater than 36 sectors.
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:
If
you don’t think that’s enough, try:
GNU
Assembler & assembly:
Detailed requirements/hints for createimage.c
This program is a Linux tool to create a bootable
image on a floppy diskette. To make your life a bit easy, we have provided
you with a man page. You can view the man page by typing
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:
-
The man page of createimage, od, and objdump (see
man pages)
-
ELF Documentation (pages 1-1 through 1-7 and 2-1
through 2-6): describe the image format
Design review
For the design review, you need to have figured
out all the details short of the actual implementation. For bootblock.s,
you need to know where it gets loaded, how it loads the OS and what other
things have to be setup before invoking the kernel. For createimage,
you need to know what part of the executable file you need to extract and
put in the "image."
Before you come to the second
precept of that project duration, please have your design review and questions
ready.
Submitting
Programming Assignments
Submit your final solution
to:
yruan@cs.princeton.edu
You should submit README,
Makefile, bootblock.s, and createimage.c.
You may submit more than
once and only the last one will be graded.
Each group needs to submit
only one copy. This means that only one of you needs to submit. But
don't forget your partner's name.
Low-level Details
Display memory
During booting, you can write directly to the screen
by writing to the display RAM which is mapped starting at 0xb800:0000.
Each location on the screen requires two bytes---one to specify the attribute
(Use 0x07) and the second for the character itself. The text screen
is 80x25 characters. So, to write to i-throw
and j-th
column, you write the 2 bytes starting at offset ((i-1)*80+(j-1))*2.
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.
BIOS Int 0x13 Function 2 (From Undocumented PC)
Reads a number of 512 bytes diskette sectors starting
from a specified location. The data read is placed into RAM at the location
specified by ES:BX. The buffer must be sufficiently large to hold the data
AND must not cross a 64K linear address boundary.
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
BIOS Int 0x10 Function 0x0e (From Undocumented PC)
This function sends a character to the display at
the current cursor position on the active display page. As necessary, it
automatically wraps lines, scrolls and interprets some control characters
for specific actions. Note : Linefeed is 0x0a and carriage return is 0x0d.
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