0% found this document useful (0 votes)
4 views10 pages

Lecture Slides 08 080-Exceptional-Control

Uploaded by

yihuangece
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Lecture Slides 08 080-Exceptional-Control

Uploaded by

yihuangece
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

University of Washington

Control Flow
 Processors do only one thing:
 From startup to shutdown, a CPU simply reads and executes (interprets)
a sequence of instructions, one at a time
 This sequence is the CPU’s control flow (or flow of control)

Physical control flow


<startup>
inst1
time inst2
inst3

instn
<shutdown>
Exceptional Control Flow
University of Washington

Altering the Control Flow


 Up to now: two ways to change control flow:
 Jumps (conditional and unconditional)
 Call and return
Both react to changes in program state
 Processor also needs to react to changes in system state
 user hits “Ctrl-C” at the keyboard
 user clicks on a different application’s window on the screen
 data arrives from a disk or a network adapter
 instruction divides by zero
 system timer expires
 Can jumps and procedure calls achieve this?
 Jumps and calls are not sufficient – the system needs mechanisms for
“exceptional” control flow!

Exceptional Control Flow


University of Washington

Exceptions
 An exception is transfer of control to the operating system (OS)
in response to some event (i.e., change in processor state)
User Process OS

event I_current exception


I_next exception processing
by exception handler
• return to I_current
• return to I_next
• abort

 Examples:
div by 0, page fault, I/O request completes, Ctrl-C
 How does the system know where to jump to in the OS?

Exceptional Control Flow


University of Washington

Interrupt Vectors
Exception
numbers

code for  Each type of event has a


exception handler 0 unique exception number k
Exception code for
Table exception handler 1
 k = index into exception table
0 (a.k.a. interrupt vector)
1
code for
2 exception handler 2
...  Handler k is called each time
n-1 ... exception k occurs

code for
exception handler n-1

Exceptional Control Flow


University of Washington

Asynchronous Exceptions (Interrupts)


 Caused by events external to the processor
 Indicated by setting the processor’s interrupt pin(s)
 Handler returns to “next” instruction
 Examples:
 I/O interrupts
 hitting Ctrl-C on the keyboard
 clicking a mouse button or tapping a touchscreen
 arrival of a packet from a network
 arrival of data from a disk
 Hard reset interrupt
 hitting the reset button on front panel
 Soft reset interrupt
 hitting Ctrl-Alt-Delete on a PC

Exceptional Control Flow


University of Washington

Synchronous Exceptions
 Caused by events that occur as a result of executing an
instruction:
 Traps
Intentional: transfer control to OS to perform some function
 Examples: system calls, breakpoint traps, special instructions
 Returns control to “next” instruction
 Faults
 Unintentional but possibly recoverable
 Examples: page faults (recoverable), segment protection faults
(unrecoverable), integer divide-by-zero exceptions (unrecoverable)
 Either re-executes faulting (“current”) instruction or aborts
 Aborts
 Unintentional and unrecoverable
 Examples: parity error, machine check
 Aborts current program
Exceptional Control Flow
University of Washington

Trap Example: Opening File


 User calls: open(filename, options)
 Function open executes system call instruction int
0804d070 <__libc_open>:
. . .
804d082: cd 80 int $0x80
804d084: 5b pop %ebx
. . .

User Process OS

int exception
pop
open file
returns

 OS must find or create file, get it ready for reading or writing


 Returns integer file descriptor
Exceptional Control Flow
University of Washington

Fault Example: Page Fault


int a[1000];
 User writes to memory location main ()
{
 That portion (page) of user’s memory a[500] = 13;
is currently on disk }

80483b7: c7 05 10 9d 04 08 0d movl $0xd,0x8049d10

User Process OS

exception: page fault


movl
Create page and
returns load into memory

 Page handler must load page into physical memory


 Returns to faulting instruction: mov is executed again!
 Successful on second try
Exceptional Control Flow
University of Washington

Fault Example: Invalid Memory Reference


int a[1000];
main ()
{
a[5000] = 13;
}

80483b7: c7 05 60 e3 04 08 0d movl $0xd,0x804e360

User Process OS

exception: page fault


movl
detect invalid address
signal process

 Page handler detects invalid address


 Sends SIGSEGV signal to user process
 User process exits with “segmentation fault”
Exceptional Control Flow
University of Washington

Summary
 Exceptions
 Events that require non-standard control flow
 Generated externally (interrupts) or internally (traps and faults)
 After an exception is handled, one of three things may happen:
 Re-execute the current instruction
 Resume execution with the next instruction
 Abort the process that caused the exception

Exceptional Control Flow

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy