Exception Processing ECE511: Digital System & Microprocessor.

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling (2)
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
Processor System Architecture
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Interrupts (contd..) Multiple I/O devices may be connected to the processor and the memory via a bus. Some or all of these devices may be capable of generating.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
1 Lecture 2: Review of Computer Organization Operating System Spring 2007.
68k Software Model ECE511: Digital System & Microprocessor.
7/23 Coldfire Exceptions and Interrupts Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee
1 Computer System Overview OS-1 Course AA
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
M68K Assembly Language Programming R.Renner Chapters 9-10 Memory-Mapped I/O Exceptions & Interrupts Notice: Chapter slides in this series originally provided.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
ECE511: Digital System & Microprocessor
Midterm Wednesday 11/19 Overview: 25% First Midterm material - Number/character representation and conversion, number arithmetic - DeMorgan’s Law, Combinational.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
Exception and Interrupt Handling
Introduction to Embedded Systems
Exceptions and Interrupts 2
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
MICROPROCESSOR INPUT/OUTPUT
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
The Stack This is a special data structure: –The first item to be placed into the stack will be the last item taken out. Two basic operations: –Push: Places.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
AT91 Interrupt Handling. 2 Stops the execution of main software Redirects the program flow, based on an event, to execute a different software subroutine.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Lecture 1: Review of Computer Organization
68k Software Model ECE511: Digital System & Microprocessor.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Resets & Interrupts MTT CPU08 Core Motorola CPU08 RESETS & INTERRUPTS.
Copyright © 2007 by Curt Hill Interrupts How the system responds.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Structure and Role of a Processor
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling.
MICROPROCESSOR DETAILS 1 Updated April 2011 ©Paul R. Godin prgodin gmail.com.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Interrupts and exceptions
Processor States normal exception
MICROPROCESSOR BASED SYSTEM DESIGN
Microprocessor Systems Design I
Timer and Interrupts.
Interrupts In 8085 and 8086.
Computer System Overview
Processor Fundamentals
X1 & X2 These are also called Crystal Input Pins.
BIC 10503: COMPUTER ARCHITECTURE
COMPUTER PERIPHERALS AND INTERFACES
Architectural Support for OS
Interrupts.
CNET 315 Microprocessor & Assembly Language
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Basic Instruction Cycle
Computer System Overview
Architectural Support for OS
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

Exception Processing ECE511: Digital System & Microprocessor

What we are going to learn in this session: What are exceptions. How M68k handles exceptions. M68k execution states and how they relate to exception handling.

Introduction

Exceptions Out-of-ordinary events that happen during M68k run-time. Caused by:  Interrupt requests.  Errors during processing cycle.  Arithmetic operations that cannot be completed.  Illegal instructions.

Exception Example (Divide by Zero) MOVE.W#0,D0 MOVE.L#500000, D1 DIVUD0,D1 500,000 / 0 = ? * Divide by Zero Exception

Exception Example: Address Error Memory range = $ to $ MOVE.B#$0A,$ $0000 $0001 $0002 … … $3FFE $3FFF $4000 $4500? (Address out of range) * Address Error Exception

Exception Example: Address Error MOVE.B#$A00A,$ $0000 $0001 $0002 … … $3FFE $3FFF $4000 Word transfer to odd address. * Address Error Exception

External peripheral asks for attention by outputting interrupt on IPL 0, IPL 1, IPL 2. Exception Example: Interrupt Request M68k External Peripheral 1 M68k is executing instructions normally. 2 External peripheral has important task for M68k. 3 M68k compares interrupt level to SR. 4 TSI2I2 I1I1 I0I0 XNZVC M68k services/holds interrupt based on interrupt level 5

Exception Example: Spurious Interrupt S0 S1 S2 S3 S4 S5 S6 S7 S0 S1 S2 CLK A 1 – A 23 AS LDS/UDS R/W DTACK D 0 – D 15 FC 0 – FC 2 DTACK never responds

Exceptions Exceptions should be handled properly:  Can cause data loss.  System failure.  No prioritizing of tasks. M68k handles exceptions using Exception Handling.

M68k Execution States

M68k always functions in either of the three states:  Normal.  Halted.  Exception.

Normal State M68k operating normally. Executing in user mode (S=0). Has a restricted instruction set:  Can’t execute privileged instructions.  Prevents from executing potentially destructive instructions. Reserved for SV.

Restricted Commands in Normal State STOP RESET RTE Any commands that modify the SR. MOVE USP

Exception State Handles special events (exceptions), then returns to normal execution. Can execute all instructions. Always saves processor context before handling exception, restored when returned to normal execution. Always executes in SV mode (S=1).

