This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ARM interrupts


> Hi Eric,
> 
> > When I compile the following c program:
> > 
> >  void at91_default_irq_handler() __attribute__ ((interrupt ("FIQ")));
> >  void at91_default_irq_handler() {}
> > 
> > Then I get the following assembly code:
> > 
> > entry code:
> > 1) str ip, [sp, #-4]!
> > 2) mov ip, sp
> > 3) sub lr, lr, #4
> > 4) stmfd sp!, {fp, ip, lr, pc}
> > 5) sub fp, ip, #4
> > 6) ldmea fp, {fp, ip, pc}^
>  
> > Who can explain this?
> 
> It is a bug in the compiler.  Gcc thought that it was able to use a
> single instruction to return from the interrupt handler.  It had
> forgotten to allow for the fact that IP had to be pushed before the
> stack frame could be created.
> 
> Please try applying the following patch to your sources and rebuilding
> gcc.  It should fix the problem.
> 
> Cheers
>         Nick
> 
> 2003-01-23  Nick Clifton  <nickc@redhat.com>
> 
> 	* config/arm/arm.c (use_return_insn): Do not allow interrupt
> 	handlers with a stack frame to use a single instruction return
> 	- they need to pop the IP register. 
> 	(arm_expand_prologue): Do not pre-bias the LR register for
> 	interrupt handlers unless they are going to use a single
> 	instruction return.

Sorry, but this is just gross.  Interrupt functions shouldn't even be
trying to produce APCS-style framed entry sequences.

The entry sequence should instead be something like

	sub	lr, lr, #4		/* If required for return sequence. */
	stmfd	sp!, {...,fp,sp,ip,lr}	/* Note, no pc.  */
	add	fp, sp, #16+sizeof(...)
#ifdef ATPCS_STACK_ALIGN
	bic	sp, sp, #7		/* If stack alignment required.  */
#endif

	...
	ldmea	fp, {...,fp,sp,ip,pc}^

Note that you have to use a "frame-pointer" if you want stack alignment.  If you don't then it's possible to compile a frameless entry sequence.

R.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]