annotate gcc/ada/libgnarl/s-interr.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . I N T E R R U P T S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNARL was developed by the GNARL team at Florida State University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- Note: the compiler generates direct calls to this interface, via Rtsfind.
kono
parents:
diff changeset
33 -- Any changes to this interface may require corresponding compiler changes.
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 -- This package encapsulates the implementation of interrupt or signal
kono
parents:
diff changeset
36 -- handlers. It is logically an extension of the body of Ada.Interrupts. It
kono
parents:
diff changeset
37 -- is made a child of System to allow visibility of various runtime system
kono
parents:
diff changeset
38 -- internal data and operations.
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 -- See System.Interrupt_Management for core interrupt/signal interfaces
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 -- These two packages are separated to allow System.Interrupt_Management to be
kono
parents:
diff changeset
43 -- used without requiring the whole tasking implementation to be linked and
kono
parents:
diff changeset
44 -- elaborated.
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 with System.Tasking;
kono
parents:
diff changeset
47 with System.Tasking.Protected_Objects.Entries;
kono
parents:
diff changeset
48 with System.OS_Interface;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 package System.Interrupts is
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 pragma Elaborate_Body;
kono
parents:
diff changeset
53 -- Comment needed on why this is here ???
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 -------------------------
kono
parents:
diff changeset
56 -- Constants and types --
kono
parents:
diff changeset
57 -------------------------
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 Default_Interrupt_Priority : constant System.Interrupt_Priority :=
kono
parents:
diff changeset
60 System.Interrupt_Priority'Last;
kono
parents:
diff changeset
61 -- Default value used when a pragma Interrupt_Handler or Attach_Handler is
kono
parents:
diff changeset
62 -- specified without an Interrupt_Priority pragma, see D.3(10).
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 type Ada_Interrupt_ID is range 0 .. System.OS_Interface.Max_Interrupt;
kono
parents:
diff changeset
65 -- Avoid inheritance by Ada.Interrupts.Interrupt_ID of unwanted operations
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 type Interrupt_ID is range 0 .. System.OS_Interface.Max_Interrupt;
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 subtype System_Interrupt_Id is Interrupt_ID;
kono
parents:
diff changeset
70 -- This synonym is introduced so that the type is accessible through
kono
parents:
diff changeset
71 -- rtsfind, otherwise the name clashes with its homonym in Ada.Interrupts.
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 type Parameterless_Handler is access protected procedure;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 ----------------------
kono
parents:
diff changeset
76 -- General services --
kono
parents:
diff changeset
77 ----------------------
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 -- Attempt to attach a Handler to an Interrupt to which an Entry is
kono
parents:
diff changeset
80 -- already bound will raise a Program_Error.
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 function Is_Reserved (Interrupt : Interrupt_ID) return Boolean;
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 function Is_Entry_Attached (Interrupt : Interrupt_ID) return Boolean;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 function Is_Handler_Attached (Interrupt : Interrupt_ID) return Boolean;
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 function Current_Handler
kono
parents:
diff changeset
89 (Interrupt : Interrupt_ID) return Parameterless_Handler;
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 -- Calling the following procedures with New_Handler = null and Static =
kono
parents:
diff changeset
92 -- true means that we want to modify the current handler regardless of the
kono
parents:
diff changeset
93 -- previous handler's binding status. (i.e. we do not care whether it is a
kono
parents:
diff changeset
94 -- dynamic or static handler)
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 procedure Attach_Handler
kono
parents:
diff changeset
97 (New_Handler : Parameterless_Handler;
kono
parents:
diff changeset
98 Interrupt : Interrupt_ID;
kono
parents:
diff changeset
99 Static : Boolean := False);
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 procedure Exchange_Handler
kono
parents:
diff changeset
102 (Old_Handler : out Parameterless_Handler;
kono
parents:
diff changeset
103 New_Handler : Parameterless_Handler;
kono
parents:
diff changeset
104 Interrupt : Interrupt_ID;
kono
parents:
diff changeset
105 Static : Boolean := False);
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 procedure Detach_Handler
kono
parents:
diff changeset
108 (Interrupt : Interrupt_ID;
kono
parents:
diff changeset
109 Static : Boolean := False);
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 function Reference
kono
parents:
diff changeset
112 (Interrupt : Interrupt_ID) return System.Address;
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 --------------------------------
kono
parents:
diff changeset
115 -- Interrupt Entries Services --
kono
parents:
diff changeset
116 --------------------------------
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 -- Routines needed for Interrupt Entries
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 procedure Bind_Interrupt_To_Entry
kono
parents:
diff changeset
121 (T : System.Tasking.Task_Id;
kono
parents:
diff changeset
122 E : System.Tasking.Task_Entry_Index;
kono
parents:
diff changeset
123 Int_Ref : System.Address);
kono
parents:
diff changeset
124 -- Bind the given interrupt to the given entry. If the interrupt is
kono
parents:
diff changeset
125 -- already bound to another entry, Program_Error will be raised.
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 procedure Detach_Interrupt_Entries (T : System.Tasking.Task_Id);
kono
parents:
diff changeset
128 -- This procedure detaches all the Interrupt Entries bound to a task
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 ------------------------------
kono
parents:
diff changeset
131 -- POSIX.5 Signals Services --
kono
parents:
diff changeset
132 ------------------------------
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 -- Routines needed for POSIX dot5 POSIX_Signals
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 procedure Block_Interrupt (Interrupt : Interrupt_ID);
kono
parents:
diff changeset
137 -- Block the Interrupt on the process level
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 procedure Unblock_Interrupt (Interrupt : Interrupt_ID);
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 function Unblocked_By
kono
parents:
diff changeset
142 (Interrupt : Interrupt_ID) return System.Tasking.Task_Id;
kono
parents:
diff changeset
143 -- It returns the ID of the last Task which Unblocked this Interrupt.
kono
parents:
diff changeset
144 -- It returns Null_Task if no tasks have ever requested the Unblocking
kono
parents:
diff changeset
145 -- operation or the Interrupt is currently Blocked.
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 function Is_Blocked (Interrupt : Interrupt_ID) return Boolean;
kono
parents:
diff changeset
148 -- Comment needed ???
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 procedure Ignore_Interrupt (Interrupt : Interrupt_ID);
kono
parents:
diff changeset
151 -- Set the sigaction for the interrupt to SIG_IGN
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 procedure Unignore_Interrupt (Interrupt : Interrupt_ID);
kono
parents:
diff changeset
154 -- Comment needed ???
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 function Is_Ignored (Interrupt : Interrupt_ID) return Boolean;
kono
parents:
diff changeset
157 -- Comment needed ???
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 -- Note : Direct calls to sigaction, sigprocmask, thr_sigsetmask, or any
kono
parents:
diff changeset
160 -- other low-level interface that changes the signal action or signal mask
kono
parents:
diff changeset
161 -- needs careful thought.
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 -- One may achieve the effect of system calls first making RTS blocked (by
kono
parents:
diff changeset
164 -- calling Block_Interrupt) for the signal under consideration. This will
kono
parents:
diff changeset
165 -- make all the tasks in RTS blocked for the Interrupt.
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 ----------------------
kono
parents:
diff changeset
168 -- Protection Types --
kono
parents:
diff changeset
169 ----------------------
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 -- Routines and types needed to implement Interrupt_Handler and
kono
parents:
diff changeset
172 -- Attach_Handler.
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 -- There are two kinds of protected objects that deal with interrupts:
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 -- (1) Only Interrupt_Handler pragmas are used. We need to be able to tell
kono
parents:
diff changeset
177 -- if an Interrupt_Handler applies to a given procedure, so
kono
parents:
diff changeset
178 -- Register_Interrupt_Handler has to be called for all the potential
kono
parents:
diff changeset
179 -- handlers, it should be done by calling Register_Interrupt_Handler with
kono
parents:
diff changeset
180 -- the handler code address. On finalization, which can happen only has
kono
parents:
diff changeset
181 -- part of library level finalization since PO with Interrupt_Handler
kono
parents:
diff changeset
182 -- pragmas can only be declared at library level, nothing special needs to
kono
parents:
diff changeset
183 -- be done since the default handlers have been restored as part of task
kono
parents:
diff changeset
184 -- completion which is done just before global finalization.
kono
parents:
diff changeset
185 -- Dynamic_Interrupt_Protection should be used in this case.
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 -- (2) Attach_Handler pragmas are used, and possibly Interrupt_Handler
kono
parents:
diff changeset
188 -- pragma. We need to attach the handlers to the given interrupts when the
kono
parents:
diff changeset
189 -- object is elaborated. This should be done by constructing an array of
kono
parents:
diff changeset
190 -- pairs (interrupt, handler) from the pragmas and calling Install_Handlers
kono
parents:
diff changeset
191 -- with it (types to be used are New_Handler_Item and New_Handler_Array).
kono
parents:
diff changeset
192 -- On finalization, we need to restore the handlers that were installed
kono
parents:
diff changeset
193 -- before the elaboration of the PO, so we need to store these previous
kono
parents:
diff changeset
194 -- handlers. This is also done by Install_Handlers, the room for this
kono
parents:
diff changeset
195 -- information is provided by adding a discriminant which is the number
kono
parents:
diff changeset
196 -- of Attach_Handler pragmas and an array of this size in the protection
kono
parents:
diff changeset
197 -- type, Static_Interrupt_Protection.
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 procedure Register_Interrupt_Handler
kono
parents:
diff changeset
200 (Handler_Addr : System.Address);
kono
parents:
diff changeset
201 -- This routine should be called by the compiler to allow the handler be
kono
parents:
diff changeset
202 -- used as an Interrupt Handler. That means call this procedure for each
kono
parents:
diff changeset
203 -- pragma Interrupt_Handler providing the address of the handler (not
kono
parents:
diff changeset
204 -- including the pointer to the actual PO, this way this routine is called
kono
parents:
diff changeset
205 -- only once for each type definition of PO).
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 type Static_Handler_Index is range 0 .. Integer'Last;
kono
parents:
diff changeset
208 subtype Positive_Static_Handler_Index is
kono
parents:
diff changeset
209 Static_Handler_Index range 1 .. Static_Handler_Index'Last;
kono
parents:
diff changeset
210 -- Comment needed ???
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 type Previous_Handler_Item is record
kono
parents:
diff changeset
213 Interrupt : Interrupt_ID;
kono
parents:
diff changeset
214 Handler : Parameterless_Handler;
kono
parents:
diff changeset
215 Static : Boolean;
kono
parents:
diff changeset
216 end record;
kono
parents:
diff changeset
217 -- Contains all the information needed to restore a previous handler
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 type Previous_Handler_Array is array
kono
parents:
diff changeset
220 (Positive_Static_Handler_Index range <>) of Previous_Handler_Item;
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 type New_Handler_Item is record
kono
parents:
diff changeset
223 Interrupt : Interrupt_ID;
kono
parents:
diff changeset
224 Handler : Parameterless_Handler;
kono
parents:
diff changeset
225 end record;
kono
parents:
diff changeset
226 -- Contains all the information from an Attach_Handler pragma
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 type New_Handler_Array is
kono
parents:
diff changeset
229 array (Positive_Static_Handler_Index range <>) of New_Handler_Item;
kono
parents:
diff changeset
230 -- Comment needed ???
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 -- Case (1)
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 type Dynamic_Interrupt_Protection is new
kono
parents:
diff changeset
235 Tasking.Protected_Objects.Entries.Protection_Entries with null record;
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 -- ??? Finalize is not overloaded since we currently have no
kono
parents:
diff changeset
238 -- way to detach the handlers during library level finalization.
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 function Has_Interrupt_Or_Attach_Handler
kono
parents:
diff changeset
241 (Object : access Dynamic_Interrupt_Protection) return Boolean;
kono
parents:
diff changeset
242 -- Returns True
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 -- Case (2)
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 type Static_Interrupt_Protection
kono
parents:
diff changeset
247 (Num_Entries : Tasking.Protected_Objects.Protected_Entry_Index;
kono
parents:
diff changeset
248 Num_Attach_Handler : Static_Handler_Index)
kono
parents:
diff changeset
249 is new
kono
parents:
diff changeset
250 Tasking.Protected_Objects.Entries.Protection_Entries (Num_Entries) with
kono
parents:
diff changeset
251 record
kono
parents:
diff changeset
252 Previous_Handlers : Previous_Handler_Array (1 .. Num_Attach_Handler);
kono
parents:
diff changeset
253 end record;
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 function Has_Interrupt_Or_Attach_Handler
kono
parents:
diff changeset
256 (Object : access Static_Interrupt_Protection) return Boolean;
kono
parents:
diff changeset
257 -- Returns True
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 overriding procedure Finalize (Object : in out Static_Interrupt_Protection);
kono
parents:
diff changeset
260 -- Restore previous handlers as required by C.3.1(12) then call
kono
parents:
diff changeset
261 -- Finalize (Protection).
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 procedure Install_Handlers
kono
parents:
diff changeset
264 (Object : access Static_Interrupt_Protection;
kono
parents:
diff changeset
265 New_Handlers : New_Handler_Array);
kono
parents:
diff changeset
266 -- Store the old handlers in Object.Previous_Handlers and install
kono
parents:
diff changeset
267 -- the new static handlers.
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 procedure Install_Restricted_Handlers
kono
parents:
diff changeset
270 (Prio : Any_Priority;
kono
parents:
diff changeset
271 Handlers : New_Handler_Array);
kono
parents:
diff changeset
272 -- Install the static Handlers for the given interrupts and do not
kono
parents:
diff changeset
273 -- store previously installed handlers. This procedure is used when
kono
parents:
diff changeset
274 -- the Ravenscar restrictions are in place since in that case there
kono
parents:
diff changeset
275 -- are only library-level protected handlers that will be installed
kono
parents:
diff changeset
276 -- at initialization and never be replaced.
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 end System.Interrupts;