crt1.S start code
Mike Frysinger
vapier at gentoo.org
Fri Dec 23 22:07:32 UTC 2005
On Fri, Dec 23, 2005 at 10:29:05PM +0100, Thomas Eschenbacher wrote:
> Mike Frysinger wrote:
> > On Fri, Dec 23, 2005 at 03:53:15PM -0500, Lei Sun wrote:
> >
> >>/* 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
> >
> > this code is the same as in glibc and it's worked thus far, so i think
> > it's safe to assume the current code is correct
>
> I can definitely confirm the opposite. I have debugged this, that stuff
> is definitely NOT working for linux/arm, uclinux/arm and also not for
> uclinux/armnommu. Take a board with a real cpu and a debugger and you
> will see what happens!
i dont know what you mean by 'real cpu' but the code works fine on
a netwinder (StrongARM-110) and a nslu2 (XScale-IXP425/IXC1100)
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[])
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
More information about the uClibc
mailing list