aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/libgnarl/s-osinte__rtems.adb
blob: 19b45c4dc192a836b1a2fbedf18540ca7edfc983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
------------------------------------------------------------------------------
--                                                                          --
--                GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS               --
--                                                                          --
--                   S Y S T E M . O S _ I N T E R F A C E                  --
--                                                                          --
--                                  B o d y                                 --
--                                                                          --
--            Copyright (C) 1991-2017, Florida State University             --
--          Copyright (C) 1995-2024, Free Software Foundation, Inc.         --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
-- GNARL was developed by the GNARL team at Florida State University. It is --
-- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
-- State University (http://www.gnat.com).                                  --
--                                                                          --
-- The GNARL files that were developed for RTEMS are maintained by  On-Line --
-- Applications Research Corporation (http://www.oarcorp.com)  in  coopera- --
-- tion with Ada Core Technologies Inc. and Florida State University.       --
--                                                                          --
------------------------------------------------------------------------------

--  This is the RTEMS version of this package

--  This package encapsulates all direct interfaces to OS services
--  that are needed by children of System.

with Interfaces.C; use Interfaces.C;

package body System.OS_Interface is

   ---------------
   -- RTEMS API --
   ---------------

   type RTEMS_Attributes is new unsigned;

   RTEMS_SIMPLE_BINARY_SEMAPHORE : constant := 16#00000020#;
   RTEMS_FIFO                    : constant := 16#00000000#;

   type RTEMS_Interval is new unsigned;

   RTEMS_NO_TIMEOUT : constant := 0;

   type RTEMS_Options is new unsigned;

   RTEMS_WAIT             : constant := 16#00000000#;
   RTEMS_INTERRUPT_UNIQUE : constant := 16#00000001#;

   type RTEMS_Name is new unsigned;

   function RTEMS_Build_Name (C1, C2, C3, C4 : Character) return RTEMS_Name
     with Import, External_Name => "rtems_build_name", Convention => C;

   function RTEMS_Semaphore_Create
     (Name             : RTEMS_Name;
      Count            : unsigned;
      Attributes       : RTEMS_Attributes;
      Priority_Ceiling : unsigned;
      Semaphore        : out Binary_Semaphore_Id) return int
     with Import, External_Name => "rtems_semaphore_create", Convention => C;

   function RTEMS_Semaphore_Delete (Semaphore : Binary_Semaphore_Id) return int
     with Import, External_Name => "rtems_semaphore_delete", Convention => C;

   function RTEMS_Semaphore_Flush (Semaphore : Binary_Semaphore_Id)
     return int
     with Import, External_Name => "rtems_semaphore_flush", Convention => C;

   function RTEMS_Semaphore_Obtain
     (Semaphore : Binary_Semaphore_Id;
      Options   : RTEMS_Options;
      Timeout   : RTEMS_Interval) return int
     with Import, External_Name => "rtems_semaphore_obtain", Convention => C;

   function RTEMS_Semaphore_Release (Semaphore : Binary_Semaphore_Id)
     return int
     with Import, External_Name => "rtems_semaphore_release", Convention => C;

   -----------------
   -- To_Duration --
   -----------------

   function To_Duration (TS : timespec) return Duration is
   begin
      return Duration (TS.tv_sec) + Duration (TS.tv_nsec) / 10#1#E9;
   end To_Duration;

   ------------------------
   -- To_Target_Priority --
   ------------------------

   function To_Target_Priority
     (Prio : System.Any_Priority) return Interfaces.C.int
   is
   begin
      return Interfaces.C.int (Prio);
   end To_Target_Priority;

   -----------------
   -- To_Timespec --
   -----------------

   function To_Timespec (D : Duration) return timespec is
      S : time_t;
      F : Duration;
   begin
      S := time_t (Long_Long_Integer (D));
      F := D - Duration (S);

      --  If F has negative value due to round-up, adjust for positive F value

      if F < 0.0 then
         S := S - 1;
         F := F + 1.0;
      end if;
      return timespec'(tv_sec => S,
                       tv_nsec => long (Long_Long_Integer (F * 10#1#E9)));
   end To_Timespec;

   -----------------------------
   -- Binary_Semaphore_Create --
   -----------------------------

   function Binary_Semaphore_Create return Binary_Semaphore_Id is
      Semaphore : Binary_Semaphore_Id;
      Status    : int;
   begin
      Status :=
        RTEMS_Semaphore_Create
          (Name             => RTEMS_Build_Name ('G', 'N', 'A', 'T'),
           Count            => 0,
           Attributes       => RTEMS_SIMPLE_BINARY_SEMAPHORE or RTEMS_FIFO,
           Priority_Ceiling => 0,
           Semaphore        => Semaphore);

      pragma Assert (Status = 0);

      return Semaphore;
   end Binary_Semaphore_Create;

   -----------------------------
   -- Binary_Semaphore_Delete --
   -----------------------------

   function Binary_Semaphore_Delete (ID : Binary_Semaphore_Id)
     return int is
   begin
      return RTEMS_Semaphore_Delete (ID);
   end Binary_Semaphore_Delete;

   -----------------------------
   -- Binary_Semaphore_Obtain --
   -----------------------------

   function Binary_Semaphore_Obtain (ID : Binary_Semaphore_Id)
     return int is
   begin
      return RTEMS_Semaphore_Obtain (ID, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
   end Binary_Semaphore_Obtain;

   ------------------------------
   -- Binary_Semaphore_Release --
   ------------------------------

   function Binary_Semaphore_Release (ID : Binary_Semaphore_Id)
     return int is
   begin
      return RTEMS_Semaphore_Release (ID);
   end Binary_Semaphore_Release;

   ----------------------------
   -- Binary_Semaphore_Flush --
   ----------------------------

   function Binary_Semaphore_Flush (ID : Binary_Semaphore_Id) return int is
   begin
      return RTEMS_Semaphore_Flush (ID);
   end Binary_Semaphore_Flush;

   -----------------------
   -- Interrupt_Connect --
   -----------------------

   function Interrupt_Connect
     (Vector    : Interrupt_Vector;
      Handler   : Interrupt_Handler;
      Parameter : System.Address := System.Null_Address) return int
   is
      function RTEMS_Interrupt_Handler_Install
         (Vector    : Interrupt_Vector;
          Info      : char_array;
          Options   : RTEMS_Options;
          Handler   : Interrupt_Handler;
          Parameter : System.Address) return int
        with Import,
             External_Name => "rtems_interrupt_handler_install",
             Convention => C;

      Info_String : constant char_array := To_C ("GNAT Interrupt Handler");
      --  Handler name that is registered with RTEMS
   begin
      return
        RTEMS_Interrupt_Handler_Install
          (Vector    => Vector,
           Info      => Info_String,
           Options   => RTEMS_INTERRUPT_UNIQUE,
           Handler   => Handler,
           Parameter => Parameter);
   end Interrupt_Connect;

   --------------------------------
   -- Interrupt_Number_To_Vector --
   --------------------------------

   function Interrupt_Number_To_Vector (intNum : int)
     return Interrupt_Vector
   is
   begin
      return Interrupt_Vector (intNum);
   end Interrupt_Number_To_Vector;

   ------------------
   -- pthread_init --
   ------------------

   procedure pthread_init is
   begin
      null;
   end pthread_init;

   --------------------
   -- Get_Stack_Base --
   --------------------

   function Get_Stack_Base (thread : pthread_t) return Address is
      pragma Warnings (Off, thread);

   begin
      return Null_Address;
   end Get_Stack_Base;

   -----------------
   -- sigaltstack --
   -----------------

   function sigaltstack
     (ss  : not null access stack_t;
      oss : access stack_t) return int is
      pragma Unreferenced (ss);
      pragma Unreferenced (oss);
   begin
      return 0;
   end sigaltstack;

   -----------------------------------
   -- pthread_rwlockattr_setkind_np --
   -----------------------------------

   function pthread_rwlockattr_setkind_np
     (attr : access pthread_rwlockattr_t;
      pref : int) return int is
      pragma Unreferenced (attr);
      pragma Unreferenced (pref);
   begin
      return 0;
   end pthread_rwlockattr_setkind_np;

end System.OS_Interface;