diff --git a/rtl/solaris/i386/start.inc b/rtl/solaris/i386/start.inc index 4024a98c7c..42c4e97239 100644 --- a/rtl/solaris/i386/start.inc +++ b/rtl/solaris/i386/start.inc @@ -53,6 +53,8 @@ procedure __Argv;cdecl;external 'c' name '__Argv'; Dump of assembler code for function _start: } procedure _start;assembler;nostackframe;public name '_start'; asm + mov %esp,%eax + mov %eax,StackTopPtr pushl $0x0 pushl $0x0 mov %esp,%ebp diff --git a/rtl/solaris/sparc/start.inc b/rtl/solaris/sparc/start.inc index 72b463d3c1..6a6c096ea4 100644 --- a/rtl/solaris/sparc/start.inc +++ b/rtl/solaris/sparc/start.inc @@ -24,9 +24,16 @@ procedure PascalMain;cdecl;external name 'PASCALMAIN'; procedure _start;assembler;nostackframe;public name '_start'; asm - // Terminate the stack frame, and reserve space for functions to - // drop their arguments. + // Terminate the stack frame mov %g0, %fp + + // Save current %sp to StackTopPtr + mov %sp, %o2 + sethi %hi(StackTopPtr),%o1 + or %o1,%lo(StackTopPtr),%o1 + st %o2, [%o1] + + // Reserve space for functions to drop their arguments. sub %sp, 6*4, %sp // Extract the arguments and environment as encoded on the stack. The diff --git a/rtl/solaris/system.pp b/rtl/solaris/system.pp index f27fb25f8a..9149072161 100644 --- a/rtl/solaris/system.pp +++ b/rtl/solaris/system.pp @@ -28,6 +28,10 @@ var argc:longint; argv:PPchar; envp:PPchar; +{$define FPC_SYSTEM_HAS_STACKTOP} +var + StackTopPtr : pointer; + {$if defined(CPUARM) or defined(CPUM68K) or (defined(CPUSPARC) and defined(VER2_6))} {$define fpc_softfpu_interface} @@ -264,10 +268,21 @@ begin result := stklen; end; +function StackTop : pointer; +begin + if assigned(StackTopPtr) then + StackTop:=StackTopPtr + else + StackTop:=StackBottom + StackLength; +end; + Begin IsConsole := TRUE; StackLength := CheckInitialStkLen(InitialStkLen); - StackBottom := Sptr - StackLength; + if assigned(StackTopPtr) then + StackBottom:=StackTopPtr - StackLength + else + StackBottom := Sptr - StackLength; { Set up signals handlers (may be needed by init code to test cpu features) } InstallSignals; { Setup heap } diff --git a/rtl/solaris/x86_64/start.inc b/rtl/solaris/x86_64/start.inc index ab2f157a4e..e33644e3c7 100644 --- a/rtl/solaris/x86_64/start.inc +++ b/rtl/solaris/x86_64/start.inc @@ -168,6 +168,14 @@ asm * there was a genuine call to _start. */ *) + movq %rsp,%rax + // Save %rsp to StackTopPtr +{$ifdef FPC_PIC} + movq StackTopPtr@GOTPCREL(%rip),%rcx +{$else FPC_PIC} + movq $StackTopPtr,%rcx +{$endif FPC_PIC} + movq %rax,(%rcx) pushq $0x0 pushq $0x0 movq %rsp,%rbp