the Operating System OS Datorteknik Operating System bild
the Operating System (OS) Datorteknik Operating. System bild 1
The Operating System (OS) P 1: Editor P 2: Compiler P 3: Quake Arena Operating System MIPS At any one time the processor (MIPS) is only excecuting one program (process). Datorteknik Operating. System bild 2
The Operating System (OS) P 1: Editor P 2: Compiler P 3: Quake Arena Operating System MIPS At any one time the processor (MIPS) is only excecuting one program (process). Datorteknik Operating. System bild 3
The Operating System (OS) P 1: Editor P 2: Compiler P 3: Quake Arena Operating System MIPS At any one time the processor (MIPS) is only excecuting one program (process). Datorteknik Operating. System bild 4
The Operating System (OS) P 1: Editor P 2: Compiler P 3: Quake Arena Operating System MIPS At any one time the processor (MIPS) is only excecuting one program (process). Datorteknik Operating. System bild 5
The Operating System (OS) P 1: Editor P 2: Compiler P 3: Quake Arena Operating System MIPS At any one time the processor (MIPS) is only excecuting one program (process). Datorteknik Operating. System bild 6
Our Assembler. text . data . ktext . kdata User Kernel Datorteknik Operating. System bild 7
The Hardware. text . data User ERROR! OK . ktext . kdata Kernel Datorteknik Operating. System bild 8
How does the User program pass control to the Operating System? Take control on ERROR Pass control explicitly Datorteknik Operating. System bild 9
ERROR Ex, Arithmetical Overflow li $4 0 x 80000000 neg $4 $4 (sub $4 $0 $4) 0 x 0000 - 0 x 80000000 Sign differs Same Sign ! ERROR Datorteknik Operating. System bild 10
Signed/Unsigned Arithmetics The only difference is that – Unsigned never causes ERROR – Signed causes ERROR on Overflow etc. Signed Unsigned ADD SUB ADDI. . ADDU SUBU ADDIU. . Datorteknik Operating. System bild 11
Memory Error Instruction Memory = Bad PC Data Alignment Error Access Protected Memory from User mode Nonexistent Memory (Page fault Chapter 7) Datorteknik Operating. System bild 12
Do not confuse ! A Memory that tells the pipeline to Wait – relate to “cache miss” A Memory Error or Page Fault – relate to “TLB miss” Datorteknik Operating. System bild 13
The Consequence A Memory that tells the pipeline to Wait – Pipeline Stall A Memory Error or Page Fault – Exception Datorteknik Operating. System bild 14
Pass Control Explicitly The User wants some service from the Operating System – – – File I/O Graphics Sound Allocate Memory Terminate Program (no HALT instruction in real MIPS) SYSCALL (causes an exception) Datorteknik Operating. System bild 15
How to choose service: Is there different SYSCALLs? NO! Only one, use a register ($a 0) to choose Use other registers ($a 1, . . . ) as parameters Use $v 0 for result ori $a 1 $r 0 ‘A’ ; Char ‘A’ ori $a 0 $r 0 0 x 00 ; Write Char syscall ori $a 0 $r 0 0 x 01 ; Read Char syscall or $a 1 $r 0 $v 0 ; Move result $v 0 ->$a 1 ori $a 0 $r 0 0 x 00 ; Echo Char syscall Datorteknik Operating. System bild 16
Other ways for the Operating System to take control? External Interrupts, (not caused by User program) – – – Timers Harddisk Graphics Sound Keyboard, Mouse, other perhipals Datorteknik Operating. System bild 17
Coprocessor CP 0 8 Bad Memory Address 12 Status Register 13 Cause Register 14 Exception Address (EPC) Datorteknik Operating. System bild 18
Status Register CP 0 ($12) “Mode Stack” External Interrupt enable/disable Datorteknik Operating. System bild 19
“Mode Stack” 5 OLD KU PREVIOUS IE KU IE CURRENT 0 KU IE KU 0 Kernel Mode 1 User Mode IE 0 External Interrupt Disable 1 External Interrupt Enable Datorteknik Operating. System bild 20
Exception / Interrupt Occurs OLD PREVIOUS CURRENT KU IE KU IE 0 0 KU 0 Kernel Mode 1 User Mode IE 0 External Interrupt Disable 1 External Interrupt Enable Datorteknik Operating. System bild 21
RFE Instruction (priviliged) OLD KU ? PREVIOUS IE ? CURRENT KU IE We restore the PREVIOUS (KU, IE) into CURRENT Datorteknik Operating. System bild 22
External Interrupts Bit 0, (Current Interrupt Enable) – All External Interrupts Enable/ Disable Bit 15. . 10, (individual interrupt enable) 15 INT 4 INT 3 INT 2 INT 1 10 0 INT 0 Current IE . . . Datorteknik Operating. System bild 23
Enable External Interrupt 2 Bit 0 = 1, (External Interrupt Enabled) Bit 12 = 1, Interrupt 2 Enabled 15 10 INT 5 INT 4 0 0 INT 3 0 0 INT 2 INT 1 INT 0 1 0 0 . . . Current IE = 1 Datorteknik Operating. System bild 24
Cause Register (CP 0 $13) 31 BS Bit 5. . 2, Exception Cause Code Bit 15. . 10, Interrupt Pending Bit 31, Exception Occur In Branch Slot 15 . . 10 INT 5 INT 4 INT 3 INT 2 INT 1 INT 0 Pending Interrupts 5. . Ex 3 2 Ex 1 Ex 0 . . . Exception Cause Code see LSI Logic User’s Manual Datorteknik Operating. System bild 25
Check if Interrupt 2 Pending Mask with bit 12 15 CP 0 $13 AND 10 INT 5 INT 4 0 0 INT 3 INT 2 INT 1 INT 0 0 1 0 0 0 INT 2 0 0 Datorteknik Operating. System bild 26
Resume User Program CP 0 $14 Holds the Exception Address (Addr to instruction in EX stage) mfc 0 $k 0 $14 jr $k 0 rfe ; resume address ; $k 0 kernel reg ; “delayed branch” Datorteknik Operating. System bild 27
Shared “Stack” Assume that the User program uses the stack: Can the Kernel use the same stack ($sp)? Yes, but remember never to use memory below $sp, it will be destroyed (overwritten)!! $sp Kernel Data $sp User Data Datorteknik Operating. System bild 28
- Slides: 28