Assignment 5, due Feb. 16

Part of the homework for CS:3620, Spring 2018
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On all assignments, your name must be legible as it appears on your University ID card! Assignments are due at the start of class on the day indicated (usually Friday). Exceptions will be by advance arrangement unless there is what lawyers call "an act of God" (something outside your control). Homework must be turned in on paper, either in class or in the teaching assistant's mailbox. Never push late work under someone's door!

  1. Background: In the discussion of queues in the notes for Feb. 7, Figure 10 shows an implementation of a FIFO queue. The implementation given uses the mod operation to increment the queue's head or tail. The code looks like this in C (with SIZE defined differently from size in the original):
    typedef struct {
            int head, tail, count; /* all initially zero */
            char buffer[SIZE];
    } queue;
    
    void enqueue( queue* q; char ch ) {
            q->count = q->count + 1;
            q->buffer[ q->tail ] = ch;
            q->tail = (q->tail + 1) % SIZE;  /* marked */
    }
    

    a) Rewrite the marked line so it just increments the tail and then checks to see if it incremented too far and resets the tail to zero. (0.5 points)

    b) Suppose SIZE is a power of two. Rewrite the marked line so that it uses the & operator instead of the % (mod) operator. (0.5 points)

  2. Background: Look at the implementation of put() in Figure 9 of the notes for Feb. 7. Now assume that the I/O driver uses echo path 3 from Figure 14 in the same chapter of the notes. This means that the user code and the input interrupt service routine are competing to put characters in the output queue.

    a) Assume the code for put() from Figure 9 is used by the user. Identify the point in this code where the interrupt service routine that echoes input keypresses must not interrupt. Note: The code given does not prevent an interrupt at this point; once you identify this point, you will have identified a critical section in the code. (0.5 points)

    b) Give appropriate code for the user-level version of put that can be used to protect this critical section. (0.5 points)

  3. Background: The code given in the notes assumes just one COM port. Suppose, instead, that you have multiple identical COM ports — identical except that they have different blocks of 8 consecutive device addresses. Only one of these COM1, uses the block from 3F816 to 3FF16. Furthermore, assume that all of them use the same interrupt address. That is, assume that there is a single interrupt service routine shared by all of the COM ports.

    On the operating system side, we'd like to think of an array of COM ports, call it comport[], with legal index values from zero to COMPORTS. conceptually, each COM port in this array is an object.

    a) Describe the (conceptual, since they're likely to be written in C) methods of each COM port that would be called from the interrupt service routine. Your goal here is to put most of the work into these methods. (0.5 points)

    b) Give appropriate code (or object-oriented pseudocode) for the COM interrupt service routine. (0.5 points)