File : s-osinte-pikeos.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) 2009-2016, AdaCore                    --
  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. 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.                                     --
  17 --                                                                          --
  18 --                                                                          --
  19 --                                                                          --
  20 --                                                                          --
  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 ------------------------------------------------------------------------------
  31 
  32 --  This is the Ravenscar version of this package for PikeOS
  33 
  34 --  This package encapsulates all direct interfaces to OS services that are
  35 --  needed by the tasking run-time (libgnarl).
  36 
  37 pragma Restrictions (No_Elaboration_Code);
  38 
  39 with System.Parameters;
  40 with System.Multiprocessors;
  41 
  42 package System.OS_Interface is
  43    pragma Preelaborate;
  44 
  45    --  PikeOS binding
  46 
  47    --  The definitions are in p4.h
  48 
  49    type P4_uint32_t is mod 2**32;
  50    type P4_uint64_t is mod 2**64;
  51 
  52    subtype P4_uid_t is P4_uint32_t;
  53    subtype P4_thr_t is P4_uint32_t;
  54    subtype P4_time_t is P4_uint64_t;
  55    subtype P4_prio_t is P4_uint32_t;
  56    subtype P4_timeout_t is P4_uint64_t;
  57 
  58    P4_TIMEOUT_ABSOLUTE : constant P4_timeout_t := 4 * 2 ** 60;
  59 
  60    subtype P4_e_t is Integer;
  61 
  62    P4_E_OK          : constant P4_e_t      := 0;
  63    P4_E_STATE       : constant P4_e_t      := 15;
  64    P4_E_BADTIMEOUT  : constant P4_e_t      := 21;
  65    P4_TIMEPART_KEEP : constant P4_uint32_t := 16#FFFF_FFFE#;
  66    P4_PRIO_KEEP     : constant P4_prio_t   := 16#FFFF_FFFE#;
  67 
  68    ----------------
  69    -- Interrupts --
  70    ----------------
  71 
  72    Max_Interrupt : constant := 2**9;
  73    --  Number of asynchronous interrupts (corresponds to P4_NUM_INTERRUPT)
  74 
  75    subtype Interrupt_ID is P4_uint32_t;
  76    --  Interrupt identifiers
  77 
  78    No_Interrupt : constant := 16#Ffff_Ffff#;
  79    --  Special value indicating no interrupt (corresponds to P4_INT_DETACH)
  80 
  81    type Interrupt_Handler is access procedure (Id : Interrupt_ID);
  82 
  83    --------------------------
  84    -- Interrupt processing --
  85    --------------------------
  86 
  87    function Current_Interrupt return Interrupt_ID;
  88    --  Function that returns the hardware interrupt currently being handled (if
  89    --  any). In case no hardware interrupt is being handled the returned value
  90    --  is No_Interrupt.
  91 
  92    --  Why is the following commented out ???
  93 
  94    --  function Priority_Of_Interrupt (Id : Interrupt_ID) return Any_Priority;
  95    --  Obtain the software priority of any hardware interrupt. This makes
  96    --  easier the selection of the priority of the protected handler
  97    --  attached to interrupts.
  98 
  99    procedure Attach_Handler
 100      (Handler : Interrupt_Handler;
 101       Id      : Interrupt_ID);
 102    --  Attach a handler to a hardware interrupt
 103 
 104    ----------
 105    -- Time --
 106    ----------
 107 
 108    subtype Time is P4_time_t;
 109    --  Representation of the time in the underlying tasking system
 110 
 111    type Time_Span is range -2 ** 63 .. 2 ** 63 - 1;
 112    for Time_Span'Size use 64;
 113    --  Represents length of time intervals in the underlying tasking system
 114 
 115    Ticks_Per_Second : constant Natural := 1_000_000_000;
 116    --  Number of clock ticks per second (PikeOS resolution is 1ns)
 117 
 118    function Clock return Time;
 119    --  Get the number of ticks elapsed since startup
 120 
 121    procedure Delay_Until (T : Time);
 122    --  Suspend the calling task until the absolute time specified by T
 123 
 124    -------------
 125    -- Threads --
 126    -------------
 127 
 128    type Thread_Descriptor is private;
 129    --  Type that contains information about a thread (registers, priority, etc)
 130 
 131    type Thread_Id is access all Thread_Descriptor;
 132    --  Identifiers for the underlying threads
 133 
 134    Null_Thread_Id : constant Thread_Id := null;
 135    --  Identifier for a non valid thread
 136 
 137    procedure Initialize
 138      (Environment_Thread : Thread_Id;
 139       Main_Priority      : System.Any_Priority);
 140    --  Procedure for initializing the underlying tasking system
 141 
 142    procedure Thread_Create
 143      (Id            : Thread_Id;
 144       Code          : System.Address;
 145       Arg           : System.Address;
 146       Priority      : System.Any_Priority;
 147       Base_CPU      : System.Multiprocessors.CPU_Range;
 148       Stack_Address : System.Address;
 149       Stack_Size    : System.Parameters.Size_Type);
 150    --  Create a new thread
 151 
 152    function Thread_Self return Thread_Id;
 153    --  Return the thread identifier for the calling task
 154 
 155    function Lwp_Self return System.Address;
 156    --  Return the LWP for the calling task
 157 
 158    ----------
 159    -- ATCB --
 160    ----------
 161 
 162    procedure Set_ATCB (ATCB : System.Address);
 163    --  Associate the specified ATCB to the currently running thread
 164 
 165    function Get_ATCB return System.Address;
 166    --  Get the ATCB associated to the currently running thread
 167 
 168    ----------------
 169    -- Scheduling --
 170    ----------------
 171 
 172    procedure Set_Priority (Priority  : System.Any_Priority);
 173    --  Set the active priority of the executing thread to the given value
 174 
 175    function Get_Priority  (Id : Thread_Id) return System.Any_Priority;
 176    --  Get the current base priority of a thread
 177 
 178    procedure Sleep;
 179    --  The calling thread is unconditionally suspended
 180 
 181    procedure Wakeup (Id : Thread_Id);
 182    --  The referred thread becomes ready (the thread must be suspended)
 183 
 184    ---------------------
 185    -- Multiprocessors --
 186    ---------------------
 187 
 188    function Current_CPU return Multiprocessors.CPU;
 189    --  Return the id of the current CPU
 190 
 191    function Get_Affinity (Id : Thread_Id) return Multiprocessors.CPU_Range;
 192    --  Return CPU affinity of the given thread (maybe Not_A_Specific_CPU)
 193 
 194    function Get_CPU (Id : Thread_Id) return Multiprocessors.CPU;
 195    --  Return the CPU in charge of the given thread (always a valid CPU)
 196 
 197 private
 198    type Thread_Descriptor is record
 199       ATCB : System.Address;
 200       --  Address of the Ada Task Control Block corresponding to the Ada task
 201       --  that executes on this thread.
 202 
 203       Num : P4_thr_t;
 204       --  PikeOS thread identifier
 205 
 206       Base_Priority : System.Any_Priority;
 207       --  Base priority of the thread
 208    end record;
 209 end System.OS_Interface;