dl-startup.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Any assembly language/system dependent hacks needed to setup boot1.c so it
  2. * will work as expected and cope with whatever platform specific wierdness is
  3. * needed for this architecture.
  4. * Copyright (C) 2005 by Joakim Tjernlund
  5. */
  6. __asm__(
  7. " .text\n"
  8. " .globl _start\n"
  9. " .type _start,@function\n"
  10. " .hidden _start\n"
  11. "_start:\n"
  12. " mr 3,1\n" /* Pass SP to _dl_start in r3 */
  13. " li 0,0\n"
  14. " stwu 1,-16(1)\n" /* Make room on stack for _dl_start to store LR */
  15. " stw 0,0(1)\n" /* Clear Stack frame */
  16. " bl _dl_start@local\n" /* Perform relocation */
  17. /* Save the address of the apps entry point in CTR register */
  18. " mtctr 3\n" /* application entry point */
  19. #ifdef HAVE_ASM_PPC_REL16
  20. " bcl 20,31,1f\n"
  21. "1: mflr 31\n"
  22. " addis 31,31,_GLOBAL_OFFSET_TABLE_-1b@ha\n"
  23. " addi 31,31,_GLOBAL_OFFSET_TABLE_-1b@l\n"
  24. #else
  25. " bl _GLOBAL_OFFSET_TABLE_-4@local\n" /* Put our GOT pointer in r31, */
  26. " mflr 31\n"
  27. #endif
  28. /* I'm quite sure this piece of code is always compiled as PIC but let's be sure */
  29. #if defined(PPC_HAS_SECUREPLT) && defined(__PIC__)
  30. " mr 30,31\n"
  31. #endif
  32. " addi 1,1,16\n" /* Restore SP */
  33. " lwz 7,_dl_skip_args@got(31)\n" /* load EA of _dl_skip_args */
  34. " lwz 7,0(7)\n" /* Load word from _dl_skip_args */
  35. " lwz 8,0(1)\n" /* Load argc from stack */
  36. " subf 8,7,8\n" /* Subtract _dl_skip_args from argc. */
  37. " slwi 7,7,2\n" /* Multiply by 4 */
  38. " stwux 8,1,7\n" /* Adjust the stack pointer to skip _dl_skip_args words and store adjusted argc on stack. */
  39. #if 0
  40. /* Try beeing SVR4 ABI compliant?, even though it is not needed for uClibc on Linux */
  41. /* argc */
  42. " lwz 3,0(1)\n"
  43. /* find argv one word offset from the stack pointer */
  44. " addi 4,1,4\n"
  45. /* find environment pointer (argv+argc+1) */
  46. " lwz 5,0(1)\n"
  47. " addi 5,5,1\n"
  48. " rlwinm 5,5,2,0,29\n"
  49. " add 5,5,4\n"
  50. /* pass the auxilary vector in r6. This is passed to us just after _envp. */
  51. "2: lwzu 0,4(6)\n"
  52. " cmpwi 0,0\n"
  53. " bne 2b\n"
  54. " addi 6,6,4\n"
  55. #endif
  56. /* Pass a termination function pointer (in this case _dl_fini) in r3. */
  57. /* Paulus promized he would keep r3 zero in the exec ABI. */
  58. " lwz 3,_dl_fini@got(31)\n"
  59. " mr 7,3\n" /* Pass _dl_fini in r7 to maintain compat */
  60. " bctr\n" /* Jump to entry point */
  61. " .size _start,.-_start\n"
  62. " .previous\n"
  63. );
  64. /*
  65. * Get a pointer to the argv array. On many platforms this can be just
  66. * the address of the first argument, on other platforms we need to
  67. * do something a little more subtle here.
  68. */
  69. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS)+1)
  70. /*
  71. * Here is a macro to perform a relocation. This is only used when
  72. * bootstrapping the dynamic loader. RELP is the relocation that we
  73. * are performing, REL is the pointer to the address we are relocating.
  74. * SYMBOL is the symbol involved in the relocation, and LOAD is the
  75. * load address.
  76. */
  77. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  78. {int type=ELF_R_TYPE((RELP)->r_info); \
  79. Elf32_Addr finaladdr=(SYMBOL)+(RELP)->r_addend;\
  80. if (type==R_PPC_RELATIVE) { \
  81. *REL=(Elf32_Word)(LOAD)+(RELP)->r_addend;\
  82. } else if (type==R_PPC_ADDR32 || type==R_PPC_GLOB_DAT) {\
  83. *REL=finaladdr; \
  84. } else if (type==R_PPC_JMP_SLOT) { \
  85. Elf32_Sword delta=finaladdr-(Elf32_Word)(REL);\
  86. *REL=OPCODE_B(delta); \
  87. PPC_DCBST(REL); PPC_SYNC; PPC_ICBI(REL);\
  88. } else { \
  89. _dl_exit(100+ELF_R_TYPE((RELP)->r_info));\
  90. } \
  91. }