dl-startup.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  5. */
  6. /*
  7. * vineetg: Refactoring/cleanup of loader entry point
  8. * Removed 6 useless insns
  9. * Joern Improved it even further:
  10. * -better insn scheduling
  11. * -no need for conditional code for _dl_skip_args
  12. * -use of assembler .&2 expressions vs. @gotpc refs (avoids need for GP)
  13. *
  14. * What this code does:
  15. * -ldso starts execution here when kernel returns from execve()
  16. * -calls into generic ldso entry point _dl_start( )
  17. * -optionally adjusts argc for executable if exec passed as cmd
  18. * -calls into app main with address of finaliser
  19. */
  20. __asm__(
  21. ".section .text \n"
  22. ".align 4 \n"
  23. ".global _start \n"
  24. ".hidden _start \n"
  25. ".type _start,@function \n"
  26. "_start: \n"
  27. " ; ldso entry point, returns app entry point \n"
  28. " bl.d _dl_start \n"
  29. " mov_s r0, sp ; pass ptr to aux vector tbl \n"
  30. " ; If ldso ran as cmd with executable file nm as arg \n"
  31. " ; skip the extra args calc by dl_start() \n"
  32. " ld_s r1, [sp] ; orig argc from aux-vec Tbl \n"
  33. " ld r12, [pcl, _dl_skip_args@pcl] \n"
  34. " add r2, pcl, _dl_fini@pcl ; finalizer \n"
  35. " add2 sp, sp, r12 ; discard argv entries from stack\n"
  36. " sub_s r1, r1, r12 ; adjusted argc, on stack \n"
  37. " st_s r1, [sp] \n"
  38. " j_s.d [r0] ; app entry point \n"
  39. " mov_s r0, r2 ; ptr to finalizer _dl_fini \n"
  40. ".size _start,.-_start \n"
  41. ".previous \n"
  42. );
  43. /*
  44. * Get a pointer to the argv array. On many platforms this can be just
  45. * the address if the first argument, on other platforms we need to
  46. * do something a little more subtle here.
  47. */
  48. #define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long*) ARGS + 1)
  49. /*
  50. * Dynamic loader bootstrapping:
  51. * The only relocations that should be found are either R_ARC_RELATIVE for
  52. * data relocations (.got, etc) or R_ARC_JMP_SLOT for code relocations
  53. * (.plt). It is safe to assume that all of these relocations are word
  54. * aligned.
  55. * @RELP is the reloc entry being processed
  56. * @REL is the pointer to the address we are relocating.
  57. * @SYMBOL is the symbol involved in the relocation
  58. * @LOAD is the load address.
  59. */
  60. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  61. do { \
  62. int type = ELF32_R_TYPE((RELP)->r_info); \
  63. if (likely(type == R_ARC_RELATIVE)) \
  64. *REL += (unsigned long) LOAD; \
  65. else if (type == R_ARC_JMP_SLOT) \
  66. *REL = SYMBOL; \
  67. else if (type != R_ARC_NONE) \
  68. _dl_exit(1); \
  69. }while(0)
  70. /*
  71. * This will go away once we have DT_RELACOUNT
  72. */
  73. #define ARCH_NEEDS_BOOTSTRAP_RELOCS
  74. /* we dont need to spit out argc, argv etc for debugging */
  75. #define NO_EARLY_SEND_STDERR 1