dl-startup.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Architecture specific code used by dl-startup.c
  3. *
  4. * Copyright (C) 2005-2007 Atmel Corporation
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. /* This is the library loader's main entry point. Let _dl_boot2 do its
  9. * initializations and jump to the application's entry point
  10. * afterwards. */
  11. __asm__(" .text\n"
  12. " .global _start\n"
  13. " .type _start,@function\n"
  14. "_start:\n"
  15. /* All arguments are on the stack initially */
  16. " mov r12, sp\n"
  17. " rcall _dl_start\n"
  18. /* Returns user entry point in r12. Save it. */
  19. " mov r0, r12\n"
  20. /* We're PIC, so get the Global Offset Table */
  21. " lddpc r6, .L_GOT\n"
  22. ".L_RGOT:\n"
  23. " rsub r6, pc\n"
  24. /* Adjust argc and argv according to _dl_skip_args */
  25. " ld.w r1, r6[_dl_skip_args@got]\n"
  26. " ld.w r1, r1[0]\n"
  27. " ld.w r2, sp++\n"
  28. " sub r2, r1\n"
  29. " add sp, sp, r1 << 2\n"
  30. " st.w --sp, r2\n"
  31. /* Load the finalizer function */
  32. " ld.w r12, r6[_dl_fini@got]\n"
  33. /* Jump to the user's entry point */
  34. " mov pc, r0\n\n"
  35. " .align 2\n"
  36. ".L_GOT:"
  37. " .long .L_RGOT - _GLOBAL_OFFSET_TABLE_\n"
  38. " .size _start, . - _start\n"
  39. " .previous\n");
  40. /* Get a pointer to the argv array. On many platforms this can be just
  41. * the address of the first argument, on other platforms we need to
  42. * do something a little more subtle here. */
  43. #define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long *)ARGS + 1)
  44. /* We can't call functions before the GOT has been initialized */
  45. #define NO_FUNCS_BEFORE_BOOTSTRAP
  46. /*
  47. * Relocate the GOT during dynamic loader bootstrap. This will add
  48. * the load address to all entries in the GOT, which is necessary
  49. * because the linker doesn't generate R_AVR32_RELATIVE relocs for the
  50. * GOT.
  51. */
  52. static __always_inline
  53. void PERFORM_BOOTSTRAP_GOT(struct elf_resolve *tpnt)
  54. {
  55. Elf32_Addr i, nr_got;
  56. register Elf32_Addr *__r6 __asm__("r6");
  57. Elf32_Addr *got = __r6;
  58. nr_got = tpnt->dynamic_info[DT_AVR32_GOTSZ_IDX] / sizeof(*got);
  59. for (i = 2; i < nr_got; i++)
  60. got[i] += tpnt->loadaddr;
  61. }
  62. #define PERFORM_BOOTSTRAP_GOT(tpnt) PERFORM_BOOTSTRAP_GOT(tpnt)
  63. /* Handle relocation of the symbols in the dynamic loader. */
  64. static __always_inline
  65. void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
  66. unsigned long symbol_addr,
  67. unsigned long load_addr, Elf32_Sym *symtab)
  68. {
  69. switch(ELF32_R_TYPE(rpnt->r_info)) {
  70. case R_AVR32_NONE:
  71. break;
  72. case R_AVR32_GLOB_DAT:
  73. case R_AVR32_JMP_SLOT:
  74. *reloc_addr = symbol_addr;
  75. break;
  76. case R_AVR32_RELATIVE:
  77. SEND_STDERR_DEBUG("Applying RELATIVE relocation: ");
  78. SEND_ADDRESS_STDERR_DEBUG(load_addr, 0);
  79. SEND_STDERR_DEBUG(" + ");
  80. SEND_ADDRESS_STDERR_DEBUG(rpnt->r_addend, 1);
  81. *reloc_addr = load_addr + rpnt->r_addend;
  82. break;
  83. default:
  84. SEND_STDERR("BOOTSTRAP_RELOC: unhandled reloc_type ");
  85. SEND_NUMBER_STDERR(ELF32_R_TYPE(rpnt->r_info), 1);
  86. SEND_STDERR("REL, SYMBOL, LOAD: ");
  87. SEND_ADDRESS_STDERR(reloc_addr, 0);
  88. SEND_STDERR(", ");
  89. SEND_ADDRESS_STDERR(symbol_addr, 0);
  90. SEND_STDERR(", ");
  91. SEND_ADDRESS_STDERR(load_addr, 1);
  92. _dl_exit(1);
  93. }
  94. }