Patch to main() invocation in mips/crt0.S
J. Johnston
jjohnstn@redhat.com
Tue Jan 7 18:45:00 GMT 2003
Richard Sandiford wrote:
> This patch makes mips/crt0.S call main() with the equivalent of:
>
> char *argv[1] = { 0 };
> char *envp[1] = { 0 };
> main (0, argv, envp);
>
> Tested 6 ABIs (o32, o64, EABI32, EABI32/long64, EABI64, EABI64/long32)
> with a mips64vrel-elf build. OK to install?
>
Yes.
-- Jeff J.
> Richard
>
>
> * mips/crt0.S (_start): Allocate 64 bytes of stack instead of 32.
> Pass an empty argv and envp to main().
>
> Index: libgloss/mips/crt0.S
> ===================================================================
> RCS file: /cvs/src/src/libgloss/mips/crt0.S,v
> retrieving revision 1.5
> diff -c -d -p -F^[(a-zA-Z0-9_^#] -r1.5 crt0.S
> *** libgloss/mips/crt0.S 12 Nov 2002 23:14:24 -0000 1.5
> --- libgloss/mips/crt0.S 17 Dec 2002 10:46:50 -0000
> *************** 3:
> *** 157,172 ****
> lw t0,0(a0) # last address of memory available
> la t1,K0BASE # cached kernel memory
> addu t0,t0,t1 # get the end of memory address
> ! /* We must subtract 24 bytes for the 3 8 byte arguments to main, in
> ! case main wants to write them back to the stack. The caller is
> ! supposed to allocate stack space for parameters in registers in
> ! the old MIPS ABIs. We must do this even though we aren't passing
> ! arguments, because main might be declared to have them.
> !
> ! Some ports need a larger alignment for the stack, so we subtract
> ! 32, which satisifes the stack for the arguments and keeps the
> ! stack pointer better aligned. */
> ! subu t0,t0,32 # and generate a starting stack-pointer
> 4:
> move sp,t0 # set stack pointer
> sw sp,__stackbase # keep this for future ref
> --- 157,166 ----
> lw t0,0(a0) # last address of memory available
> la t1,K0BASE # cached kernel memory
> addu t0,t0,t1 # get the end of memory address
> ! /* Allocate 32 bytes for the register parameters. Allocate 16
> ! bytes for a null argv and envp. Round the result up to 64
> ! bytes to preserve alignment. */
> ! subu t0,t0,64
> 4:
> move sp,t0 # set stack pointer
> sw sp,__stackbase # keep this for future ref
> *************** #endif
> *** 213,221 ****
> jal _init # run global constructors
> nop
>
> ! move a0,zero # set argc to 0
> jal main # call the program start function
> ! nop
>
> # fall through to the "exit" routine
> jal exit # call libc exit to run the G++
> --- 207,223 ----
> jal _init # run global constructors
> nop
>
> ! addiu a1,sp,32 # argv = sp + 32
> ! addiu a2,sp,40 # envp = sp + 40
> ! #if __mips64
> ! sd zero,(a1) # argv[argc] = 0
> ! sd zero,(a2) # envp[0] = 0
> ! #else
> ! sw zero,(a1)
> ! sw zero,(a2)
> ! #endif
> jal main # call the program start function
> ! move a0,zero # set argc to 0
>
> # fall through to the "exit" routine
> jal exit # call libc exit to run the G++
More information about the Newlib
mailing list