home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / s-interr.ads < prev    next >
Text File  |  2000-07-19  |  12KB  |  273 lines

  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 S                    --
  6. --                                                                          --
  7. --                                  S p e c                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.16 $
  10. --                                                                          --
  11. --          Copyright (C) 1992-2000 Free Software Foundation, Inc.          --
  12. --                                                                          --
  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.                                                      --
  23. --                                                                          --
  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.                                      --
  30. --                                                                          --
  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).                                  --
  34. --                                                                          --
  35. ------------------------------------------------------------------------------
  36.  
  37. --  Note: the compiler generates direct calls to this interface, via Rtsfind.
  38. --  Any changes to this interface may require corresponding compiler changes.
  39.  
  40. --  This package encapsulates the implementation of interrupt or signal
  41. --  handlers.  It is logically an extension of the body of Ada.Interrupts.
  42. --  It is made a child of System to allow visibility of various
  43. --  runtime system internal data and operations.
  44.  
  45. --  See System.Interrupt_Management for core interrupt/signal interfaces.
  46.  
  47. --  These two packages are separated in order to allow
  48. --  System.Interrupt_Management to be used without requiring the whole
  49. --  tasking implementation to be linked and elaborated.
  50.  
  51. with System.Tasking;
  52. --  used for Task_ID
  53.  
  54. with System.Tasking.Protected_Objects.Entries;
  55. --  used for Protection_Entries;
  56.  
  57. with System.Interrupt_Management;
  58. --  used for Interrupt_ID
  59.  
  60. package System.Interrupts is
  61.  
  62.    pragma Elaborate_Body;
  63.  
  64.    -------------------------
  65.    -- Constants and types --
  66.    -------------------------
  67.  
  68.    Default_Interrupt_Priority : constant System.Interrupt_Priority :=
  69.      System.Interrupt_Priority'Last;
  70.    --  Default value used when a pragma Interrupt_Handler or Attach_Handler is
  71.    --  specified without an Interrupt_Priority pragma, see D.3(10).
  72.  
  73.    type Ada_Interrupt_ID is new System.Interrupt_Management.Interrupt_ID;
  74.    --  avoid inheritance by Ada.Interrupts.Interrupt_ID of unwanted operations
  75.  
  76.    type Interrupt_ID is new System.Interrupt_Management.Interrupt_ID;
  77.  
  78.    type Parameterless_Handler is access protected procedure;
  79.  
  80.    ----------------------
  81.    -- General services --
  82.    ----------------------
  83.  
  84.    --  Attempt to attach a Handler to an Interrupt to which an Entry is
  85.    --  already bound will raise a Program_Error.
  86.  
  87.    function Is_Reserved (Interrupt : Interrupt_ID) return Boolean;
  88.  
  89.    function Is_Entry_Attached (Interrupt : Interrupt_ID) return Boolean;
  90.  
  91.    function Is_Handler_Attached (Interrupt : Interrupt_ID) return Boolean;
  92.  
  93.    function Current_Handler
  94.      (Interrupt : Interrupt_ID)
  95.       return Parameterless_Handler;
  96.  
  97.    --  Calling the following procedures with New_Handler = null
  98.    --  and Static = true means that we want to modify the current handler
  99.    --  regardless of the previous handler's binding status.
  100.    --  (i.e. we do not care whether it is a dynamic or static handler)
  101.  
  102.    procedure Attach_Handler
  103.      (New_Handler : Parameterless_Handler;
  104.       Interrupt   : Interrupt_ID;
  105.       Static      : Boolean := False);
  106.  
  107.    procedure Exchange_Handler
  108.      (Old_Handler : out Parameterless_Handler;
  109.       New_Handler : Parameterless_Handler;
  110.       Interrupt   : Interrupt_ID;
  111.       Static      : Boolean := False);
  112.  
  113.    procedure Detach_Handler
  114.      (Interrupt : Interrupt_ID;
  115.       Static    : Boolean := False);
  116.  
  117.    function Reference (Interrupt : Interrupt_ID)
  118.      return System.Address;
  119.  
  120.    ---------------------------------
  121.    --  Interrupt entries services --
  122.    ---------------------------------
  123.  
  124.    --  Routines needed for Interrupt Entries
  125.    --  Attempt to bind an Entry to an Interrupt to which a Handler is
  126.    --  already attached will raise a Program_Error.
  127.  
  128.    procedure Bind_Interrupt_To_Entry
  129.      (T       : System.Tasking.Task_ID;
  130.       E       : System.Tasking.Task_Entry_Index;
  131.       Int_Ref : System.Address);
  132.  
  133.    procedure Detach_Interrupt_Entries (T : System.Tasking.Task_ID);
  134.    --  This procedure detaches all the Interrupt Entries bound to a task.
  135.  
  136.    -------------------------------
  137.    --  POSIX.5 signals services --
  138.    -------------------------------
  139.  
  140.    --  Routines needed for POSIX dot5 POSIX_Signals
  141.  
  142.    procedure Block_Interrupt (Interrupt : Interrupt_ID);
  143.    --  Block the Interrupt on the process level
  144.  
  145.    procedure Unblock_Interrupt (Interrupt : Interrupt_ID);
  146.  
  147.    function Unblocked_By
  148.      (Interrupt   : Interrupt_ID)
  149.       return System.Tasking.Task_ID;
  150.    --  It returns the ID of the last Task which Unblocked this Interrupt.
  151.    --  It returns Null_Task if no tasks have ever requested the
  152.    --  Unblocking operation or the Interrupt is currently Blocked.
  153.  
  154.    function Is_Blocked (Interrupt : Interrupt_ID) return Boolean;
  155.  
  156.    procedure Ignore_Interrupt (Interrupt : Interrupt_ID);
  157.    --  Set the sigacion for the interrupt to SIG_IGN.
  158.  
  159.    procedure Unignore_Interrupt (Interrupt : Interrupt_ID);
  160.  
  161.    function Is_Ignored (Interrupt : Interrupt_ID) return Boolean;
  162.  
  163.    --  Note : Direct calls to sigaction, sigprocmask, thr_sigsetmask or any
  164.    --  other low-level interface that changes the signal action or signal mask
  165.    --  needs a careful thought.
  166.    --  One may acheive the effect of system calls first making RTS blocked
  167.    --  (by calling Block_Interrupt) for the signal under consideration.
  168.    --  This will make all the tasks in RTS blocked for the Interrupt.
  169.  
  170.    ----------------------
  171.    -- Protection types --
  172.    ----------------------
  173.  
  174.    --  Routines and types needed to implement Interrupt_Handler and
  175.    --  Attach_Handler.
  176.  
  177.    --  There are two kinds of protected objects that deal with interrupts:
  178.  
  179.    --  (1) Only Interrupt_Handler pragmas are used. We need to be able to
  180.    --  tell if an Interrupt_Handler applies to a given procedure, so
  181.    --  Register_Interrupt_Handler has to be called for all the potential
  182.    --  handlers, it should be done by calling Register_Interrupt_Handler
  183.    --  with the handler code address. On finalization, which can happen only
  184.    --  has part of library level finalization since PO with
  185.    --  Interrupt_Handler pragmas can only be declared at library level,
  186.    --  nothing special needs to be done since the default handlers have been
  187.    --  restored as part of task completion which is done just before global
  188.    --  finalization.  Dynamic_Interrupt_Protection should be used in this
  189.    --  case.
  190.  
  191.    --  (2) Attach_Handler pragmas are used, and possibly Interrupt_Handler
  192.    --  pragma. We need to attach the handlers to the given interrupts when
  193.    --  the objet is elaborated. This should be done by constructing an array
  194.    --  of pairs (interrupt, handler) from the pragmas and calling
  195.    --  Install_Handlers with it (types to be used are New_Handler_Item and
  196.    --  New_Handler_Array). On finalization, we need to restore the handlers
  197.    --  that were installed before the elaboration of the PO, so we need to
  198.    --  store these previous handlers. This is also done by Install_Handlers,
  199.    --  the room for these informations is provided by adding a discriminant
  200.    --  which is the number of Attach_Handler pragmas and an array of this
  201.    --  size in the protection type, Static_Interrupt_Protection.
  202.  
  203.    procedure Register_Interrupt_Handler
  204.      (Handler_Addr : System.Address);
  205.    --  This routine should be called by the compiler to allow the
  206.    --  handler be used as an Interrupt Handler. That means call this
  207.    --  procedure for each pragma Interrup_Handler providing the
  208.    --  address of the handler (not including the pointer to the
  209.    --  actual PO, this way this routine is called only once for
  210.    --  each type definition of PO).
  211.  
  212.    type Static_Handler_Index is range 0 .. Integer'Last;
  213.    subtype Positive_Static_Handler_Index is
  214.      Static_Handler_Index range 1 .. Static_Handler_Index'Last;
  215.  
  216.    type Previous_Handler_Item is record
  217.       Interrupt : Interrupt_ID;
  218.       Handler   : Parameterless_Handler;
  219.       Static    : Boolean;
  220.    end record;
  221.    --  Contains all the information needed to restore a previous handler.
  222.  
  223.    type Previous_Handler_Array is array
  224.      (Positive_Static_Handler_Index range <>) of Previous_Handler_Item;
  225.  
  226.    type New_Handler_Item is record
  227.       Interrupt : Interrupt_ID;
  228.       Handler   : Parameterless_Handler;
  229.    end record;
  230.    --  Contains all the information from an Attach_Handler pragma.
  231.  
  232.    type New_Handler_Array is array (Positive_Static_Handler_Index range <>) of
  233.      New_Handler_Item;
  234.  
  235.    --  Case (1)
  236.  
  237.    type Dynamic_Interrupt_Protection is new
  238.      Tasking.Protected_Objects.Entries.Protection_Entries with null record;
  239.  
  240.    --  ??? Finalize is not overloaded since we currently have no
  241.    --  way to detach the handlers during library level finalization.
  242.  
  243.    function Has_Interrupt_Or_Attach_Handler
  244.      (Object : access Dynamic_Interrupt_Protection) return Boolean;
  245.    --  Returns True.
  246.  
  247.    --  Case (2)
  248.  
  249.    type Static_Interrupt_Protection
  250.      (Num_Entries : Tasking.Protected_Objects.Protected_Entry_Index;
  251.       Num_Attach_Handler : Static_Handler_Index) is new
  252.      Tasking.Protected_Objects.Entries.Protection_Entries (Num_Entries) with
  253.    record
  254.       Previous_Handlers : Previous_Handler_Array (1 .. Num_Attach_Handler);
  255.    end record;
  256.  
  257.    function Has_Interrupt_Or_Attach_Handler
  258.      (Object : access Static_Interrupt_Protection)
  259.       return   Boolean;
  260.    --  Returns True.
  261.  
  262.    procedure Finalize (Object : in out Static_Interrupt_Protection);
  263.    --  Restore previous handlers as required by C.3.1(12) then call
  264.    --  Finalize (Protection).
  265.  
  266.    procedure Install_Handlers
  267.      (Object       : access Static_Interrupt_Protection;
  268.       New_Handlers : in New_Handler_Array);
  269.    --  Store the old handlers in Object.Previous_Handlers and install
  270.    --  the new static handlers.
  271.  
  272. end System.Interrupts;
  273.