Fall 2000

Project 5: I/O in MIPS

Polling and Interrupt Driven

CS61C Dave Patterson



Project Due Date: Your mission is to submit Project 5 on or before 11:59 P.M. Saturday, November 4, 2000.


Project Overview:

This project consists of 3 parts. To get full credit, you will have to fully implement all 3 parts.
 
  1. You are provided with an incorrect version of a character output handler corresponding to C's putchar function; you will fix it.
  2. You will write an interrupt handler for terminal output through SPIM's terminal device.
  3. You will modify your interrupt handler to provide both input AND output.


Project Assignment:

    Complete the following mission objectives.

Mission objective #1: Copy the files
Copy all the files, io.s, print.s, and o.s, from ~/cs61c/proj5 into your project5 directory. Also, since you are trying to access reserved part of memory (so you need to be in kernel mode), in this project always start spim with the command "spim -memio -quiet name_file.s," or "spim -memio -quiet," and then load and run the file.
 

Mission Objective #2: Output with polling
print.s contains an incorrect version of a character output handler corresponding to C's putchar function. The problem is that it fails to check that the terminal is ready to accept a character before it sends the character to the terminal.

Run the program and observe its behavior when attempting to print the given string; then try it with a longer string. Fix the code by inserting, immediately prior to storing into the terminal data register, a short loop that exists only when the terminal "ready bit" is on (this is not difficult, just a few lines of code will do it).
 

Mission Object #3: Interrupt driven output
For the second part of the project you will modify the file o.s. This file contains a function print which places a string into a ring buffer one character at a time, and an interrupt handler. The print function is already created for you. It puts each character into the ring buffer and then ensures that interrupts are enabled for the terminal output device. If the ring buffer is full, it simply waits until the ring buffer has enough space.

Your interrupt handler should complete the process of outputting characters. When an interrupt is received, it should do the following: if a character is waiting to be outputted and the terminal is ready to print out the character, that character should be printed and the ring buffer advanced to the next character. If a character is waiting and the terminal is not ready (a possibility if some other interrupt is received which you don't currently handle), your interrupt handler should simply return. And if there are no character waiting to be outputted, interrupts should be disabled for the character output device, to prevent the output device from sending further interrupts.

Once it is completed, your program should continue to print the sentence on the monitor (stop it with an interrupt signal CTRL+C).

More information on Ringer Buffers and an example interrupt code: Ring Buffers and Example Code
 

Mission Objective #4: Interrupt driven Input/Output
Now that you have a working output routine in o.s, you should copy your code into io.s and proceed to modify it along the following lines. You should change it so that it handles input as well as output. You will need to write a function called getchar which reads characters from a different ring buffer, and waits if the buffer is empty for a character to become available. You should also modify your interrupt handler so that if there is a character waiting on the input and space in the new ring buffer, the character is read in and inserted into the new ring buffer. Otherwise, the character should be discarded.


Submit Project:

To submit your project, use the command submit proj5 in your project directory. The following files are required for successful submission:


Final Remarks:

You are to do this work individually or in pairs with other students (2 students per team).  It is OK to assist your classmates with their projects, but do not copy code or cheat. Last updated: 10/26/00 by Jonathan Tse