1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
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 --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
32 ------------------------------------------------------------------------------
34 -- This is the VxWorks version of this package
36 -- Make a careful study of all signals available under the OS, to see which
37 -- need to be reserved, kept always unmasked, or kept always unmasked. Be on
38 -- the lookout for special signals that may be used by the thread library.
40 package body System.Interrupt_Management is
42 use System.OS_Interface;
43 use type Interfaces.C.int;
45 type Signal_List is array (Signal_ID range <>) of Signal_ID;
46 Exception_Signals : constant Signal_List (1 .. 4) :=
47 (SIGFPE, SIGILL, SIGSEGV, SIGBUS);
49 Exception_Action : aliased struct_sigaction;
50 -- Keep this variable global so that it is initialized only once
52 procedure Map_And_Raise_Exception (signo : Signal);
53 pragma Import (C, Map_And_Raise_Exception, "__gnat_map_signal");
54 -- Map signal to Ada exception and raise it. Different versions
55 -- of VxWorks need different mappings.
57 -----------------------
58 -- Local Subprograms --
59 -----------------------
61 function State (Int : Interrupt_ID) return Character;
62 pragma Import (C, State, "__gnat_get_interrupt_state");
63 -- Get interrupt state. Defined in init.c The input argument is the
64 -- interrupt number, and the result is one of the following:
66 Runtime : constant Character := 'r';
67 Default : constant Character := 's';
68 -- 'n' this interrupt not set by any Interrupt_State pragma
69 -- 'u' Interrupt_State pragma set state to User
70 -- 'r' Interrupt_State pragma set state to Runtime
71 -- 's' Interrupt_State pragma set state to System (use "default"
74 procedure Notify_Exception (signo : Signal);
75 -- Identify the Ada exception to be raised using
76 -- the information when the system received a synchronous signal.
78 ----------------------
79 -- Notify_Exception --
80 ----------------------
82 procedure Notify_Exception (signo : Signal) is
83 Mask : aliased sigset_t;
86 pragma Unreferenced (Result);
89 Result := pthread_sigmask (SIG_SETMASK, null, Mask'Unchecked_Access);
90 Result := sigdelset (Mask'Access, signo);
91 Result := pthread_sigmask (SIG_SETMASK, Mask'Unchecked_Access, null);
93 Map_And_Raise_Exception (signo);
96 ---------------------------
97 -- Initialize_Interrupts --
98 ---------------------------
100 -- Since there is no signal inheritance between VxWorks tasks, we need
101 -- to initialize signal handling in each task.
103 procedure Initialize_Interrupts is
105 old_act : aliased struct_sigaction;
107 for J in Exception_Signals'Range loop
110 (Signal (Exception_Signals (J)), Exception_Action'Access,
111 old_act'Unchecked_Access);
112 pragma Assert (Result = 0);
114 end Initialize_Interrupts;
120 Initialized : Boolean := False;
122 procedure Initialize is
123 mask : aliased sigset_t;
132 -- Change this if you want to use another signal for task abort.
133 -- SIGTERM might be a good one.
135 Abort_Task_Interrupt := SIGABRT;
137 Exception_Action.sa_handler := Notify_Exception'Address;
138 Exception_Action.sa_flags := SA_ONSTACK;
139 Result := sigemptyset (mask'Access);
140 pragma Assert (Result = 0);
142 for J in Exception_Signals'Range loop
143 Result := sigaddset (mask'Access, Signal (Exception_Signals (J)));
144 pragma Assert (Result = 0);
147 Exception_Action.sa_mask := mask;
149 -- Initialize hardware interrupt handling
151 pragma Assert (Reserve = (Interrupt_ID'Range => False));
153 -- Check all interrupts for state that requires keeping them reserved
155 for J in Interrupt_ID'Range loop
156 if State (J) = Default or else State (J) = Runtime then
161 -- Add exception signals to the set of unmasked signals
163 for J in Exception_Signals'Range loop
164 Keep_Unmasked (Exception_Signals (J)) := True;
167 -- The abort signal must also be unmasked
169 Keep_Unmasked (Abort_Task_Interrupt) := True;
172 end System.Interrupt_Management;