dl-startup.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Architecture specific code used by dl-startup.c
  3. * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
  4. */
  5. __asm__ (
  6. " .text\n"
  7. " .globl _start\n"
  8. " .type _start,@function\n"
  9. " .hidden _start\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. /* Get a pointer to the argv array. On many platforms this can be just
  37. * the address of the first argument, on other platforms we need to
  38. * do something a little more subtle here. */
  39. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) & ARGS)+1)
  40. /* Handle relocation of the symbols in the dynamic loader. */
  41. static __always_inline
  42. void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
  43. unsigned long symbol_addr, unsigned long load_addr, attribute_unused Elf32_Sym *symtab)
  44. {
  45. switch (ELF_R_TYPE(rpnt->r_info))
  46. {
  47. case R_386_32:
  48. *reloc_addr += symbol_addr;
  49. break;
  50. case R_386_PC32:
  51. *reloc_addr += symbol_addr - (unsigned long) reloc_addr;
  52. break;
  53. case R_386_GLOB_DAT:
  54. case R_386_JMP_SLOT:
  55. *reloc_addr = symbol_addr;
  56. break;
  57. case R_386_RELATIVE:
  58. *reloc_addr += load_addr;
  59. break;
  60. default:
  61. _dl_exit(1);
  62. }
  63. }