This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: PC at the time of interrupt in ISR
- From: Andrew Lunn <andrew dot lunn at ascom dot ch>
- To: Niclas Eriksson <niclas dot eriksson at omicron dot se>
- Cc: ecos-discuss at sources dot redhat dot com
- Date: Fri, 8 Nov 2002 13:33:33 +0100
- Subject: Re: [ECOS] PC at the time of interrupt in ISR
- References: <EKEKIBPEJMPPIGAMBGJBGEPLCCAA.niclas.eriksson@omicron.se>
On Fri, Nov 08, 2002 at 01:25:53PM +0100, Niclas Eriksson wrote:
> Hi,
> Is there an easy way to get the program counter (PC) at the time of the
> interrupt from within an ISR ?
> I'm using Ecos on an ARM7 target, the Atmel AT91EB40 board.
> Thanks in advance,
There are two ways... One is HAL dependent, but works on ARM:
/* This is the interrupt handler. It finds out the PC address before
the interrupt and calls the increment. It then clears the interrupt
and returns */
cyg_uint32
prof_ISR(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs) {
prof_do_ISR(regs->pc);
prof_clear_timer_intr();
cyg_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_TIMER_2);
return (CYG_ISR_HANDLED);
}
It uses an undocument extra parameter to the ISR. Since this is
undocument, this feature may disappear, but its been there for over 3
years....
The second way is:
externC HAL_SavedRegisters *hal_saved_interrupt_state;
/* This is the interrupt handler. It finds out the PC address before
the interrupt and calls the increment. It then clears the interrupt
and returns */
cyg_uint32
prof_ISR(cyg_vector_t vector, cyg_addrword_t data) {
if ( hal_saved_interrupt_state )
{
/* Current instruction, not next */
prof_do_ISR(hal_saved_interrupt_state->pc);
}
cyg_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_TM1);
return (CYG_ISR_HANDLED);
}
Im not sure of the documentation status of this....but it should work
for all HAL types ( i think. I've only used it in mips )
Look back in the mail archive. This has been discussed before.
Note that ARM increments the PC before servicing the ISR. So PC will
be 4 bytes after the instruction that got interrupted.
Andrew
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss