1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . S E C O N D A R Y _ S T A C K --
9 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This is the HI-E version of this package.
36 with Unchecked_Conversion;
38 package body System.Secondary_Stack is
40 use type SSE.Storage_Offset;
42 type Memory is array (Mark_Id range <>) of SSE.Storage_Element;
44 type Stack_Id is record
47 Mem : Memory (1 .. Mark_Id'Last);
49 pragma Suppress_Initialization (Stack_Id);
51 type Stack_Ptr is access Stack_Id;
53 function From_Addr is new Unchecked_Conversion (Address, Stack_Ptr);
55 function Get_Sec_Stack return Stack_Ptr;
56 pragma Import (C, Get_Sec_Stack, "__gnat_get_secondary_stack");
57 -- Return the address of the secondary stack.
58 -- In a multi-threaded environment, Sec_Stack should be a thread-local
61 -- Possible implementation of Get_Sec_Stack in a single-threaded
64 -- Chunk : aliased Memory (1 .. Default_Secondary_Stack_Size);
65 -- for Chunk'Alignment use Standard'Maximum_Alignment;
66 -- -- The secondary stack.
68 -- function Get_Sec_Stack return Stack_Ptr is
70 -- return From_Addr (Chunk'Address);
74 -- SS_Init (Chunk'Address, Default_Secondary_Stack_Size);
75 -- end System.Secondary_Stack;
82 (Address : out System.Address;
83 Storage_Size : SSE.Storage_Count)
85 Max_Align : constant Mark_Id := Mark_Id (Standard'Maximum_Alignment);
86 Max_Size : constant Mark_Id :=
87 ((Mark_Id (Storage_Size) + Max_Align - 1) / Max_Align)
89 Sec_Stack : constant Stack_Ptr := Get_Sec_Stack;
92 if Sec_Stack.Top + Max_Size > Sec_Stack.Last then
96 Address := Sec_Stack.Mem (Sec_Stack.Top)'Address;
97 Sec_Stack.Top := Sec_Stack.Top + Mark_Id (Max_Size);
104 procedure SS_Free (Stk : in out System.Address) is
114 (Stk : System.Address;
115 Size : Natural := Default_Secondary_Stack_Size)
117 Stack : Stack_Ptr := From_Addr (Stk);
119 pragma Assert (Size >= 2 * Mark_Id'Max_Size_In_Storage_Elements);
121 Stack.Top := Stack.Mem'First;
122 Stack.Last := Mark_Id (Size) - 2 * Mark_Id'Max_Size_In_Storage_Elements;
129 function SS_Mark return Mark_Id is
131 return Get_Sec_Stack.Top;
138 procedure SS_Release (M : Mark_Id) is
140 Get_Sec_Stack.Top := M;
143 end System.Secondary_Stack;