diff --git a/src/kernel/glue/Jamfile b/src/kernel/glue/Jamfile index e8a2a6097b..2acd866a6a 100755 --- a/src/kernel/glue/Jamfile +++ b/src/kernel/glue/Jamfile @@ -1,8 +1,8 @@ SubDir OBOS_TOP src kernel glue ; KernelObjects - crt0.c init_term_dyn.c start_dyn.c ; +SubInclude OBOS_TOP src kernel glue arch ; diff --git a/src/kernel/glue/arch/Jamfile b/src/kernel/glue/arch/Jamfile new file mode 100644 index 0000000000..4b6b6f7a6b --- /dev/null +++ b/src/kernel/glue/arch/Jamfile @@ -0,0 +1 @@ +SubInclude OBOS_TOP src kernel glue arch $(OBOS_ARCH) ; diff --git a/src/kernel/glue/arch/x86/Jamfile b/src/kernel/glue/arch/x86/Jamfile new file mode 100644 index 0000000000..21d6039251 --- /dev/null +++ b/src/kernel/glue/arch/x86/Jamfile @@ -0,0 +1,7 @@ +SubDir OBOS_TOP src kernel glue arch x86 ; + +KernelObjects + crti.S + crtn.S + ; + diff --git a/src/kernel/glue/arch/x86/crti.S b/src/kernel/glue/arch/x86/crti.S new file mode 100644 index 0000000000..0fafe1ee27 --- /dev/null +++ b/src/kernel/glue/arch/x86/crti.S @@ -0,0 +1,38 @@ +/* + * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + +/** This file contains the first part of the ".init" and ".fini" sections in + * the ELF executable. + * The functions defined here will be called during initialization/termination + * of the loaded executable/library. The ".init" and ".fini" sections are + * stacked together like this: + * + * crti.S entry point + * call to _init_before/_term_before + * crtbegin.S GCC specific: constructors/destructors are called, ... + * crtend.S + * crtn.S call to _init_after/_term_after + * exit + */ + +#define FUNCTION(x) .global x; .type x,@function; x + +.section .init +FUNCTION(_init): + pushl %ebp + movl %esp, %ebp + pushl 0xc(%ebp) // program args + pushl 0x8(%ebp) // image ID + call _init_before + // crtbegin.o stuff comes here + +.section .fini +FUNCTION(_fini): + pushl %ebp + movl %esp, %ebp + pushl 0xc(%ebp) // program args + pushl 0x8(%ebp) // image ID + call _term_before + // crtbegin.o stuff comes here diff --git a/src/kernel/glue/arch/x86/crtn.S b/src/kernel/glue/arch/x86/crtn.S new file mode 100644 index 0000000000..3cf2cb1c10 --- /dev/null +++ b/src/kernel/glue/arch/x86/crtn.S @@ -0,0 +1,23 @@ +/* + * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + +/** This file contains the final part of the ".init" and ".fini" sections in + * the ELF executable. It is tightly connected to crti.S. + * Have a look at crti.S to find a description of what happens here. + */ + +.section .init + // the image ID and program args are still on the stack + call _init_after + movl %ebp, %esp + popl %ebp + ret + +.section .fini + // the image ID and program args are still on the stack + call _term_after + movl %ebp, %esp + popl %ebp + ret diff --git a/src/kernel/glue/crt0.c b/src/kernel/glue/crt0.c deleted file mode 100755 index 9d8d8ff36f..0000000000 --- a/src/kernel/glue/crt0.c +++ /dev/null @@ -1,62 +0,0 @@ -/* -** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ - - -#include "init_term_dyn.h" - - -void _init(int id, void *args) __attribute__((section(".init"))); -void _fini(int id, void *args) __attribute__((section(".fini"))); - -// constructor/destructor lists as defined in the ld-script -extern void (*__ctor_list)(void); -extern void (*__ctor_end)(void); -extern void (*__dtor_list)(void); -extern void (*__dtor_end)(void); - - -static void -_call_ctors(void) -{ - void (**f)(void); - - for (f = &__ctor_list; f < &__ctor_end; f++) { - (**f)(); - } -} - - -static void -_call_dtors(void) -{ - void (**f)(void); - - for (f = &__dtor_list; f < &__dtor_end; f++) { - (**f)(); - } -} - - -void -_init(int id, void *args) -{ - _init_before(id, args); - - _call_ctors(); - - _init_after(id, args); -} - - -void -_fini(int id, void *args) -{ - _term_before(id, args); - - _call_dtors(); - - _term_after(id, args); -} - diff --git a/src/kernel/glue/init_term_dyn.c b/src/kernel/glue/init_term_dyn.c index d9e7d70aff..d19051db4f 100644 --- a/src/kernel/glue/init_term_dyn.c +++ b/src/kernel/glue/init_term_dyn.c @@ -1,7 +1,7 @@ -/* -** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ +/* + * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include @@ -10,11 +10,11 @@ #include "init_term_dyn.h" -/* These functions are called from _init()/_fini() (in crti.S, crtn.S) - * _init/fini_before() is called before crtbegin/end code is executed, - * _init/fini_after() after this. - * crtbegin contains code to initialize all global constructors and - * probably other GCC related things. +/** These functions are called from _init()/_fini() (in crti.S, crtn.S) + * _init/_term_before() is called before crtbegin/end code is executed, + * _init/_term_after() after this. + * crtbegin contains code to initialize all global constructors and + * other GCC related things (like exception frames). */