chapter 13 arm exception handling ( real-time embedded multithreading : using threadx ® and arm ®...

24
Chapter 13 ARM Exception Handling (Real-Time Embedded Multithreading : Using ThreadX® and ARM ®) Department of Computer Science Hsu Hao Chen Professor Hsung-Pin Chang

Post on 19-Dec-2015

239 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Chapter 13

ARM Exception Handling

(Real-Time Embedded Multithreading : Using ThreadX® and ARM®)

Department of Computer Science Hsu Hao ChenProfessor Hsung-Pin Chang

Page 2: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Outline

Exception Resulting for ARM Exception (Actions) Reset Vector Initialization ThreadX Initialization Thread Scheduling ThreadX Interrupt Handling Internal Interrupt Processing

Page 3: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Exception Resulting for ARM

Exceptions resulting for the direct effect of executing an instruction

Exceptions resulting as a side effect of executing an instruction

Exceptions resulting from external interrupts, unrelated to instruction execution

Page 4: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Exception (Actions) (1/2)

Step 1: Save CPSR -> SPSR

Step 2: Change to the operating mode

corresponding to the exception Step 3:

Modify the CPSR of the new operating mode Step 4:

Save r15(PC) register -> r14(LR) register Step 5:

Change the PC to the appropriate exception vector

Page 5: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Exception (Actions) (2/2)

Page 6: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Reset Vector Initialization(1/2)

Page 7: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Reset Vector Initialization(2/2)

LDR pc,=__my_low_level_init

branch (jump) or load PC

Page 8: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

ThreadX Initialization(1/2)

Note: any code after tx_kernel_enter will never be executed

Page 9: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

ThreadX Initialization(2/2)

tx_kernel_enter

_tx_initialize_low_level

tx_application_define

_tx_thread_schedule

Page 10: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Thread Scheduling

Recovering thread context Solicited context Interrupt context

Saving thread context _tx_thread_system_return

Page 11: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Solicited Context

extremely small(48 bytes of stack space)

Page 12: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Interrupt Context

Page 13: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Example :ARM code fragment(1/6)

Page 14: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

**

**

Page 15: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Example :ARM code fragment(3/6)

Page 16: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Example :ARM code fragment(4/6)

Page 17: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Example :ARM code fragment(5/6)

LDMIA sp!, {r0,r1} //r0= *sp!//r1= *(sp!

+4)

IA: Increment AfterIB: Increment BeforeDA: Decrement AfterDB: Decrement Before

Page 18: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Example :ARM code fragment(6/6)

MSRNE SPSR_cxsf, r1 //copy r1->SPSR_cxsf

NE: Not equal

BX lr //branch (jump) to lr

Mov pc, lr //copy lr->pc

Page 19: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

ThreadX Interrupt Handling IRQ interrupt handling

LDR pc, =__tx_irq_handler FIQ interrupt handling

LDR pc, =__tx_fiq_handler

Page 20: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Example Of A ThreadX IRQ Handler

Page 21: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Example Of A ThreadX FIQ Handler

Page 22: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Internal Interrupt Processing

Idle system Saving solicited thread contexts

_tx_thread_context_save Saving interrupt thread contexts Nested interrupt handling

Enable and disable nesting for IRQ interrupt handlers

Enable and disable nesting for FIQ interrupt handlers

Page 23: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Enable And Disable Nesting For IRQ Interrupt Handlers

EXPORT __tx_irq_handlerEXPORT __tx_irq_processing_return__tx_irq_handler

B _tx_thread_context_save__tx_irq_processing_returnBL _tx_thread_irq_nesting_start

BL application_irq_handler

BL _tx_thread_irq_nesting_endB _tx_thread_context_restore

Page 24: Chapter 13 ARM Exception Handling ( Real-Time Embedded Multithreading : Using ThreadX ® and ARM ® ) Department of Computer Science Hsu Hao Chen Professor

Enable And Disable Nesting For FIQ Interrupt Handlers

EXPORT __tx_fiq_handlerEXPORT __tx_fiq_processing_return__tx_fiq_handler

B _tx_thread_fiq_context_save__tx_fiq_processing_returnBL _tx_thread_fiq_nesting_start

BL application_fiq_handler

BL _tx_thread_fiq_nesting_endB _tx_thread_fiq_context_restore