The Operating System (OS) MicroComputer Engineering OperatingSystem slide 1!
The Operating System (OS) P1:! Editor! P2: Compiler! P3:! Quake! Arena! Operating System! MIPS! At any one time the processor (MIPS) is only excecuting one program (process).! MicroComputer Engineering OperatingSystem slide 2!
The Operating System (OS) P1:! Editor! P2: Compiler! P3:! Quake! Arena! Operating System! MIPS! At any one time the processor (MIPS) is only excecuting one program (process).! MicroComputer Engineering OperatingSystem slide 3!
The Operating System (OS) P1:! Editor! P2: Compiler! P3:! Quake! Arena! Operating System! MIPS! At any one time the processor (MIPS) is only excecuting one program (process).! MicroComputer Engineering OperatingSystem slide 4!
The Operating System (OS) P1:! Editor! P2: Compiler! P3:! Quake! Arena! Operating System! MIPS! At any one time the processor (MIPS) is only excecuting one program (process).! MicroComputer Engineering OperatingSystem slide 5!
The Operating System (OS) P1:! Editor! P2: Compiler! P3:! Quake! Arena! Operating System! MIPS! At any one time the processor (MIPS) is only excecuting one program (process).! MicroComputer Engineering OperatingSystem slide 6!
Our Assembler User!.text!.data! Kernel!.ktext!.kdata! MicroComputer Engineering OperatingSystem slide 7!
The Hardware User!.text!.data! ERROR!! Kernel!.ktext!.kdata! OK! MicroComputer Engineering OperatingSystem slide 8!
How does the User program pass control to the Operating System? Take control on ERROR! Pass control explicitly! MicroComputer Engineering OperatingSystem slide 9!
ERROR Ex, Arithmetical Overflow! li $4 0x80000000 neg $4 $4 (sub $4 $0 $4) 0x00000000-0x80000000 0x80000000 Sign differs! Same Sign! ERROR! MicroComputer Engineering OperatingSystem slide 10!
Signed/Unsigned Arithmetics The only difference is that! Unsigned never causes ERROR! Signed causes ERROR on Overflow etc.! Signed!! ADD! SUB! ADDI!..!! Unsigned!! ADDU! SUBU! ADDIU!..!! MicroComputer Engineering OperatingSystem slide 11!
Memory Error Instruction Memory = Bad PC! Data Alignment Error! Access Protected Memory from User mode! Nonexistent Memory! (Page fault Chapter 7)! MicroComputer Engineering OperatingSystem slide 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, more about that later! MicroComputer Engineering OperatingSystem slide 13!
The Consequence A Memory that tells the pipeline to Wait! Pipeline Stall! A Memory Error or Page Fault! Exception! MicroComputer Engineering OperatingSystem slide 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)! MicroComputer Engineering OperatingSystem slide 15!
How to choose service: Is there different SYSCALLs?! NO! Only one, use a register ($a0) to choose! Use other registers ($a1,...) as parameters! Use $v0 for result ori $a1 $r0 A ; Char A ori $a0 $r0 0x00 ; Write Char syscall ori $a0 $r0 0x01 ; Read Char syscall or $a1 $r0 $v0 ; Move result $v0->$a1 ori $a0 $r0 0x00 ; Echo Char syscall MicroComputer Engineering OperatingSystem slide 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! MicroComputer Engineering OperatingSystem slide 17!
Coprocessor CP0 8 Bad Memory Address! 12 Status Register! 13 Cause Register! 14 Exception Address (EPC)! MicroComputer Engineering OperatingSystem slide 18!
Status Register CP0 ($12) Mode Stack! External Interrupt enable/disable! MicroComputer Engineering OperatingSystem slide 19!
Mode Stack OLD! PREVIOUS! CURRENT! 5! 0! KU IE! KU IE! KU IE! KU!!! IE! 0 Kernel Mode! 1 User Mode!! 0 External Interrupt Disable! 1 External Interrupt Enable! MicroComputer Engineering OperatingSystem slide 20!
Exception / Interrupt Occurs OLD! PREVIOUS! CURRENT! KU IE! KU IE! KU IE! KU IE! KU IE! 0 0! KU!!! IE! 0 Kernel Mode! 1 User Mode!! 0 External Interrupt Disable! 1 External Interrupt Enable! MicroComputer Engineering OperatingSystem slide 21!
RFE Instruction (priviliged) OLD! PREVIOUS! CURRENT! KU IE! KU IE! KU IE!??! KU IE! KU IE! We restore the PREVIOUS (KU,IE) into CURRENT! MicroComputer Engineering OperatingSystem slide 22!
External Interrupts Bit 0, (Current Interrupt Enable)! All External Interrupts Enable/ Disable! Bit 15..10, (individual interrupt enable)! 15! 10! 0! INT 5! INT 4! INT 3! INT 2! INT 1! INT 0! Current! IE!...! MicroComputer Engineering OperatingSystem slide 23!
Enable External Interrupt 2 Bit 0 = 1, (External Interrupt Enabled)! Bit 12 = 1, Interrupt 2 Enabled! 15! 10! 0! INT 5! INT 4! INT 3! INT 2! INT 1! INT 0! 0! 0! 0! 1! 0! 0!...! Current! IE = 1! MicroComputer Engineering OperatingSystem slide 24!
Cause Register (CP0 $13) Bit 5..2, Exception Cause Code! Bit 15..10, Interrupt Pending! Bit 31, Exception Occur In Branch Slot! 31! 15! 10! 5! 2! BS! INT 5! INT 4! INT 3! INT 2! INT 1! INT 0! Ex 3! Ex 2! Ex 1! Ex 0!...!...!...! Pending Interrupts! Exception Cause Code! see LSI Logic User s Manual! MicroComputer Engineering OperatingSystem slide 25!
Check if Interrupt 2 Pending Mask with bit 12! 15! 10! CP0 $13! INT 5! INT 4! INT 3! INT 2! INT 1! INT 0! AND! 0! 0! 0! 1! 0! 0! 0! 0! 0! INT 2! 0! 0! MicroComputer Engineering OperatingSystem slide 26!
Resume User Program! CP0 $14 Holds the Exception Address! (Addr to instruction in EX stage)! mfc0 $k0 $14 ; resume address jr $k0 ; $k0 kernel reg rfe ; delayed branch MicroComputer Engineering OperatingSystem slide 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! User Data! User Data! $sp! Kernel Data! Kernel Data! User Data! User Data! MicroComputer Engineering OperatingSystem slide 28!