crt1.S start code

Lei Sun lei_sun at comcast.net
Sat Dec 24 01:54:01 UTC 2005


Hi Mike:
   Please refer to my original post on this

_start:

/* clear the frame pointer and link registers */
    mov fp, #0
    mov lr, #0
    /* pop argc off the stack and save a pointer to argv */
    ldr a2, [sp], #4
    mov a3, sp
Here , a3 should be the pointer to array of string.  in the kernel source , 
argv is pushed into start_stack + 4, that's where we should load the value 
into a3, in the original crt1.S code , however, it load the SP itself, which 
is wrong.

In your test code, you loaded [sp] into r1, which is right, didn't really 
prove anything.

thanks!
lei
>
> $ cat test.S
> #define __NR_exit  (0x900000+1)
> #define __NR_write (0x900000+4)
>
> .text
> .global _start
> .type   _start, %function
> _start:
> @ cache argc
> ldr r4, [sp], #4
>
> @ write out argv[0] to stdout
> mov r0, #1
> ldr r1, [sp]
> mov r2, #6     @ assume we execute as './test'
> swi __NR_write
>
> @ and finish up by calling exit(argc)
> mov r0, r4
> swi __NR_exit
>
> $ gcc -c test.S -o test.o
> $ ld test.o -o test
> $ ./test a b c ; echo $'\n'$?
> ./test
> 4
> -mike
> _______________________________________________
> uClibc mailing list
> uClibc at uclibc.org
> http://busybox.net/cgi-bin/mailman/listinfo/uclibc 




More information about the uClibc mailing list