ocarina-backends-pok_c-runtime.adb 22.5 KB
Newer Older
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--       O C A R I N A . B A C K E N D S . P O K _ C . R U N T I M E        --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2014 ESA & ISAE.      --
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
--                                                                          --
-- Ocarina  is free software;  you  can  redistribute  it and/or  modify    --
-- it under terms of the GNU General Public License as published by the     --
-- Free Software Foundation; either version 2, or (at your option) any      --
-- later version. Ocarina is distributed  in  the  hope  that it will be    --
-- useful, but WITHOUT ANY WARRANTY;  without even the implied warranty of  --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received  a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING.   --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA.                                       --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable to be   --
-- covered  by the  GNU  General  Public  License. This exception does not  --
-- however invalidate  any other reasons why the executable file might be   --
-- covered by the GNU Public License.                                       --
--                                                                          --
jhugues's avatar
jhugues committed
29 30
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
31 32 33 34 35 36 37 38 39
--                                                                          --
------------------------------------------------------------------------------

with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Case_Util;

with Utils; use Utils;

with Charset; use Charset;
40
with Ocarina.Namet;   use Ocarina.Namet;
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

with Ocarina.Backends.C_Tree.Nodes;
with Ocarina.Backends.C_Tree.Nutils;

package body Ocarina.Backends.POK_C.Runtime is

   use Ocarina.Backends.C_Tree.Nodes;
   use Ocarina.Backends.C_Tree.Nutils;

   Initialized : Boolean := False;

   Current_Kernel_Unit : Node_Id;

   RED : array (RE_Id) of Node_Id := (RE_Id'Range => No_Node);
   RHD : array (RH_Id) of Node_Id := (RH_Id'Range => No_Node);

   --  Arrays of run-time entity and unit designators

   type Casing_Rule is record
      Size : Natural;
      From : String_Access;
      Into : String_Access;
   end record;

65
   Rules      : array (1 .. 64) of Casing_Rule;
66 67 68 69 70 71 72 73 74 75 76 77 78
   Rules_Last : Natural := 0;

   procedure Apply_Casing_Rules (S : in out String);
   --  Apply the registered casing rules on the string S

   procedure Register_Casing_Rule (S : String);
   --  Register a custom casing rule

   ------------------------
   -- Apply_Casing_Rules --
   ------------------------

   procedure Apply_Casing_Rules (S : in out String) is
79 80
      New_Word : Boolean         := True;
      Length   : Natural         := S'Length;
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
      S1       : constant String := To_Lower (S);
   begin
      GNAT.Case_Util.To_Mixed (S);

      for I in S'Range loop
         if New_Word then
            New_Word := False;
            for J in 1 .. Rules_Last loop
               if Rules (J).Size <= Length
                 and then S1 (I .. I + Rules (J).Size - 1) = Rules (J).From.all
               then
                  S (I .. I + Rules (J).Size - 1) := Rules (J).Into.all;
               end if;
            end loop;
         end if;
         if S (I) = '_' then
            New_Word := True;
            for J in 1 .. Rules_Last loop
               if Rules (J).Size <= Length
                 and then S1 (I .. I + Rules (J).Size - 1) = Rules (J).From.all
               then
                  S (I .. I + Rules (J).Size - 1) := Rules (J).Into.all;
               end if;
            end loop;
         end if;
         Length := Length - 1;
      end loop;
   end Apply_Casing_Rules;

   ----------------
   -- Initialize --
   ----------------

   procedure Initialize is
115 116 117
      Name     : Name_Id;
      N        : Node_Id;
      Is_Local : Boolean;
118 119 120 121 122 123 124 125 126
   begin
      --  Initialize the runtime only once

      if Initialized then
         return;
      end if;

      Initialized := True;

Julien's avatar
Julien committed
127 128 129 130 131
      --
      --  If we use DeOS, all the types and functions
      --  related to ARINC are associated to the file apex.h
      --

Julien's avatar
Julien committed
132
      if POK_Flavor = DEOS then
133

134 135 136 137
         for E in ART_Id loop
            RE_Header_Table (E) := RH_Apex;
         end loop;

Julien's avatar
Julien committed
138
         RE_Header_Table (RE_Fifo) := RH_Apex;
139
         RE_Header_Table (RE_Pok_Port_Kind_Sampling) := RH_Apex;
Julien's avatar
Julien committed
140
         RE_Header_Table (RE_Pok_Port_Kind_Queueing) := RH_Apex;
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
         RE_Header_Table (RE_Source) := RH_Apex;
         RE_Header_Table (RE_Destination) := RH_Apex;
         RE_Header_Table (RE_Pok_Errno_Empty) := RH_Apex;
         RE_Header_Table (RE_Null) := RH_Apex;
         RE_Header_Table (RE_Normal) := RH_Apex;
         RE_Header_Table (RE_Bool_T) := RH_Apex;
         RE_Header_Table (RE_Uint8_T) := RH_Apex;
         RE_Header_Table (RE_Uint16_T) := RH_Apex;
         RE_Header_Table (RE_Uint32_T) := RH_Apex;
         RE_Header_Table (RE_Uint64_T) := RH_Apex;
         RE_Header_Table (RE_Int8_T) := RH_Apex;
         RE_Header_Table (RE_Int16_T) := RH_Apex;
         RE_Header_Table (RE_Int32_T) := RH_Apex;
         RE_Header_Table (RE_Int64_T) := RH_Apex;

156 157 158 159 160 161 162
         for E in ARF_Id loop
            RE_Header_Table (E) := RH_Apex;
         end loop;

         for E in ART_Id loop
            RE_Header_Table (E) := RH_Apex;
         end loop;
Julien's avatar
Julien committed
163 164
      end if;

165 166 167 168 169 170 171 172 173 174 175 176 177 178
      if POK_Flavor = VXWORKS then
         for E in ART_Id loop
            RE_Header_Table (E) := RH_ApexType;
         end loop;

         RE_Header_Table (RE_Periodic_Wait) := RH_ApexTime;

         RE_Header_Table (RE_Create_Process) := RH_ApexProcess;
         RE_Header_Table (RE_Start) := RH_ApexProcess;

         RE_Header_Table (RE_Create_Process) := RH_ApexProcess;

         RE_Header_Table (RE_Set_Partition_Mode) := RH_ApexPartition;

Julien's avatar
Julien committed
179 180 181 182 183 184
         RE_Header_Table (RE_Create_Blackboard) := RH_ApexBlackboard;
         RE_Header_Table (RE_Display_Blackboard) := RH_ApexBlackboard;
         RE_Header_Table (RE_Read_Blackboard) := RH_ApexBlackboard;
         RE_Header_Table (RE_Clear_Blackboard) := RH_ApexBlackboard;
         RE_Header_Table (RE_Blackboard_Id_Type) := RH_ApexBlackboard;

185 186 187 188 189 190 191 192 193 194 195 196
         RE_Header_Table (RE_Queuing_Port_Id_Type) := RH_ApexQueuing;
         RE_Header_Table (RE_Create_Queuing_Port) := RH_ApexQueuing;
         RE_Header_Table (RE_Send_Queuing_Message) := RH_ApexQueuing;
         RE_Header_Table (RE_Receive_Queuing_Message) := RH_ApexQueuing;
         RE_Header_Table (RE_Get_Queuing_Port_Id) := RH_ApexQueuing;

         RE_Header_Table (RE_Sampling_Port_Id_Type) := RH_ApexSampling;
         RE_Header_Table (RE_Create_Sampling_Port) := RH_ApexSampling;
         RE_Header_Table (RE_Write_Sampling_Message) := RH_ApexSampling;
         RE_Header_Table (RE_Read_Sampling_Message) := RH_ApexSampling;
         RE_Header_Table (RE_Get_Sampling_Port_Id) := RH_ApexSampling;

197 198 199 200
         RE_Header_Table (RE_Create_Buffer) := RH_ApexBuffer;
         RE_Header_Table (RE_Send_Buffer) := RH_ApexBuffer;
         RE_Header_Table (RE_Receive_Buffer) := RH_ApexBuffer;
         RE_Header_Table (RE_Buffer_Id_Type) := RH_ApexBuffer;
Julien's avatar
Julien committed
201

202 203 204 205
         RE_Header_Table (RE_Normal) := RH_ApexType;
         RE_Header_Table (RE_Process_Attribute_Type) := RH_ApexType;
         RE_Header_Table (RE_Fifo) := RH_ApexType;
         RE_Header_Table (RE_Pok_Port_Kind_Sampling) := RH_ApexType;
Julien's avatar
Julien committed
206
         RE_Header_Table (RE_Infinite_Time_Value) := RH_ApexType;
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
         RE_Header_Table (RE_Pok_Port_Kind_Queueing) := RH_ApexType;
         RE_Header_Table (RE_Source) := RH_ApexType;
         RE_Header_Table (RE_Destination) := RH_ApexType;
         RE_Header_Table (RE_Pok_Errno_Empty) := RH_ApexType;
         RE_Header_Table (RE_Null) := RH_ApexType;
         RE_Header_Table (RE_Normal) := RH_ApexType;
         RE_Header_Table (RE_Bool_T) := RH_ApexType;
         RE_Header_Table (RE_Uint8_T) := RH_ApexType;
         RE_Header_Table (RE_Uint16_T) := RH_ApexType;
         RE_Header_Table (RE_Uint32_T) := RH_ApexType;
         RE_Header_Table (RE_Uint64_T) := RH_ApexType;
         RE_Header_Table (RE_Int8_T) := RH_ApexType;
         RE_Header_Table (RE_Int16_T) := RH_ApexType;
         RE_Header_Table (RE_Int32_T) := RH_ApexType;
         RE_Header_Table (RE_Int64_T) := RH_ApexType;
      end if;

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
      if POK_Flavor = ARINC653 then
         RH_Service_Table (RH_Assert)     := RHS_Null;
         RH_Service_Table (RH_Thread)     := RHS_Core;
         RH_Service_Table (RH_Error)      := RHS_ARINC653;
         RH_Service_Table (RH_Blackboard) := RHS_ARINC653;
         RH_Service_Table (RH_Buffer)     := RHS_ARINC653;
         RH_Service_Table (RH_Queueing)   := RHS_ARINC653;
         RH_Service_Table (RH_Semaphore)  := RHS_ARINC653;
         RH_Service_Table (RH_Event)      := RHS_ARINC653;
         RH_Service_Table (RH_Sampling)   := RHS_ARINC653;
         RH_Service_Table (RH_Types)      := RHS_ARINC653;
         RH_Service_Table (RH_Time)       := RHS_ARINC653;
         RH_Service_Table (RH_Partition)  := RHS_ARINC653;
      end if;

      --  When we use the ARINC653 API, we change the include/
      --  directory for headers files. So, we change the following
      --  table that indicates the directory of each include file.

      Register_Casing_Rule ("AADL");
      Register_Casing_Rule ("char_array");
      Register_Casing_Rule ("nul");

      --  Apply casing rule for POK functions.
      --  All types are in lower case.

      for E in PRF_Id loop
         Set_Str_To_Name_Buffer (RE_Id'Image (E));
         Set_Str_To_Name_Buffer (Name_Buffer (4 .. Name_Len));

         Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));

256
         while Name_Buffer (Name_Len) = '_' loop
257 258 259 260 261
            Name_Len := Name_Len - 1;
         end loop;

         Name := Name_Find;

262
         Name    := Utils.To_Lower (Name);
263
         RED (E) := New_Node (K_Defining_Identifier);
264
         Set_Name (RED (E), Name);
265 266 267 268 269 270 271 272 273 274 275
      end loop;

      --  Apply casing rule for ARINC653 functions.
      --  All functions are in upper case.

      for E in ARF_Id loop
         Set_Str_To_Name_Buffer (RE_Id'Image (E));
         Set_Str_To_Name_Buffer (Name_Buffer (4 .. Name_Len));

         Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));