The Status Register TSI2I2 I1I1 I0I0 XNZVC Supervisor Mode, S = 1 (Exception State, Halted State) User Mode, S = 0 (Normal State)

Halted State M68k stops execution of all instructions. Done by activating HALT line:  Stops execution after current instruction.  Waits until HALT is inactive.  Resumes normal execution.

Halted State Reason:  Catastrophic system failures (double bus faults, hardware failure).  User: intentionally activating the HALT line. Purpose:  Protect data inside memory.

How States are Changed NormalHaltedException Double bus fault/User-initiated S=0, RTE, Edit SR S=1, Exceptions, Interrupt Reset Exception User-initiated

Exception Handling

Series of steps performed to handle exceptions. Ensures exceptions processed properly & resume normal execution. Allows M68k to:  Save all processor status before exception.  Handle the exception.  Restore processor status when exception has been handled.

What Happens During an Exception? Contents of SR saved to memory. S bit is set. Exception vector is obtained. Processor context (PC & SR) saved on software stack. PC set to address of exception vector. Execution resumes from new PC location. Control and context restored & execution resumes from last address before exception.

Exception Handler Operation TRAPV Save PC and SR to stack. Read handler address from Vector Table. Read original PC and SR from stack. Save D0-D7, A0-A7 Handler Code Reload D0-D7, A0-A7 RTE Next Instruction

Exception Processing Steps

1. Adjust SR. 2. Get Vector Number. 3. Save processor information. 4. Fetch new PC. 5. Restore context, resume last instruction in Normal mode.

Step 1: Adjust SR To enter SV state and prepare for exception processing:  Store SR internally.  Set S = 1 (SV Mode).  Set T = 0 (Disable Tracing).  If interrupt, update Interrupt Mask Bits.

SR Bits Modified by Step 1 TSI2I2 I1I1 I0I0 XNZVC S = 1T = 0 Updated if: I REQ > I CURRENT

Step 2: Get Vector Number Determines what type of exception, and get location of its appropriate handler. VN: 8-bit value indicating exception type.  Supplied by external device or M68k.  What kind of exception is happening.  Ranges from $00 (0) to $FF (255). VN used to find Vector Address (VA).

Vector Address (VA) Special memory location that stores addresses of exception handlers. VA obtained by multiplying VN with 4.  VN x 4 = VA. VA contains a long-word value containing address of exception handler. Contents inside VA loaded into PC, execution continued at this location.

How Exception Handling Works 1.VN given by external circuit/M68k. Based on VN, M68k knows what type of exception has occurred. VA = VN x 4 VN 2. VN x 4 = VA. Address of exception handler contained inside VA. M68k loads value into PC. $0000xxx $0004xxx $0008$3000 $000Cxxx $0010xxx PC$ M68k saves registers into stack, execution resumes at exception handler address. $3000 $3002 $3004 $0006 $0018 Exception handler code RTE

Vector Table (Antonakos, pg. 110) VNAssignment 0Reset: Initial SSP and PC 2Bus Error 3Address Error 5Divide by Zero 8Privilege Violation 9Trace 24Spurious Interrupt 25-31Interrupt Auto-vectors 32-47TRAP Instruction Vectors VA = VN x 4 0 = $0000 $ $007C $0080 – 00BC 96 = $ = $ = $ = $ = $000C 8 = $0008

Step 3: Save Processor Information Saves processor context into stack:  PC: next instruction after exception processing.  SR.  Bus cycle attempted, part of instruction (for bus error and address error). SSP is used  already in SV mode.

How Context Saved into Stack – Typical Exception Status Register PC (High Word) PC (Low Word) Old SSP location  New SSP location 

How Context Saved into Stack PC = $ SR = $0115 SSP = $002FFF $0115 $0000 $1111 … $002FFF $002FFD $002FFB $002FF8 SSP SSP-2 SSP-4 SSP-6 Old SSP location  New SSP location 

Step 4: Fetch New PC Loads PC from vector table in Step 2. Processing resumes at exception handler. Returned to normal processing using (Return to Exception) RTE.

Exception Handler Contains instructions on how to process the exception. Located in SV memory space. RTE at the end, resumes normal execution.

Exception Handler Contents Save Registers Handler Code Reload Registers RTE (Return to Exception) Save Registers, PC into Stack Code to handle exception Reload Registers from Stack Reload PC from stack, execution resumes at next instruction after exception.

Exception Example (Divide by Zero) MOVE.W#0,D0 MOVE.L#500000, D1 DIVUD0,D1 PC = $1040 SR = 500,000 / 0 = ? * Divide by Zero Exception TSIIIXNZVC

