You copied the Doc URL to your clipboard.

Example exception handlers

The following code provides examples of how exception handlers might be structured.

A simple exception handler

The following code demonstrates a simple exception handler for non-nested interrupts:

ASM_IRQ_Handler:
	; Stack all corruptible registers	   // 
	STP X0, X1, [SP, #-16]!			// save PCS corruptible
	STP X2, X3, [SP, #-16]!			// interrupts
	...						// PUSH the rest of the
							   // corruptible registers

Corruptible Registers are X0-X15.

	BL	identify_and_clear_source
	BL	C_IRQ_Handler

	; Restore corruptible registers
	...
	LDP X2, X3, [SP], #16				// Restore PCS corruptible
	LDP X0, X1, [SP], #16				// interrupts

	; Return from exception			    //
	ERET						   // Return from exception

A nested exception handler

The following code demonstrates a simple exception handler for nested interrupts:

ASM_IRQ_Handler:
	; Stack all corruptible registers			// Save
	...
	; Read SPSR_EL1 and ELR_EL1 into GP registers	// PCS
	MRS X0, SPSR_EL1					   // Corruptible
	MRS X1, ELR_EL1					    // registers
	; Stack SPSR_EL1 and ELR_EL1			    // SPSR_EL1
	STP X0, X1, [SP, #-16]!				  // ELR-EL1
	BL	identify_and_clear_source
	; Unmask IRQs
	MSR DAIFClr, #0b0010				     // Unmask
	BL	C_IRQ_Handler				   // IRQs
	; Mask IRQs
	MSR DAIFSet, #0b0010				     // Mask
	; Restore SPSR_EL1 and ELR_EL1			  // IRQs

	LDP X0, X1, [SP], #16				     // Restore PCS
	MSR SPSR_EL1, X0					    // corruptible
	MSR ELR_EL1, X1					     // registers, SPSR_EL1
	; Restore corruptible registers			  // and ELR_EL1
	...
	ERET							   // Exception return
Was this page helpful? Yes No