13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The device interface 157Sometimes the same register is overloaded to combine various meanings. For example,let’s examine the keyboard on a DEC PDP-11. This device can be used only for input.Two device registers are associated with each keyboard. They appear to be in main storeas far as the kernel is concerned, although the architecture of the PDP-11 actually implementsthe registers in an area distinct from main store. Here are declarations that definethese registers:1 const2 InterruptEnable = [bit 6];3 InputReady = [bit 15];4 type5 KeyboardRegisters =6 record7 Status : bits; { 16 bits long }8 Unused : char; { 8 bits }9 Data : char; { 8 bits }10 end;The only instruction given by the cpu to the keyboard is ‘‘cause an interrupt when thenext character is typed.’’ This instruction is given by setting the InterruptEnable bit in theStatus register (line 7). The keyboard sets the InputReady bit in the same register to indicatethat there is a character that has been typed but has not yet been read by the cpu.The cpu never sends any data to the keyboard. The keyboard transmits data to the cpu byplacing a character in the Data field.The cpu can tell if an operation has completed in two ways. Polling involveschecking periodically all the device registers of busy devices to see if the Ready bit hasbeen set by the device in the Status register. (We called this bit ‘‘InputReady’’ for thekeyboard.) <strong>An</strong> extreme form of polling is busy waiting, in which the cpu executes aloop continually examining a Ready bit and waiting for it to be set by the device.Because polling is time consuming, it is more common to request the device tocause an interrupt instead when the device next becomes ready. As shown in Figure5.4, device drivers in the kernel are typically arranged to respond to such an interrupt,switching to the kernel from any process. The kernel can then perform whatever actionsare appropriate — for example, starting the next transput order to that device. We callthis activity servicing the interrupt. If the interrupt signals the completion of an operationfor which a process has been blocked, the kernel might move that process from itstransput-wait or main-store wait list back to the ready list before switching context backto the interrupted process.More complex devices, like tapes and disks, are not connected directly to the cpu.Instead, they are first connected to a controller, which monitors the device status, appliescontrol to motors, performs data checking, and knows the format of the medium. Figure5.5 shows this situation. The controller accepts orders from the cpu and either accepts orreturns data. The controller communicates with the cpu through its device registers. Asingle controller may manage several devices of the same type. For example, a disk controllercan simultaneously perform a seek on one disk and a transfer on another. (Simultaneoustransfers are not possible.) However, a tape controller cannot manage a diskunit, nor can a disk controller manage a tape unit. Occasionally, controllers, which arecomputers in their own right, encounter program errors due to an unanticipated sequenceof events. Most controllers accept a ‘‘reset’’ order that restores them to a default state.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!