start.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. member of the Free Pascal development team.
  6. Program startup
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. type
  14. TCdeclProcedure = procedure; cdecl;
  15. function atexit(proc:TCdeclProcedure):longint;cdecl;external 'c' name 'atexit';
  16. procedure _cleanup;cdecl;external 'c' name '_cleanup';
  17. procedure _DYNAMIC;cdecl;external 'c' name '_DYNAMIC';
  18. procedure __fpstart;cdecl;external 'c' name '__fpstart';
  19. procedure PascalMain;cdecl;external name 'PASCALMAIN';
  20. procedure _start;assembler;nostackframe;public name '_start';
  21. asm
  22. // Terminate the stack frame, and reserve space for functions to
  23. // drop their arguments.
  24. mov %g0, %fp
  25. sub %sp, 6*4, %sp
  26. // Extract the arguments and environment as encoded on the stack. The
  27. // argument info starts after one register window (16 words) past the SP.
  28. ld [%sp+22*4], %o2
  29. sethi %hi(argc),%o1
  30. or %o1,%lo(argc),%o1
  31. st %o2, [%o1]
  32. add %sp, 23*4, %o0
  33. sethi %hi(argv),%o1
  34. or %o1,%lo(argv),%o1
  35. st %o0, [%o1]
  36. // envp=(argc+1)*4+argv
  37. inc %o2
  38. sll %o2, 2, %o2
  39. add %o2, %o0, %o2
  40. sethi %hi(envp),%o1
  41. or %o1,%lo(envp),%o1
  42. st %o2, [%o1]
  43. // Check to see if there is an _cleanup() function linked in, and if
  44. // so, register it with atexit() as the last thing to be run by
  45. // atexit().
  46. sethi %hi(_cleanup), %o0
  47. or %o0, %lo(_cleanup), %o0
  48. cmp %o0,%g0
  49. be .L1
  50. nop
  51. call atexit
  52. nop
  53. .L1:
  54. // Now check to see if we have an _DYNAMIC table, and if so then
  55. // we need to register the function pointer previously in %edx, but
  56. // now conveniently saved on the stack as the argument to pass to
  57. // atexit().
  58. sethi %hi(_DYNAMIC), %o0
  59. or %o0, %lo(_DYNAMIC), %o0
  60. cmp %o0,%g0
  61. be .L2
  62. nop
  63. call atexit
  64. nop
  65. .L2:
  66. // Register _fini() with atexit(). We will take care of calling _init()
  67. // directly.
  68. //
  69. // sethi %hi(_fini), %o0
  70. // or %o0, %lo(_fini), %o0
  71. // call atexit
  72. // Call _init(argc, argv, environ), _fpstart(argc, argv, environ), and
  73. // main(argc, argv, environ).
  74. ld [%sp+22*4], %o0
  75. add %sp, 23*4, %o1
  76. add %o0, 1, %o2
  77. sll %o2, 2, %o2
  78. add %o2, %o1, %o2
  79. call __fpstart
  80. nop
  81. call PASCALMAIN
  82. nop
  83. // Die very horribly if exit returns
  84. unimp
  85. end;
  86. {
  87. $Log$
  88. Revision 1.2 2005-02-14 17:13:31 peter
  89. * truncate log
  90. Revision 1.1 2005/02/14 16:32:41 peter
  91. * solaris updates
  92. Revision 1.1 2005/02/13 22:13:20 peter
  93. * get solaris back in shape
  94. Revision 1.8 2005/02/05 23:46:12 peter
  95. * set addr:=nil for other signals
  96. Revision 1.7 2005/02/05 23:45:38 peter
  97. * sigcontext is invalid, use siginfo only
  98. Revision 1.6 2005/01/30 18:01:15 peter
  99. * signal cleanup for linux
  100. * sigactionhandler instead of tsigaction for bsds
  101. * sigcontext moved to cpu dir
  102. }