Interrupt in system mode?

I have downloaded some examples from the net (ie. inside IDEaliST from Anglia).

I wonder why in all the example I found the interrupts are switched back in system mode instead of using interrupt mode.

for example:

/*******************************************************************************
* Macro Name     : IRQ_to_SYS
* Description    : This macro used to switch form IRQ mode to SYS mode
* Input          : none.
* Output         : none
*******************************************************************************/

	.macro	IRQ_to_SYS
		MSR		cpsr_c, #0x1F	/* Switch to SYS mode */
		STMFD	sp!, {lr}		/* Save the link register. */
	.endm

/*******************************************************************************
* Macro Name     : SYS_to_IRQ
* Description    : This macro used to switch from SYS mode to IRQ mode
                   then to return to IRQHnadler routine.
* Input          : none.
* Output         : none.
*******************************************************************************/

	.macro	SYS_to_IRQ
		LDMFD	sp!, {lr}		/* Restore the link register. */
		MSR		cpsr_c, #0xD2	/* Switch to IRQ mode. */
		MOV		pc, lr			/* Return to IRQHandler routine to clear the */
								/* pending bit. */
	.endm

/*******************************************************************************
* Function Name  : EXTIT10IRQHandler
* Description    : This function used to switch to SYS mode before entering
                   the EXTIT10_IRQHandler function
                   Then to return to IRQ mode after the
                   EXTIT10_IRQHandler function termination.
* Input          : none
* Output         : none
*******************************************************************************/

EXTIT10IRQHandler:
		IRQ_to_SYS
		mBLX	EXTIT10_IRQHandler
		SYS_to_IRQ

Is there some pitfall using interrupt mode?

thanks

This is so nested interrupts are supported.

IRQ mode is fine but it cannot be interrupted, ie. concurrent interrupts only.

Regards

Spen

mastupristi:
I have downloaded some examples from the net (ie. inside IDEaliST from Anglia).

I wonder why in all the example I found the interrupts are switched back in system mode instead of using interrupt mode.

Is there some pitfall using interrupt mode?

thanks

Yes, because this part of the ARM cpus were designed by braindead idiots.

An interrupt will always overwrite the SPSR and LR register.

You can save both at the beginning in your assembler stub, but there is one pitfall.

If you using normal function, it doesnt help, because it will always overwrite the

LR register on interrupt, and if your nestet interrupt function wants to return,

by mov pc, lr the interrupt has bitten you, and the result is undefined.

In my startup assembly file, I use the supervisor mode for everything,

i have only an small stack for the other modes to transfer

the spsr and lr registers to the supervisor mode.

Its a bit more complex than the normal startup files, which are circling around here,

but this allows for example using setjmp/longjmp from interrupts, without garbling up

the different stacks, or simply multiplexing threads from interrupts by switching

the stackpointer of the supervisor mode.