dl-startup.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. " addi 1,1,16\n" /* Restore SP */
  29. " lwz 7,_dl_skip_args@got(31)\n" /* load EA of _dl_skip_args */
  30. " lwz 7,0(7)\n" /* Load word from _dl_skip_args */
  31. " lwz 8,0(1)\n" /* Load argc from stack */
  32. " subf 8,7,8\n" /* Subtract _dl_skip_args from argc. */
  33. " slwi 7,7,2\n" /* Multiply by 4 */
  34. " stwux 8,1,7\n" /* Adjust the stack pointer to skip _dl_skip_args words and store adjusted argc on stack. */
  35. #if 0
  36. /* Try beeing SVR4 ABI compliant?, even though it is not needed for uClibc on Linux */
  37. /* argc */
  38. " lwz 3,0(1)\n"
  39. /* find argv one word offset from the stack pointer */
  40. " addi 4,1,4\n"
  41. /* find environment pointer (argv+argc+1) */
  42. " lwz 5,0(1)\n"
  43. " addi 5,5,1\n"
  44. " rlwinm 5,5,2,0,29\n"
  45. " add 5,5,4\n"
  46. /* pass the auxilary vector in r6. This is passed to us just after _envp. */
  47. "2: lwzu 0,4(6)\n"
  48. " cmpwi 0,0\n"
  49. " bne 2b\n"
  50. " addi 6,6,4\n"
  51. #endif
  52. /* Pass a termination function pointer (in this case _dl_fini) in r3. */
  53. /* Paulus promized he would keep r3 zero in the exec ABI. */
  54. " lwz 3,_dl_fini@got(31)\n"
  55. " mr 7,3\n" /* Pass _dl_fini in r7 to maintain compat */
  56. " bctr\n" /* Jump to entry point */
  57. " .size _start,.-_start\n"
  58. " .previous\n"
  59. );
  60. /*
  61. * Get a pointer to the argv array. On many platforms this can be just
  62. * the address of the first argument, on other platforms we need to
  63. * do something a little more subtle here.
  64. */
  65. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS)+1)
  66. /*
  67. * Here is a macro to perform a relocation. This is only used when
  68. * bootstrapping the dynamic loader. RELP is the relocation that we
  69. * are performing, REL is the pointer to the address we are relocating.
  70. * SYMBOL is the symbol involved in the relocation, and LOAD is the
  71. * load address.
  72. */
  73. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  74. {int type=ELF_R_TYPE((RELP)->r_info); \
  75. Elf32_Addr finaladdr=(SYMBOL)+(RELP)->r_addend;\
  76. if (type==R_PPC_RELATIVE) { \
  77. *REL=(Elf32_Word)(LOAD)+(RELP)->r_addend;\
  78. } else if (type==R_PPC_ADDR32 || type==R_PPC_GLOB_DAT) {\
  79. *REL=finaladdr; \
  80. } else if (type==R_PPC_JMP_SLOT) { \
  81. Elf32_Sword delta=finaladdr-(Elf32_Word)(REL);\
  82. *REL=OPCODE_B(delta); \
  83. PPC_DCBST(REL); PPC_SYNC; PPC_ICBI(REL);\
  84. } else { \
  85. _dl_exit(100+ELF_R_TYPE((RELP)->r_info));\
  86. } \
  87. }