Datorteknik IOControl bild 1 Input/Output Interface Address bus Data bus Control bus fffffffc Addr DE...Mem 1 Keyboard address decoder Mem n address decoder I/O Interface
Datorteknik IOControl bild 2 How to do I/O By “Polling” li $t1 0xfffffffc ;Interface address waitkey:lb $t0 0($t1) ;Poll Keybard nop beq $t0 $r0 waitkey ;no key strike nop + 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 3 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 4 Input/Output Interface Address bus Data bus Control bus CTRL[INT2]=keyboard strike fffffffc Addr DE Keyboard I/O Interface More about: Buffered I/O “Intelligent Devices” etc. later.
Datorteknik IOControl bild 5 An External Interrupt Occurs The “context” of the User program must be restored User ProgramKernel Program mfc0 $k0 $14 jr $k0 rfe... sub $t1 $t3 $t4 add $t0 $t1 $t2...
Datorteknik IOControl bild 6 Multiple Processes User 1KernelUser 2User 3 Instructions Data.text.data.text.data.text.data.ktext.kdata
Datorteknik IOControl bild 7 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 8 Process Control Block (PCB) Resume Address (next PC for this process) Global Data pointer ($gp) Stack pointer ($sp) All registers but $k0, $k1, $gp, $sp –$k0, $k1 might be trashed by the Kernel code –$gp, $sp stored in the PCB
Datorteknik IOControl bild 9 Process Control Block.text.data next_pc $gp $sp resume addr.p1 stack top of user p1 stack base for global data area for p1 $pc,$sp,$gp are initiated by the OS at “run” time PCB for Process p1
Datorteknik IOControl bild 10 Where are the 28 registers?.p1 stack $t0 $t1 ….. Let’s put them on the user program’s stack!.p1 stack $t0 $t1 ….. And adjust the $sp PCB p1 next_pc $gp $sp next_pc $gp $sp