diff --git a/src/system/glue/arch/x86_64/Jamfile b/src/system/glue/arch/x86_64/Jamfile new file mode 100644 index 0000000000..4d43342366 --- /dev/null +++ b/src/system/glue/arch/x86_64/Jamfile @@ -0,0 +1,7 @@ +SubDir HAIKU_TOP src system glue arch x86_64 ; + +KernelObjects + crti.S + crtn.S + ; + diff --git a/src/system/glue/arch/x86_64/crti.S b/src/system/glue/arch/x86_64/crti.S new file mode 100644 index 0000000000..3ef8e5f8df --- /dev/null +++ b/src/system/glue/arch/x86_64/crti.S @@ -0,0 +1,43 @@ +/* + * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. + * Distributed under the terms of the MIT License. + */ + + +#include + + +/** 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 + */ + + +.section .init +FUNCTION(_init): + push %rbp + movq %rsp, %rbp + + // Preserve image ID for call to __haiku_init_after. + push %rdi + + call __haiku_init_before + // crtbegin.o stuff comes here + +.section .fini +FUNCTION(_fini): + push %rbp + movq %rsp, %rbp + push %rdi + call __haiku_term_before + // crtend.o stuff comes here diff --git a/src/system/glue/arch/x86_64/crtn.S b/src/system/glue/arch/x86_64/crtn.S new file mode 100644 index 0000000000..8ed6433843 --- /dev/null +++ b/src/system/glue/arch/x86_64/crtn.S @@ -0,0 +1,27 @@ +/* + * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. + * 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 is preserved on the stack. + pop %rdi + call __haiku_init_after + movq %rbp, %rsp + pop %rbp + ret + +.section .fini + pop %rdi + call __haiku_term_after + movq %rbp, %rsp + pop %rbp + ret