Programming Assignment 1 - Basic Processes

Operating Systems, Spring 2015


Table of Contents

Due Date

This assignment is due on Wednesday, 11 February, no later than 11:50 p.m.. See the turn-in page (last modified on 2015 February 7) for information about turning in your assignment.

Prerequsites

Make sure you have read and understand the simulator (last modified on 2015 March 27) and hardware (last modified on 2015 January 30) documentation before you wade into this assignment. There are links into relevant parts of these documents below, but you need to have an over-all view of both the simulator and the hardware for the parts to make sense.

Introduction

This assignment implements a simple batch-oriented operating system, which behaves as follows:

  1. After the operating system boots up, it reads the first program from the batch disk and executes it as a process.
  2. When there are no more processes executing, the operating system halts the system.
In these assignments, implementing an operating system involves two parts:
  1. Implementing the interrupt handlers. In this first assignment, this means implementing the three interrupts (the disk, reboot, and system-call interrupts) described in the hardware documentation.
  2. Implementing system calls. Your system-call interrupt handler has to implement the exit system call described below.

The Batch Disk

A batch disk is a disk containing a set of programs to be run. Programs occupy consecutive disk blocks starting with disk block 1, the second block on the disk. A program always occupies a positive number of blocks, and each program follows the next with no wasted disk blocks between them. The first word of the first block of every program contains the first word of the program.

The index block - disk block 0, the first block on the disk - contains an index of the programs in the disk. The ith word of the index block contains the size in disk blocks of the ith program in the batch disk. Unused entries in the index block are set to zero. Every batch disk contains an index block.

For example, this diagram

an example batch disk

shows a batch disk containing three programs. The first program has size 3; that is, the first program occupies three disk blocks. The second program has size 1 and the third program has size 2.

Loading Programs for Execution

A program is laid out on disk as a sequence of disk blocks. The order of the program’s contents on disk must be preserved in primary storage when a program is loaded into primary storage for execution. The program’s disk-block contents must not be re-arranged in primary storage, and all the program’s disk blocks must be read into primary storage before the program can be run.

A program is loaded in User Space in order of increasing addresses. The contents of the program’s first disk block is loaded into User Space starting at location i; the contents of the program’s second disk block is loaded into User Space starting at location i + Hardware.Disk.blockSize, and so on. The program’s blocks must all fit in User Space. A program may be loaded anywhere in User Space it can fit.

Once loaded into primary storage, the program’s first instruction has address i, the address of the first word of the program. The program counter should be set to i when the process first executes.

After boot-up initialization, the operating system should load and begin executing the first program on the batch disk; word 0 of the index block contains information on the first program. If the batch disk contains no programs, the operating system should halt.

The Scheduler

For this assignment, you may implement any scheduler you want.

System Calls

Your operating system needs to support one system call: exit. This is the first of many system calls you will be implementing in these assignments, so you might want to give some though to designing an easily changeable system-call implementation (or you have to be willing to throw-away and rewrite your system-call implementation several times, which is probably the better approach to take).

This assignment defines only one system call:
exit system call (OperatingSystem.SystemCall.exit)
The currently executing process is finished. There is no return from this system call.

exit sys call arguments and results

Interrupt Handlers

You will need to implement three interrupt handlers for this assignment:
  1. the reboot interrupt handler: install the operating system at system boot.
  2. the disk interrupt handler: take care of disk interrupts.
  3. the system-call interrupt handler: implement system calls.
The reboot interrupt handler installs your operating system in the hardware; the disk interrupt handler takes care of interrupts from the disk; and the system-call interrupt handles system calls from the executing process. As with system calls, you’ll be implementing and re-implementing several other interrupt handlers in later assignments, so some thought now may save you some pain later.

Test Batch Disks

The directory /export/home/class/mucsos/pa1 contains some batch disks you can use to test your operating system:

Here are examples of successful runs of an operating system on each disk:

$ java -cp arcsim.jar:. main os pa1-empty

The system is halted.
Total execution time:  10 ticks, idle time: 9 ticks (90%).

$ java -cp arcsim.jar:. main os pa1-solo

The system is halted.
Total execution time:  429 ticks, idle time: 99 ticks (23%).

$ 

For this assignment, as long as your operating system runs correctly the numbers produced by your operating system don’t matter. As a sanity check, however, the numbers produced should be within 50% of the numbers shown above.

Here are the same executions with run-times included:

$ time java -cp arcsim.jar:. main os pa1-empty

The system is halted.
Total execution time:  10 ticks, idle time: 9 ticks (90%).

real    0m0.415s
user    0m0.300s
sys     0m0.080s

$ time java -cp arcsim.jar:. main os pa1-solo

The system is halted.
Total execution time:  429 ticks, idle time: 99 ticks (23%).

real    0m0.410s
user    0m0.316s
sys     0m0.076s

$ 

If you’re looking for a way to proceed, you might want to consider the following steps:

  1. Get disk io working so the operating system handles the empty disk (the os must read the disk to discover it’s empty). This requires implementing a disk-interrupt handler as well as code to read the disk. It also requires a simple scheduler to run the idle process.
  2. Modify the scheduler and disk manager to read in a program and execute the associated process; this lets the operating system run the solo disk. You’ll also have to add a system-call interrupt handler and implement the exit system call.

This page last modified on 2015 February 8.