mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-04 21:49:37 +01:00
* Since StackTop=StackBottom+StackLength, any two variables are sufficient to describe stack, the third one is redundant.
* As a first part of cleanup, replaced StackTop with function returning StackBottom+StackLength. * On Win32 and Win64, StackTop returns the stack base from TIB instead. git-svn-id: trunk@27119 -
This commit is contained in:
parent
bca09a8f69
commit
3a55c4301e
@ -535,7 +535,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
stackbottom:=pointer(heap_brk); {In DOS mode, heap_brk is
|
stackbottom:=pointer(heap_brk); {In DOS mode, heap_brk is
|
||||||
also the stack bottom.}
|
also the stack bottom.}
|
||||||
StackTop := StackBottom + InitialStkLen;
|
StackLength:=sptr-stackbottom;
|
||||||
{$WARNING To be checked/corrected!}
|
{$WARNING To be checked/corrected!}
|
||||||
ApplicationType := 1; (* Running under DOS. *)
|
ApplicationType := 1; (* Running under DOS. *)
|
||||||
IsConsole := true;
|
IsConsole := true;
|
||||||
@ -549,8 +549,11 @@ begin
|
|||||||
osOS2:
|
osOS2:
|
||||||
begin
|
begin
|
||||||
DosGetInfoBlocks (@TIB, @PIB);
|
DosGetInfoBlocks (@TIB, @PIB);
|
||||||
StackBottom := pointer (TIB^.Stack);
|
StackLength:=CheckInitialStkLen(InitialStklen);
|
||||||
StackTop := TIB^.StackLimit;
|
{ TODO: verify if TIB^.StackLimit is correct,
|
||||||
|
from MSWindows point of view TIB^.Stack should be used instead }
|
||||||
|
StackBottom := TIB^.StackLimit - StackLength;
|
||||||
|
|
||||||
Environment := pointer (PIB^.Env);
|
Environment := pointer (PIB^.Env);
|
||||||
ApplicationType := PIB^.ProcType;
|
ApplicationType := PIB^.ProcType;
|
||||||
ProcessID := PIB^.PID;
|
ProcessID := PIB^.PID;
|
||||||
@ -562,7 +565,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
stackbottom:=nil; {Not sure how to get it, but seems to be
|
stackbottom:=nil; {Not sure how to get it, but seems to be
|
||||||
always zero.}
|
always zero.}
|
||||||
StackTop := StackBottom + InitialStkLen;
|
StackLength:=sptr-stackbottom;
|
||||||
{$WARNING To be checked/corrected!}
|
{$WARNING To be checked/corrected!}
|
||||||
ApplicationType := 1; (* Running under DOS. *)
|
ApplicationType := 1; (* Running under DOS. *)
|
||||||
IsConsole := true;
|
IsConsole := true;
|
||||||
@ -570,7 +573,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
exitproc:=nil;
|
exitproc:=nil;
|
||||||
StackLength := CheckInitialStkLen (InitialStkLen);
|
|
||||||
|
|
||||||
{Initialize the heap.}
|
{Initialize the heap.}
|
||||||
initheap;
|
initheap;
|
||||||
|
|||||||
@ -177,7 +177,7 @@ end;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
StackLength := CheckInitialStkLen(InitialStkLen);
|
StackLength := CheckInitialStkLen(InitialStkLen);
|
||||||
StackBottom := StackTop - StackLength;
|
StackBottom := Sptr - StackLength;
|
||||||
{ OS specific startup }
|
{ OS specific startup }
|
||||||
|
|
||||||
{ Setup heap }
|
{ Setup heap }
|
||||||
|
|||||||
@ -647,7 +647,6 @@ Begin
|
|||||||
and to ensure that StackLength = StackTop - StackBottom }
|
and to ensure that StackLength = StackTop - StackBottom }
|
||||||
StackLength := CheckInitialStkLen(InitialStkLen)-256;
|
StackLength := CheckInitialStkLen(InitialStkLen)-256;
|
||||||
StackBottom := __stkbottom;
|
StackBottom := __stkbottom;
|
||||||
StackTop := StackBottom + StackLength;
|
|
||||||
{ To be set if this is a GUI or console application }
|
{ To be set if this is a GUI or console application }
|
||||||
IsConsole := TRUE;
|
IsConsole := TRUE;
|
||||||
{ To be set if this is a library and not a program }
|
{ To be set if this is a library and not a program }
|
||||||
|
|||||||
@ -682,6 +682,13 @@ End;
|
|||||||
Miscellaneous
|
Miscellaneous
|
||||||
*****************************************************************************}
|
*****************************************************************************}
|
||||||
|
|
||||||
|
{$ifndef FPC_SYSTEM_HAS_STACKTOP}
|
||||||
|
function StackTop: pointer;
|
||||||
|
begin
|
||||||
|
result:=StackBottom+StackLength;
|
||||||
|
end;
|
||||||
|
{$endif FPC_SYSTEM_HAS_STACKTOP}
|
||||||
|
|
||||||
{$ifndef FPC_SYSTEM_HAS_GET_PC_ADDR}
|
{$ifndef FPC_SYSTEM_HAS_GET_PC_ADDR}
|
||||||
{ This provides a dummy implementation
|
{ This provides a dummy implementation
|
||||||
of get_pc_addr function, for CPU's that don't need
|
of get_pc_addr function, for CPU's that don't need
|
||||||
|
|||||||
@ -701,10 +701,10 @@ Var
|
|||||||
StdErr : Text;
|
StdErr : Text;
|
||||||
InOutRes : Word;
|
InOutRes : Word;
|
||||||
{ Stack checking }
|
{ Stack checking }
|
||||||
StackTop,
|
|
||||||
StackBottom : Pointer;
|
StackBottom : Pointer;
|
||||||
StackLength : SizeUInt;
|
StackLength : SizeUInt;
|
||||||
|
|
||||||
|
function StackTop: Pointer;
|
||||||
|
|
||||||
{ Numbers for routines that have compiler magic }
|
{ Numbers for routines that have compiler magic }
|
||||||
{$I innr.inc}
|
{$I innr.inc}
|
||||||
|
|||||||
@ -351,9 +351,8 @@ begin
|
|||||||
{$endif}
|
{$endif}
|
||||||
{$endif}
|
{$endif}
|
||||||
IsConsole := TRUE;
|
IsConsole := TRUE;
|
||||||
StackTop := initialstkptr;
|
|
||||||
StackLength := CheckInitialStkLen(initialStkLen);
|
StackLength := CheckInitialStkLen(initialStkLen);
|
||||||
StackBottom := StackTop - StackLength;
|
StackBottom := initialstkptr - StackLength;
|
||||||
{ Set up signals handlers (may be needed by init code to test cpu features) }
|
{ Set up signals handlers (may be needed by init code to test cpu features) }
|
||||||
InstallSignals;
|
InstallSignals;
|
||||||
{$if defined(cpui386) or defined(cpuarm)}
|
{$if defined(cpui386) or defined(cpuarm)}
|
||||||
|
|||||||
@ -340,7 +340,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
StackTop := __stktop;
|
|
||||||
StackBottom := __stkbottom;
|
StackBottom := __stkbottom;
|
||||||
StackLength := __stktop - __stkbottom;
|
StackLength := __stktop - __stkbottom;
|
||||||
InstallInterruptHandlers;
|
InstallInterruptHandlers;
|
||||||
|
|||||||
@ -272,7 +272,7 @@ end;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
StackLength := CheckInitialStkLen(InitialStkLen);
|
StackLength := CheckInitialStkLen(InitialStkLen);
|
||||||
StackBottom := StackTop - StackLength;
|
StackBottom := Sptr - StackLength;
|
||||||
{ OS specific startup }
|
{ OS specific startup }
|
||||||
|
|
||||||
{ Set up signals handlers }
|
{ Set up signals handlers }
|
||||||
|
|||||||
@ -1125,11 +1125,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
{$ENDIF OS2EXCEPTIONS}
|
{$ENDIF OS2EXCEPTIONS}
|
||||||
DosGetInfoBlocks (@TIB, @PIB);
|
DosGetInfoBlocks (@TIB, @PIB);
|
||||||
StackBottom := TIB^.Stack;
|
|
||||||
{ $IFNDEF OS2EXCEPTIONS}
|
|
||||||
StackTop := TIB^.StackLimit;
|
|
||||||
{ $ENDIF OS2EXCEPTIONS}
|
|
||||||
StackLength := CheckInitialStkLen (InitialStkLen);
|
StackLength := CheckInitialStkLen (InitialStkLen);
|
||||||
|
{ TODO: verify if TIB^.StackLimit is correct,
|
||||||
|
from MSWindows point of view TIB^.Stack should be used instead }
|
||||||
|
StackBottom := TIB^.StackLimit - StackLength;
|
||||||
|
|
||||||
{Set type of application}
|
{Set type of application}
|
||||||
ApplicationType := PIB^.ProcType;
|
ApplicationType := PIB^.ProcType;
|
||||||
|
|||||||
@ -247,7 +247,7 @@ end;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
StackLength := CheckInitialStkLen(InitialStkLen);
|
StackLength := CheckInitialStkLen(InitialStkLen);
|
||||||
StackBottom := StackTop - StackLength;
|
StackBottom := Sptr - StackLength;
|
||||||
{ OS specific startup }
|
{ OS specific startup }
|
||||||
|
|
||||||
{ Set up signals handlers }
|
{ Set up signals handlers }
|
||||||
|
|||||||
@ -128,6 +128,12 @@ function main_wrapper(arg: Pointer; proc: Pointer): ptrint; forward;
|
|||||||
procedure OutermostHandler; external name '__FPC_DEFAULT_HANDLER';
|
procedure OutermostHandler; external name '__FPC_DEFAULT_HANDLER';
|
||||||
{$endif FPC_USE_WIN32_SEH}
|
{$endif FPC_USE_WIN32_SEH}
|
||||||
|
|
||||||
|
{$define FPC_SYSTEM_HAS_STACKTOP}
|
||||||
|
function StackTop: pointer; assembler;nostackframe;
|
||||||
|
asm
|
||||||
|
movl %fs:(4),%eax
|
||||||
|
end;
|
||||||
|
|
||||||
{ include system independent routines }
|
{ include system independent routines }
|
||||||
{$I system.inc}
|
{$I system.inc}
|
||||||
|
|
||||||
@ -642,9 +648,6 @@ function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
|
|||||||
result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
|
result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
|
||||||
st : Pointer;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{ get some helpful informations }
|
{ get some helpful informations }
|
||||||
GetStartupInfo(@startupinfo);
|
GetStartupInfo(@startupinfo);
|
||||||
@ -654,12 +657,6 @@ begin
|
|||||||
|
|
||||||
MainInstance:=SysInstance;
|
MainInstance:=SysInstance;
|
||||||
|
|
||||||
asm
|
|
||||||
movl %fs:(4),%eax
|
|
||||||
movl %eax,st
|
|
||||||
end;
|
|
||||||
StackTop:=st;
|
|
||||||
|
|
||||||
{ pass dummy value }
|
{ pass dummy value }
|
||||||
StackLength := CheckInitialStkLen($1000000);
|
StackLength := CheckInitialStkLen($1000000);
|
||||||
StackBottom := StackTop - StackLength;
|
StackBottom := StackTop - StackLength;
|
||||||
|
|||||||
@ -116,6 +116,12 @@ asm
|
|||||||
end;
|
end;
|
||||||
{$endif FPC_USE_WIN64_SEH}
|
{$endif FPC_USE_WIN64_SEH}
|
||||||
|
|
||||||
|
{$define FPC_SYSTEM_HAS_STACKTOP}
|
||||||
|
function StackTop: pointer; assembler;nostackframe;
|
||||||
|
asm
|
||||||
|
movq %gs:(8),%rax
|
||||||
|
end;
|
||||||
|
|
||||||
{ include system independent routines }
|
{ include system independent routines }
|
||||||
{$I system.inc}
|
{$I system.inc}
|
||||||
|
|
||||||
@ -581,14 +587,7 @@ function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
|
|||||||
result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
|
result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function GetExceptionPointer : Pointer; assembler;nostackframe;
|
|
||||||
asm
|
|
||||||
movq %gs:(8),%rax
|
|
||||||
end;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
StackTop:=GetExceptionPointer;
|
|
||||||
{ pass dummy value }
|
{ pass dummy value }
|
||||||
StackLength := CheckInitialStkLen($1000000);
|
StackLength := CheckInitialStkLen($1000000);
|
||||||
StackBottom := StackTop - StackLength;
|
StackBottom := StackTop - StackLength;
|
||||||
|
|||||||
@ -1350,15 +1350,9 @@ end;
|
|||||||
{$endif WINCE_EXCEPTION_HANDLING}
|
{$endif WINCE_EXCEPTION_HANDLING}
|
||||||
|
|
||||||
procedure Exe_entry;[public, alias : '_FPC_EXE_Entry'];
|
procedure Exe_entry;[public, alias : '_FPC_EXE_Entry'];
|
||||||
var
|
|
||||||
st: pointer;
|
|
||||||
begin
|
begin
|
||||||
IsLibrary:=false;
|
IsLibrary:=false;
|
||||||
{$ifdef CPUARM}
|
{$ifdef CPUARM}
|
||||||
asm
|
|
||||||
str sp,st
|
|
||||||
end;
|
|
||||||
StackTop:=st;
|
|
||||||
asm
|
asm
|
||||||
mov fp,#0
|
mov fp,#0
|
||||||
bl PASCALMAIN;
|
bl PASCALMAIN;
|
||||||
@ -1373,11 +1367,6 @@ begin
|
|||||||
mov %esp,%fs:(0)
|
mov %esp,%fs:(0)
|
||||||
{$endif WINCE_EXCEPTION_HANDLING}
|
{$endif WINCE_EXCEPTION_HANDLING}
|
||||||
pushl %ebp
|
pushl %ebp
|
||||||
movl %esp,%eax
|
|
||||||
movl %eax,st
|
|
||||||
end;
|
|
||||||
StackTop:=st;
|
|
||||||
asm
|
|
||||||
xorl %eax,%eax
|
xorl %eax,%eax
|
||||||
movw %ss,%ax
|
movw %ss,%ax
|
||||||
movl %eax,_SS
|
movl %eax,_SS
|
||||||
@ -1758,7 +1747,7 @@ initialization
|
|||||||
if not(IsLibrary) then
|
if not(IsLibrary) then
|
||||||
SysInitFPU;
|
SysInitFPU;
|
||||||
StackLength := CheckInitialStkLen(InitialStkLen);
|
StackLength := CheckInitialStkLen(InitialStkLen);
|
||||||
StackBottom := StackTop - StackLength;
|
StackBottom := Sptr - StackLength;
|
||||||
{ some misc stuff }
|
{ some misc stuff }
|
||||||
hprevinst:=0;
|
hprevinst:=0;
|
||||||
if not IsLibrary then
|
if not IsLibrary then
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user