dl-startup.h 2.4 KB

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