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 --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 ------------------------------------------------------------------------------
35 -- This is the HI-E version of this package.
37 with Unchecked_Conversion
;
39 package body System
.Secondary_Stack
is
41 use type SSE
.Storage_Offset
;
43 type Memory
is array (Mark_Id
range <>) of SSE
.Storage_Element
;
45 type Stack_Id
is record
48 Mem
: Memory
(1 .. Mark_Id
'Last);
50 pragma Suppress_Initialization
(Stack_Id
);
52 type Stack_Ptr
is access Stack_Id
;
54 function From_Addr
is new Unchecked_Conversion
(Address
, Stack_Ptr
);
56 function Get_Sec_Stack
return Stack_Ptr
;
57 pragma Import
(C
, Get_Sec_Stack
, "__gnat_get_secondary_stack");
58 -- Return the address of the secondary stack.
59 -- In a multi-threaded environment, Sec_Stack should be a thread-local
62 -- Possible implementation of Get_Sec_Stack in a single-threaded
65 -- Chunk : aliased Memory (1 .. Default_Secondary_Stack_Size);
66 -- for Chunk'Alignment use Standard'Maximum_Alignment;
67 -- -- The secondary stack.
69 -- function Get_Sec_Stack return Stack_Ptr is
71 -- return From_Addr (Chunk'Address);
75 -- SS_Init (Chunk'Address, Default_Secondary_Stack_Size);
76 -- end System.Secondary_Stack;
83 (Address
: out System
.Address
;
84 Storage_Size
: SSE
.Storage_Count
)
86 Max_Align
: constant Mark_Id
:= Mark_Id
(Standard
'Maximum_Alignment);
87 Max_Size
: constant Mark_Id
:=
88 ((Mark_Id
(Storage_Size
) + Max_Align
- 1) / Max_Align
)
90 Sec_Stack
: constant Stack_Ptr
:= Get_Sec_Stack
;
93 if Sec_Stack
.Top
+ Max_Size
> Sec_Stack
.Last
then
97 Address
:= Sec_Stack
.Mem
(Sec_Stack
.Top
)'Address;
98 Sec_Stack
.Top
:= Sec_Stack
.Top
+ Mark_Id
(Max_Size
);
105 procedure SS_Free
(Stk
: in out System
.Address
) is
115 (Stk
: System
.Address
;
116 Size
: Natural := Default_Secondary_Stack_Size
)
118 Stack
: Stack_Ptr
:= From_Addr
(Stk
);
120 pragma Assert
(Size
>= 2 * Mark_Id
'Max_Size_In_Storage_Elements);
122 Stack
.Top
:= Stack
.Mem
'First;
123 Stack
.Last
:= Mark_Id
(Size
) - 2 * Mark_Id
'Max_Size_In_Storage_Elements;
130 function SS_Mark
return Mark_Id
is
132 return Get_Sec_Stack
.Top
;
139 procedure SS_Release
(M
: Mark_Id
) is
141 Get_Sec_Stack
.Top
:= M
;
144 end System
.Secondary_Stack
;