File : s-osinte-bb.ads


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                  GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                --
   4 --                                                                          --
   5 --                    S Y S T E M . O S _ I N T E R F A C E                 --
   6 --                                                                          --
   7 --                                   S p e c                                --
   8 --                                                                          --
   9 --             Copyright (C) 1991-1994, Florida State University            --
  10 --          Copyright (C) 1995-2016, Free Software Foundation, Inc.         --
  11 --                                                                          --
  12 -- GNARL is free software; you can  redistribute it  and/or modify it under --
  13 -- terms of the  GNU General Public License as published  by the Free Soft- --
  14 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
  15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
  16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  17 -- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
  18 --                                                                          --
  19 --                                                                          --
  20 --                                                                          --
  21 --                                                                          --
  22 --                                                                          --
  23 -- You should have received a copy of the GNU General Public License and    --
  24 -- a copy of the GCC Runtime Library Exception along with this program;     --
  25 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
  26 -- <http://www.gnu.org/licenses/>.                                          --
  27 --                                                                          --
  28 -- GNARL was developed by the GNARL team at Florida State University.       --
  29 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
  30 --                                                                          --
  31 ------------------------------------------------------------------------------
  32 
  33 --  Ravenscar version of this package for bare board targets
  34 
  35 --  This package encapsulates all direct interfaces to OS services that are
  36 --  needed by the tasking run-time (libgnarl).
  37 
  38 pragma Restrictions (No_Elaboration_Code);
  39 --  This could use a comment, why is it here???
  40 
  41 with System.Multiprocessors;
  42 with System.Storage_Elements;
  43 
  44 with System.BB.Threads.Queues;
  45 with System.BB.Time;
  46 with System.BB.Interrupts;
  47 with System.BB.Board_Support;
  48 with System.BB.Parameters;
  49 with System.BB.CPU_Primitives.Multiprocessors;
  50 
  51 package System.OS_Interface is
  52    pragma Preelaborate;
  53 
  54    ----------------
  55    -- Interrupts --
  56    ----------------
  57 
  58    Max_Interrupt : constant := System.BB.Interrupts.Max_Interrupt;
  59    --  Number of asynchronous interrupts
  60 
  61    subtype Interrupt_ID is System.BB.Interrupts.Interrupt_ID;
  62    --  Interrupt identifiers
  63 
  64    No_Interrupt : constant Interrupt_ID := System.BB.Interrupts.No_Interrupt;
  65    --  Special value indicating no interrupt
  66 
  67    subtype Interrupt_Handler is System.BB.Interrupts.Interrupt_Handler;
  68    --  Interrupt handlers
  69 
  70    --------------------------
  71    -- Interrupt processing --
  72    --------------------------
  73 
  74    function Current_Interrupt return Interrupt_ID
  75      renames System.BB.Interrupts.Current_Interrupt;
  76    --  Function that returns the hardware interrupt currently being
  77    --  handled (if any). In case no hardware interrupt is being handled
  78    --  the returned value is No_Interrupt.
  79 
  80    procedure Attach_Handler
  81      (Handler : Interrupt_Handler;
  82       Id      : Interrupt_ID;
  83       PO_Prio : Interrupt_Priority)
  84      renames System.BB.Interrupts.Attach_Handler;
  85    --  Attach a handler to a hardware interrupt
  86 
  87    procedure Power_Down renames System.BB.Board_Support.Power_Down;
  88    --  Put current CPU in power-down mode
  89 
  90    ----------
  91    -- Time --
  92    ----------
  93 
  94    subtype Time is System.BB.Time.Time;
  95    --  Representation of the time in the underlying tasking system
  96 
  97    subtype Time_Span is System.BB.Time.Time_Span;
  98    --  Represents the length of time intervals in the underlying tasking
  99    --  system.
 100 
 101    Ticks_Per_Second : constant := System.BB.Parameters.Ticks_Per_Second;
 102    --  Number of clock ticks per second
 103 
 104    function Clock return Time renames System.BB.Time.Clock;
 105    --  Get the number of ticks elapsed since startup
 106 
 107    procedure Delay_Until (T : Time) renames System.BB.Time.Delay_Until;
 108    --  Suspend the calling task until the absolute time specified by T
 109 
 110    -------------
 111    -- Threads --
 112    -------------
 113 
 114    subtype Thread_Descriptor is System.BB.Threads.Thread_Descriptor;
 115    --  Type that contains the information about a thread (registers,
 116    --  priority, etc.).
 117 
 118    subtype Thread_Id is System.BB.Threads.Thread_Id;
 119    --  Identifiers for the underlying threads
 120 
 121    Null_Thread_Id : constant Thread_Id :=
 122                       System.BB.Threads.Null_Thread_Id;
 123    --  Identifier for a non valid thread
 124 
 125    Lwp_Self : constant System.Address := Null_Address;
 126    --  LWP is not used by gdb on ravenscar
 127 
 128    procedure Initialize
 129      (Environment_Thread : Thread_Id;
 130       Main_Priority      : System.Any_Priority)
 131      renames System.BB.Threads.Initialize;
 132    --  Procedure for initializing the underlying tasking system
 133 
 134    procedure Initialize_Slave
 135      (Idle_Thread   : Thread_Id;
 136       Idle_Priority : Integer;
 137       Stack_Address : System.Address;
 138       Stack_Size    : System.Storage_Elements.Storage_Offset)
 139      renames System.BB.Threads.Initialize_Slave;
 140    --  Procedure to initialize the idle thread
 141 
 142    procedure Thread_Create
 143      (Id            : Thread_Id;
 144       Code          : System.Address;
 145       Arg           : System.Address;
 146       Priority      : Integer;
 147       Base_CPU      : System.Multiprocessors.CPU_Range;
 148       Stack_Address : System.Address;
 149       Stack_Size    : System.Storage_Elements.Storage_Offset)
 150      renames System.BB.Threads.Thread_Create;
 151    --  Create a new thread
 152 
 153    function Thread_Self return Thread_Id renames System.BB.Threads.Thread_Self;
 154    --  Return the thread identifier for the calling task
 155 
 156    ----------
 157    -- ATCB --
 158    ----------
 159 
 160    procedure Set_ATCB (Id : Thread_Id; ATCB : System.Address)
 161      renames System.BB.Threads.Set_ATCB;
 162    --  Associate the specified ATCB to the thread ID
 163 
 164    function Get_ATCB return System.Address renames System.BB.Threads.Get_ATCB;
 165    --  Get the ATCB associated to the currently running thread
 166 
 167    ----------------
 168    -- Scheduling --
 169    ----------------
 170 
 171    procedure Set_Priority (Priority : Integer)
 172      renames System.BB.Threads.Set_Priority;
 173    --  Set the active priority of the executing thread to the given value
 174 
 175    function Get_Priority  (Id : Thread_Id) return Integer
 176      renames System.BB.Threads.Get_Priority;
 177    --  Get the current base priority of a thread
 178 
 179    procedure Sleep renames System.BB.Threads.Sleep;
 180    --  The calling thread is unconditionally suspended
 181 
 182    procedure Wakeup (Id : Thread_Id) renames System.BB.Threads.Wakeup;
 183    --  The referred thread becomes ready (the thread must be suspended)
 184 
 185    ---------------------
 186    -- Multiprocessors --
 187    ---------------------
 188 
 189    function Get_Affinity (Id : Thread_Id) return Multiprocessors.CPU_Range
 190      renames System.BB.Threads.Get_Affinity;
 191    --  Return CPU affinity of the given thread (maybe Not_A_Specific_CPU)
 192 
 193    function Get_CPU  (Id : Thread_Id) return Multiprocessors.CPU
 194      renames System.BB.Threads.Get_CPU;
 195    --  Return the CPU in charge of the given thread (always a valid CPU)
 196 
 197    function Current_Priority
 198      (CPU_Id : Multiprocessors.CPU) return System.Any_Priority
 199      renames System.BB.Threads.Queues.Current_Priority;
 200    --  Return the active priority of the current thread or
 201    --  System.Any_Priority'First if no threads are running.
 202 
 203    function Current_CPU return Multiprocessors.CPU
 204      renames System.BB.CPU_Primitives.Multiprocessors.Current_CPU;
 205    --  Return the id of the current CPU
 206 
 207 end System.OS_Interface;