Professional Documents
Culture Documents
Exception processing: Interrupt and resume programming execution Interrupt processing: Read interrupt registers, find and call ISR
4.
5. 6. 7.
Save machine contexts Re-enable interrupts Save user-level registers Read interrupt vector code Calculate ISR address and jump to ISR Restore machine contexts and user-level registers Return to program execution
; STEP 2: make execution recoverable and enable ; external interrupt Set MSR[EE] and MSR[RI] bits; others: mtspr EIE, r3 EIE: set MSR[EE] and MSR[RI]
EID: set MSR[RI] only
4
External Interrupt Exception Prologue (Continue) ; STEP 3: SAVE OTHER APPROPRIATE CONTEXT
mflr r3 stw r3, 8 (sp) mfcr r3 stw r3, 20 (sp)
Save LR and CR LR will be changed when calling ISR ISR will have branches that change CR r3 is used because CR and LR cannot be saved into memory directly
Save other registers assume that any ISR uses only r3-r6 must save more if ISR is written in C
selectively Interrupt vector code: To help generate ISR address Interrupt prioritization: To help select the interrupt with the highest priority
IRQ[0:7] external
3 IRQ Reset Timer
USIU
1
1
Eight interrupt levels assigned to internal devices Eight IRQ pins reserved for extern devices
Hard drive, video card, IRQ[0]: connect to reset
7
External IRQ[0:7]
SIPEND
I0 I1 I2 I3 I4 I5 I6 I7 16 31
I0 L0 I1 L1 I2 L2 I3 L3 I4 L4 I5 L5 I6 L6 I7 L7
reserved
9
I0 L0 I1 L1 I2 L2 I3 L3 I4 L4 I5 L5 I6 L6 I7 L7
SIMASK
16
reserved
31
I0 L0 I1 L1 I2 L2 I3 L3 I4 L4 I5 L5 I6 L6 I7 L7
reserved
Priority: 0 Highest
11
Other ESR
Other ESR
ISR n
12
; STEP 5: BRANCH TO INTERRUPT HANDLER blrl blrl: branch to address in LR and save PC+4 in LR
basically this is a function call using function pointer at target address: b kth_isr_addr
13
15
Restore CR and LR again use r3 as a bridge CR and LR (and any other SPR) cannot be loaded directly with data from memory
16
mtspr NRI, r3 lwz r3, 12 (sp) mtsrr0 r3 lwz r3, 16 (sp) mtsrr1 r3 lwz r3, 24 (sp) addi sp, sp, 40
cannot be interrupted from now on; NRI: SPR for fast clearing MSR[EE] and MSR[RI]
Restore SRR0, SRR1 and r3 again use r3 as a bridge in restoring SRR0 and SRR1 r3 is the first to be saved and the last one to be restored
; STEP 7: RETURN TO PROGRAM rfi ; End of Interrupt rfi (return from interrupt):
restores MSR bits saved in SRR1 restores next-PC saved in SRR0
17
18
4 5
19
IMB3 Bus
functions, e.g. counting pulses MIOS1: Modular I/O System; QADC64: Queued Analog-to-digital converter TouCAN: Control Area Network, two-wire, up to 1Mbps and 40m; e.g. network inside vehicle QSMCM: Queued Serial Multi-channel Module IMB3 bus: Inter-Module Bus
20
addr/data
UIPEND
8
UMCR[IRQUX]
mapped I/O
22
USIU
Timebase Clock SIPEND SIMASK SIVEC
PIT
PLL
SW watchdog Decrementer
Note: External IRQ is controlled by SIEL triggered by falling edge or low level
24
Finally!
IREQ 1
MSR[EE]
Vector table
&
NMI 2 Decrementer 3
Inst buffer
inst
Three interrupt lines to processor core: IREQ, NMI, and Decrementer MSR[EE]: Enable external interrupt IREQ: External interrupt NMI: Non-maskable interrupt (e.g. reset button is pushed) Decrementer: fast timer interrupt
Other processor components not shown
26