mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-12 21:49:43 +02:00
Fix StackTop computation by using StackTopPtr variable set in _start code
git-svn-id: trunk@33009 -
This commit is contained in:
parent
3de617c79e
commit
aec9ef1b70
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 }
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user