next up previous contents
Next: Disk Device Up: Nachos Machine Previous: Software Managed TLB

Console Device

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:

Console(char *readFile, char *writeFile, VoidFunctionPtr readAvail, VoidFunctionPtr writeDone, int callArg)
The constructor creates an instance of a terminal console. Argument readFile contains the Unix file name of where the data is to be read from; if NULL, standard input is assumed. Likewise, argument writeFile indicates where output written to the console is to go; if NULL, standard output is assumed. When a character becomes available for reading, readAvail is invoked with an argument of callArg to notify the Nachos that a character is available. The character itself is retrieved by calling Console::GetChar(). Upon return, it is assumed that the character has been retrieved and when the next one arrives, readAvail will be called again.

void PutChar(char ch)
Writes character ch to the output device. Once output has started, it is an error to invoke PutChar() again before the corresponding I/O complete interrupt has taken place. Once the console device has written the character to the device, it invokes the user-supplied procedure writeDone , passing it callArg as an argument.

char GetChar()
Retrieves a character from the console. GetChar returns EOF if no new data is available. Normally, the user would not invoke GetChar unless the availability of new data had first been signalled via the readAvail() interrupt service routine.

void CheckCharAvail()
an internal procedure used to see if new data is available for reading.

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.


next up previous contents
Next: Disk Device Up: Nachos Machine Previous: Software Managed TLB

Thomas Narten
Mon Feb 3 15:00:27 EST 1997