si_c.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2005 by Michael Van Canneyt, Peter Vreman,
  4. & Daniel Mantione, members of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. var
  12. libc_environ: pchar; external name '__environ';
  13. libc_fpu_control: word; external name '__fpu_control';
  14. libc_init_proc: procedure; external name '_init';
  15. libc_fini_proc: procedure; external name '_fini';
  16. procedure libc_atexit; external name '__libc_atexit';
  17. procedure libc_exit(ec : longint); external name '__libc_exit';
  18. procedure libc_init; external name '__libc_init';
  19. procedure libc_setfpucw; external name '__setfpucw';
  20. procedure libc_start_main; external name '__libc_start_main';
  21. function fpc_getgot : pointer; [external name 'FPC_GETGOT'];
  22. {******************************************************************************
  23. C library start/halt
  24. ******************************************************************************}
  25. procedure _FPC_libc_start; assembler; nostackframe; public name '_start';
  26. asm
  27. { first stack frame }
  28. mov %g0, %fp
  29. { space for arguments }
  30. sub %sp, 6*8, %sp
  31. {$ifdef FPC_PIC}
  32. sethi %hi(_GLOBAL_OFFSET_TABLE_-8),%l7
  33. or %l7,%lo(_GLOBAL_OFFSET_TABLE_-4),%l7
  34. call FPC_GETGOT
  35. nop
  36. {$endif FPC_PIC}
  37. { extract argc }
  38. ldx [%sp+STACK_BIAS+22*8], %o2
  39. sethi %hi(operatingsystem_parameter_argc),%o1
  40. or %o1,%lo(operatingsystem_parameter_argc),%o1
  41. {$ifdef FPC_PIC}
  42. ldx [%o1+%l7],%o1
  43. {$endif FPC_PIC}
  44. st %o2, [%o1]
  45. { extract argv }
  46. add %sp, STACK_BIAS+23*8, %o0
  47. sethi %hi(operatingsystem_parameter_argv),%o1
  48. or %o1,%lo(operatingsystem_parameter_argv),%o1
  49. {$ifdef FPC_PIC}
  50. ldx [%o1+%l7],%o1
  51. {$endif FPC_PIC}
  52. stx %o0, [%o1]
  53. { envp=argv+(argc+1)*8 }
  54. inc %o2
  55. sllx %o2, 3, %o2
  56. add %o2, %o0, %o2
  57. sethi %hi(operatingsystem_parameter_envp),%o1
  58. or %o1,%lo(operatingsystem_parameter_envp),%o1
  59. {$ifdef FPC_PIC}
  60. ldx [%o1+%l7],%o1
  61. {$endif FPC_PIC}
  62. stx %o2, [%o1]
  63. { Save initial stackpointer }
  64. sethi %hi(initialstkptr),%o1
  65. or %o1,%lo(initialstkptr),%o1
  66. {$ifdef FPC_PIC}
  67. ldx [%o1+%l7],%o1
  68. {$endif FPC_PIC}
  69. stx %sp, [%o1]
  70. { prepare parameters to call __libc_start_main }
  71. ldx [%sp+STACK_BIAS+22*8], %o1
  72. add %sp, STACK_BIAS+23*8, %o0
  73. sethi %hi(PASCALMAIN), %o0
  74. or %o0, %lo(PASCALMAIN), %o0
  75. {$ifdef FPC_PIC}
  76. ldx [%o0+%l7],%o0
  77. {$endif FPC_PIC}
  78. sethi %hi(libc_init_proc), %o3
  79. or %o3, %lo(libc_init_proc), %o3
  80. {$ifdef FPC_PIC}
  81. ldx [%o3+%l7],%o3
  82. {$endif FPC_PIC}
  83. sethi %hi(libc_fini_proc), %o4
  84. or %o4, %lo(libc_fini_proc), %o4
  85. {$ifdef FPC_PIC}
  86. ldx [%o4+%l7],%o4
  87. {$endif FPC_PIC}
  88. { shared library termination function }
  89. mov %g1, %o5
  90. call libc_start_main
  91. nop
  92. { we shuld never return here }
  93. unimp
  94. end;
  95. procedure _FPC_libc_haltproc(e: longint); cdecl; public name '_haltproc';
  96. begin
  97. { try to exit_group }
  98. while true do
  99. asm
  100. ld e,%o0
  101. mov 188, %g1
  102. ta 0x6d
  103. end;
  104. end;