crt1.S start code

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



> sp is a pointer to the array of strings while [sp] is a pointer to the
> first string ...



> sp   -> argv    (*char[])
> [sp] -> argv[0] (char[])

I actully dumped out the stack from kernel , and also dumped stack and a3 
from uClibc, i saw the difference
sp is not a pointer to the array of strings, sp is the stack pointer! [sp] 
actually point to an array of strings!

ldr a3, sp

actually load the stack pointer into a3 and passed into main as the argv , 
which i thought was wrong, and i changed the code into
ldr a3, [sp]  and it worked!

> so if you "load it up into a debbuger", then yes argv will look like
> "garbage" because you have to dereference it once to get at the actual
> string
>
> $ 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