diff --git a/base-linux/lib/mk/arm/startup.mk b/base-linux/lib/mk/arm/startup.mk deleted file mode 100644 index fdcb7c4fd..000000000 --- a/base-linux/lib/mk/arm/startup.mk +++ /dev/null @@ -1,5 +0,0 @@ -LIBS += syscall - -include $(BASE_DIR)/lib/mk/startup.inc - -vpath crt0.s $(REP_DIR)/src/platform/arm diff --git a/base-linux/lib/mk/x86_32/startup.mk b/base-linux/lib/mk/x86_32/startup.mk deleted file mode 100644 index de2ff3bf9..000000000 --- a/base-linux/lib/mk/x86_32/startup.mk +++ /dev/null @@ -1,5 +0,0 @@ -LIBS += syscall - -include $(BASE_DIR)/lib/mk/startup.inc - -vpath crt0.s $(REP_DIR)/src/platform/x86_32 diff --git a/base-linux/lib/mk/x86_64/startup.mk b/base-linux/lib/mk/x86_64/startup.mk deleted file mode 100644 index c10565d9b..000000000 --- a/base-linux/lib/mk/x86_64/startup.mk +++ /dev/null @@ -1,5 +0,0 @@ -LIBS += syscall - -include $(BASE_DIR)/lib/mk/startup.inc - -vpath crt0.s $(REP_DIR)/src/platform/x86_64 diff --git a/base-linux/src/platform/_main_helper.h b/base-linux/src/platform/_main_helper.h index 98a419431..7cdb5b60c 100644 --- a/base-linux/src/platform/_main_helper.h +++ b/base-linux/src/platform/_main_helper.h @@ -19,11 +19,9 @@ #include /* - * Define 'lx_environ' pointer that is supposed to be initialized by the - * startup code. + * Define 'lx_environ' pointer. */ -__attribute__((weak)) char **lx_environ = (char **)0; - +char **lx_environ; /** @@ -36,6 +34,20 @@ static inline void main_thread_bootstrap() { using namespace Genode; + extern Genode::addr_t *__initial_sp; + + /* + * Initialize the 'lx_environ' pointer + * + * environ = &argv[argc + 1] + * __initial_sp[0] = argc (always 1 in Genode) + * __initial_sp[1] = argv[0] + * __initial_sp[2] = NULL + * __initial_sp[3] = environ + * + */ + lx_environ = (char**)&__initial_sp[3]; + /* reserve context area */ Genode::addr_t base = Native_config::context_area_virtual_base(); Genode::size_t size = Native_config::context_area_virtual_size(); diff --git a/base-linux/src/platform/arm/crt0.s b/base-linux/src/platform/arm/crt0.s deleted file mode 100644 index ce570f4ab..000000000 --- a/base-linux/src/platform/arm/crt0.s +++ /dev/null @@ -1,66 +0,0 @@ -/* - * \brief Startup code for Genode applications - * \author Christian Helmuth - * \author Christian Prochaska - * \date 2006-07-06 - */ - -/* - * Copyright (C) 2006-2012 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/*--- .text (program code) -------------------------*/ - .text - - .globl _start -_start: - - ldr r1,=__initial_sp - str sp,[r1] - - /* - * environ = &argv[argc + 1] - * in Genode argc is always 1 - */ - add sp,sp,#12 - ldr r1,=lx_environ - str sp,[r1] - - /* XXX Switch to our own stack. */ - ldr sp,=_stack_high - - /* Clear the frame pointer and the link register so that stack backtraces will work. */ - mov fp,#0 - mov lr,#0 - - /* Jump into init C code */ - b _main - -/*--------------------------------------------------*/ - .data - .globl __dso_handle -__dso_handle: - .long 0 - - .globl __initial_sp -__initial_sp: - .long 0 - -/*--- .eh_frame (exception frames) -----------------*/ -/* - .section .eh_frame,"aw" - .globl __EH_FRAME_BEGIN__ -__EH_FRAME_BEGIN__: -*/ - -/*--- .bss (non-initialized data) ------------------*/ - .bss - .p2align 4 - .globl _stack_low -_stack_low: - .space 64*1024 - .globl _stack_high -_stack_high: diff --git a/base-linux/src/platform/x86_32/crt0.s b/base-linux/src/platform/x86_32/crt0.s deleted file mode 100644 index 20d64a037..000000000 --- a/base-linux/src/platform/x86_32/crt0.s +++ /dev/null @@ -1,70 +0,0 @@ -/* - * \brief Startup code for Genode applications - * \author Christian Helmuth - * \date 2006-07-06 - */ - -/* - * Copyright (C) 2006-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/*--- .text (program code) -------------------------*/ - .text - - .globl _start -_start: - - movl %esp, __initial_sp - /* - * environ = &argv[argc + 1] - * in Genode argc is always 1 - */ - popl %eax /* argc */ - popl %eax /* argv[0] */ - popl %eax /* NULL */ - movl %esp, lx_environ - - /* XXX Switch to our own stack. */ - movl $_stack_high,%esp - - /* Clear the base pointer so that stack backtraces will work. */ - xorl %ebp,%ebp - - /* Jump into init C code */ - call _main - - /* We should never get here since _main does not return */ -1: int $3 - jmp 2f - .ascii "_main() returned." -2: jmp 1b - - -/*--------------------------------------------------*/ - .data - .globl __dso_handle -__dso_handle: - .long 0 - - .globl __initial_sp -__initial_sp: - .long 0 - -/*--- .eh_frame (exception frames) -----------------*/ -/* - .section .eh_frame,"aw" - .globl __EH_FRAME_BEGIN__ -__EH_FRAME_BEGIN__: -*/ - -/*--- .bss (non-initialized data) ------------------*/ - .bss - .p2align 4 - .globl _stack_low -_stack_low: - .space 64*1024 - .globl _stack_high -_stack_high: diff --git a/base-linux/src/platform/x86_64/crt0.s b/base-linux/src/platform/x86_64/crt0.s deleted file mode 100644 index 4c6f4e139..000000000 --- a/base-linux/src/platform/x86_64/crt0.s +++ /dev/null @@ -1,74 +0,0 @@ -/* - * \brief Startup code for Genode applications - * \author Christian Helmuth - * \date 2006-07-06 - */ - -/* - * Copyright (C) 2006-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/*--- .text (program code) -------------------------*/ - .text - - .globl _start -_start: - - movq __initial_sp@GOTPCREL(%rip), %rax - movq %rsp, (%rax) - /* - * environ = &argv[argc + 1] - * in Genode argc is always 1 - */ - popq %rax /* argc */ - popq %rax /* argv[0] */ - popq %rax /* NULL */ - movq lx_environ@GOTPCREL(%rip), %rax - movq %rsp, (%rax) - - /* XXX Switch to our own stack. */ - leaq _stack_high@GOTPCREL(%rip), %rax - movq (%rax), %rsp - - /* Clear the base pointer so that stack backtraces will work. */ - xorq %rbp,%rbp - - /* Jump into init C code */ - callq _main - - /* We should never get here since _main does not return */ -1: int $3 - jmp 2f - .ascii "_main() returned." -2: jmp 1b - - -/*--------------------------------------------------*/ - .data - .p2align 8 - .globl __dso_handle -__dso_handle: - .quad 0 - - .globl __initial_sp -__initial_sp: - .quad 0 - -/*--- .eh_frame (exception frames) -----------------*/ -/* - .section .eh_frame,"aw" - .globl __EH_FRAME_BEGIN__ -__EH_FRAME_BEGIN__: -*/ - -/*--- .bss (non-initialized data) ------------------*/ - .bss - .p2align 8 - .globl _stack_low -_stack_low: - .space 64*1024 - .globl _stack_high -_stack_high: diff --git a/base/lib/mk/startup.inc b/base/lib/mk/startup.inc index b984a4369..21a8aecb1 100644 --- a/base/lib/mk/startup.inc +++ b/base/lib/mk/startup.inc @@ -3,4 +3,6 @@ SRC_CC += _main.cc REP_INC_DIR += src/platform +LIBS += syscall + vpath _main.cc $(BASE_DIR)/src/platform diff --git a/base/src/platform/arm/crt0.s b/base/src/platform/arm/crt0.s index c260e259c..6ab9e245e 100644 --- a/base/src/platform/arm/crt0.s +++ b/base/src/platform/arm/crt0.s @@ -26,15 +26,8 @@ _start: .initial_sp: .word __initial_sp .stack_high: .word _stack_high -/*--------------------------------------------------*/ - .data .globl __dso_handle -__dso_handle: - .long 0 - - .globl __initial_sp -__initial_sp: - .long 0 +__dso_handle: .long 0 /*--- .bss (non-initialized data) ------------------*/ .section ".bss" @@ -46,10 +39,6 @@ _stack_low: .globl _stack_high _stack_high: - /* - * Symbol referenced by ldso's crt0.s, which is needed by base-hw only. - * It is defined here merely to resolve the symbol for non-base-hw - * platforms. - */ - .globl _main_utcb - _main_utcb: .long 0 + /* initial value of the SP register */ + .globl __initial_sp +__initial_sp: .space 4 diff --git a/base/src/platform/x86_32/crt0.s b/base/src/platform/x86_32/crt0.s index 1a0bd6a14..2952f173e 100644 --- a/base/src/platform/x86_32/crt0.s +++ b/base/src/platform/x86_32/crt0.s @@ -33,16 +33,8 @@ _start: .ascii "_main() returned." 2: jmp 1b - -/*--------------------------------------------------*/ - .data .globl __dso_handle -__dso_handle: - .long 0 - - .globl __initial_sp -__initial_sp: - .long 0 +__dso_handle: .long 0 /*--- .eh_frame (exception frames) -----------------*/ /* @@ -59,3 +51,7 @@ _stack_low: .space 64*1024 .global _stack_high _stack_high: + + /* initial value of the ESP register */ + .globl __initial_sp +__initial_sp: .space 4 diff --git a/base/src/platform/x86_64/crt0.s b/base/src/platform/x86_64/crt0.s index aacbdec04..4d1edc74a 100644 --- a/base/src/platform/x86_64/crt0.s +++ b/base/src/platform/x86_64/crt0.s @@ -36,17 +36,8 @@ _start: .ascii "_main() returned." 2: jmp 1b - -/*--------------------------------------------------*/ - .data - .p2align 8 .globl __dso_handle -__dso_handle: - .quad 0 - - .globl __initial_sp -__initial_sp: - .quad 0 +__dso_handle: .quad 0 /*--- .eh_frame (exception frames) -----------------*/ /* @@ -63,3 +54,7 @@ _stack_low: .space 64*1024 .global _stack_high _stack_high: + + /* initial value of the RSP register */ + .globl __initial_sp +__initial_sp: .space 8 diff --git a/os/lib/mk/arm/ldso_crt0_lx.mk b/os/lib/mk/arm/ldso_crt0_lx.mk deleted file mode 100644 index 39c497073..000000000 --- a/os/lib/mk/arm/ldso_crt0_lx.mk +++ /dev/null @@ -1,3 +0,0 @@ -SRC_S = crt0.s - -vpath crt0.s $(REP_DIR)/src/lib/ldso/arm/linux diff --git a/os/lib/mk/linux/ldso-arch.mk b/os/lib/mk/linux/ldso-arch.mk index a525589e6..862721c22 100644 --- a/os/lib/mk/linux/ldso-arch.mk +++ b/os/lib/mk/linux/ldso-arch.mk @@ -1,6 +1,6 @@ SRC_CC = parent_cap.cc binary_name.cc -LIBS = ldso_crt0_lx +LIBS = ldso_crt0 vpath parent_cap.cc $(REP_DIR)/src/lib/ldso/arch/linux vpath binary_name.cc $(REP_DIR)/src/lib/ldso/arch/linux diff --git a/os/lib/mk/x86_32/ldso_crt0_lx.mk b/os/lib/mk/x86_32/ldso_crt0_lx.mk deleted file mode 100644 index 542b66f1c..000000000 --- a/os/lib/mk/x86_32/ldso_crt0_lx.mk +++ /dev/null @@ -1,3 +0,0 @@ -SRC_S = crt0.s - -vpath crt0.s $(REP_DIR)/src/lib/ldso/x86_32/linux/ diff --git a/os/lib/mk/x86_64/ldso_crt0_lx.mk b/os/lib/mk/x86_64/ldso_crt0_lx.mk deleted file mode 100644 index 2b2ef31b0..000000000 --- a/os/lib/mk/x86_64/ldso_crt0_lx.mk +++ /dev/null @@ -1,3 +0,0 @@ -SRC_S = crt0.s - -vpath crt0.s $(REP_DIR)/src/lib/ldso/x86_64/linux/ diff --git a/os/src/lib/ldso/arm/crt0.s b/os/src/lib/ldso/arm/crt0.s index 529a1da5e..0de856d11 100644 --- a/os/src/lib/ldso/arm/crt0.s +++ b/os/src/lib/ldso/arm/crt0.s @@ -17,9 +17,6 @@ .globl _start_ldso _start_ldso: - ldr r2, .initial_utcb - str r0, [r2] - ldr r2, .initial_sp str sp, [r2] @@ -29,5 +26,4 @@ _start_ldso: .initial_sp: .word __initial_sp .stack_high: .word _stack_high - .initial_utcb: .word _main_utcb diff --git a/os/src/lib/ldso/arm/linux/crt0.s b/os/src/lib/ldso/arm/linux/crt0.s deleted file mode 100644 index 8ac1d1439..000000000 --- a/os/src/lib/ldso/arm/linux/crt0.s +++ /dev/null @@ -1,58 +0,0 @@ -/* - * \brief Startup code for ld.lib.so (linux_arm) - * \author Christian Prochaska - * \date 2012-07-06 - */ - -/* - * Copyright (C) 2012 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/*--- .text (program code) -------------------------*/ -.section ".text.crt0" - - .globl _start_ldso -_start_ldso: - - ldr sl, .L_GOT -.L_GOT_OFF: - add sl, pc, sl - - ldr r1, .initial_sp - ldr r1, [sl, r1] - str sp, [r1] - - /* - * environ = &argv[argc + 1] - * in Genode argc is always 1 - */ - add sp, sp,#12 - ldr r1, .lx_environ - ldr r1, [sl, r1] - str sp, [r1] - - /* XXX Switch to our own stack. */ - ldr r1, .stack_high - ldr sp, [sl, r1] - - /* relocate ldso */ - mov r1, #0 - bl init_rtld - - /* - * Clear the frame pointer and the link register so that stack - * backtraces will work. - */ - mov fp, #0 - mov lr, #0 - - /* Jump into init C code */ - b _main - - .L_GOT: .word _GLOBAL_OFFSET_TABLE_ - (.L_GOT_OFF + 8) - .initial_sp: .word __initial_sp(GOT) - .lx_environ: .word lx_environ(GOT) - .stack_high: .word _stack_high(GOT) diff --git a/os/src/lib/ldso/include/arm/call_main.h b/os/src/lib/ldso/include/arm/call_main.h index 2af320382..20bb350c1 100644 --- a/os/src/lib/ldso/include/arm/call_main.h +++ b/os/src/lib/ldso/include/arm/call_main.h @@ -13,9 +13,9 @@ #ifndef _ARM__CALL_MAIN_H_ #define _ARM__CALL_MAIN_H_ - /** - * Restore SP from initial sp and jump to entry function - */ +/** + * Restore SP from initial sp and jump to entry function + */ void call_main(void (*func)(void)) { extern long __initial_sp; diff --git a/os/src/lib/ldso/include/x86_32/call_main.h b/os/src/lib/ldso/include/x86_32/call_main.h index 3aa5f0b3b..ab22c8c9b 100644 --- a/os/src/lib/ldso/include/x86_32/call_main.h +++ b/os/src/lib/ldso/include/x86_32/call_main.h @@ -13,9 +13,9 @@ #ifndef _X86_32__CALL_MAIN_H_ #define _X86_32__CALL_MAIN_H_ - /** - * Restore SP from initial sp and jump to entry function - */ +/** + * Restore SP from initial sp and jump to entry function + */ void call_main(void (*func)(void)) { extern long __initial_sp; diff --git a/os/src/lib/ldso/main.c b/os/src/lib/ldso/main.c index b5e836dc5..55bca60b5 100644 --- a/os/src/lib/ldso/main.c +++ b/os/src/lib/ldso/main.c @@ -52,7 +52,7 @@ static void *setup_stack(const char *name, long fd) (char*)fd, (char*)AT_NULL, //AT terminator }; - + void *sp = malloc(sizeof(sp_argc) + sizeof(sp_argv) + (env_count * sizeof(long)) + sizeof(sp_at)); void *sp_tmp = sp; @@ -88,6 +88,8 @@ int main(int argc, char **argv) void *sp = setup_stack(binary, (long)fd); printf("Starting ldso ...\n"); + + /* this is usually '_start' */ func_ptr_type main_func = _rtld(sp, &exit_proc, &objp); /* DEBUGGING @@ -97,11 +99,11 @@ int main(int argc, char **argv) */ /* start loaded application */ printf("Starting application ... environ: %p\n", lx_environ); - + call_main(main_func); exit_proc(); - + printf("Exiting ldso\n"); return 0; } diff --git a/os/src/lib/ldso/x86_32/linux/crt0.s b/os/src/lib/ldso/x86_32/linux/crt0.s deleted file mode 100644 index 8003823fc..000000000 --- a/os/src/lib/ldso/x86_32/linux/crt0.s +++ /dev/null @@ -1,54 +0,0 @@ -/* - * \brief Startup code for Genode applications - * \author Christian Helmuth - * \date 2006-07-06 - */ - -/* - * Copyright (C) 2006-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/*--- .text (program code) -------------------------*/ - .text - - .globl _start_ldso -_start_ldso: - - /* set global offset table the taditional way */ - call 3f -3: - popl %ebx; - addl $_GLOBAL_OFFSET_TABLE_+ (. - 3b), %ebx - - movl %esp, __initial_sp@GOTOFF(%ebx) - - /* - * environ = &argv[argc + 1] - * in Genode argc is always 1 - */ - popl %eax /* argc */ - popl %eax /* argv[0] */ - popl %eax /* NULL */ - movl %esp, lx_environ@GOTOFF(%ebx) - - /* XXX Switch to our own stack. */ - leal _stack_high@GOTOFF(%ebx), %esp - - /* relocate ldso */ - call init_rtld - - /* Clear the base pointer so that stack backtraces will work. */ - xorl %ebp,%ebp - - /* Jump into init C code */ - call _main - - /* We should never get here since _main does not return */ -1: int $3 - jmp 2f - .ascii "_main() returned." -2: jmp 1b - diff --git a/os/src/lib/ldso/x86_64/linux/crt0.s b/os/src/lib/ldso/x86_64/linux/crt0.s deleted file mode 100644 index 5bcd66035..000000000 --- a/os/src/lib/ldso/x86_64/linux/crt0.s +++ /dev/null @@ -1,52 +0,0 @@ -/* - * \brief Startup code for ldso 64Bit-Linux version - * \author Christian Helmuth - * \author Sebastian Sumpf - * \date 2011-05-10 - */ - -/* - * Copyright (C) 2011-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/*--- .text (program code) -------------------------*/ - .text - - .globl _start_ldso -_start_ldso: - - /* initialize GLOBAL OFFSET TABLE */ - leaq _GLOBAL_OFFSET_TABLE_(%rip),%r15 - - movq __initial_sp@GOTPCREL(%rip), %rax - movq %rsp, (%rax) - /* - * environ = &argv[argc + 1] - * in Genode argc is always 1 - */ - popq %rax /* argc */ - popq %rax /* argv[0] */ - popq %rax /* NULL */ - movq lx_environ@GOTPCREL(%rip), %rax - movq %rsp, (%rax) - - /* XXX Switch to our own stack. */ - leaq _stack_high@GOTPCREL(%rip),%rax - movq (%rax), %rsp - - call init_rtld - - /* Clear the base pointer so that stack backtraces will work. */ - xorq %rbp,%rbp - - /* Jump into init C code */ - call _main - - /* We should never get here since _main does not return */ -1: int $3 - jmp 2f - .ascii "_main() returned." -2: jmp 1b