dl-startup.h 3.3 KB

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