276
         while Name_Buffer (Name_Len) = '_' loop
277 278 279 280 281
            Name_Len := Name_Len - 1;
         end loop;

         Name := Name_Find;

282
         Name    := Utils.To_Upper (Name);
283
         RED (E) := New_Node (K_Defining_Identifier);
284
         Set_Name (RED (E), Name);
285 286 287 288 289 290 291 292 293 294 295
      end loop;

      --  Apply casing rule for POK types.
      --  All types are in lower case.

      for E in PRT_Id loop
         Set_Str_To_Name_Buffer (RE_Id'Image (E));
         Set_Str_To_Name_Buffer (Name_Buffer (4 .. Name_Len));

         Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));

296
         while Name_Buffer (Name_Len) = '_' loop
297 298 299 300 301
            Name_Len := Name_Len - 1;
         end loop;

         Name := Name_Find;

302
         Name    := Utils.To_Lower (Name);
303
         RED (E) := New_Node (K_Defining_Identifier);
304
         Set_Name (RED (E), Name);
305 306 307 308 309 310 311 312 313 314 315
      end loop;

      --  Apply casing rule for ARINC653 types.
      --  All types are in upper case.

      for E in ART_Id loop
         Set_Str_To_Name_Buffer (RE_Id'Image (E));
         Set_Str_To_Name_Buffer (Name_Buffer (4 .. Name_Len));

         Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));

