1 / 15

CSC 2405 Computer Systems II

CSC 2405 Computer Systems II. Exceptions Mini-Lecture Traps & Interrupts. is. is. here is an analogy. . . Teacher. OS. each student. I/O device. Consider the inefficiency of OS polling. device 1 ready?. device 2 ready?. device n ready?. Because polling is so inefficient ,.

diallo
Download Presentation

CSC 2405 Computer Systems II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 2405Computer Systems II Exceptions Mini-Lecture Traps & Interrupts

  2. is is here is an analogy. . . Teacher OS each student I/O device Consider the inefficiency of OS polling.

  3. device 1ready? device 2ready? device nready? Because polling is so inefficient, instead of OS ask . . .

  4. device 1 device 2 device n Turn the situation upside down OS ready! . . .

  5. is is Teacher (tries to) answerquestion OS handlesinterrupt student with aquestion raises hand device readysends interruptrequest the analogy continues. . .

  6. Types of Exceptions • traps • interrupts

  7. Exceptions • An exception is a transfer of control to the OS in response to some event (i.e., change in processor state) User Process OS exception current event next exception processing by exception handler exception return (optional) Chapter 8

  8. Example Exceptions • Divide by zero – n / 0 • Segmentation fault – program tries to access memory it doesn’t “own” • Abnormal termination – abort • Overflow – usually mult or add • Bad or illegal instruction – no such function • Termination request – program requests to exit Chapter 8

  9. Interrupt Vectors • Each type of event has a unique exception number k • Index into jump table (a.k.a., interrupt vector) • Jump table entry k points to a function (exception handler). • Handler k is called each time exception k occurs. Exception numbers code for exception handler 0 interrupt vector code for exception handler 1 0 1 code for exception handler 2 2 ... ... n-1 code for exception handler n-1 Chapter 8

  10. Asynchronous Exceptions (Interrupts) • Caused by events external to the processor • Indicated by setting the processor’s interrupt pin • handler returns to “next” instruction. • Examples: • I/O interrupts • hitting ctl-c at the keyboard • arrival of a packet from a network • arrival of a data sector from a disk • Hard reset interrupt • hitting the reset button • Soft reset interrupt • hitting ctl-alt-delete on a PC Chapter 8

  11. Trap Example • Opening a File • User calls open(filename, options) • Function open executes system call instruction int • OS must find or create file, get it ready for reading or writing • Returns integer file descriptor 0804d070 <__libc_open>: . . . 804d082: cd 80 int $0x80 804d084: 5b pop %ebx . . . User Process OS exception int pop Open file return Chapter 8

  12. User Process OS page fault event movl Create page and load into memory return Fault Example #1 int a[1000]; main () { a[500] = 13; } • Memory Reference • User writes to memory location • That portion (page) of user’s memory is currently on disk • Page handler must load page into physical memory • Returns to faulting instruction • Successful on second try 80483b7: c7 05 10 9d 04 08 0d movl $0xd,0x8049d10 Chapter 8

  13. Fault Example #2 int a[1000]; main () { a[5000] = 13; } • Memory Reference • User writes to memory location • Address is not valid • Page handler detects invalid address • Sends SIGSEG signal to user process • User process exits with “segmentation fault” 80483b7: c7 05 60 e3 04 08 0d movl $0xd,0x804e360 User Process OS page fault event movl Detect invalid address Signal process Chapter 8

  14. Synchronous Exceptions • Caused by events that occur as a result of executing an instruction: • Traps • Intentional • Examples: system calls, breakpoint traps, special instructions • Returns control to “next” instruction • Faults • Unintentional but possibly recoverable • Examples: page faults (recoverable), protection faults (unrecoverable). • Either re-executes faulting (“current”) instruction or aborts. • Aborts • unintentional and unrecoverable • Examples: parity error, machine check. • Aborts current program Chapter 8

More Related