lect.14.OS2.4up

lect.14.OS2.4up - Announcements Reminders Lab3 and PA2...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
EE108b Lecture 14 C. Kozyrakis 1 EE108B Lecture 14 Virtual Memory Christos Kozyrakis Stanford University http://eeclass.stanford.edu/ee108b EE108b Lecture 14 C. Kozyrakis 2 Announcements • Reminders – Lab3 and PA2 (part a) are due on today EE108b Lecture 14 C. Kozyrakis 3 Review: Hardware Support for Operating System • Operating system – Manages hardware resources (CPU, memory, I/O devices) • On behalf of user applications – Provides protection and isolation – Virtualization • Processes and virtual memory • What hardware support is required for the OS? – Kernel and user mode • Kernel mode: access to all state including privileged state • User mode: access to user state ONLY – Exceptions/interrupts – Virtual memory support EE108b Lecture 14 C. Kozyrakis 4 MIPS Interrupts • What does the CPU do on an exception? – Set EPC register to point to the restart location – Change CPU mode to kernel and disable interrupts – Set Cause register to reason for exception also set BadVaddr register if address exception – Jump to interrupt vector • Interrupt Vectors – 0x8000 0000 : TLB refill – 0x8000 0180 : All other exceptions • Privileged state – EPC – Cause – BadVaddr
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C. Kozyrakis 5 A Really Simple Exception Handler xcpt_cnt: la $k0, xcptcount # get address of counter lw $k1, 0($k0) # load counter addu $k1, 1 # increment counter sw $k1, 0($k0) # store counter eret # restore status reg: enable # interrupts and user mode # return to program (EPC ) Can’t survive nested exceptions – OK since does not re-enable interrupts Does not use any user registers – No need to save them EE108b Lecture 14 C. Kozyrakis 6 Interrupt vectors Accelerating handler dispatch • 1. Each type of interrupt has a unique exception number k • 2. Jump table (interrupt vector) entry k points to a function (exception handler). • 3. Handler k is called each time exception k occurs interrupt vector 0 1 2 ... n-1 code for exception handler 0 code for exception handler 0 code for exception handler 1 code for exception handler 1 code for exception handler 2 code for exception handler 2 code for exception handler n-1 code for exception handler n-1 ... Exception numbers But the CPU is much faster than I/O devices and most OSs use a common handler anyway Make the common case fast! EE108b Lecture 14 C. Kozyrakis 7 Exception Example #1 User Process OS page fault Create page and load into memory return event lw Memory Reference – User writes to memory location – That portion (page) of user’s memory is currently not in memory – Page handler must load page into physical memory – Returns to faulting instruction – Successful on second try int a[1000]; main () { a[500] = 13; } EE108b Lecture 14 C. Kozyrakis 8 Exception Example #2 User Process OS page fault Detect invalid address event lw Memory Reference – User writes to memory location – Address is not valid – Page handler detects invalid address – Sends
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

lect.14.OS2.4up - Announcements Reminders Lab3 and PA2...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online