316
         while Name_Buffer (Name_Len) = '_' loop
317 318 319 320 321
            Name_Len := Name_Len - 1;
         end loop;

         Name := Name_Find;

322
         Name    := Utils.To_Upper (Name);
323
         RED (E) := New_Node (K_Defining_Identifier);
324
         Set_Name (RED (E), Name);
325 326 327 328 329 330 331 332 333 334 335
      end loop;

      --  Apply casing rule for headers, there is no difference
      --  between POK and ARINC653 headers casing rules, so, we
      --  use the same.

      for E in RH_Id loop
         Set_Str_To_Name_Buffer (RH_Id'Image (E));
         Set_Str_To_Name_Buffer (Name_Buffer (4 .. Name_Len));
         Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));

336
         while Name_Buffer (Name_Len) = '_' loop
337 338 339 340 341 342 343
            Name_Len := Name_Len - 1;
         end loop;

         if RH_Service_Table (E) = RHS_Generated then
            Is_Local := True;
         elsif RH_Service_Table (E) /= RHS_Null then
            Is_Local := False;
344
            Name     := Name_Find;
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
            Set_Str_To_Name_Buffer (RHS_Id'Image (RH_Service_Table (E)));
            Set_Str_To_Name_Buffer (Name_Buffer (5 .. Name_Len));
            Add_Str_To_Name_Buffer ("/");
            Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));
            Get_Name_String_And_Append (Name);
         else
            Is_Local := False;
         end if;

         Name := Name_Find;

         Name := Utils.To_Lower (Name);

         N := New_Node (K_Defining_Identifier);
         Set_Name (N, Name);
         RHD (E) := Make_Include_Clause (N, Is_Local);
      end loop;

      --  Apply casing rule for constants, there is no difference
      --  between POK and ARINC653 constants casing rules, so, we
      --  use the same.

      for E in RC_Id loop
         Set_Str_To_Name_Buffer (RC_Id'Image (E));
         Set_Str_To_Name_Buffer (Name_Buffer (4 .. Name_Len));
         Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));

         while Name_Buffer (Name_Len) in '0' .. '9'
           or else Name_Buffer (Name_Len) = '_'
         loop
            Name_Len := Name_Len - 1;
         end loop;

         Name := Name_Find;

