Daily bump.
[official-gcc.git] / gcc / ada / s-intman-vxworks.adb
blobdacc418f05ceda6b483096de6e085d421c93b761
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT 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 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2009, 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 3, 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. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 -- This is the VxWorks version of this package
34 -- Make a careful study of all signals available under the OS, to see which
35 -- need to be reserved, kept always unmasked, or kept always unmasked. Be on
36 -- the lookout for special signals that may be used by the thread library.
38 package body System.Interrupt_Management is
40 use System.OS_Interface;
41 use type Interfaces.C.int;
43 type Signal_List is array (Signal_ID range <>) of Signal_ID;
44 Exception_Signals : constant Signal_List (1 .. 4) :=
45 (SIGFPE, SIGILL, SIGSEGV, SIGBUS);
47 Exception_Action : aliased struct_sigaction;
48 -- Keep this variable global so that it is initialized only once
50 procedure Notify_Exception
51 (signo : Signal;
52 siginfo : System.Address;
53 sigcontext : System.Address);
54 pragma Import (C, Notify_Exception, "__gnat_error_handler");
55 -- Map signal to Ada exception and raise it. Different versions
56 -- of VxWorks need different mappings.
58 -----------------------
59 -- Local Subprograms --
60 -----------------------
62 function State (Int : Interrupt_ID) return Character;
63 pragma Import (C, State, "__gnat_get_interrupt_state");
64 -- Get interrupt state. Defined in init.c The input argument is the
65 -- interrupt number, and the result is one of the following:
67 Runtime : constant Character := 'r';
68 Default : constant Character := 's';
69 -- 'n' this interrupt not set by any Interrupt_State pragma
70 -- 'u' Interrupt_State pragma set state to User
71 -- 'r' Interrupt_State pragma set state to Runtime
72 -- 's' Interrupt_State pragma set state to System (use "default"
73 -- system handler)
75 ---------------------------
76 -- Initialize_Interrupts --
77 ---------------------------
79 -- Since there is no signal inheritance between VxWorks tasks, we need
80 -- to initialize signal handling in each task.
82 procedure Initialize_Interrupts is
83 Result : int;
84 old_act : aliased struct_sigaction;
85 begin
86 for J in Exception_Signals'Range loop
87 Result :=
88 sigaction
89 (Signal (Exception_Signals (J)), Exception_Action'Access,
90 old_act'Unchecked_Access);
91 pragma Assert (Result = 0);
92 end loop;
93 end Initialize_Interrupts;
95 ----------------
96 -- Initialize --
97 ----------------
99 Initialized : Boolean := False;
100 -- Set to True once Initialize is called, further calls have no effect
102 procedure Initialize is
103 mask : aliased sigset_t;
104 Result : int;
106 begin
107 if Initialized then
108 return;
109 end if;
111 Initialized := True;
113 -- Change this if you want to use another signal for task abort.
114 -- SIGTERM might be a good one.
116 Abort_Task_Interrupt := SIGABRT;
118 Exception_Action.sa_handler := Notify_Exception'Address;
119 Exception_Action.sa_flags := SA_ONSTACK + SA_SIGINFO;
120 Result := sigemptyset (mask'Access);
121 pragma Assert (Result = 0);
123 for J in Exception_Signals'Range loop
124 Result := sigaddset (mask'Access, Signal (Exception_Signals (J)));
125 pragma Assert (Result = 0);
126 end loop;
128 Exception_Action.sa_mask := mask;
130 -- Initialize hardware interrupt handling
132 pragma Assert (Reserve = (Interrupt_ID'Range => False));
134 -- Check all interrupts for state that requires keeping them reserved
136 for J in Interrupt_ID'Range loop
137 if State (J) = Default or else State (J) = Runtime then
138 Reserve (J) := True;
139 end if;
140 end loop;
142 -- Add exception signals to the set of unmasked signals
144 for J in Exception_Signals'Range loop
145 Keep_Unmasked (Exception_Signals (J)) := True;
146 end loop;
148 -- The abort signal must also be unmasked
150 Keep_Unmasked (Abort_Task_Interrupt) := True;
151 end Initialize;
153 end System.Interrupt_Management;