Skip to content

Commit

Permalink
Implement Secondary_Stack_Size.
Browse files Browse the repository at this point in the history
  * common/gcc7/s-tarest.adb: if Secondary_Stack_Size isn't
      Unspecified_Size, use it as-is.

  * common/gnat-gpl-2017/s-tarest.adb: likewise. Remove unneeded 'with
      Interfaces;'.

  * common/gcc8/s-tarest.adb (Parameters): add SStack_Addr.
    (Wrapper): if P.SStack_Addr is null, allocate secondary stack on
      task stack. If it isn't, register it as-is in the ATCB.
    (Create_Restricted_Task): pass Sec_Stack_Address to Wrapper.
      If Secondary_Stack_Size isn't Unspecified_Size, use it as-is
      (regardless of whether it's going to be used).
  • Loading branch information
simonjwright committed Jun 14, 2018
1 parent 1f6fc56 commit de0aae9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
10 changes: 6 additions & 4 deletions common/gcc7/s-tarest.adb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2016, 2017 Free Software Foundation, Inc. --
-- Copyright (C) 2016-2018 Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -35,7 +35,7 @@
-- This package represents the high level tasking interface used by the
-- compiler to expand Ada 95 tasking constructs into simpler run time calls.

-- This is is the version for the Cortex GNAT RTS project.
-- This is the version for the Cortex GNAT RTS project.

with Ada.Unchecked_Conversion;
with System.Address_To_Access_Conversions;
Expand Down Expand Up @@ -107,7 +107,6 @@ package body System.Tasking.Restricted.Stages is
Created_Task : Task_Id) is

pragma Unreferenced (Stack_Address);
pragma Unreferenced (Secondary_Stack_Size);
pragma Unreferenced (Task_Info);
pragma Unreferenced (CPU);
pragma Unreferenced (Chain);
Expand All @@ -121,6 +120,7 @@ package body System.Tasking.Restricted.Stages is
constant Parameters_Conversion.Object_Pointer :=
Parameters_Conversion.To_Pointer (Wrapper_Parameter_Address);

use type System.Parameters.Size_Type;
use type FreeRTOS.Tasks.Task_Handle;
begin
if Wrapper_Parameter_Address = System.Null_Address then
Expand All @@ -131,7 +131,9 @@ package body System.Tasking.Restricted.Stages is
Task_Proc => State,
Discriminants => Discriminants,
SStack_Size =>
System.Parameters.Secondary_Stack_Size (Actual_Stack_Size));
(if Secondary_Stack_Size = System.Parameters.Unspecified_Size
then System.Parameters.Secondary_Stack_Size (Actual_Stack_Size)
else Secondary_Stack_Size));

