Download presentation
Presentation is loading. Please wait.
Published byIsis Odell Modified over 10 years ago
1
Datorteknik OperatingSystem bild 1 the Operating System (OS)
2
Datorteknik OperatingSystem bild 2 The Operating System (OS) Operating System P1: Editor P2: Compiler P3: Quake Arena MIPS At any one time the processor (MIPS) is only excecuting one program (process).
3
Datorteknik OperatingSystem bild 3 Our Assembler.data.kdata.text.ktext User Kernel
4
Datorteknik OperatingSystem bild 4 The Hardware.data.kdata.text.ktext User Kernel OK ERROR!
5
Datorteknik OperatingSystem bild 5 How does the User program pass control to the Operating System? Take control on ERROR Pass control explicitly
6
Datorteknik OperatingSystem bild 6 ERROR Ex, Arithmetical Overflow li $4 0x80000000 neg $4 $4 (sub $4 $0 $4) 0x00000000 - 0x80000000 0x80000000 Sign differs Same Sign ! ERROR
7
Datorteknik OperatingSystem bild 7 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..
8
Datorteknik OperatingSystem bild 8 Memory Error Instruction Memory = Bad PC Data Alignment Error Access Protected Memory from User mode Nonexistent Memory (Page fault Chapter 7)
9
Datorteknik OperatingSystem bild 9 Do not confuse ! A Memory that tells the pipeline to Wait –relate to “cache miss” A Memory Error or Page Fault –realte to “TLB miss”
10
Datorteknik OperatingSystem bild 10 The Consequence A Memory that tells the pipeline to Wait –Pipeline Stall A Memory Error or Page Fault –Exception
11
Datorteknik OperatingSystem bild 11 Pass control excplicitly 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 (casuses an exception)
12
Datorteknik OperatingSystem bild 12 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
13
Datorteknik OperatingSystem bild 13 Other ways for the Operating System to take control? External Interrupts, (not caused by User program) –Timers –Harddisk –Graphics –Sound –Keyboard, Mouse, other perhipals
14
Datorteknik OperatingSystem bild 14 Coprocessor CP0 8 Bad Memory Address 12 Status Register 13 Cause Register 14 Exception Address
15
Datorteknik OperatingSystem bild 15 Status Register CP0 ($12) “Mode Stack” External Interrupt enable/disable
16
Datorteknik OperatingSystem bild 16 “Mode Stack” OLDPREVIOUSCURRENT KU IE 0 Kernel Mode 1 User Mode 0 External Interrupt Disable 1 External Interrupt Enable KU IE KU IE 5 0
17
Datorteknik OperatingSystem bild 17 Exception / Interrupt Occurs OLDPREVIOUSCURRENT KU IE 0 0 Kernel Mode 1 User Mode 0 External Interrupt Disable 1 External Interrupt Enable KU IE
18
Datorteknik OperatingSystem bild 18 RFE Instruction (priviliged) OLDPREVIOUSCURRENT KU IE ? We restore the PREVIOUS (KU,IE) into CURRENT
19
Datorteknik OperatingSystem bild 19 External Interrupts Bit 0, (Current Interrupt Enable) –All External Interrupts Enable/ Disable Bit 15..10, (individual interrupt enable) INT 4INT 3INT 2INT 1INT 0 Current IE............ INT 5 15100
20
Datorteknik OperatingSystem bild 20 Enable External Interrupt 2 Bit 0 = 1, (External Interrupt Enabled) Bit 12 = 1, Interrupt 2 Enabled Current IE = 1............ 15100 INT 4INT 3INT 2INT 1INT 0INT 5 000001
21
Datorteknik OperatingSystem bild 21 Cause Register (CP0 $13) Bit 5..2, Exception Cause Code Bit 15..10, Interrupt Pending Bit 31, Exception Occur In Branch Slot 10 INT 5INT 4INT 3INT 2INT 1Ex 3Ex 2Ex 1Ex 0BS 523115 INT 0....... Exception Cause Code see Table 4.3 LSI Logic Pending Interrupts
22
Datorteknik OperatingSystem bild 22 Check if Interrupt 2 Pending Mask with bit 12 1510 INT 4INT 3INT 2INT 1INT 0INT 5 AND 00000 CP0 $13 000001 INT 2
23
Datorteknik OperatingSystem bild 23 Resume User Program CP0 $14 Holds the Exception Address (Addr to instruction in EX stage) mfc0$k0 $14; resume address jr$k0; $k0 kernal reg rfe ; “delayed branch”
24
Datorteknik OperatingSystem bild 24 Shared “Stack” Assume that the User program uses the stack: Can the Kernal use the same stack ($sp)? Yes, but remember never to use memory below $sp, it will be destroyed (overwritten)!! $sp User Data Kernal Data
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.