380
         Name    := To_Upper (Name);
381
         RED (E) := New_Node (K_Defining_Identifier);
382
         Set_Name (RED (E), Name);
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
      end loop;

      --  Apply casing rule for variables, there is no difference
      --  between POK and ARINC653 variables casing rules, so, we
      --  use the same.

      for E in RV_Id loop
         Set_Str_To_Name_Buffer (RV_Id'Image (E));
         Set_Str_To_Name_Buffer (Name_Buffer (4 .. Name_Len));
         Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));

         while Name_Buffer (Name_Len) in '0' .. '9'
           or else Name_Buffer (Name_Len) = '_'
         loop
            Name_Len := Name_Len - 1;
         end loop;

         Name := Name_Find;

402
         Name    := To_Lower (Name);
403
         RED (E) := New_Node (K_Defining_Identifier);
404
         Set_Name (RED (E), Name);
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
      end loop;

      --  Apply casing rule for members. The difference
      --  between POK and ARINC653 is made inside the loop.

      for E in MR_Id loop
         Set_Str_To_Name_Buffer (RC_Id'Image (E));
         Set_Str_To_Name_Buffer (Name_Buffer (4 .. Name_Len));
         Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));

         while Name_Buffer (Name_Len) in '0' .. '9'
           or else Name_Buffer (Name_Len) = '_'
         loop
            Name_Len := Name_Len - 1;
         end loop;

         Name := Name_Find;

         --  If we use the ARINC653 backend flavor, the
         --  members are in upper case. Otherwise, we use
         --  lower case.

