[PATCH]: Make Sparc Target Multi-Arch

Peter.Schauer Peter.Schauer@regent.e-technik.tu-muenchen.de
Wed May 3 02:14:00 GMT 2000


> Kevin
> (who still doesn't understand the problem with AT_ENTRY_POINT on
> Sparc32)

For details of the ABI see the Sparc Architecture Manual.
I have Version 8 (Prentice Hall ISBN 0-13-825001-4) and the calling
conventions for functions returning aggregate values are explained
in Appendix D.3.

Here is a short summary:

Given

struct x
{
  int a[4];
};

struct x gx;

struct x
sret ()
{
  return gx;
}

main ()
{
  int i;
  for (i = 0; i < 4; i++)
    gx.a[i] = i + 1;
  gx = sret ();
}

Sun Sparc32 cc generates the following code:

sret:
        save    %sp,-104,%sp
        sethi   %hi(gx),%l0
        or      %l0,%lo(gx),%l0
        st      %l0,[%fp-4]
        ba      .L14
        nop

        ! block 2
.L14:
        ld      [%fp-4],%l0
        mov     %l0,%o0
        or      %g0,16,%o1
        call    .stret4
        nop
	.
	.
	.
!   19    gx = sret ();

        add     %fp,-24,%l2
        call    sret
        st      %l2,[%sp+64]
        unimp   16

where .stret4 is a library function, which contains

0xef716a88 <.stret4>:   ld  [ %i7 + 8 ], %o3
0xef716a8c <.stret4+4>: and  %o1, 0xfff, %o4
0xef716a90 <.stret4+8>: sethi  %hi(0), %o5
0xef716a94 <.stret4+12>:        or  %o4, %o5, %o5
0xef716a98 <.stret4+16>:        cmp  %o5, %o3
0xef716a9c <.stret4+20>:        bne  0xef716ab8 <.stret4+48>
0xef716aa0 <.stret4+24>:        ld  [ %fp + 0x40 ], %i0
0xef716aa4 <.stret4+28>:        subcc  %o1, 4, %o1
0xef716aa8 <.stret4+32>:        ld  [ %o0 + %o1 ], %o4
0xef716aac <.stret4+36>:        bg  0xef716aa4 <.stret4+28>
0xef716ab0 <.stret4+40>:        st  %o4, [ %i0 + %o1 ]
0xef716ab4 <.stret4+44>:        add  %i7, 4, %i7
0xef716ab8 <.stret4+48>:        ret
0xef716abc <.stret4+52>:        restore

The extra unimp word after the `call sret' contains the size of the
struct return value expected by the caller, which is checked in .stret4,
so that the callee does not clobber memory in the caller (if the caller
does for some reason not expect a struct return value or expects a structure
with a different size).

If we are using ON_STACK, sparc_fix_call_dummy patches the unimp instruction
in the call dummy code to contain the right value.

If we are using AT_ENTRY, we would have to put the extra unimp instruction
after the entry point, but I consider that dangerous.

gcc generated code for sret does not check the unimp word, so there is
no problem with gcc compiled code.

Hope that explains the issue,

-- 
Peter Schauer			pes@regent.e-technik.tu-muenchen.de


More information about the Gdb-patches mailing list