Created_Task.Common.Base_Priority := (if Priority = Unspecified_Priority
then System.Default_Priority
Expand Down
58 changes: 42 additions & 16 deletions common/gcc8/s-tarest.adb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2016-2017 Free Software Foundation, Inc. --
-- Copyright (C) 2016-2018 Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -35,7 +35,7 @@
-- This package represents the high level tasking interface used by the
-- compiler to expand Ada 95 tasking constructs into simpler run time calls.

-- This is is the version for the Cortex GNAT RTS project.
-- This is the version for the Cortex GNAT RTS project.

with Ada.Unchecked_Conversion;
with System.Address_To_Access_Conversions;
Expand All @@ -55,6 +55,7 @@ package body System.Tasking.Restricted.Stages is
ATCB : Task_Id;
Task_Proc : Task_Procedure_Access;
Discriminants : System.Address;
SStack_Addr : System.Secondary_Stack.SS_Stack_Ptr;
SStack_Size : System.Parameters.Size_Type;
end record;

Expand All @@ -63,25 +64,48 @@ package body System.Tasking.Restricted.Stages is

procedure Wrapper (Arg1 : System.Address) is
function Convert_Task_Id
is new Ada.Unchecked_Conversion (Task_Id, System.Address);
is new Ada.Unchecked_Conversion (Task_Id, System.Address);

P : constant Parameters_Conversion.Object_Pointer :=
Parameters_Conversion.To_Pointer (Arg1);

Secondary_Stack :
aliased System.Secondary_Stack.SS_Stack (Size => P.SStack_Size);
-- At this point, the stack is the task's stack
use type System.Secondary_Stack.SS_Stack_Ptr;
begin
-- Save the ATCB in the FreeRTOS TCB
FreeRTOS.TCB.Set_Application_Parameter (Convert_Task_Id (P.ATCB));

-- Register the secondary stack
P.ATCB.Secondary_Stack := Secondary_Stack'Unchecked_Access;
-- Unchecked_Access is OK because it can only be accessed from
-- the current task, within Task_Proc.

-- Call the task procedure
P.Task_Proc (P.Discriminants);
-- Secondary stack handling:
--
-- If P.SStack_Addr is Null_Address, then we are to allocate a
-- region from the bottom of the task's stack, size P.SStack_Size.
--
-- If P.SStack_Addr isn't Null_Address, it's a region of the
-- task's package's BSS allocated and initialized by the
-- compiler.

if P.SStack_Addr = null then
declare
-- At this point, the stack is the task's stack. Declare
-- a stack here.
Secondary_Stack :
aliased System.Secondary_Stack.SS_Stack (Size => P.SStack_Size);
begin
-- Register the secondary stack
P.ATCB.Secondary_Stack := Secondary_Stack'Unchecked_Access;
-- Unchecked_Access is OK because it can only be accessed from
-- the current task, within Task_Proc.

-- Call the task procedure. The secondary stack is still
-- on the stack.
P.Task_Proc (P.Discriminants);
end;
else
-- Register the compiler-allocated secondary stack
P.ATCB.Secondary_Stack := P.SStack_Addr;

-- Call the task procedure
P.Task_Proc (P.Discriminants);
end if;

-- If we return here, the task procedure has exited (and not
-- because of an exception, which would already have reached
Expand All @@ -108,8 +132,6 @@ package body System.Tasking.Restricted.Stages is
Created_Task : Task_Id) is

pragma Unreferenced (Stack_Address);
pragma Unreferenced (Sec_Stack_Address);
pragma Unreferenced (Secondary_Stack_Size);
pragma Unreferenced (Task_Info);
pragma Unreferenced (CPU);
pragma Unreferenced (Chain);
Expand All @@ -123,6 +145,7 @@ package body System.Tasking.Restricted.Stages is
constant Parameters_Conversion.Object_Pointer :=
Parameters_Conversion.To_Pointer (Wrapper_Parameter_Address);

use type System.Parameters.Size_Type;
use type FreeRTOS.Tasks.Task_Handle;
begin
if Wrapper_Parameter_Address = System.Null_Address then
Expand All @@ -132,8 +155,11 @@ package body System.Tasking.Restricted.Stages is
(ATCB => Created_Task,
Task_Proc => State,
Discriminants => Discriminants,
SStack_Addr => Sec_Stack_Address,
SStack_Size =>
System.Parameters.Secondary_Stack_Size (Actual_Stack_Size));
(if Secondary_Stack_Size = System.Parameters.Unspecified_Size
then System.Parameters.Secondary_Stack_Size (Actual_Stack_Size)
else Secondary_Stack_Size)); -- don't think this will happen?

Created_Task.Common.Base_Priority := (if Priority = Unspecified_Priority
then System.Default_Priority
Expand Down
11 changes: 6 additions & 5 deletions common/gnat-gpl-2017/s-tarest.adb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2016, 2017 Free Software Foundation, Inc. --
-- Copyright (C) 2016-2018 Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
Expand Down Expand Up @@ -35,10 +35,9 @@
-- This package represents the high level tasking interface used by the
-- compiler to expand Ada 95 tasking constructs into simpler run time calls.

-- This is is the version for the Cortex GNAT RTS project.
-- This is the version for the Cortex GNAT RTS project.

with Ada.Unchecked_Conversion;
with Interfaces;
with System.Address_To_Access_Conversions;
with System.FreeRTOS.TCB;
with System.Memory;
Expand Down Expand Up @@ -108,7 +107,6 @@ package body System.Tasking.Restricted.Stages is
Created_Task : Task_Id) is

pragma Unreferenced (Stack_Address);
pragma Unreferenced (Secondary_Stack_Size);
pragma Unreferenced (Task_Info);
pragma Unreferenced (CPU);
pragma Unreferenced (Chain);
Expand All @@ -122,6 +120,7 @@ package body System.Tasking.Restricted.Stages is
constant Parameters_Conversion.Object_Pointer :=
Parameters_Conversion.To_Pointer (Wrapper_Parameter_Address);

use type System.Parameters.Size_Type;
use type FreeRTOS.Tasks.Task_Handle;
begin
if Wrapper_Parameter_Address = System.Null_Address then
Expand All @@ -132,7 +131,9 @@ package body System.Tasking.Restricted.Stages is
Task_Proc => State,
Discriminants => Discriminants,
SStack_Size =>
System.Parameters.Secondary_Stack_Size (Actual_Stack_Size));
(if Secondary_Stack_Size = System.Parameters.Unspecified_Size
then System.Parameters.Secondary_Stack_Size (Actual_Stack_Size)
else Secondary_Stack_Size));

Created_Task.Common.Base_Priority := (if Priority = Unspecified_Priority
then System.Default_Priority
Expand Down

0 comments on commit de0aae9

Please sign in to comment.