dl-startup.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. " .type _dl_boot,@function\n"
  10. "_dl_boot:\n"
  11. " mr 3,1\n" /* Pass SP to _dl_boot2 in r3 */
  12. " addi 1,1,-16\n" /* Make room on stack for _dl_boot2 to store LR */
  13. " li 4,0\n"
  14. " stw 4,0(1)\n" /* Clear Stack frame */
  15. " bl _dl_boot2@local\n" /* Perform relocation */
  16. " addi 1,1,16\n" /* Restore SP */
  17. " mtctr 3\n" /* Load applications entry point */
  18. " bctr\n" /* Jump to entry point */
  19. " .size _dl_boot,.-_dl_boot\n"
  20. " .previous\n"
  21. );
  22. #define DL_BOOT(X) static void* __attribute_used__ _dl_boot2(X)
  23. /*
  24. * Get a pointer to the argv array. On many platforms this can be just
  25. * the address if the first argument, on other platforms we need to
  26. * do something a little more subtle here.
  27. */
  28. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS)+1)
  29. /*
  30. * Here is a macro to perform a relocation. This is only used when
  31. * bootstrapping the dynamic loader. RELP is the relocation that we
  32. * are performing, REL is the pointer to the address we are relocating.
  33. * SYMBOL is the symbol involved in the relocation, and LOAD is the
  34. * load address.
  35. */
  36. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  37. {int type=ELF32_R_TYPE((RELP)->r_info); \
  38. Elf32_Addr finaladdr=(SYMBOL)+(RELP)->r_addend;\
  39. if (type==R_PPC_RELATIVE) { \
  40. *REL=(Elf32_Word)(LOAD)+(RELP)->r_addend;\
  41. } else if (type==R_PPC_ADDR32 || type==R_PPC_GLOB_DAT) {\
  42. *REL=finaladdr; \
  43. } else if (type==R_PPC_JMP_SLOT) { \
  44. Elf32_Sword delta=finaladdr-(Elf32_Word)(REL);\
  45. *REL=OPCODE_B(delta); \
  46. PPC_DCBST(REL); PPC_SYNC; PPC_ICBI(REL);\
  47. } else { \
  48. _dl_exit(100+ELF32_R_TYPE((RELP)->r_info));\
  49. } \
  50. }
  51. /*
  52. * Transfer control to the user's application, once the dynamic loader
  53. * is done. This routine has to exit the current function, then
  54. * call the _dl_elf_main function.
  55. */
  56. #define START() return _dl_elf_main