427 428 429
         if POK_Flavor = ARINC653 or else POK_Flavor = DEOS
            or else POK_Flavor = VXWORKS
         then
430 431 432 433 434
            Name := To_Upper (Name);
         else
            Name := To_Lower (Name);
         end if;
         RED (E) := New_Node (K_Defining_Identifier);
435
         Set_Name (RED (E), Name);
436 437 438 439 440 441 442 443 444 445
      end loop;

   end Initialize;

   -----------
   -- Reset --
   -----------

   procedure Reset is
   begin
446 447
      RED        := (RE_Id'Range => No_Node);
      RHD        := (RH_Id'Range => No_Node);
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
      Rules_Last := 0;

      Initialized := False;
   end Reset;

   --------
   -- RE --
   --------

   function RE (Id : RE_Id) return Node_Id is
   begin
      if RE_Header_Table (Id) /= RH_Null then
         Add_Include (RH (RE_Header_Table (Id)));
      end if;

      return Copy_Node (RED (Id));
   end RE;

   --------
   -- RF --
   --------

   function RF (Id : RF_Id) return Node_Id is
      N : Node_Id;
      R : RE_Id;
   begin
      N := RE (Id);
      R := RF_Define_Table (Id);
      if R /= RE_Null then
         Add_Define_Deployment (RE (R));
      end if;

      --  Add functionnality in the kernel
      --  according to model needs.
      --  WiP functionnality at this time, needs to describe
      --  each function needs.
      if Id = RE_Pok_Blackboard_Read then
         Push_Entity (Entity (Current_Kernel_Unit));
         Push_Entity (Current_Kernel_Unit);

         Add_Define_Deployment (RE (RE_Pok_Needs_Gettick));

         Pop_Entity;
         Pop_Entity;
      end if;

      return N;
   end RF;

   --------
   -- RH --
   --------

   function RH (Id : RH_Id) return Node_Id is
   begin
      return Copy_Node (RHD (Id));
   end RH;

   --------------------------
   -- Register_Casing_Rule --
   --------------------------

   procedure Register_Casing_Rule (S : String) is
   begin
512
      Rules_Last              := Rules_Last + 1;
513 514 515 516 517 518 519 520 521 522 523
      Rules (Rules_Last).Size := S'Length;
      Rules (Rules_Last).Into := new String'(S);
      Rules (Rules_Last).From := new String'(S);
      To_Lower (Rules (Rules_Last).From.all);
   end Register_Casing_Rule;

   --------------------------
   -- Update_Headers_Names --
   --------------------------

   procedure Update_Headers_Names is
524
      Name : Name_Id;
525 526 527 528 529 530
   begin
      for E in RH_Id loop
         Set_Str_To_Name_Buffer (RH_Id'Image (E));
         Set_Str_To_Name_Buffer (Name_Buffer (4 .. Name_Len));
         Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));

531
         while Name_Buffer (Name_Len) = '_' loop
532 533 534 535
            Name_Len := Name_Len - 1;
         end loop;

         if RH_Service_Table (E) /= RHS_Generated
536 537
           and then RH_Service_Table (E) /= RHS_Null
         then
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
            Name := Name_Find;
            Set_Str_To_Name_Buffer (RHS_Id'Image (RH_Service_Table (E)));
            Set_Str_To_Name_Buffer (Name_Buffer (5 .. Name_Len));
            Add_Str_To_Name_Buffer ("/");
            Apply_Casing_Rules (Name_Buffer (1 .. Name_Len));
            Get_Name_String_And_Append (Name);
         end if;

         Name := Name_Find;

         Name := Utils.To_Lower (Name);

         Set_Name (Header_Name (RHD (E)), Name);
      end loop;
   end Update_Headers_Names;

   -----------------
   -- Normal_Mode --
   -----------------

   procedure Normal_Mode is
   begin
      if POK_Flavor = ARINC653 then
         ARINC653_Mode;
      else
         POK_Mode;
      end if;
   end Normal_Mode;

   --------------
   -- POK_Mode --
   --------------

   procedure POK_Mode is
   begin
      RH_Service_Table (RH_Assert)     := RHS_Null;
      RH_Service_Table (RH_Thread)     := RHS_Core;
      RH_Service_Table (RH_Blackboard) := RHS_Middleware;
      RH_Service_Table (RH_Buffer)     := RHS_Middleware;
      RH_Service_Table (RH_Queueing)   := RHS_Middleware;
      RH_Service_Table (RH_Semaphore)  := RHS_Core;
      RH_Service_Table (RH_Event)      := RHS_Core;
      RH_Service_Table (RH_Sampling)   := RHS_Middleware;
      RH_Service_Table (RH_Types)      := RHS_Null;
      RH_Service_Table (RH_Time)       := RHS_Core;
      RH_Service_Table (RH_Partition)  := RHS_Core;

      Update_Headers_Names;
   end POK_Mode;

   -------------------
   -- ARINC653_Mode --
   -------------------

   procedure ARINC653_Mode is
   begin
      RH_Service_Table (RH_Assert)     := RHS_Null;
      RH_Service_Table (RH_Thread)     := RHS_Core;
      RH_Service_Table (RH_Blackboard) := RHS_ARINC653;
      RH_Service_Table (RH_Buffer)     := RHS_ARINC653;
      RH_Service_Table (RH_Queueing)   := RHS_ARINC653;
      RH_Service_Table (RH_Semaphore)  := RHS_ARINC653;
      RH_Service_Table (RH_Event)      := RHS_ARINC653;
      RH_Service_Table (RH_Sampling)   := RHS_ARINC653;
      RH_Service_Table (RH_Types)      := RHS_ARINC653;
      RH_Service_Table (RH_Time)       := RHS_ARINC653;
      RH_Service_Table (RH_Partition)  := RHS_ARINC653;

      Update_Headers_Names;
   end ARINC653_Mode;

   -----------------
   -- Kernel_Mode --
   -----------------

   procedure Kernel_Mode is
   begin
      --  Same as User_Mode but for the kernel
616 617 618
      RH_Service_Table (RH_Types)     := RHS_Null;
      RH_Service_Table (RH_Partition) := RHS_Core;
      RH_Service_Table (RH_Error)     := RHS_Core;
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656

      Update_Headers_Names;
   end Kernel_Mode;

   ---------------
   -- User_Mode --
   ---------------

   procedure User_Mode is
   begin
      --  Switch to user mode, change header name
      --  locations, change their containing directories.
      if POK_Flavor = ARINC653 then
         RH_Service_Table (RH_Assert)     := RHS_Null;
         RH_Service_Table (RH_Thread)     := RHS_Core;
         RH_Service_Table (RH_Blackboard) := RHS_ARINC653;
         RH_Service_Table (RH_Error)      := RHS_ARINC653;
         RH_Service_Table (RH_Buffer)     := RHS_ARINC653;
         RH_Service_Table (RH_Queueing)   := RHS_ARINC653;
         RH_Service_Table (RH_Sampling)   := RHS_ARINC653;
         RH_Service_Table (RH_Types)      := RHS_ARINC653;
         RH_Service_Table (RH_Time)       := RHS_ARINC653;
         RH_Service_Table (RH_Partition)  := RHS_ARINC653;
      else
         RH_Service_Table (RH_Assert)     := RHS_Null;
         RH_Service_Table (RH_Thread)     := RHS_Core;
         RH_Service_Table (RH_Blackboard) := RHS_Middleware;
         RH_Service_Table (RH_Buffer)     := RHS_Middleware;
         RH_Service_Table (RH_Queueing)   := RHS_Middleware;
         RH_Service_Table (RH_Sampling)   := RHS_Middleware;
         RH_Service_Table (RH_Types)      := RHS_Null;
         RH_Service_Table (RH_Time)       := RHS_Core;
         RH_Service_Table (RH_Partition)  := RHS_Core;
      end if;

      Update_Headers_Names;
   end User_Mode;

657
   procedure Register_Kernel_Unit (Unit : Node_Id) is
658 659 660 661 662 663
   begin
      Current_Kernel_Unit := Unit;
   end Register_Kernel_Unit;

   function Get_Errcode_OK return Node_Id is
   begin
Julien's avatar
Julien committed
664
      if POK_Flavor = ARINC653 or else POK_Flavor = DEOS then
665 666 667 668 669 670 671
         return RE (RE_No_Error);
      else
         return RE (RE_Pok_Errno_Ok);
      end if;
   end Get_Errcode_OK;

end Ocarina.Backends.POK_C.Runtime;