1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . I N T E R R U P T S --
11 -- Copyright (C) 1991-2001 Free Software Foundation, Inc. --
13 -- GNARL is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNARL; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNARL was developed by the GNARL team at Florida State University. It is --
32 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
33 -- State University (http://www.gnat.com). --
35 ------------------------------------------------------------------------------
39 -- All user-handleable signals are masked at all times in all
40 -- tasks/threads except possibly for the Interrupt_Manager task.
42 -- When a user task wants to have the effect of masking/unmasking an
43 -- signal, it must call Block_Interrupt/Unblock_Interrupt, which
44 -- will have the effect of unmasking/masking the signal in the
45 -- Interrupt_Manager task. These comments do not apply to vectored
46 -- hardware interrupts, which may be masked or unmasked using routined
47 -- interfaced to the relevant VxWorks system calls.
49 -- Note : Direct calls to sigaction, sigprocmask, pthread_sigsetmask or any
50 -- other low-level interface that changes the signal action or
51 -- signal mask needs careful consideration.
52 -- One may achieve the effect of system calls first masking RTS blocked
53 -- (by calling Block_Interrupt) for the signal under consideration.
54 -- This will make all the tasks in RTS blocked for the signal.
56 -- Once we associate a Signal_Server_Task with an signal, the task never
57 -- goes away, and we never remove the association. On the other hand, it
58 -- is more convenient to terminate an associated Interrupt_Server_Task
59 -- for a vectored hardware interrupt (since we use a binary semaphore
60 -- for synchronization with the umbrella handler).
62 -- There is no more than one signal per Signal_Server_Task and no more than
63 -- one Signal_Server_Task per signal. The same relation holds for hardware
64 -- interrupts and Interrupt_Server_Task's at any given time. That is,
65 -- only one non-terminated Interrupt_Server_Task exists for a give
66 -- interrupt at any time.
68 -- Within this package, the lock L is used to protect the various status
69 -- tables. If there is a Server_Task associated with a signal or interrupt,
70 -- we use the per-task lock of the Server_Task instead so that we protect the
71 -- status between Interrupt_Manager and Server_Task. Protection among
72 -- service requests are ensured via user calls to the Interrupt_Manager
75 -- This is the VxWorks version of this package, supporting both signals
76 -- and vectored hardware interrupts.
78 with Unchecked_Conversion
;
80 with System
.OS_Interface
; use System
.OS_Interface
;
84 with Interfaces
.VxWorks
;
86 with Ada
.Task_Identification
;
87 -- used for Task_ID type
90 -- used for Raise_Exception
92 with System
.Task_Primitives
;
96 with System
.Interrupt_Management
;
100 -- Abort_Task_Interrupt
102 with System
.Interrupt_Management
.Operations
;
103 -- used for Thread_Block_Interrupt
104 -- Thread_Unblock_Interrupt
105 -- Install_Default_Action
106 -- Install_Ignore_Action
107 -- Copy_Interrupt_Mask
108 -- Set_Interrupt_Mask
109 -- Empty_Interrupt_Mask
110 -- Fill_Interrupt_Mask
111 -- Add_To_Interrupt_Mask
112 -- Delete_From_Interrupt_Mask
114 -- Interrupt_Self_Process
115 -- Get_Interrupt_Mask
116 -- Set_Interrupt_Mask
120 pragma Elaborate_All
(System
.Interrupt_Management
.Operations
);
122 with System
.Error_Reporting
;
125 with System
.Task_Primitives
.Operations
;
126 -- used for Write_Lock
133 with System
.Task_Primitives
.Interrupt_Operations
;
134 -- used for Set_Interrupt_ID
136 with System
.Storage_Elements
;
137 -- used for To_Address
146 -- Interrupt_Manager_ID
148 with System
.Tasking
.Utilities
;
149 -- used for Make_Independent
151 with System
.Tasking
.Rendezvous
;
152 -- used for Call_Simple
153 pragma Elaborate_All
(System
.Tasking
.Rendezvous
);
155 with System
.Tasking
.Initialization
;
156 -- used for Defer_Abort
159 package body System
.Interrupts
is
162 use System
.Error_Reporting
;
165 package PRI
renames System
.Task_Primitives
;
166 package POP
renames System
.Task_Primitives
.Operations
;
167 package PIO
renames System
.Task_Primitives
.Interrupt_Operations
;
168 package IMNG
renames System
.Interrupt_Management
;
169 package IMOP
renames System
.Interrupt_Management
.Operations
;
171 function To_Ada
is new Unchecked_Conversion
172 (System
.Tasking
.Task_ID
, Ada
.Task_Identification
.Task_Id
);
174 function To_System
is new Unchecked_Conversion
175 (Ada
.Task_Identification
.Task_Id
, Task_ID
);
181 -- WARNING: System.Tasking.Utilities performs calls to this task
182 -- with low-level constructs. Do not change this spec without synchro-
185 task Interrupt_Manager
is
186 entry Initialize
(Mask
: IMNG
.Interrupt_Mask
);
189 (New_Handler
: Parameterless_Handler
;
190 Interrupt
: Interrupt_ID
;
192 Restoration
: Boolean := False);
194 entry Exchange_Handler
195 (Old_Handler
: out Parameterless_Handler
;
196 New_Handler
: Parameterless_Handler
;
197 Interrupt
: Interrupt_ID
;
201 (Interrupt
: Interrupt_ID
;
204 entry Bind_Interrupt_To_Entry
206 E
: Task_Entry_Index
;
207 Interrupt
: Interrupt_ID
);
209 entry Detach_Interrupt_Entries
(T
: Task_ID
);
211 pragma Interrupt_Priority
(System
.Interrupt_Priority
'First);
212 end Interrupt_Manager
;
214 task type Signal_Server_Task
(Interrupt
: Interrupt_ID
) is
215 pragma Interrupt_Priority
(System
.Interrupt_Priority
'First + 1);
216 end Signal_Server_Task
;
217 -- Server task for signal handling
219 type Signal_Task_Access
is access Signal_Server_Task
;
221 task type Interrupt_Server_Task
222 (Interrupt
: Interrupt_ID
; Int_Sema
: SEM_ID
) is
223 -- Server task for vectored hardware interrupt handling
224 pragma Interrupt_Priority
(System
.Interrupt_Priority
'First + 2);
225 end Interrupt_Server_Task
;
227 type Interrupt_Task_Access
is access Interrupt_Server_Task
;
229 -------------------------------
230 -- Local Types and Variables --
231 -------------------------------
233 type Entry_Assoc
is record
235 E
: Task_Entry_Index
;
238 type Handler_Assoc
is record
239 H
: Parameterless_Handler
;
240 Static
: Boolean; -- Indicates static binding;
243 User_Handler
: array (Interrupt_ID
) of Handler_Assoc
:=
244 (others => (null, Static
=> False));
245 pragma Volatile_Components
(User_Handler
);
246 -- Holds the protected procedure handler (if any) and its Static
247 -- information for each interrupt or signal. A handler is static
248 -- iff it is specified through the pragma Attach_Handler.
250 User_Entry
: array (Interrupt_ID
) of Entry_Assoc
:=
251 (others => (T
=> Null_Task
, E
=> Null_Task_Entry
));
252 pragma Volatile_Components
(User_Entry
);
253 -- Holds the task and entry index (if any) for each interrupt / signal
255 -- Type and Head, Tail of the list containing Registered Interrupt
256 -- Handlers. These definitions are used to register the handlers
257 -- specified by the pragma Interrupt_Handler.
259 type Registered_Handler
;
260 type R_Link
is access all Registered_Handler
;
262 type Registered_Handler
is record
263 H
: System
.Address
:= System
.Null_Address
;
264 Next
: R_Link
:= null;
267 Registered_Handler_Head
: R_Link
:= null;
268 Registered_Handler_Tail
: R_Link
:= null;
270 Server_ID
: array (Interrupt_ID
) of System
.Tasking
.Task_ID
:=
271 (others => System
.Tasking
.Null_Task
);
272 pragma Atomic_Components
(Server_ID
);
273 -- Holds the Task_ID of the Server_Task for each interrupt / signal.
274 -- Task_ID is needed to accomplish locking per interrupt base. Also
275 -- is needed to determine whether to create a new Server_Task.
277 Semaphore_ID_Map
: array
278 (Interrupt_ID
range 0 .. System
.VxWorks
.Num_HW_Interrupts
) of SEM_ID
:=
280 -- Array of binary semaphores associated with vectored interrupts
281 -- Note that the last bound should be Max_HW_Interrupt, but this will raise
282 -- Storage_Error if Num_HW_Interrupts is null, so use an extra 4 bytes
285 Signal_Access_Hold
: Signal_Task_Access
;
286 -- Variable for allocating a Signal_Server_Task
288 Interrupt_Access_Hold
: Interrupt_Task_Access
;
289 -- Variable for allocating an Interrupt_Server_Task
291 L
: aliased PRI
.RTS_Lock
;
292 -- L protects the contents of the above tables for interrupts / signals
293 -- for which Server_ID (I) = Null_Task.
295 -- If Server_ID (I) /= Null_Task then protection is via the
296 -- per-task (TCB) lock of Server_ID (I).
298 -- For deadlock prevention, L should not be locked after
299 -- any other lock is held, hence we use PO_Level which is the highest
300 -- lock level for error checking.
302 Task_Lock
: array (Interrupt_ID
) of Boolean := (others => False);
303 -- Booleans indicating whether the per task lock is used
305 Default_Handler
: array (HW_Interrupt
) of Interfaces
.VxWorks
.VOIDFUNCPTR
;
306 -- Vectored interrupt handlers installed prior to program startup.
307 -- These are saved only when the umbrella handler is installed for
308 -- a given interrupt number.
310 -----------------------
311 -- Local Subprograms --
312 -----------------------
314 procedure Check_Reserved_Interrupt
(Interrupt
: Interrupt_ID
);
315 -- Check if Id is a reserved interrupt, and if so raise Program_Error
316 -- with an appropriate message, otherwise return.
318 procedure Finalize_Interrupt_Servers
;
319 -- Unbind the handlers for hardware interrupt server tasks at program
322 procedure Lock_Interrupt
324 Interrupt
: Interrupt_ID
);
325 -- Protect the tables using L or the per-task lock. Set the Boolean
326 -- value Task_Lock if the lock is made using per-task lock.
327 -- This information is needed so that Unlock_Interrupt
328 -- performs unlocking on the same lock. The situation we are preventing
329 -- is, for example, when Attach_Handler is called for the first time
330 -- we lock L and create an Server_Task. For a matching unlocking, if we
331 -- rely on the fact that there is a Server_Task, we will unlock the
334 procedure Unlock_Interrupt
336 Interrupt
: Interrupt_ID
);
337 -- Unlock interrupt previously locked by Lock_Interrupt
339 function Is_Registered
(Handler
: Parameterless_Handler
) return Boolean;
342 procedure Notify_Interrupt
(Param
: System
.Address
);
343 -- Umbrella handler for vectored interrupts (not signals)
345 procedure Install_Default_Action
(Interrupt
: HW_Interrupt
);
346 -- Restore a handler that was in place prior to program execution
348 procedure Install_Umbrella_Handler
349 (Interrupt
: HW_Interrupt
;
350 Handler
: Interfaces
.VxWorks
.VOIDFUNCPTR
);
351 -- Install the runtime umbrella handler for a vectored hardware
354 function To_Signal
(S
: Interrupt_ID
) return IMNG
.Interrupt_ID
;
355 -- Convert interrupt ID to signal number.
357 procedure Unimplemented
(Feature
: String);
358 pragma No_Return
(Unimplemented
);
359 -- Used to mark a call to an unimplemented function. Raises Program_Error
360 -- with an appropriate message noting that Feature is unimplemented.
366 -- Calling this procedure with New_Handler = null and Static = True
367 -- means we want to detach the current handler regardless of the
368 -- previous handler's binding status (ie. do not care if it is a
369 -- dynamic or static handler).
371 -- This option is needed so that during the finalization of a PO, we
372 -- can detach handlers attached through pragma Attach_Handler.
374 procedure Attach_Handler
375 (New_Handler
: Parameterless_Handler
;
376 Interrupt
: Interrupt_ID
;
377 Static
: Boolean := False)
380 Check_Reserved_Interrupt
(Interrupt
);
381 Interrupt_Manager
.Attach_Handler
(New_Handler
, Interrupt
, Static
);
384 -----------------------------
385 -- Bind_Interrupt_To_Entry --
386 -----------------------------
388 -- This procedure raises a Program_Error if it tries to
389 -- bind an interrupt to which an Entry or a Procedure is
392 procedure Bind_Interrupt_To_Entry
394 E
: Task_Entry_Index
;
395 Int_Ref
: System
.Address
)
397 Interrupt
: constant Interrupt_ID
:=
398 Interrupt_ID
(Storage_Elements
.To_Integer
(Int_Ref
));
401 Check_Reserved_Interrupt
(Interrupt
);
402 Interrupt_Manager
.Bind_Interrupt_To_Entry
(T
, E
, Interrupt
);
403 end Bind_Interrupt_To_Entry
;
405 ---------------------
406 -- Block_Interrupt --
407 ---------------------
409 procedure Block_Interrupt
(Interrupt
: Interrupt_ID
) is
411 Unimplemented
("Block_Interrupt");
414 ------------------------------
415 -- Check_Reserved_Interrupt --
416 ------------------------------
418 procedure Check_Reserved_Interrupt
(Interrupt
: Interrupt_ID
) is
420 if Is_Reserved
(Interrupt
) then
422 (Program_Error
'Identity,
423 "Interrupt" & Interrupt_ID
'Image (Interrupt
) & " is reserved");
427 end Check_Reserved_Interrupt
;
429 ---------------------
430 -- Current_Handler --
431 ---------------------
433 function Current_Handler
434 (Interrupt
: Interrupt_ID
)
435 return Parameterless_Handler
438 Check_Reserved_Interrupt
(Interrupt
);
440 -- ??? Since Parameterless_Handler is not Atomic, the
441 -- current implementation is wrong. We need a new service in
442 -- Interrupt_Manager to ensure atomicity.
444 return User_Handler
(Interrupt
).H
;
451 -- Calling this procedure with Static = True means we want to Detach the
452 -- current handler regardless of the previous handler's binding status
453 -- (i.e. do not care if it is a dynamic or static handler).
455 -- This option is needed so that during the finalization of a PO, we can
456 -- detach handlers attached through pragma Attach_Handler.
458 procedure Detach_Handler
459 (Interrupt
: Interrupt_ID
;
460 Static
: Boolean := False)
463 Check_Reserved_Interrupt
(Interrupt
);
464 Interrupt_Manager
.Detach_Handler
(Interrupt
, Static
);
467 ------------------------------
468 -- Detach_Interrupt_Entries --
469 ------------------------------
471 procedure Detach_Interrupt_Entries
(T
: Task_ID
) is
473 Interrupt_Manager
.Detach_Interrupt_Entries
(T
);
474 end Detach_Interrupt_Entries
;
476 ----------------------
477 -- Exchange_Handler --
478 ----------------------
480 -- Calling this procedure with New_Handler = null and Static = True
481 -- means we want to detach the current handler regardless of the
482 -- previous handler's binding status (ie. do not care if it is a
483 -- dynamic or static handler).
485 -- This option is needed so that during the finalization of a PO, we
486 -- can detach handlers attached through pragma Attach_Handler.
488 procedure Exchange_Handler
489 (Old_Handler
: out Parameterless_Handler
;
490 New_Handler
: Parameterless_Handler
;
491 Interrupt
: Interrupt_ID
;
492 Static
: Boolean := False)
495 Check_Reserved_Interrupt
(Interrupt
);
496 Interrupt_Manager
.Exchange_Handler
497 (Old_Handler
, New_Handler
, Interrupt
, Static
);
498 end Exchange_Handler
;
504 procedure Finalize
(Object
: in out Static_Interrupt_Protection
) is
506 -- ??? loop to be executed only when we're not doing library level
507 -- finalization, since in this case all interrupt / signal tasks are
510 if not Interrupt_Manager
'Terminated then
511 for N
in reverse Object
.Previous_Handlers
'Range loop
512 Interrupt_Manager
.Attach_Handler
513 (New_Handler
=> Object
.Previous_Handlers
(N
).Handler
,
514 Interrupt
=> Object
.Previous_Handlers
(N
).Interrupt
,
515 Static
=> Object
.Previous_Handlers
(N
).Static
,
516 Restoration
=> True);
520 Tasking
.Protected_Objects
.Entries
.Finalize
521 (Tasking
.Protected_Objects
.Entries
.Protection_Entries
(Object
));
524 --------------------------------
525 -- Finalize_Interrupt_Servers --
526 --------------------------------
528 -- Restore default handlers for interrupt servers. Signal servers
529 -- restore the default handlers when they're aborted. This is called
530 -- by the Interrupt_Manager task when it receives the abort signal
531 -- during program finalization.
533 procedure Finalize_Interrupt_Servers
is
535 if HW_Interrupt
'Last >= 0 then
536 for Int
in HW_Interrupt
loop
537 if Server_ID
(Interrupt_ID
(Int
)) /= null
539 not Ada
.Task_Identification
.Is_Terminated
540 (To_Ada
(Server_ID
(Interrupt_ID
(Int
))))
542 Interrupt_Manager
.Attach_Handler
543 (New_Handler
=> null,
544 Interrupt
=> Interrupt_ID
(Int
),
546 Restoration
=> True);
550 end Finalize_Interrupt_Servers
;
552 -------------------------------------
553 -- Has_Interrupt_Or_Attach_Handler --
554 -------------------------------------
556 function Has_Interrupt_Or_Attach_Handler
557 (Object
: access Dynamic_Interrupt_Protection
)
562 end Has_Interrupt_Or_Attach_Handler
;
564 function Has_Interrupt_Or_Attach_Handler
565 (Object
: access Static_Interrupt_Protection
)
570 end Has_Interrupt_Or_Attach_Handler
;
572 ----------------------
573 -- Ignore_Interrupt --
574 ----------------------
576 procedure Ignore_Interrupt
(Interrupt
: Interrupt_ID
) is
578 Unimplemented
("Ignore_Interrupt");
579 end Ignore_Interrupt
;
581 ----------------------------
582 -- Install_Default_Action --
583 ----------------------------
585 procedure Install_Default_Action
(Interrupt
: HW_Interrupt
) is
587 -- Restore original interrupt handler
589 Interfaces
.VxWorks
.intVecSet
590 (Interfaces
.VxWorks
.INUM_TO_IVEC
(Integer (Interrupt
)),
591 Default_Handler
(Interrupt
));
592 Default_Handler
(Interrupt
) := null;
593 end Install_Default_Action
;
595 ----------------------
596 -- Install_Handlers --
597 ----------------------
599 procedure Install_Handlers
600 (Object
: access Static_Interrupt_Protection
;
601 New_Handlers
: New_Handler_Array
) is
603 for N
in New_Handlers
'Range loop
604 -- We need a lock around this ???
606 Object
.Previous_Handlers
(N
).Interrupt
:= New_Handlers
(N
).Interrupt
;
607 Object
.Previous_Handlers
(N
).Static
:= User_Handler
608 (New_Handlers
(N
).Interrupt
).Static
;
610 -- We call Exchange_Handler and not directly Interrupt_Manager.
611 -- Exchange_Handler so we get the Is_Reserved check.
614 (Old_Handler
=> Object
.Previous_Handlers
(N
).Handler
,
615 New_Handler
=> New_Handlers
(N
).Handler
,
616 Interrupt
=> New_Handlers
(N
).Interrupt
,
619 end Install_Handlers
;
621 ------------------------------
622 -- Install_Umbrella_Handler --
623 ------------------------------
625 procedure Install_Umbrella_Handler
626 (Interrupt
: HW_Interrupt
;
627 Handler
: Interfaces
.VxWorks
.VOIDFUNCPTR
)
629 use Interfaces
.VxWorks
;
631 Vec
: constant Interrupt_Vector
:=
632 INUM_TO_IVEC
(Interfaces
.VxWorks
.int
(Interrupt
));
633 Old_Handler
: constant VOIDFUNCPTR
:=
635 (INUM_TO_IVEC
(Interfaces
.VxWorks
.int
(Interrupt
)));
636 Stat
: Interfaces
.VxWorks
.STATUS
;
639 -- Only install umbrella handler when no Ada handler has already been
640 -- installed. Note that the interrupt number is passed as a parameter
641 -- when an interrupt occurs, so the umbrella handler has a different
642 -- wrapper generated by intConnect for each interrupt number.
644 if Default_Handler
(Interrupt
) = null then
646 intConnect
(Vec
, VOIDFUNCPTR
(Handler
), System
.Address
(Interrupt
));
647 Default_Handler
(Interrupt
) := Old_Handler
;
649 end Install_Umbrella_Handler
;
655 function Is_Blocked
(Interrupt
: Interrupt_ID
) return Boolean is
657 Unimplemented
("Is_Blocked");
661 -----------------------
662 -- Is_Entry_Attached --
663 -----------------------
665 function Is_Entry_Attached
(Interrupt
: Interrupt_ID
) return Boolean is
667 Check_Reserved_Interrupt
(Interrupt
);
668 return User_Entry
(Interrupt
).T
/= Null_Task
;
669 end Is_Entry_Attached
;
671 -------------------------
672 -- Is_Handler_Attached --
673 -------------------------
675 function Is_Handler_Attached
(Interrupt
: Interrupt_ID
) return Boolean is
677 Check_Reserved_Interrupt
(Interrupt
);
678 return User_Handler
(Interrupt
).H
/= null;
679 end Is_Handler_Attached
;
685 function Is_Ignored
(Interrupt
: Interrupt_ID
) return Boolean is
687 Unimplemented
("Is_Ignored");
695 -- See if Handler has been "pragma"ed using Interrupt_Handler.
696 -- Always consider a null handler as registered.
698 function Is_Registered
(Handler
: Parameterless_Handler
) return Boolean is
699 type Fat_Ptr
is record
700 Object_Addr
: System
.Address
;
701 Handler_Addr
: System
.Address
;
704 function To_Fat_Ptr
is new Unchecked_Conversion
705 (Parameterless_Handler
, Fat_Ptr
);
711 if Handler
= null then
715 Fat
:= To_Fat_Ptr
(Handler
);
717 Ptr
:= Registered_Handler_Head
;
719 while (Ptr
/= null) loop
720 if Ptr
.H
= Fat
.Handler_Addr
then
735 function Is_Reserved
(Interrupt
: Interrupt_ID
) return Boolean is
737 if Interrupt
< System
.VxWorks
.Num_HW_Interrupts
then
740 return IMNG
.Reserve
(To_Signal
(Interrupt
));
749 -- This package has been modified several times.
750 -- Do we still need this fancy locking scheme, now that more operations
751 -- are entries of the interrupt manager task?
753 -- More likely, we will need to convert one or more entry calls to
754 -- protected operations, because presently we are violating locking order
755 -- rules by calling a task entry from within the runtime system.
757 procedure Lock_Interrupt
759 Interrupt
: Interrupt_ID
) is
761 Initialization
.Defer_Abort
(Self_ID
);
763 POP
.Write_Lock
(L
'Access);
765 if Task_Lock
(Interrupt
) then
766 pragma Assert
(Server_ID
(Interrupt
) /= null,
767 "Task_Lock is true for null server task");
769 (not Ada
.Task_Identification
.Is_Terminated
770 (To_Ada
(Server_ID
(Interrupt
))),
771 "Attempt to lock per task lock of terminated server: " &
772 "Task_Lock => True");
774 POP
.Unlock
(L
'Access);
775 POP
.Write_Lock
(Server_ID
(Interrupt
));
777 elsif Server_ID
(Interrupt
) /= Null_Task
then
779 (not Ada
.Task_Identification
.Is_Terminated
780 (To_Ada
(Server_ID
(Interrupt
))),
781 "Attempt to lock per task lock of terminated server: " &
782 "Task_Lock => False");
784 Task_Lock
(Interrupt
) := True;
785 POP
.Unlock
(L
'Access);
786 POP
.Write_Lock
(Server_ID
(Interrupt
));
791 ------------------------
792 -- Notify_Interrupt --
793 ------------------------
795 -- Umbrella handler for vectored hardware interrupts (as opposed to
796 -- signals and exceptions). As opposed to the signal implementation,
797 -- this handler is only installed in the vector table while there is
798 -- an active association of an Ada handler to the interrupt.
800 -- Otherwise, the handler that existed prior to program startup is
801 -- in the vector table. This ensures that handlers installed by
802 -- the BSP are active unless explicitly replaced in the program text.
804 -- Each Interrupt_Server_Task has an associated binary semaphore
805 -- on which it pends once it's been started. This routine determines
806 -- The appropriate semaphore and and issues a semGive call, waking
807 -- the server task. When a handler is unbound,
808 -- System.Interrupts.Unbind_Handler issues a semFlush, and the
809 -- server task deletes its semaphore and terminates.
811 procedure Notify_Interrupt
(Param
: System
.Address
) is
812 Interrupt
: Interrupt_ID
:= Interrupt_ID
(Param
);
813 Discard_Result
: STATUS
;
816 Discard_Result
:= semGive
(Semaphore_ID_Map
(Interrupt
));
817 end Notify_Interrupt
;
823 function Reference
(Interrupt
: Interrupt_ID
) return System
.Address
is
825 Check_Reserved_Interrupt
(Interrupt
);
826 return Storage_Elements
.To_Address
827 (Storage_Elements
.Integer_Address
(Interrupt
));
830 --------------------------------
831 -- Register_Interrupt_Handler --
832 --------------------------------
834 procedure Register_Interrupt_Handler
(Handler_Addr
: System
.Address
) is
835 New_Node_Ptr
: R_Link
;
837 -- This routine registers a handler as usable for dynamic
838 -- interrupt handler association. Routines attaching and detaching
839 -- handlers dynamically should determine whether the handler is
840 -- registered. Program_Error should be raised if it is not registered.
842 -- Pragma Interrupt_Handler can only appear in a library
843 -- level PO definition and instantiation. Therefore, we do not need
844 -- to implement an unregister operation. Nor do we need to
845 -- protect the queue structure with a lock.
847 pragma Assert
(Handler_Addr
/= System
.Null_Address
);
849 New_Node_Ptr
:= new Registered_Handler
;
850 New_Node_Ptr
.H
:= Handler_Addr
;
852 if Registered_Handler_Head
= null then
853 Registered_Handler_Head
:= New_Node_Ptr
;
854 Registered_Handler_Tail
:= New_Node_Ptr
;
857 Registered_Handler_Tail
.Next
:= New_Node_Ptr
;
858 Registered_Handler_Tail
:= New_Node_Ptr
;
860 end Register_Interrupt_Handler
;
866 function To_Signal
(S
: Interrupt_ID
) return IMNG
.Interrupt_ID
is
868 return IMNG
.Interrupt_ID
(S
- System
.VxWorks
.Num_HW_Interrupts
);
871 -----------------------
872 -- Unblock_Interrupt --
873 -----------------------
875 procedure Unblock_Interrupt
(Interrupt
: Interrupt_ID
) is
877 Unimplemented
("Unblock_Interrupt");
878 end Unblock_Interrupt
;
884 function Unblocked_By
885 (Interrupt
: Interrupt_ID
) return System
.Tasking
.Task_ID
is
887 Unimplemented
("Unblocked_By");
891 ------------------------
892 -- Unignore_Interrupt --
893 ------------------------
895 procedure Unignore_Interrupt
(Interrupt
: Interrupt_ID
) is
897 Unimplemented
("Unignore_Interrupt");
898 end Unignore_Interrupt
;
904 procedure Unimplemented
(Feature
: String) is
907 (Program_Error
'Identity,
908 Feature
& " not implemented on VxWorks");
911 ----------------------
912 -- Unlock_Interrupt --
913 ----------------------
915 procedure Unlock_Interrupt
917 Interrupt
: Interrupt_ID
) is
919 if Task_Lock
(Interrupt
) then
921 (not Ada
.Task_Identification
.Is_Terminated
922 (To_Ada
(Server_ID
(Interrupt
))),
923 "Attempt to unlock per task lock of terminated server");
925 POP
.Unlock
(Server_ID
(Interrupt
));
927 POP
.Unlock
(L
'Access);
930 Initialization
.Undefer_Abort
(Self_ID
);
931 end Unlock_Interrupt
;
933 -----------------------
934 -- Interrupt_Manager --
935 -----------------------
937 task body Interrupt_Manager
is
938 ---------------------
939 -- Local Variables --
940 ---------------------
942 Intwait_Mask
: aliased IMNG
.Interrupt_Mask
;
943 Old_Mask
: aliased IMNG
.Interrupt_Mask
;
944 Self_ID
: Task_ID
:= POP
.Self
;
950 procedure Bind_Handler
(Interrupt
: Interrupt_ID
);
951 -- This procedure does not do anything if a signal is blocked.
952 -- Otherwise, we have to interrupt Server_Task for status change through
955 procedure Unbind_Handler
(Interrupt
: Interrupt_ID
);
956 -- This procedure does not do anything if a signal is blocked.
957 -- Otherwise, we have to interrupt Server_Task for status change
958 -- through an abort signal.
960 -- The following two procedures are labelled Unprotected... in order to
961 -- indicate that Lock/Unlock_Interrupt operations are needed around
962 -- around calls to them.
964 procedure Unprotected_Exchange_Handler
965 (Old_Handler
: out Parameterless_Handler
;
966 New_Handler
: Parameterless_Handler
;
967 Interrupt
: Interrupt_ID
;
969 Restoration
: Boolean := False);
971 procedure Unprotected_Detach_Handler
972 (Interrupt
: Interrupt_ID
;
979 procedure Bind_Handler
(Interrupt
: Interrupt_ID
) is
981 if Interrupt
< System
.VxWorks
.Num_HW_Interrupts
then
982 Install_Umbrella_Handler
983 (HW_Interrupt
(Interrupt
), Notify_Interrupt
'Access);
986 -- Mask this task for the given signal so that all tasks
987 -- are masked for the signal and the actual delivery of the
988 -- signal will be caught using "sigwait" by the
989 -- corresponding Server_Task.
991 IMOP
.Thread_Block_Interrupt
(To_Signal
(Interrupt
));
992 -- We have installed a handler or an entry before we called
993 -- this procedure. If the handler task is waiting to be
994 -- awakened, do it here. Otherwise, the signal will be
997 POP
.Wakeup
(Server_ID
(Interrupt
), Interrupt_Server_Idle_Sleep
);
1001 --------------------
1002 -- Unbind_Handler --
1003 --------------------
1005 procedure Unbind_Handler
(Interrupt
: Interrupt_ID
) is
1007 Ret_Interrupt
: IMNG
.Interrupt_ID
;
1009 use type IMNG
.Interrupt_ID
;
1013 if Interrupt
< System
.VxWorks
.Num_HW_Interrupts
then
1015 -- Hardware interrupt
1017 Install_Default_Action
(HW_Interrupt
(Interrupt
));
1019 -- Flush server task off semaphore, allowing it to terminate
1021 S
:= semFlush
(Semaphore_ID_Map
(Interrupt
));
1022 pragma Assert
(S
= 0);
1025 -- Currently, there is a handler or an entry attached and
1026 -- the corresponding Server_Task is waiting on "sigwait."
1027 -- We have to wake up the Server_Task and make it
1028 -- wait on a condition variable by sending an
1029 -- Abort_Task_Interrupt
1031 -- Make sure corresponding Server_Task is out of its own
1034 POP
.Abort_Task
(Server_ID
(Interrupt
));
1035 Ret_Interrupt
:= IMOP
.Interrupt_Wait
(Intwait_Mask
'Access);
1036 pragma Assert
(Ret_Interrupt
= IMNG
.Abort_Task_Interrupt
);
1038 IMOP
.Install_Default_Action
(To_Signal
(Interrupt
));
1040 -- Unmake the Interrupt for this task in order to allow default
1043 IMOP
.Thread_Unblock_Interrupt
(To_Signal
(Interrupt
));
1047 --------------------------------
1048 -- Unprotected_Detach_Handler --
1049 --------------------------------
1051 procedure Unprotected_Detach_Handler
1052 (Interrupt
: Interrupt_ID
;
1055 Old_Handler
: Parameterless_Handler
;
1057 if User_Entry
(Interrupt
).T
/= Null_Task
then
1059 -- If an interrupt entry is installed raise
1060 -- Program_Error. (propagate it to the caller).
1062 Unlock_Interrupt
(Self_ID
, Interrupt
);
1063 Raise_Exception
(Program_Error
'Identity,
1064 "An interrupt entry is already installed");
1067 -- Note : Static = True will pass the following check. This is the
1068 -- case when we want to detach a handler regardless of the static
1069 -- status of the Current_Handler.
1071 if not Static
and then User_Handler
(Interrupt
).Static
then
1073 -- Trying to detach a static Interrupt Handler.
1074 -- raise Program_Error.
1076 Unlock_Interrupt
(Self_ID
, Interrupt
);
1077 Raise_Exception
(Program_Error
'Identity,
1078 "Trying to detach a static Interrupt Handler");
1081 Old_Handler
:= User_Handler
(Interrupt
).H
;
1085 User_Handler
(Interrupt
).H
:= null;
1086 User_Handler
(Interrupt
).Static
:= False;
1088 if Old_Handler
/= null then
1089 Unbind_Handler
(Interrupt
);
1092 end Unprotected_Detach_Handler
;
1094 ----------------------------------
1095 -- Unprotected_Exchange_Handler --
1096 ----------------------------------
1098 procedure Unprotected_Exchange_Handler
1099 (Old_Handler
: out Parameterless_Handler
;
1100 New_Handler
: Parameterless_Handler
;
1101 Interrupt
: Interrupt_ID
;
1103 Restoration
: Boolean := False) is
1105 if User_Entry
(Interrupt
).T
/= Null_Task
then
1107 -- If an interrupt entry is already installed, raise
1108 -- Program_Error. (propagate it to the caller).
1110 Unlock_Interrupt
(Self_ID
, Interrupt
);
1111 Raise_Exception
(Program_Error
'Identity,
1112 "An interrupt is already installed");
1115 -- Note : A null handler with Static = True will
1116 -- pass the following check. This is the case when we want to
1117 -- detach a handler regardless of the Static status
1118 -- of Current_Handler.
1119 -- We don't check anything if Restoration is True, since we
1120 -- may be detaching a static handler to restore a dynamic one.
1122 if not Restoration
and then not Static
1123 and then (User_Handler
(Interrupt
).Static
1125 -- Trying to overwrite a static Interrupt Handler with a
1128 -- The new handler is not specified as an
1129 -- Interrupt Handler by a pragma.
1131 or else not Is_Registered
(New_Handler
))
1133 Unlock_Interrupt
(Self_ID
, Interrupt
);
1135 (Program_Error
'Identity,
1136 "Trying to overwrite a static Interrupt Handler with a " &
1140 -- Save the old handler
1142 Old_Handler
:= User_Handler
(Interrupt
).H
;
1146 User_Handler
(Interrupt
).H
:= New_Handler
;
1148 if New_Handler
= null then
1150 -- The null handler means we are detaching the handler.
1152 User_Handler
(Interrupt
).Static
:= False;
1155 User_Handler
(Interrupt
).Static
:= Static
;
1158 -- Invoke a corresponding Server_Task if not yet created.
1159 -- Place Task_ID info in Server_ID array.
1161 if New_Handler
/= null
1163 (Server_ID
(Interrupt
) = Null_Task
1165 Ada
.Task_Identification
.Is_Terminated
1166 (To_Ada
(Server_ID
(Interrupt
))))
1168 -- When a new Server_Task is created, it should have its
1169 -- signal mask set to the All_Tasks_Mask.
1171 IMOP
.Set_Interrupt_Mask
1172 (IMOP
.All_Tasks_Mask
'Access, Old_Mask
'Access);
1174 if Interrupt
< System
.VxWorks
.Num_HW_Interrupts
then
1176 -- Vectored hardware interrupt
1178 Interrupt_Access_Hold
:=
1179 new Interrupt_Server_Task
1180 (Interrupt
, semBCreate
(SEM_Q_FIFO
, SEM_EMPTY
));
1181 Server_ID
(Interrupt
) :=
1182 To_System
(Interrupt_Access_Hold
.all'Identity);
1187 Signal_Access_Hold
:= new Signal_Server_Task
(Interrupt
);
1188 Server_ID
(Interrupt
) :=
1189 To_System
(Signal_Access_Hold
.all'Identity);
1192 IMOP
.Set_Interrupt_Mask
(Old_Mask
'Access);
1195 if (New_Handler
= null) and then Old_Handler
/= null then
1197 -- Restore default handler
1199 Unbind_Handler
(Interrupt
);
1201 elsif Old_Handler
= null then
1203 -- Save default handler
1205 Bind_Handler
(Interrupt
);
1208 end Unprotected_Exchange_Handler
;
1210 -- Start of processing for Interrupt_Manager
1213 -- By making this task independent of any master, when the process
1214 -- goes away, the Interrupt_Manager will terminate gracefully.
1216 System
.Tasking
.Utilities
.Make_Independent
;
1218 -- Environment task gets its own interrupt mask, saves it,
1219 -- and then masks all signals except the Keep_Unmasked set.
1221 -- During rendezvous, the Interrupt_Manager receives the old
1222 -- signal mask of the environment task, and sets its own
1223 -- signal mask to that value.
1225 -- The environment task will call this entry of Interrupt_Manager
1226 -- during elaboration of the body of this package.
1228 accept Initialize
(Mask
: IMNG
.Interrupt_Mask
) do
1230 The_Mask
: aliased IMNG
.Interrupt_Mask
;
1233 IMOP
.Copy_Interrupt_Mask
(The_Mask
, Mask
);
1234 IMOP
.Set_Interrupt_Mask
(The_Mask
'Access);
1238 -- Note: All tasks in RTS will have all reserved signals
1239 -- being masked (except the Interrupt_Manager) and Keep_Unmasked
1240 -- signals unmasked when created.
1242 -- Abort_Task_Interrupt is one of the signals unmasked
1243 -- in all tasks. We mask the signal in this particular task
1244 -- so that "sigwait" is can catch an explicit
1245 -- Abort_Task_Interrupt from a Server_Task.
1247 -- This sigwaiting is needed to ensure that a Signal_Server_Task is
1248 -- out of its own sigwait state. This extra synchronization is
1249 -- necessary to prevent following scenarios:
1251 -- 1) Interrupt_Manager sends an Abort_Task_Interrupt to a
1252 -- Signal_Server_Task then changes its own signal mask (OS level).
1253 -- If a signal (corresponding to the Signal_Server_Task) arrives
1254 -- in the meantime, we have the Interrupt_Manager umnasked and
1255 -- the Signal_Server_Task waiting on sigwait.
1257 -- 2) For unbinding a handler, we install a default action in the
1258 -- Interrupt_Manager. POSIX.1c states that the result of using
1259 -- "sigwait" and "sigaction" simultaneously on the same signal
1260 -- is undefined. Therefore, we need to be informed from the
1261 -- Signal_Server_Task that it is out of its sigwait stage.
1263 IMOP
.Empty_Interrupt_Mask
(Intwait_Mask
'Access);
1264 IMOP
.Add_To_Interrupt_Mask
1265 (Intwait_Mask
'Access, IMNG
.Abort_Task_Interrupt
);
1266 IMOP
.Thread_Block_Interrupt
(IMNG
.Abort_Task_Interrupt
);
1269 -- A block is needed to absorb Program_Error exception
1272 Old_Handler
: Parameterless_Handler
;
1277 accept Attach_Handler
1278 (New_Handler
: Parameterless_Handler
;
1279 Interrupt
: Interrupt_ID
;
1281 Restoration
: Boolean := False)
1283 Lock_Interrupt
(Self_ID
, Interrupt
);
1284 Unprotected_Exchange_Handler
1285 (Old_Handler
, New_Handler
, Interrupt
, Static
, Restoration
);
1286 Unlock_Interrupt
(Self_ID
, Interrupt
);
1289 or accept Exchange_Handler
1290 (Old_Handler
: out Parameterless_Handler
;
1291 New_Handler
: Parameterless_Handler
;
1292 Interrupt
: Interrupt_ID
;
1295 Lock_Interrupt
(Self_ID
, Interrupt
);
1296 Unprotected_Exchange_Handler
1297 (Old_Handler
, New_Handler
, Interrupt
, Static
);
1298 Unlock_Interrupt
(Self_ID
, Interrupt
);
1299 end Exchange_Handler
;
1301 or accept Detach_Handler
1302 (Interrupt
: Interrupt_ID
;
1305 Lock_Interrupt
(Self_ID
, Interrupt
);
1306 Unprotected_Detach_Handler
(Interrupt
, Static
);
1307 Unlock_Interrupt
(Self_ID
, Interrupt
);
1310 or accept Bind_Interrupt_To_Entry
1312 E
: Task_Entry_Index
;
1313 Interrupt
: Interrupt_ID
)
1315 Lock_Interrupt
(Self_ID
, Interrupt
);
1317 -- If there is a binding already (either a procedure or an
1318 -- entry), raise Program_Error (propagate it to the caller).
1320 if User_Handler
(Interrupt
).H
/= null
1321 or else User_Entry
(Interrupt
).T
/= Null_Task
1323 Unlock_Interrupt
(Self_ID
, Interrupt
);
1325 (Program_Error
'Identity,
1326 "A binding for this interrupt is already present");
1329 User_Entry
(Interrupt
) := Entry_Assoc
' (T => T, E => E);
1331 -- Indicate the attachment of interrupt entry in the ATCB.
1332 -- This is needed so when an interrupt entry task terminates
1333 -- the binding can be cleaned. The call to unbinding must be
1334 -- make by the task before it terminates.
1336 T.Interrupt_Entry := True;
1338 -- Invoke a corresponding Server_Task if not yet created.
1339 -- Place Task_ID info in Server_ID array.
1341 if Server_ID (Interrupt) = Null_Task or else
1342 Ada.Task_Identification.Is_Terminated
1343 (To_Ada (Server_ID (Interrupt))) then
1345 -- When a new Server_Task is created, it should have its
1346 -- signal mask set to the All_Tasks_Mask.
1348 IMOP.Set_Interrupt_Mask
1349 (IMOP.All_Tasks_Mask'Access, Old_Mask'Access);
1351 if Interrupt < System.VxWorks.Num_HW_Interrupts then
1352 Interrupt_Access_Hold := new Interrupt_Server_Task
1353 (Interrupt, semBCreate (SEM_Q_FIFO, SEM_EMPTY));
1354 Server_ID (Interrupt) :=
1355 To_System (Interrupt_Access_Hold.all'Identity);
1358 Signal_Access_Hold := new Signal_Server_Task (Interrupt);
1359 Server_ID (Interrupt) :=
1360 To_System (Signal_Access_Hold.all'Identity);
1363 IMOP.Set_Interrupt_Mask (Old_Mask'Access);
1366 Bind_Handler (Interrupt);
1367 Unlock_Interrupt (Self_ID, Interrupt);
1368 end Bind_Interrupt_To_Entry;
1370 or accept Detach_Interrupt_Entries (T : Task_ID)
1372 for Int in Interrupt_ID'Range loop
1373 if not Is_Reserved (Int) then
1374 Lock_Interrupt (Self_ID, Int);
1376 if User_Entry (Int).T = T then
1378 User_Entry (Int) := Entry_Assoc'
1379 (T
=> Null_Task
, E
=> Null_Task_Entry
);
1380 Unbind_Handler
(Int
);
1383 Unlock_Interrupt
(Self_ID
, Int
);
1387 -- Indicate in ATCB that no interrupt entries are attached.
1389 T
.Interrupt_Entry
:= False;
1390 end Detach_Interrupt_Entries
;
1396 -- If there is a Program_Error we just want to propagate it to
1397 -- the caller and do not want to stop this task.
1399 when Program_Error
=>
1404 (Shutdown
("Interrupt_Manager---exception not expected" &
1406 Exception_Information
(E
)));
1411 pragma Assert
(Shutdown
("Interrupt_Manager---should not get here"));
1413 when Standard
'Abort_Signal =>
1414 -- Flush interrupt server semaphores, so they can terminate
1415 Finalize_Interrupt_Servers
;
1417 end Interrupt_Manager
;
1419 ------------------------
1420 -- Signal_Server_Task --
1421 ------------------------
1423 task body Signal_Server_Task
is
1424 Intwait_Mask
: aliased IMNG
.Interrupt_Mask
;
1425 Ret_Interrupt
: IMNG
.Interrupt_ID
;
1426 Self_ID
: Task_ID
:= Self
;
1427 Tmp_Handler
: Parameterless_Handler
;
1429 Tmp_Entry_Index
: Task_Entry_Index
;
1431 use type IMNG
.Interrupt_ID
;
1434 -- By making this task independent of master, when the process
1435 -- goes away, the Server_Task will terminate gracefully.
1437 System
.Tasking
.Utilities
.Make_Independent
;
1439 -- Install default action in system level.
1441 IMOP
.Install_Default_Action
(To_Signal
(Interrupt
));
1443 -- Note: All tasks in RTS will have all reserved signals
1444 -- masked (except the Interrupt_Manager) and Keep_Unmasked
1445 -- unmasked when created.
1447 -- Abort_Task_Interrupt is one of the signals unmasked
1448 -- in all tasks. We mask it in this particular task
1449 -- so that "sigwait" can catch an explicit
1450 -- Abort_Task_Interrupt from the Interrupt_Manager.
1452 -- There are two signals that this task catches through
1453 -- "sigwait." One is the signal it is designated to catch
1454 -- in order to execute an user handler or entry. The other is
1455 -- Abort_Task_Interrupt. This signal is sent from the
1456 -- Interrupt_Manager to inform of status changes (e.g: become Blocked,
1457 -- or a handler or entry is to be detached).
1459 -- Prepare the mask to be used for sigwait.
1461 IMOP
.Empty_Interrupt_Mask
(Intwait_Mask
'Access);
1463 IMOP
.Add_To_Interrupt_Mask
1464 (Intwait_Mask
'Access, To_Signal
(Interrupt
));
1466 IMOP
.Add_To_Interrupt_Mask
1467 (Intwait_Mask
'Access, IMNG
.Abort_Task_Interrupt
);
1469 IMOP
.Thread_Block_Interrupt
(IMNG
.Abort_Task_Interrupt
);
1471 PIO
.Set_Interrupt_ID
(To_Signal
(Interrupt
), Self_ID
);
1474 System
.Tasking
.Initialization
.Defer_Abort
(Self_ID
);
1475 POP
.Write_Lock
(Self_ID
);
1477 if User_Handler
(Interrupt
).H
= null
1478 and then User_Entry
(Interrupt
).T
= Null_Task
1481 -- No signal binding. If a signal is received,
1482 -- Interrupt_Manager will take the default action.
1484 Self_ID
.Common
.State
:= Interrupt_Server_Blocked_Interrupt_Sleep
;
1485 POP
.Sleep
(Self_ID
, Interrupt_Server_Idle_Sleep
);
1486 Self_ID
.Common
.State
:= Runnable
;
1489 -- A handler or an entry is installed. At this point all tasks
1490 -- mask for the signal is masked. Catch it using
1493 -- This task may wake up from sigwait by receiving a signal
1494 -- (Abort_Task_Interrupt) from the Interrupt_Manager for unbinding
1495 -- a procedure handler or an entry. Or it could be a wake up
1496 -- from status change (Unblocked -> Blocked). If that is not
1497 -- the case, we should excecute the attached procedure or entry.
1499 POP
.Unlock
(Self_ID
);
1501 Ret_Interrupt
:= IMOP
.Interrupt_Wait
(Intwait_Mask
'Access);
1503 if Ret_Interrupt
= IMNG
.Abort_Task_Interrupt
then
1504 -- Inform the Interrupt_Manager of wakeup from above sigwait.
1506 POP
.Abort_Task
(Interrupt_Manager_ID
);
1507 POP
.Write_Lock
(Self_ID
);
1510 POP
.Write_Lock
(Self_ID
);
1512 -- Even though we have received a signal, the status may
1513 -- have changed before we got the Self_ID lock above.
1514 -- Therefore we make sure a handler or an entry is still
1515 -- bound and make appropriate call.
1516 -- If there is no call to make we need to regenerate the
1517 -- signal in order not to lose it.
1519 if User_Handler
(Interrupt
).H
/= null then
1521 Tmp_Handler
:= User_Handler
(Interrupt
).H
;
1523 -- RTS calls should not be made with self being locked.
1525 POP
.Unlock
(Self_ID
);
1528 POP
.Write_Lock
(Self_ID
);
1530 elsif User_Entry
(Interrupt
).T
/= Null_Task
then
1532 Tmp_ID
:= User_Entry
(Interrupt
).T
;
1533 Tmp_Entry_Index
:= User_Entry
(Interrupt
).E
;
1535 -- RTS calls should not be made with self being locked.
1537 POP
.Unlock
(Self_ID
);
1539 System
.Tasking
.Rendezvous
.Call_Simple
1540 (Tmp_ID
, Tmp_Entry_Index
, System
.Null_Address
);
1542 POP
.Write_Lock
(Self_ID
);
1544 -- This is a situation where this task woke up receiving a
1545 -- signal and before it got the lock the signal was blocked.
1546 -- We do not want to lose the signal so we regenerate it at
1547 -- the process level.
1549 IMOP
.Interrupt_Self_Process
(Ret_Interrupt
);
1554 POP
.Unlock
(Self_ID
);
1555 System
.Tasking
.Initialization
.Undefer_Abort
(Self_ID
);
1557 -- Undefer abort here to allow a window for this task
1558 -- to be aborted at the time of system shutdown.
1560 end Signal_Server_Task
;
1562 ---------------------------
1563 -- Interrupt_Server_Task --
1564 ---------------------------
1566 -- Server task for vectored hardware interrupt handling
1568 task body Interrupt_Server_Task
is
1569 Self_ID
: Task_ID
:= Self
;
1570 Tmp_Handler
: Parameterless_Handler
;
1572 Tmp_Entry_Index
: Task_Entry_Index
;
1578 System
.Tasking
.Utilities
.Make_Independent
;
1579 Semaphore_ID_Map
(Interrupt
) := Int_Sema
;
1582 -- Pend on semaphore that will be triggered by the
1583 -- umbrella handler when the associated interrupt comes in
1585 S
:= semTake
(Int_Sema
, WAIT_FOREVER
);
1586 pragma Assert
(S
= 0);
1588 if User_Handler
(Interrupt
).H
/= null then
1590 -- Protected procedure handler
1592 Tmp_Handler
:= User_Handler
(Interrupt
).H
;
1595 elsif User_Entry
(Interrupt
).T
/= Null_Task
then
1597 -- Interrupt entry handler
1599 Tmp_ID
:= User_Entry
(Interrupt
).T
;
1600 Tmp_Entry_Index
:= User_Entry
(Interrupt
).E
;
1601 System
.Tasking
.Rendezvous
.Call_Simple
1602 (Tmp_ID
, Tmp_Entry_Index
, System
.Null_Address
);
1605 -- Semaphore has been flushed by an unbind operation in
1606 -- the Interrupt_Manager. Terminate the server task.
1608 -- Wait for the Interrupt_Manager to complete its work
1610 POP
.Write_Lock
(Self_ID
);
1612 -- Delete the associated semaphore
1614 S
:= semDelete
(Int_Sema
);
1616 pragma Assert
(S
= 0);
1618 -- Set status for the Interrupt_Manager
1620 Semaphore_ID_Map
(Interrupt
) := 0;
1621 Task_Lock
(Interrupt
) := False;
1622 Server_ID
(Interrupt
) := Null_Task
;
1623 POP
.Unlock
(Self_ID
);
1628 end Interrupt_Server_Task
;
1631 -- Elaboration code for package System.Interrupts
1633 -- Get Interrupt_Manager's ID so that Abort_Interrupt can be sent.
1635 Interrupt_Manager_ID
:= To_System
(Interrupt_Manager
'Identity);
1637 -- Initialize the lock L.
1639 Initialization
.Defer_Abort
(Self
);
1640 POP
.Initialize_Lock
(L
'Access, POP
.PO_Level
);
1641 Initialization
.Undefer_Abort
(Self
);
1643 -- During the elaboration of this package body we want the RTS to
1644 -- inherit its signal mask from the Environment Task.
1646 -- The Environment Task should have gotten its mask from
1647 -- the enclosing process during the RTS start up. (See
1648 -- in s-inmaop.adb). Pass the Interrupt_Mask of the Environment
1649 -- task to the Interrupt_Manager.
1651 -- Note : At this point we know that all tasks (including
1652 -- RTS internal servers) are masked for non-reserved signals
1653 -- (see s-taprop.adb). Only the Interrupt_Manager will have
1654 -- masks set up differently, inheriting the original Environment
1657 Interrupt_Manager
.Initialize
(IMOP
.Environment_Mask
);
1658 end System
.Interrupts
;