Fixed stack checking for embedded target. Based on work by Christo Crause

git-svn-id: trunk@42157 -
This commit is contained in:
Jeppe Johansen 2019-06-01 19:18:31 +00:00
parent be7b653fef
commit 2f501be2a0
3 changed files with 18 additions and 2 deletions

View File

@ -113,6 +113,8 @@ function get_caller_frame(framebp:pointer;addr:pointer=nil):pointer;assembler;no
{$define FPC_SYSTEM_HAS_SPTR} {$define FPC_SYSTEM_HAS_SPTR}
Function Sptr : pointer;assembler;nostackframe; Function Sptr : pointer;assembler;nostackframe;
asm asm
in r24, 0x3d
in r25, 0x3e
end; end;

View File

@ -20,6 +20,8 @@ Unit System;
interface interface
{*****************************************************************************} {*****************************************************************************}
{$define FPC_SYSTEM_HAS_STACKTOP}
{$define FPC_IS_SYSTEM} {$define FPC_IS_SYSTEM}
{$define HAS_CMDLINE} {$define HAS_CMDLINE}
@ -203,6 +205,14 @@ const calculated_cmdline:Pchar=nil;
{***************************************************************************** {*****************************************************************************
Misc. System Dependent Functions Misc. System Dependent Functions
*****************************************************************************} *****************************************************************************}
var
_stack_top: record end; external name '_stack_top';
function StackTop: pointer;
begin
StackTop:=@_stack_top;
end;
procedure haltproc;cdecl;external name '_haltproc'; procedure haltproc;cdecl;external name '_haltproc';
@ -277,7 +287,7 @@ begin
end; end;
var var
initialstkptr : Pointer; // external name '__stkptr'; initialstkptr : record end; external name '_stack_top';
{$endif FPC_HAS_FEATURE_STACKCHECK} {$endif FPC_HAS_FEATURE_STACKCHECK}
begin begin
@ -294,7 +304,7 @@ begin
{$ifdef FPC_HAS_FEATURE_STACKCHECK} {$ifdef FPC_HAS_FEATURE_STACKCHECK}
StackLength := CheckInitialStkLen(initialStkLen); StackLength := CheckInitialStkLen(initialStkLen);
StackBottom := initialstkptr - StackLength; StackBottom := @initialstkptr - StackLength;
{$endif FPC_HAS_FEATURE_STACKCHECK} {$endif FPC_HAS_FEATURE_STACKCHECK}
{$ifdef FPC_HAS_FEATURE_EXCEPTIONS} {$ifdef FPC_HAS_FEATURE_EXCEPTIONS}

View File

@ -44,7 +44,11 @@ type
{$endif FPC_HAS_FEATURE_TEXTIO} {$endif FPC_HAS_FEATURE_TEXTIO}
const const
{$ifdef CPUAVR}
STACK_MARGIN = 64; { Stack size margin for stack checking }
{$else}
STACK_MARGIN = 16384; { Stack size margin for stack checking } STACK_MARGIN = 16384; { Stack size margin for stack checking }
{$endif}
{ Random / Randomize constants } { Random / Randomize constants }
OldRandSeed : Cardinal = 0; OldRandSeed : Cardinal = 0;