InputOutput Interface Address bus Data bus Control bus
Input/Output Interface Address bus Data bus Control bus address decoder fffffffc Addr DE I/O Interface Mem 1 . . . Mem n Keyboard Datorteknik IOControl bild 1
How to do I/O By “Polling” waitkey: li $t 1 0 xfffffffc lb $t 0 0($t 1) nop beq $t 0 $r 0 waitkey nop ; Interface address ; Poll Keybard ; no key strike + Very simple and fast - Can’t do any useful work while waiting - Only OK in a single process system, might miss data if other process takes over Datorteknik IOControl bild 2
External Interrupt Let the Interface generate an External Interrupt when data is available + Access I/O Interface only when needed + I/O handling is done by OS (Operating System) – I/O addresses can be “privileged” for SAFETY + Data is never lost (if processor fast enough) - Slower than “Polling” – We will address that problem later Datorteknik IOControl bild 3
Input/Output Interface Address bus Data bus Control bus CTRL[INT 2]=keyboard strike fffffffc Addr DE I/O Interface Keyboard More about: Buffered I/O “Intelligent Devices” etc. later. Datorteknik IOControl bild 4
An External Interrupt Occurs The “context” of the User program must be restored User Program . . . sub $t 1 $t 3 $t 4 add $t 0 $t 1 $t 2. . . Kernel Program mfc 0 $k 0 $14 jr $k 0 rfe Datorteknik IOControl bild 5
Multiple Processes User 1 Instructions Data User 2 User 3 Kernel . text . ktext . data . kdata Datorteknik IOControl bild 6
Time Slicing, Context Switch On Each Timer Interrupt – Store the User program “Context” – Choose next User program (process) Round robin process scheduling – Restore its “Context” – Pass control to User program Datorteknik IOControl bild 7
Process Control Block (PCB) Resume Address (next PC for this process) Global Data pointer ($gp) Stack pointer ($sp) All registers but $k 0, $k 1, $gp, $sp – $k 0, $k 1 might be trashed by the Kernel code – $gp, $sp stored in the PCB Datorteknik IOControl bild 8
Process Control Block PCB for Process p 1 next_pc . text resume addr $gp base for global data area for p 1 . data $sp top of user p 1 stack $pc, $sp, $gp are initiated by the OS at “run” time Datorteknik IOControl bild 9
Where are the 28 registers? PCB p 1 next_pc PCB p 1 Let’s put them on the user program’s stack! $gp $sp $t 0 $t 1 …. . . p 1 stack And adjust the $sp next_pc $gp $sp $t 0 $t 1 …. . . p 1 stack Datorteknik IOControl bild 10
- Slides: 10