Nachos provides a terminal console device and a single disk device. Nachos devices are accessed through low-level primitives that simply initiate an I/O operation. The operation itself is performed later, with an ``operation complete'' interrupt notifying Nachos when the operation has completed.
The Console class simulates the behavior of a character-oriented CRT device. Data can be written to the device one character at a time through the PutChar() routine. When a character has successfully been transmitted, a ``transmit complete'' interrupt takes place and the user-supplied handler is invoked. The interrupt handler presumably checks if more characters are waiting to be output, invoking PutChar again if appropriate.
Likewise, input characters arrive one-at-a-time. When a new character arrives, the console device generates an interrupt and the user-supplied input interrupt service routine is invoked to retrieve the character from the device and (presumably) place it into a buffer from which higher-level routines (e.g., GetChar()) can retrieve it later.
The Console object supports the following operations:
When a console device is created by the constructor, the appropriate Unix files (or stdin/stdout) are opened and a timer event is scheduled to take place 100 time units in the future. When the timer expires, the routine CheckCharAvail is invoked to see if any data is present. If so, CheckCharAvail reads that character and invokes the user-supplied input interrupt handler readAvail. It then schedules a new timer event so that the process repeats every 100 time units. Thus, CheckCharAvail simply polls every 100 clock ticks for new data, calling the interrupt service routine whenever data is present for processing.
Device output is initiated by calling PutChar, giving it a single character to output. Once character output has been initiated, the device is made busy until the output complete interrupt takes place. PutChar simply outputs the one character, sets an internal flag to indicate that the device is busy, and then schedules a timer interrupt to take place 100 clock ticks later. When the timer expires, the state of the device is changed from busy to idle, and the user-supplied output interrupt complete routine is invoked. This routine would presumably invoke PutChar if additional output characters were queued awaiting output.