From: Jan-Benedict G. <jb...@us...> - 2005-09-24 22:13:57
|
Update of /cvsroot/linux-vax/toolchain/patches In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19128 Added Files: uclibc-000003-crt0-part1.patch Log Message: - First round of crt0.S games. - It's yet wrong (wrong {,number of} argument{s,} pushed onto the stack for the final call into uClibc), but I'll now try to attempt to link a minimal main() function with this. - Does anybody know a correct linker call for this beforehand? --- NEW FILE: uclibc-000003-crt0-part1.patch --- diff -Nurp src-uclibc-fresh/libc/sysdeps/linux/vax/clone.S src-uclibc-hacked/libc/sysdeps/linux/vax/clone.S --- src-uclibc-fresh/libc/sysdeps/linux/vax/clone.S 2005-09-24 11:12:03.000000000 +0200 +++ src-uclibc-hacked/libc/sysdeps/linux/vax/clone.S 2005-09-24 13:18:07.000000000 +0200 @@ -21,28 +21,27 @@ #include <bits/errno.h> #include <sys/syscall.h> -.section .rodata - .align 2 -.LC0: - .long 120 +.section .rodata + .align 2 +.LC0: .long 120 /* SYS_clone */ .text -.align 4 + .align 4 .type __clone,@function .globl __clone; __clone: - .word 0x40 -/* subl2 $8, %sp */ + .word 0x0040 + /* subl2 $8, %sp */ movl 4(%ap), %r1 movl 8(%ap), %r0 - mcoml $21,%r6 + mcoml $21, %r6 - /* sanity check args */ + /* Sanity check args. */ tstl %r1 jeql CLONE_ERROR_LABEL tstl %r0 jeql CLONE_ERROR_LABEL - /* need to setup the child stack the same as the parent */ + /* Need to setup the child stack the same as the parent. */ subl2 $24, %r0 movl 16(%ap), 20(%r0) movl %r1, 16(%r0) @@ -50,36 +49,37 @@ __clone: addl2 $16, %r1 movl %r1, 12(%r0) - /* do the system call */ + /* Do the system call. */ pushl %ap pushl %r0 - pushl 12(%ap) + pushl 12(%ap) pushl $0x2 movl %sp, %ap - chmk .LC0 # %r0 .LC0 -4(%fp) -8(%fp) + chmk .LC0 /* %r0 .LC0 -4(%fp) -8(%fp) */ addl2 $12, %sp movl (%sp)+, %ap - movl %r0,%r6 + movl %r0, %r6 jneq CLONE_ERROR_LABEL movl $0, %fp pushl 4(%ap) movl (%r1), %r0 - calls $1,(%r0) + calls $1, (%r0) pushl %r0 calls $1, _exit + CLONE_ERROR_LABEL: - cmpl %r6, $-126 + cmpl %r6, $-126 /* -ENOKEY?!?! Fuck, this must be wrong! */ jlequ CLONE_RETURN_LABEL calls $0, __errno_location - mnegl %r6,(%r0) - mcoml $0,%r6 - movl %r6,%r0 + mnegl %r6, (%r0) + mcoml $0, %r6 + movl %r6, %r0 ret CLONE_RETURN_LABEL: ret .globl clone; - clone = __clone + clone = __clone diff -Nurp src-uclibc-fresh/libc/sysdeps/linux/vax/crt0.S src-uclibc-hacked/libc/sysdeps/linux/vax/crt0.S --- src-uclibc-fresh/libc/sysdeps/linux/vax/crt0.S 2005-09-24 11:12:03.000000000 +0200 +++ src-uclibc-hacked/libc/sysdeps/linux/vax/crt0.S 1970-01-01 01:00:00.000000000 +0100 @@ -1,58 +0,0 @@ -/* crt0 for VAX */ - -/* program stack looks like - argc argument counter (integer) - argv[0] program name (pointer) - argv[1...N] program args (pointers) - argv[argc-1] end of args (integer) - NULL - env[0...N] environment variables (pointers) - NULL -*/ - -#include <features.h> - -.text -.align 4 - -.global __start -__start: -.global _start -_start: - .word 0x0101 - /* clear the frame pointer */ - movl $0, %fp - - movl (%sp)+, %r4 - movl %sp, %r3 - /* r4 has argc in it .. add one to get over NULL - - move it left shifted 2 into r0 */ - addl3 %r4, $1, %r0 - ashl $2, %r0, %r0 - /* add size of args to r3 to get start of environ into r2 */ - addl3 %r3, %r0, %r2 - - /* */ -#if defined L_crt1 && defined __UCLIBC_CTOR_DTOR__ - /* Push .init and .fini arguments to __uClibc_start_main() on the stack */ - pushl $_fini - pushl $_init - - /* Push envp, argc, and argc arguments to __uClibc_start_main() on the stack */ - pushl %r2 /* Environment pointer */ - pushl %r3 /* Argument pointer */ - pushl %r4 /* And the argument count */ - - /* Ok, now run uClibc's main() -- shouldn't return */ - calls $5, __uClibc_start_main -#else - /* start to load the arguments from the stack */ - /* arguments are on ap stack */ - pushl %r2 - pushl %r3 - pushl %r4 - - calls $3, __uClibc_main -#endif - halt -.align 2 diff -Nurp src-uclibc-fresh/libc/sysdeps/linux/vax/crt1.S src-uclibc-hacked/libc/sysdeps/linux/vax/crt1.S --- src-uclibc-fresh/libc/sysdeps/linux/vax/crt1.S 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libc/sysdeps/linux/vax/crt1.S 2005-09-24 13:04:12.000000000 +0200 @@ -0,0 +1,77 @@ +/* + * crt0 for VAX + */ + +/* + * Program stack looks like: + * sp-> argc argument counter (integer) + * argv[0] program name (pointer) + * argv[1...N] program args (pointers) + * argv[argc-1] end of args (integer) + * NULL + * env[0...N] environment variables (pointers) + * NULL + */ + +#include <features.h> + +.text +.align 4 + +.global __start +__start: +.global _start +_start: + /* Kernel uses a_interp + 2, so __start isn't exactly CALLSed, */ + /* but we need to have two bytes here, so we use NOPs. This */ + /* won't hurt, though R0 would be invalid to push, but at */ + /* lease this looks like a real function. */ + .word 0x0101 + + movl $0, %fp /* FP = 0, since this is the */ + /* top-most stack frame */ + + movl (%sp)+, %r4 /* R4 = argc */ + movl %sp, %r3 /* R3 = argv = &argv[0] */ + addl3 %r4, $1, %r0 /* R0 = argc+1 (including the */ + /* trailing NULL) */ + ashl $2, %r0, %r0 /* R0 *= 4 (length of pointer */ + /* array in bytes) */ + addl3 %r3, %r0, %r2 /* R2 = env = &env[0] (= argv + */ + /* length of argv) */ + +#if (defined L_crt1 || defined L_gcrt1) && defined __UCLIBC_CTOR_DTOR__ + pushl $_fini + pushl $_init + + /* Push envp, argc, and argc arguments to __uClibc_start_main() on the stack */ + pushl %r2 /* Environment pointer */ + pushl %r3 /* Argument pointer */ + pushl %r4 /* And the argument count */ + pushl $main /* main() */ + + /* We need to call __uClibc_main which should not return. + * __uClibc_main (int (*main) (int, char **, char **), + * int argc, + * char **argv, + * void (*init) (void), + * void (*fini) (void), + * void (*rtld_fini) (void), + * void *stack_end); + */ + calls $5, __uClibc_start_main +#else + /* start to load the arguments from the stack */ + /* arguments are on ap stack */ + pushl %r2 + pushl %r3 + pushl %r4 + + calls $3, __uClibc_main +#endif + + /* The above __uClibc_start_main() shouldn't ever return. If it + does, we just crash. */ + halt +.align 2 + diff -Nurp src-uclibc-fresh/libc/sysdeps/linux/vax/crti.S src-uclibc-hacked/libc/sysdeps/linux/vax/crti.S --- src-uclibc-fresh/libc/sysdeps/linux/vax/crti.S 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libc/sysdeps/linux/vax/crti.S 2005-09-24 11:13:20.000000000 +0200 @@ -0,0 +1,30 @@ + .file "initfini.c" + .version "01.01" +gcc2_compiled.: +__gnu_compiled_c: +#APP + + .section .init +#NO_APP + .align 1 +.globl _init + .type _init,@function +_init: + .word 0x0 +#APP + + .align 1 + + + .section .fini +#NO_APP + .align 1 +.globl _fini + .type _fini,@function +_fini: + .word 0x0 +#APP + .align 1 + + + .ident "GCC: (GNU) 2.95.2 19991024 (release) (Linux/VAX CVS)" diff -Nurp src-uclibc-fresh/libc/sysdeps/linux/vax/crtn.S src-uclibc-hacked/libc/sysdeps/linux/vax/crtn.S --- src-uclibc-fresh/libc/sysdeps/linux/vax/crtn.S 1970-01-01 01:00:00.000000000 +0100 +++ src-uclibc-hacked/libc/sysdeps/linux/vax/crtn.S 2005-09-24 11:13:20.000000000 +0200 @@ -0,0 +1,29 @@ + .file "initfini.c" + .version "01.01" +gcc2_compiled.: +__gnu_compiled_c: +#APP + + .section .init +#NO_APP + .align 1 +.globl _init + .type _init,@function +#NO_APP + ret +.Lfe2: + .size _init,.Lfe2-_init +#APP + + .section .fini +#NO_APP + .align 1 +.globl _fini + .type _fini,@function +#NO_APP + ret +.Lfe3: + .size _fini,.Lfe3-_fini +#APP + + .ident "GCC: (GNU) 2.95.2 19991024 (release) (Linux/VAX CVS)" diff -Nurp src-uclibc-fresh/libc/sysdeps/linux/vax/Makefile src-uclibc-hacked/libc/sysdeps/linux/vax/Makefile --- src-uclibc-fresh/libc/sysdeps/linux/vax/Makefile 2005-09-24 11:12:03.000000000 +0200 +++ src-uclibc-hacked/libc/sysdeps/linux/vax/Makefile 2005-09-24 11:35:37.000000000 +0200 @@ -24,8 +24,9 @@ TOPDIR=../../../../ include $(TOPDIR)Rules.mak ASFLAGS=$(CFLAGS) -CRT0_SRC=crt0.S -CRT0_OBJ=crt0.o crt1.o +CRT_SRC=crt1.S +CRT_OBJ=crt1.o +SCRT_OBJ=$(pathsubst %,S%, $(CRT_OBJ)) #SSRC=longjmp.S setjmp.S vfork.S SSRC=__longjmp.S setjmp.S _setjmp.S clone.S @@ -36,11 +37,23 @@ SOBJS=$(patsubst %.S,%.o, $(SSRC)) CSRC=vfork.c _mmap.c brk.c COBJS=$(patsubst %.c,%.o, $(CSRC)) -OBJS=$(SOBJS) $(MOBJ) $(COBJS) +OBJS=$(SOBJS) $(COBJS) +OBJ_LIST=../../../obj.sysdeps.$(TARGET_ARCH) +all: $(OBJ_LIST) -#jbglaw all: $(OBJS) $(LIBC) -all: $(OBJS) +$(OBJ_LIST): $(OBJS) $(CRT_OBJ) $(SCRT_OBJ) $(CTOR_TARGETS) + echo $(patsubst %, sysdeps/linux/$(TARGET_ARCH)/%, $(OBJS)) > $(OBJ_LIST) + $(INSTALL) -d $(TOPDIR)lib/ + cp $(CRT_OBJ) $(SCRT_OBJ) $(TOPDIR)lib/ + +$(CRT_OBJ): $(CRT_SRC) + $(CC) $(ASFLAGS) -DL_$* $< -c -o $*.o + $(STRIPTOOL) -x -R .note -R .comment $*.o + +$(SCRT_OBJ): $(CRT_SRC) + $(CC) $(ASFLAGS) $(PIEFLAG) -DL_$* $< -c -o $*.o + $(STRIPTOOL) -x -R .note -R .comment $*.o $(LIBC): ar-target |