1------------------------------------------------------------------------------
2--                                                                          --
3--                GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS               --
4--                                                                          --
5--            S Y S T E M . I N T E R R U P T _ M A N A G E M E N T         --
6--                                                                          --
7--                                  S p e c                                 --
8--                                                                          --
9--          Copyright (C) 1991-2003 Free Software Foundation, Inc.          --
10--                                                                          --
11-- GNARL 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. GNARL 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 GNARL; see file COPYING.  If not, write --
19-- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20-- MA 02111-1307, USA.                                                      --
21--                                                                          --
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.                                      --
28--                                                                          --
29-- GNARL was developed by the GNARL team at Florida State University.       --
30-- Extensive contributions were provided by Ada Core Technologies, Inc.     --
31--                                                                          --
32------------------------------------------------------------------------------
33
34--  This is the Alpha/VMS version of this package.
35--
36--  This package encapsulates and centralizes information about
37--  all uses of interrupts (or signals), including the
38--  target-dependent mapping of interrupts (or signals) to exceptions.
39
40--  PLEASE DO NOT add any with-clauses to this package.
41--  This is designed to work for both tasking and non-tasking systems,
42--  without pulling in any of the tasking support.
43
44--  PLEASE DO NOT remove the Elaborate_Body pragma from this package.
45--  Elaboration of this package should happen early, as most other
46--  initializations depend on it.
47--  Forcing immediate elaboration of the body also helps to enforce
48--  the design assumption that this is a second-level
49--  package, just one level above System.OS_Interface, with no
50--  cross-dependences.
51
52--  PLEASE DO NOT put any subprogram declarations with arguments of
53--  type Interrupt_ID into the visible part of this package.
54--  The type Interrupt_ID is used to derive the type in Ada.Interrupts,
55--  and adding more operations to that type would be illegal according
56--  to the Ada Reference Manual.  (This is the reason why the signals sets
57--  below are implemented as visible arrays rather than functions.)
58
59with System.OS_Interface;
60--  used for Signal
61--           sigset_t
62
63package System.Interrupt_Management is
64
65   pragma Elaborate_Body;
66
67   type Interrupt_Mask is limited private;
68
69   type Interrupt_ID is new System.OS_Interface.Signal;
70
71   type Interrupt_Set is array (Interrupt_ID) of Boolean;
72
73   --  The following objects serve as constants, but are initialized
74   --  in the body to aid portability.  This permits us
75   --  to use more portable names for interrupts,
76   --  where distinct names may map to the same interrupt ID value.
77   --  For example, suppose SIGRARE is a signal that is not defined on
78   --  all systems, but is always reserved when it is defined.
79   --  If we have the convention that ID zero is not used for any "real"
80   --  signals, and SIGRARE = 0 when SIGRARE is not one of the locally
81   --  supported signals, we can write
82   --     Reserved (SIGRARE) := true;
83   --  and the initialization code will be portable.
84
85   Abort_Task_Interrupt : Interrupt_ID;
86   --  The interrupt that is used to implement task abortion,
87   --  if an interrupt is used for that purpose.
88   --  This is one of the reserved interrupts.
89
90   Keep_Unmasked : Interrupt_Set := (others => False);
91   --  Keep_Unmasked (I) is true iff the interrupt I is
92   --  one that must be kept unmasked at all times,
93   --  except (perhaps) for short critical sections.
94   --  This includes interrupts that are mapped to exceptions
95   --  (see System.Interrupt_Exceptions.Is_Exception), but may also
96   --  include interrupts (e.g. timer) that need to be kept unmasked
97   --  for other reasons.
98   --  Where interrupts are implemented as OS signals, and signal masking
99   --  is per-task, the interrupt should be unmasked in ALL TASKS.
100
101   Reserve : Interrupt_Set := (others => False);
102   --  Reserve (I) is true iff the interrupt I is one that
103   --  cannot be permitted to be attached to a user handler.
104   --  The possible reasons are many.  For example,
105   --  it may be mapped to an exception, used to implement task abortion,
106   --  or used to implement time delays.
107
108   Keep_Masked : Interrupt_Set := (others => False);
109   --  Keep_Masked (I) is true iff the interrupt I must always be masked.
110   --  Where interrupts are implemented as OS signals, and signal masking
111   --  is per-task, the interrupt should be masked in ALL TASKS.
112   --  There might not be any interrupts in this class, depending on
113   --  the environment.  For example, if interrupts are OS signals
114   --  and signal masking is per-task, use of the sigwait operation
115   --  requires the signal be masked in all tasks.
116
117   procedure Initialize_Interrupts;
118   --  On systems where there is no signal inheritance between tasks (e.g
119   --  VxWorks, GNU/LinuxThreads), this procedure is used to initialize
120   --  interrupts handling in each task. Otherwise this function should
121   --  only be called by initialize in this package body.
122
123private
124
125   use type System.OS_Interface.unsigned_long;
126
127   type Interrupt_Mask is new System.OS_Interface.sigset_t;
128
129   --  Interrupts on VMS are implemented with a mailbox. A QIO read is
130   --  registered on the Rcv channel and the interrupt occurs by registering
131   --  a QIO write on the Snd channel. The maximum number of pending
132   --  interrupts is arbitrarily set at 1000. One nice feature of using
133   --  a mailbox is that it is trivially extendable to cross process
134   --  interrupts.
135
136   Rcv_Interrupt_Chan : System.OS_Interface.unsigned_short := 0;
137   Snd_Interrupt_Chan : System.OS_Interface.unsigned_short := 0;
138   Interrupt_Mailbox  : Interrupt_ID := 0;
139   Interrupt_Bufquo   : System.OS_Interface.unsigned_long
140                        := 1000 * (Interrupt_ID'Size / 8);
141
142end System.Interrupt_Management;
143