Operating Systems (V22.0202)
Homework 6
Miscellaneous Projects, Demand Paging

Due: Dec 18, 2006

Introduction

This final homework is optional but if you want to improve your grade, you should do this. It is somewhat open ended. You should do as much as you can. But in your write-up, be sure to say what you have implemented, and to say what other features you would have liked to implement (also say how you might implement them).

Generally speaking, you should begin your work starting from your solution to hw5. In particular, we assume that SOS/STM has the ability to do string I/O, supports multiprocessing, and has simple process synchronization. If you like, you can begin with our files stm.h, stm.c, sos.h, sos.c (but note that these lack the synchronization primitives).

In this document, I will first mention several possible projects, of varying degrees of difficulty, essentially independent of each other. Then I will go into detail one particular project, which is to introduce demand paging into SOS.

In this project, you are allowed to work in pairs (you would have to work hard to convince me if you want to work in groups larger than 2. Working alone is also fine.

CVS Tool: In this course, we emphasize two tools used by programmers: the C language and Makefile. Whether you work alone or in pairs, you have the opportunity to learn another important system building tool, "version control systems". These are software that help us manage large software projects that are worked on by many (or even one) programmer. We will like to use the "Concurrent Version System" (CVS) which is freely available on many platforms, including CYGWIN. Such systems allows you to keep track of different versions of a file, and even develop branching versions. Different users can simultaneously modify a file, since the system has a method of reconciling differences (which is quite amazing if you first see this at work).

If you want to use CVS, please see my web page on how to use CVS. Send us your pub_id.dsa file, and you and your partner will be ready to share files in this project.

Possible Projects

A lot of programming tools that are taken for granted in modern computer systems. But our STM/SOS environment is devoid of most of these. What are some tools which we can introduce? You should feel like a pioneer when thinking about these projects, a lot like Ken Thompson facing an idle PDP-7 computer in Bell Labs in 1969.
  1. ENHANCED ASSEMBLER:
    Enhance the assembler (assem.pl) (we recommend to continue using a perl script). The assembler is a critical tool that will be useful for the larger projects (e.g., our next project below). For instance, we would like to allow the assembler language to support
    	LOA R15,=1
    	
    instead of having to explicitly load the constant "1" into a location, and write the address of that location into our instruction for this load instruction. Also, we would like to be able to explicitly enter a literal constant at the current location: e.g.,
    	CON 123
    	CON "Hello"
    	
    should load the CONstant 123, followed by the ASCII codes for "H", "e", "l", "l", "o" into consecutive locations. Similarly, we should be able to reserve a block of memory: e.g.,
    	RES 100
    	
    will REServe the next block of 100 words of memory. The directory for the original assembler is HERE.
  2. RESIDENT SOS:
    Rewrite SOS so that it is an stm program. In short, we want a stm program called "sos.stm". When you start up the stm simulator, it begins by loading sos.stm and begin executing this! Thus, the OS in now resident stm memory, as in any real machines. An enhanced assembler would help us in this task. This project would be quite big if we want to implement multi-processing. But doing a uni-process sos should be relatively easy. This is basically a simple loop.
  3. SIMPLE FILE SYSTEM:
    Implement a simple file system (SFS) that has only one directory, and which supports only ASCII files. You need to implement the basic file functions: open, close, create, delete, read, seek, write. Initially, you may only implement "open, read, close". This would already be useful for our some of our other projects. For instance, SOS can now load stm programs from files into memory to be executed. We rely on other means for creating the actual files.
  4. LIBRARY SYSTEM:
    Unix has over 300 such library routines to carry out many of its basic functions. These routines provide an easy way to extend the functionality of the basic Kernel. We want to duplicate this in SOS.

    Implement the ability of stm programs to call system library routines. The ability of SOS to open/read/close files, as described in the previous project, would be useful, but otherwise, we can simulate this. This requires some primitive loader software. Write some useful library be able to write useful library routines to provide more flexible I/O (the equivalent of scanf and printf).

  5. SIMPLE SHELL (SS):
    We want a simple interface (SS) for interacting with SOS. This interface to sit in a while loop waiting for user commands. This is the beginning of a primitive SHELL (sh/bash/csh/tsh/ksh). In this loop, the SS can accept these commands:
    SOS commands
    Command Arguments Action
    jobs [-q quantum][-d debug_level][-m max] prog1.stm prog2.stm ... similar to arguments for SOS in hw4
    status [no arguments] shows the list of jobs currently running
    halt [no arguments] shuts down the stm hardware
    When we start up the SOS, you call "SOS [initfile]" where initfile is a file that contains various initialization values. This will (load the OS) and call SS.

    What are some parameter values that can go into the initfile? The file [initfile] is optional (or has default values). Run time parameters such as Quantum=5, DebugLevel=0, PageSize=512, UserSpaceStart=16K, etc.

    We should divide the memory into Kernel Space and User Space. UserSpaceStart is the starting address for User Space (so Kernel Space is mem[0] to mem[UserSpaceStart-1]).

  6. DEMAND PAGING:
    See next.

Demand Paging System

We now describe in detail a project for demand paging in SOS. You can design it from scratch, but perhaps the fastest way to do this project is to begin with the following C program, taken from a previous course. It is not working; you can simply try to debug this. HOWEVER, for submission, we want you to split this file into four subfiles: stm.h, stm.c, sos.h, sos.c (similar to previous projects).

We can tell you more about what is wrong: when we want to replace a page with mbit=1 (modify bit is set), there must be write-to-disk, followed by a read-from-disk. It seems that this program forgets to the write-to-disk.

In the following, we try to outline the logic found in the buggy file. To do paging, you need a secondary memory. So, in addition to main memory (mem) we have another array called disk.

DETAILS

The following are some of the main elements that you need to think about.

SUBMITTING YOUR WORK

ADDITIONAL COMMENTS