dl-startup.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Any assmbly 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. /* Overrive the default _dl_boot function, and replace it with a bit of asm.
  5. * Then call the real _dl_boot function, which is now named _dl_boot2. */
  6. asm("" \
  7. " .text\n" \
  8. " .globl _dl_boot\n" \
  9. "_dl_boot:\n" \
  10. " mr 3,1\n" \
  11. " li 4,0\n" \
  12. " addi 1,1,-16\n" \
  13. " stw 4,0(1)\n" \
  14. " bl _dl_boot2\n" \
  15. ".previous\n" \
  16. );
  17. #define DL_BOOT(X) static void __attribute__ ((unused)) _dl_boot2(X)
  18. /*
  19. * Get a pointer to the argv array. On many platforms this can be just
  20. * the address if the first argument, on other platforms we need to
  21. * do something a little more subtle here.
  22. */
  23. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS)+1)
  24. /*
  25. * Here is a macro to perform a relocation. This is only used when
  26. * bootstrapping the dynamic loader. RELP is the relocation that we
  27. * are performing, REL is the pointer to the address we are relocating.
  28. * SYMBOL is the symbol involved in the relocation, and LOAD is the
  29. * load address.
  30. */
  31. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  32. {int type=ELF32_R_TYPE((RELP)->r_info); \
  33. Elf32_Addr finaladdr=(SYMBOL)+(RELP)->r_addend;\
  34. if (type==R_PPC_RELATIVE) { \
  35. *REL=(Elf32_Word)(LOAD)+(RELP)->r_addend;\
  36. } else if (type==R_PPC_JMP_SLOT) { \
  37. Elf32_Sword delta=finaladdr-(Elf32_Word)(REL);\
  38. *REL=OPCODE_B(delta); \
  39. } else if (type==R_PPC_ADDR32) { \
  40. *REL=finaladdr; \
  41. } else { \
  42. _dl_exit(100+ELF32_R_TYPE((RELP)->r_info)); \
  43. } \
  44. PPC_DCBST(REL); PPC_SYNC; PPC_ICBI(REL); \
  45. }
  46. /*
  47. * Transfer control to the user's application, once the dynamic loader
  48. * is done. This routine has to exit the current function, then
  49. * call the _dl_elf_main function.
  50. */
  51. /* hgb@ifi.uio.no:
  52. * Adding a clobber list consisting of r0 for %1. addi on PowerPC
  53. * takes a register as the second argument, but if the register is
  54. * r0, the value 0 is used instead. If r0 is used here, the stack
  55. * pointer (r1) will be zeroed, and the dynamically linked
  56. * application will seg.fault immediatly when receiving control.
  57. */
  58. #define START() \
  59. __asm__ volatile ( \
  60. "addi 1,%1,0\n\t" \
  61. "mtlr %0\n\t" \
  62. "blrl\n\t" \
  63. : : "r" (_dl_elf_main), "r" (args) \
  64. : "r0")