dl-startup.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. " .align 16\n"
  9. " .global _start\n"
  10. " .type _start,%function\n"
  11. "_start:\n"
  12. " movq %rsp, %rdi\n"
  13. " call _dl_start\n"
  14. " # Save the user entry point address in %r12.\n"
  15. " movq %rax, %r12\n"
  16. " # See if we were run as a command with the executable file\n"
  17. " # name as an extra leading argument.\n"
  18. " movl _dl_skip_args(%rip), %eax\n"
  19. " # Pop the original argument count.\n"
  20. " popq %rdx\n"
  21. " # Adjust the stack pointer to skip _dl_skip_args words.\n"
  22. " leaq (%rsp,%rax,8), %rsp\n"
  23. " # Subtract _dl_skip_args from argc.\n"
  24. " subl %eax, %edx\n"
  25. " # Push argc back on the stack.\n"
  26. " pushq %rdx\n"
  27. " # Pass our finalizer function to the user in %rdx, as per ELF ABI.\n"
  28. " leaq _dl_fini(%rip), %rdx\n"
  29. " # And make sure %rsp points to argc stored on the stack.\n"
  30. " movq %r13, %rsp\n"
  31. " # Jump to the user's entry point.\n"
  32. " jmp *%r12\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 if 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, Elf64_Sym *sym)
  44. {
  45. switch (ELF64_R_TYPE(rpnt->r_info)) {
  46. case R_X86_64_GLOB_DAT:
  47. case R_X86_64_JUMP_SLOT:
  48. *reloc_addr = symbol_addr + rpnt->r_addend;
  49. break;
  50. case R_X86_64_DTPMOD64:
  51. *reloc_addr = 1;
  52. break;
  53. case R_X86_64_NONE:
  54. case R_X86_64_DTPOFF64:
  55. break;
  56. case R_X86_64_TPOFF64:
  57. *reloc_addr = sym->st_value + rpnt->r_addend - symbol_addr;
  58. break;
  59. default:
  60. _dl_exit(1);
  61. }
  62. }
  63. /* Transfer control to the user's application, once the dynamic loader is
  64. * done. This routine has to exit the current function, then call the
  65. * _dl_elf_main function. */
  66. #define START() return _dl_elf_main