gcc-2.95/v850 : bug in interrupt handlers
Matteo Frigo
athena@fftw.org
Sun Nov 21 06:22:00 GMT 1999
Dear gcc maintainers,
First of all, thanks for producing and supporting gcc and the
excellent GNU development tools. This email is to notify you that
gcc-2.95/v850 produces incorrect code when compiling interrupt
handlers. I am running gcc-2.95 on RedHat linux 6.0. I configured
the compiler with ./configure --target=v850.
The following program demonstrates the bug:
int k;
void __attribute__((interrupt)) foo(void)
{
int i, x=0;
for (i = 0; i < 100; ++i)
x |= i;
k = x;
}
When compiled with
/scratch/v850/gcc-2.95/gcc/xgcc -B/scratch/v850/gcc-2.95/gcc/ -O -S foo.c
I obtain the following output:
.file "foo.c"
gcc2_compiled.:
.section .text
.align 1
.global _foo
.type _foo,@function
_foo:
add -16,sp
st.w r10,12[sp]
jarl __save_interrupt,r10
add -8,sp
st.w r11,4[sp]
st.w r12,0[sp]
mov 0,r12
mov 0,r10
movea lo(99),r0,r11
.L6:
or r10,r12
add 1,r10
cmp r11,r10
ble .L6
movhi hi(_k),r0,r10
st.w r12,lo(_k)[r10]
add 8,sp #***** BUG *****
ld.w 4[sp],r11
ld.w 0[sp],r12
add 8,sp #***** add 8,sp is done twice *****
jr __return_interrupt
.Lfe1:
.size _foo,.Lfe1-_foo
.comm _k,4,4
.ident "GCC: (GNU) 2.95 19990728 (release)"
As can be seen, the compiler adds 8 twice to the stack pointer.
This behavior is incorrect because 1) sp is not restored to the
original value at the end of __return_interrupt and 2) r11 and
r12 are restored to bogus values. If the first instruction
``add 8,sp'' is removed, the resulting code is correct.
Regards,
Matteo Frigo
More information about the Gcc-bugs
mailing list