]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/ldso/ldso/i386/dl-startup.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / ldso / ldso / i386 / dl-startup.h
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Architecture specific code used by dl-startup.c
4  * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
5  */
6 __asm__ (
7     "   .text\n"
8     "   .globl  _start\n"
9     "   .type   _start,@function\n"
10     "_start:\n"
11     "   call _dl_start\n"
12     "   # Save the user entry point address in %edi.\n"
13     "   movl %eax, %edi\n"
14     "   # Point %ebx at the GOT.\n"
15     "   call 1f\n"
16     "1: popl    %ebx\n"
17     "   addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx\n"
18     "   # See if we were run as a command with the executable file\n"
19     "   # name as an extra leading argument.\n"
20     "   movl _dl_skip_args@GOTOFF(%ebx), %eax\n"
21     "   # Pop the original argument count.\n"
22     "   popl %edx\n"
23     "   # Adjust the stack pointer to skip _dl_skip_args words.\n"
24     "   leal (%esp,%eax,4), %esp\n"
25     "   # Subtract _dl_skip_args from argc.\n"
26     "   subl %eax, %edx\n"
27     "   # Push argc back on the stack.\n"
28     "   push %edx\n"
29     "   # Pass our FINI ptr() to the user in %edx, as per ELF ABI.\n"
30     "   leal _dl_fini@GOTOFF(%ebx), %edx\n"
31     "   # Jump to the user's entry point.\n"
32     "   jmp *%edi\n"
33     "   .size   _start,.-_start\n"
34     "   .previous\n"
35 );
36
37 /* Get a pointer to the argv array.  On many platforms this can be just
38  * the address of the first argument, on other platforms we need to
39  * do something a little more subtle here.  */
40 #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) & ARGS)+1)
41
42 /* Handle relocation of the symbols in the dynamic loader. */
43 static __always_inline
44 void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
45         unsigned long symbol_addr, unsigned long load_addr, attribute_unused Elf32_Sym *symtab)
46 {
47         switch (ELF32_R_TYPE(rpnt->r_info))
48         {
49                 case R_386_32:
50                         *reloc_addr += symbol_addr;
51                         break;
52                 case R_386_PC32:
53                         *reloc_addr += symbol_addr - (unsigned long) reloc_addr;
54                         break;
55                 case R_386_GLOB_DAT:
56                 case R_386_JMP_SLOT:
57                         *reloc_addr = symbol_addr;
58                         break;
59                 case R_386_RELATIVE:
60                         *reloc_addr += load_addr;
61                         break;
62                 default:
63                         _dl_exit(1);
64         }
65 }