MIPS 32-bit ABI stack pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I'm having problems mixing MIPS 32-bit object files compiled
with two different compilers.

1) gcc version 4.4.1 (Sourcery G++ Lite 4.4-305)
2) Green Hills Software (exact version unknown)

Before describing my problem, I'd like to ask a few questions.

GCC supports several MIPS ABIs. Where are they documented?
http://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html
-mabi=32
-mabi=o64
-mabi=n32
-mabi=64
-mabi=eabi

( Links for self reference )
http://gcc.gnu.org/gcc-3.4/mips-abi.html
http://www.cygwin.com/ml/binutils/2003-06/msg00436.html
http://math-atlas.sourceforge.net/devel/assembly/mipsabi32.pdf

Next question, when a function starts, is the stack pointer
(r29) supposed to point to
A) the last live value in the previous frame
OR
B) the first free/available word in the current frame
???

Do different compilers have different conventions/ABIs?

The reason I ask is because, in my default invocation,
gcc seems to consider case B:

$ cat foo.c
extern void bar(void *p);
void foo(void *p) { bar(p); }

$ mips-sde-elf-gcc -S foo.c
  .file  1 "foo.c"
  .section .mdebug.abi32
  .previous
  .gnu_attribute 4, 1
  .text
  .align  2
  .globl  foo
  .set  nomips16
  .set  nomicromips
  .ent  foo
  .type  foo, @function
foo:
  .frame  $fp,24,$31    # vars= 0, regs= 2/0, args= 16, gp= 0
  .mask  0xc0000000,-4
  .fmask  0x00000000,0
  .set  noreorder
  .set  nomacro

  addiu  $sp,$sp,-24
  sw  $31,20($sp)
  sw  $fp,16($sp)
  move  $fp,$sp
  sw  $4,24($fp)
  lw  $4,24($fp)
  jal  bar
  nop

  move  $sp,$fp
  lw  $31,20($sp)
  lw  $fp,16($sp)
  addiu  $sp,$sp,24
  j  $31
  nop

  .set  macro
  .set  reorder
  .end  foo
  .size  foo, .-foo
  .ident  "GCC: (Sourcery G++ Lite 4.4-305) 4.4.1"

gcc stores r4 at fp+24 (fp+24 being the initial value of sp)

But the other compiler seems to consider case A.

_kernel_ini_system:
  addiu   r29,r29,#-0x10
  sw      r31,0x0C(r29)
  sw      r16,0x0(r29)
  or      r16,r4,r0
  sw      r17,0x4(r29)
  ori     r17,r0,#0x1
  jal     0x80159CF4
  lw      r4,0x8(r16)

The GHS compiler preserves the value pointed to by (the inital
value of) sp.

Is my understanding of the problem correct?
If so, how do I make the two compilers agree on calling conventions?

--
Regards.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux