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 6 See the file COPYING.FPC, included in this distribution, 7 for details about the copyright. 8 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 **********************************************************************} 14 15var 16 libc_environ: pchar; external name '__environ'; 17 libc_fpu_control: word; external name '__fpu_control'; 18 libc_init_proc: procedure; external name '_init'; 19 libc_fini_proc: procedure; external name '_fini'; 20 21procedure libc_atexit; external name '__libc_atexit'; 22procedure libc_exit(ec : longint); external name '__libc_exit'; 23procedure libc_init; external name '__libc_init'; 24procedure libc_setfpucw; external name '__setfpucw'; 25procedure libc_start_main; external name '__libc_start_main'; 26 27function fpc_getgot : pointer; [external name 'FPC_GETGOT']; 28 29{****************************************************************************** 30 C library start/halt 31 ******************************************************************************} 32 33procedure _FPC_libc_start; assembler; nostackframe; public name '_start'; 34 asm 35 { first stack frame } 36 mov %g0, %fp 37 { space for arguments } 38 sub %sp, 6*8, %sp 39{$ifdef FPC_PIC} 40 sethi %hi(_GLOBAL_OFFSET_TABLE_-8),%l7 41 or %l7,%lo(_GLOBAL_OFFSET_TABLE_-4),%l7 42 call FPC_GETGOT 43 nop 44{$endif FPC_PIC} 45 { extract argc } 46 ldx [%sp+STACK_BIAS+22*8], %o2 47 sethi %hi(operatingsystem_parameter_argc),%o1 48 or %o1,%lo(operatingsystem_parameter_argc),%o1 49{$ifdef FPC_PIC} 50 ldx [%o1+%l7],%o1 51{$endif FPC_PIC} 52 st %o2, [%o1] 53 { extract argv } 54 add %sp, STACK_BIAS+23*8, %o0 55 sethi %hi(operatingsystem_parameter_argv),%o1 56 or %o1,%lo(operatingsystem_parameter_argv),%o1 57{$ifdef FPC_PIC} 58 ldx [%o1+%l7],%o1 59{$endif FPC_PIC} 60 stx %o0, [%o1] 61 62 { envp=argv+(argc+1)*8 } 63 inc %o2 64 sllx %o2, 3, %o2 65 add %o2, %o0, %o2 66 sethi %hi(operatingsystem_parameter_envp),%o1 67 or %o1,%lo(operatingsystem_parameter_envp),%o1 68{$ifdef FPC_PIC} 69 ldx [%o1+%l7],%o1 70{$endif FPC_PIC} 71 stx %o2, [%o1] 72 73 { Save initial stackpointer } 74 sethi %hi(initialstkptr),%o1 75 or %o1,%lo(initialstkptr),%o1 76{$ifdef FPC_PIC} 77 ldx [%o1+%l7],%o1 78{$endif FPC_PIC} 79 stx %sp, [%o1] 80 81 { prepare parameters to call __libc_start_main } 82 ldx [%sp+STACK_BIAS+22*8], %o1 83 add %sp, STACK_BIAS+23*8, %o0 84 85 sethi %hi(PASCALMAIN), %o0 86 or %o0, %lo(PASCALMAIN), %o0 87{$ifdef FPC_PIC} 88 ldx [%o0+%l7],%o0 89{$endif FPC_PIC} 90 91 sethi %hi(libc_init_proc), %o3 92 or %o3, %lo(libc_init_proc), %o3 93{$ifdef FPC_PIC} 94 ldx [%o3+%l7],%o3 95{$endif FPC_PIC} 96 97 sethi %hi(libc_fini_proc), %o4 98 or %o4, %lo(libc_fini_proc), %o4 99{$ifdef FPC_PIC} 100 ldx [%o4+%l7],%o4 101{$endif FPC_PIC} 102 103 { shared library termination function } 104 mov %g1, %o5 105 106 call libc_start_main 107 nop 108 109 { we shuld never return here } 110 unimp 111 end; 112 113 114procedure _FPC_libc_haltproc(e: longint); cdecl; public name '_haltproc'; 115 begin 116 { try to exit_group } 117 while true do 118 asm 119 ld e,%o0 120 mov 188, %g1 121 ta 0x6d 122 end; 123 end; 124 125