[Bug c/16308] New: Error passing constant as argument in m68k and address mode problem
ra010062 at ic dot unicamp dot br
gcc-bugzilla@gcc.gnu.org
Thu Jul 1 02:46:00 GMT 2004
It is important to enphasize that this bug was also verified in gcc 3.3.3.
When we compile a C code to the m68k architecture and in the C code we use a
constant as argument of a function, that's why the critical severity. The code
generated to the m68k is wrong.
The bug: this architecture, because it has few registers, uses the stack to
receive parameters. If a C code passes the value 5 to a function for example,
this value has to be store in the stack,after this has to be decremented by 4
(the stack goes up downward).
The code with this aim is normally generated with PEA(push effective address)
m68k coldfire family instrunction, and this instruction do not have a address
mode that loads directly the value to the stack, only what the value points to
in memory. Therefore the code is generated this way, what is wrong.
In this example the codes generated would be pea 5.w
The address mode told is (XXXX).W or (XXXX).L (described in m68k Coldfire family
manual). what problably occurs is a misunderstanding by the gcc about what this
address mode means. This cam be realized also with the use of JMP instruction
that has to jump downright to the address indicated by value x , but it jump to
address that value x points to im memory. That's what the parenthesis means,
the operand is where XXXX points to.
A example in a fibonacci function:
C code:
int fibo(int);
int main(){
int x;
x=fibo(10); <---------- the constant value being passed
return 0;
}
int fibo(int n){
if ((n==1)||(n==0)) return 1;
else
return (fibo(n-1)+fibo(n-2));
}
Assembly generated code:
#NO_APP
.file "fibonacci.c"
.text
.align 2
.globl main
.type main, @function
main:
link.w %a6,#-4
pea 10.w <-------- It should put the value 10 in the stack
jbsr fibo but puts what's in address 10
addq.l #4,%sp
move.l %d0,-4(%a6)
clr.l %d0
unlk %a6
rts
.size main, .-main
.align 2
.globl fibo
.type fibo, @function
fibo:
link.w %a6,#-4
move.l %d2,-(%sp)
moveq #1,%d0
cmp.l 8(%a6),%d0
jbeq .L4
tst.l 8(%a6)
jbne .L3
.L4:
moveq #1,%d0
move.l %d0,-4(%a6)
jbra .L2
.align 2
.L3:
move.l 8(%a6),%d0
subq.l #1,%d0
move.l %d0,-(%sp)
jbsr fibo
addq.l #4,%sp
move.l %d0,%d2
move.l 8(%a6),%d0
subq.l #2,%d0
move.l %d0,-(%sp)
jbsr fibo
addq.l #4,%sp
add.l %d0,%d2
move.l %d2,-4(%a6)
.L2:
move.l -4(%a6),%d0
move.l -8(%a6),%d2
unlk %a6
rts
.size fibo, .-fibo
.ident "GCC: (GNU) 3.4.0"
compilation line:
m68k-elf-gcc -S fibonacci.c -o fibonaccireport.s
Compilation finished at Wed Jun 30 23:36:14
The gcc was compiled in Fedora linux with the folowing:
--target=m68k-elf --with-gnu-as --with-gnu-ld --with-newlib
--enable-languages=c++,c. The binutils was installed with the same target.
--
Summary: Error passing constant as argument in m68k and address
mode problem
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: critical
Priority: P1
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ra010062 at ic dot unicamp dot br
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16308
More information about the Gcc-bugs
mailing list