dl-startup.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. See arm/boot1_arch.h for an example of what
  4. * can be done.
  5. */
  6. __asm__ ("\
  7. .text\n\
  8. .global _start\n\
  9. .type _start,%function\n\
  10. .hidden _start\n\
  11. .align 32\n\
  12. .register %g2, #scratch\n\
  13. _start:\n\
  14. /* Allocate space for functions to drop their arguments. */\n\
  15. sub %sp, 6*4, %sp\n\
  16. /* Pass pointer to argument block to _dl_start. */\n\
  17. call _dl_start\n\
  18. add %sp, 22*4, %o0\n\
  19. /* FALTHRU */\n\
  20. .globl _dl_start_user\n\
  21. .type _dl_start_user, @function\n\
  22. _dl_start_user:\n\
  23. /* Load the PIC register. */\n\
  24. 1: call 2f\n\
  25. sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7\n\
  26. 2: or %l7, %lo(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7\n\
  27. add %l7, %o7, %l7\n\
  28. /* Save the user entry point address in %l0 */\n\
  29. mov %o0, %l0\n\
  30. /* See if we were run as a command with the executable file name as an\n\
  31. extra leading argument. If so, adjust the contents of the stack. */\n\
  32. sethi %hi(_dl_skip_args), %g2\n\
  33. or %g2, %lo(_dl_skip_args), %g2\n\
  34. ld [%l7+%g2], %i0\n\
  35. ld [%i0], %i0\n\
  36. tst %i0\n\
  37. /* Pass our finalizer function to the user in %g1. */\n\
  38. sethi %hi(_dl_fini), %g1\n\
  39. or %g1, %lo(_dl_fini), %g1\n\
  40. ld [%l7+%g1], %g1\n\
  41. /* Jump to the user's entry point and deallocate the extra stack we got. */\n\
  42. jmp %l0\n\
  43. add %sp, 6*4, %sp\n\
  44. .size _dl_start_user, . - _dl_start_user\n\
  45. .previous\n\
  46. ");
  47. /*
  48. * Get a pointer to the argv array. On many platforms this can be just
  49. * the address of the first argument, on other platforms we need to
  50. * do something a little more subtle here. We assume that argc is stored
  51. * at the word just below the argvp that we return here.
  52. */
  53. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS) + 1)
  54. /*
  55. * Here is a macro to perform a relocation. This is only used when
  56. * bootstrapping the dynamic loader.
  57. */
  58. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  59. switch(ELF_R_TYPE((RELP)->r_info)) { \
  60. case R_SPARC_32: \
  61. case R_SPARC_GLOB_DAT: \
  62. *REL = SYMBOL + (RELP)->r_addend; \
  63. break; \
  64. case R_SPARC_JMP_SLOT: \
  65. REL[1] = 0x03000000 | ((SYMBOL >> 10) & 0x3fffff); \
  66. REL[2] = 0x81c06000 | (SYMBOL & 0x3ff); \
  67. break; \
  68. case R_SPARC_NONE: \
  69. case R_SPARC_WDISP30: \
  70. break; \
  71. case R_SPARC_RELATIVE: \
  72. *REL += (unsigned int) LOAD + (RELP)->r_addend; \
  73. break; \
  74. default: \
  75. _dl_exit(1); \
  76. }