Step 1: Adjust SR Store SR internally. Set S = 1 (SV Mode). Set T = 0 (Disable Tracing). If interrupt, update Interrupt Mask Bits.

Step 1: Adjust SR TSIIIXNZVC T = 0S = 1 Not interrupt = unchanged

Step 2: Get Vector Number Divide by zero exception VN is VN = 5 VN x 4 used to find Vector Address (VA). VA = VN x 4 = 20 = $000014

Vector Address (VA) Special memory location that stores addresses of exception handlers. VA obtained by multiplying VN with 4.  VN x 4 = VA. VA contains a long-word value containing address of exception handler. Contents inside VA loaded into PC, execution continued at this location.

Vector Table Value $ $ $ $ $ $00400A00 $00400B00 Address $0000 $0060 $0024 $0020 $0014 $000C $0008

Step 3: Save Processor Information Saves processor context into stack. SSP is used  already in SV mode. PC =$ SSP/A7 = $ SR = $0016 $0016 (SR) $0000 (PC) $1040 (PC) Old SSP  $4000 New SSP  $3FFA

Step 4: Fetch New PC Loads PC from vector table in Step 2. Processing resumes at exception handler. Value $ $ $ $ $ $00400A00 $00400B00 Address $0000 $0060 $0024 $0020 $0014 $000C $0008 New PC = $ 

Exception Handler Contents Save D0-D7, A0–A7 Handler Code Reload D0-D7, A0-A7 RTE (Return to Exception) Save Registers into Stack Code to handle exception Reload Registers from Stack Reload PC, SR from stack, execution resumes at next instruction after DIVU. $

Handling Multiple Exceptions

It is possible for another exception to happen when the current exception is being handled.  An bus error occurs when M68k is handling an interrupt.  A trace exception generated during a divide by zero exception.

How does M68k handle multiple exceptions? In M68k, each exception has priority level:  Reset exception has higher priority than Trace exception.  An interrupt exception is more important than a Divide-by-Zero exception. When multiple exceptions happen, the more important one executed first.

Exception Grouping & Priority GroupExceptionPriority Reset Bus Error Address Error Trace Interrupt Illegal Privilege TRAP TRAPV CHK Zero Divide 0 (Highest) (Lowest) 1 (Highest) (Lowest) 2 All have same priority. Importance

Handling Multiple Exceptions Exceptions divided into 3 priority levels:  The higher-up, the more important.  Group 0 > Group 1 > Group 2.  Reset > Bus Error > Address Error > …..

What happens during multiple exceptions? The new exception compared to the current exception being handled:  If higher, creates an exception inside an exception: Saves processor context into stack. Handle new exception. Restore context from stack, return to old exception handle.  If lower, wait, then handle new exception. Save new exception request. Wait until current exception finishes. Handle new exception.

New < Old Exception - Example During a Trace exception (T = 1), an interrupt request has occurred. How would M68k handle this situation?

Exception Grouping & Priority GroupExceptionPriority Reset Bus Error Address Error Trace Interrupt Illegal Privilege TRAP TRAPV CHK Zero Divide 0 (Highest) (Lowest) 1 (Highest) (Lowest) 2 All have same priority. Trace exception higher than interrupt. Trace will be handled first.

New < Old Exception EXG (D0,D1) Trace Handler Save context Interrupt Handler Restore Context *Trace Handler executed first, then Interrupt Handler executed.

New > Old Exception - Example During an Interrupt exception, an Address Error Exception has occurred. How would M68k handle this situation?

Exception Grouping & Priority GroupExceptionPriority Reset Bus Error Address Error Trace Interrupt Illegal Privilege TRAP TRAPV CHK Zero Divide 0 (Highest) (Lowest) 1 (Highest) (Lowest) 2 All have same priority. Address Error exception higher than Interrupt. Address Error will be handled first.

New > Old Exception EXG (D0,D1) Interrupt Handler Save context Address Error Handler Restore Context Ins. in Handler *Address Error Handler executed first, then Interrupt Handler executed.

Conclusion

Exceptions are extraordinary situations that effect normal M68k operation. Exception Handling help M68k to:  Recover from errors.  Prioritize CPU tasks. M68k recognizes exceptions using VN.

Conclusion Exception handling involves:  Saving processor context.  Handling the exception.  Restore processor context.  Return to normal execution once exception is handled. Handles are instructions used to manage exceptions.  Located in SV memory location.

Exception Handler Operation TRAPV Save return address and flags on stack. Read handler address from Vector Table. Read return address and flags from stack. Save Registers Handler Code Reload Registers RTE

The End Please read: Antonakos, pg