Docsity

Interrupts: Handling Events with Special Piece of Code, Slides of Microcontrollers

Partial preview of the text

Download Interrupts: Handling Events with Special Piece of Code and more Slides Microcontrollers in PDF only on Docsity!

Interrupts

Stopping program flow to execute a special piece of

code that handles an event

  • Definition and classification
  • PowerPC interrupt structure
  • Precise exceptions
  • Handling multiple interrupts

Nesting, prioritization

Reference: Chapter 6, Programming Environment

Section 6.4, User’s Manual

I/O Data Transfer

1. How does the CPU know when data is available?

(a) Polling (b) Interrupts

2. How is data transferred into and out of the device?

(a) Programmed I/O (b) Direct Memory Access (DMA)

Two key questions to determine how data is transferred to/from a

non-trivial I/O device:

Two basic types of interrupts

1. Those caused by an instruction

  • Examples:
    • TLB miss
    • Illegal/unimplemented instruction
    • div by 0
  • Names:
    • Trap, exception, synchronous interrupt

Two basic types of interrupts

2. Those caused by the external world

  • Examples:
    • External device
    • Reset button
    • Timer expires
    • Power failure
    • System error
  • Names:
    • interrupt, external interrupt, asynchronous interrupt.

… is in the details

  • How do you figure out where to branch to?
  • How to you insure that you can get back to where you started?
  • Don’t we have a pipeline? What about partially executed instructions?
  • What if we get an interrupt while we are processing our interrupt?
  • What if we are in a “critical section?”

Where

• If you know what caused the interrupt then you want to

jump to the code that handles that interrupt.

  • If you number the possible interrupt cases, and an interrupt comes in, you can just branch to a location, using that number as an offset (this is a branch table)
  • If you don’t have the number, you need to poll all possible sources of the interrupt to see who caused it. - Then you branch to the right code

Snazzy architectures

• A modern processor has many ( often 50+) instructions

in-flight at once.

  • What do we do with them?

• Drain the pipeline?

  • What if one of them causes an exception?

• Punt all that work

  • Slows us down

• What if the instruction that caused the exception was

executed before some other instruction?

  • What if that other instruction caused an interrupt?

Nested interrupts

• If we get one interrupt while handling another what to do?

  • Just handle it
    • But what about that dedicated register?
    • What if I’m doing something that can’t be stopped?
  • Ignore it
    • But what if it is important?
  • Prioritize
    • Take those interrupts you care about. Ignore the rest
    • Still have dedicated register problems.

Power PC

• Power PC is a great teaching tool for this because it is

so messed-up in how it handles things

  • It supports almost every option you could ever want.

• Names

  • Synchronous interrupts
  • Asynchronous interrupts

PowerPC Interrupt Structure

Machine Status Register (MSR)

  • Defines the state of the processor (Table 6-5): Power

management, endian mode, external interrupt enable, machine

check enable, privilege level, recoverable exceptions, etc.

  • When an exception occurs, MSR bits are altered as determined

by the exception.

  • Support for interrupts
    • Two special-purpose registers to store program counter and MSR: Save/Restore Registers 0 and 1 (SRR0 and SRR1)
    • One instruction: return from interrupt (rfi)

MSR

0-12 reserved 13 POW power management 14 reserved 15 ILE exception little-endian 16 EE external interrupt enable (0: delay recognition; 1: enabled) 17 PR privilege level (0: user and supervisor-level; 1: user only) 18 FP floating point available 19 ME machine check enable 20 FE0 floating point exception mode 0 21 SE single-step trace enable 22 BE branch trace enable 23 FE1 floating point exception mode 1 24 reserved 25 IP exception prefix (000 or FFF) 26 IR instruction address translation 27 DR data address translation 28-29 reserved 30 RI recoverable exception 31 LE little-endian enable (0: big-endian; 1: little-endian) Docsity.com

Example: External Interrupt

An external interrupt is signaled to the processor through the assertion of the external interrupt signal.

Execution continues at offset 0x00500 from base physical location determined by MSR[IP] bit.

SRR0: Set to the effective address that processor would have attempted to execute next if no interrupt condition were present.

SRR1: 1-4 cleared 10-15 cleared 16-23, 25-27, 30-31 loaded with equivalent bits from MSR MSR: POW = 0 FP = 0 BE = 0 DR = 0 ILE = same ME = same FE1 = 0 RI = 0 EE = 0 FE0 = 0 IP = same LE = ILE PR = 0 SE = 0 IR = 0

Precise Exceptions

  • Concurrent execution: To maximize performance, instructions are

processed concurrently, independent of the sequence in program.

  • Hardware ensures that program semantics are preserved.
  • Difficult requirement to assure when interrupt occurs after instructions

following “faulting” instruction have started or completed.

  • Precise exception model: Automatically back machine up to the

instruction that caused interrupt.

  • MPC555 uses a history buffer to support precise exceptions.

Interrupt Ordering

  • Synchronous (i.e. instruction-related) exceptions are detected at

any stage during instruction execution.

  • The earliest exception found in the processing of an instruction

precludes detection of further exceptions and is eventually handled.

  • If more than one instruction in the pipeline causes an exception,

only the first is taken. Any remaining synchronous exceptions are

ignored.

  • More than one asynchronous interrupt causes may be present at

any time, in which case only the highest priority interrupt is taken.