Assignment 5, due Feb. 20

Part of the homework for 22C:112, Spring 2009
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday). The only exceptions to this rule will be by advance arrangement unless there is what insurance companies call "an act of God" - something outside your control. Homework must be turned in on paper and in class! Late work may be turned in to the teaching assistant's mailbox, but see the late work policy. Never push late work under someone's door!

  1. Background: The Unix read(d,b,c) routine reads from device d into buffer b reading no more than c characters, and returning the count of characters actually read. For interactive devices, it returns if c characters are read, or if the user types a newline character, whichever happens first.

    The C standard library routine fgetc(f) returns one character read from file f. The variable f points to an open file object, where open file objects contain a device descriptor (used to specify a device when calling read(), a buffer, and a buffer pointer. The size of the buffer (call it BUFSIZE is bigger than one because calls to read() are relatively slow due to the overhead of system calls and due to the overhead of working down through the hierarchy of the file system and device interfaces.

    a) Assume you are inside the operating system and have concluded that the user's call to read() involved a character sequential device such as an asynchronous communications line. Propose code for read() in this context, in terms of a low-level operating system internal routine called get(d), where d is some internal device descriptor (an object handle on an operating system device that has already been determined to be character sequential). (0.5 points)

    b) Suggest code for fgetc(). (0.5 points)

  2. Background: Consider the problem of writing a serial I/O driver. Under Unix, the keyboard devices are documented in man 4 tty and man 4 ttyS, and the calls used to control the operating mode of the keyboard device are given in man termios. These calls allow you to control everything from echo mode to baud rate as one flat service. Flat, as in, there is no hierarchy here, either implementation hierarchy or behavioral hierarchy.

    If compatibility with Unix were not an issue, it would make sense to introduce an implementation hierarchy, with a low level serial port device interface that knows nothing about the data in the input or output streams and a suite of higher level device interfaces, each implemented entirely in terms of the lower level, that understands keyboards, the structure text, and various other communications protocols that can be embedded in a serial byte stream.

    a) Go through the things that the termios interfaces allow you to set and identify those that relate to the high level category described above. (0.5 points)

    b) In an ideal object-oriented implementation of the operating-system device interface, the idea of implementing one device class in terms of another is straightforward. Can you propose a way to attach high level devices to low-level devices in a Unix-like system interface? (0.5 points)

  3. Background: Within an interrupt handler, it is essential to disable at least some interrupts until the handler has completed some minimal computation.

    a) At the bare minimum, what interrupt must be disabled by each interrupt handler? (0.5 points)

    b) At what point, at the earliest, is it possible to safely enable the interrupt identified in part a? (0.5 points)