OpenAADL / ocarina
1
------------------------------------------------------------------------------
2
--                                                                          --
3
--                           OCARINA COMPONENTS                             --
4
--                                                                          --
5
--    O C A R I N A . B A C K E N D S . P O K _ C . D E P L O Y M E N T     --
6
--                                                                          --
7
--                                 B o d y                                  --
8
--                                                                          --
9
--               Copyright (C) 2008-2009 Telecom ParisTech,                 --
10
--                 2010-2019 ESA & ISAE, 2019-2020 OpenAADL                 --
11
--                                                                          --
12
-- Ocarina  is free software; you can redistribute it and/or modify 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. Ocarina is distributed in the hope that it will be useful, but     --
16
-- WITHOUT ANY WARRANTY; without even the implied warranty of               --
17
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
18
--                                                                          --
19
-- As a special exception under Section 7 of GPL version 3, you are granted --
20
-- additional permissions described in the GCC Runtime Library Exception,   --
21
-- version 3.1, as published by the Free Software Foundation.               --
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
--                    Ocarina is maintained by OpenAADL team                --
29
--                              (info@openaadl.org)                         --
30
--                                                                          --
31
------------------------------------------------------------------------------
32

33
with Ocarina.Namet;
34
with Utils; use Utils;
35
with Locations;
36

37
with Ocarina.Backends.Properties;
38
with Ocarina.Backends.Messages;
39
with Ocarina.Backends.Utils;
40
with Ocarina.Backends.C_Tree.Nutils;
41
with Ocarina.Backends.C_Tree.Nodes;
42
with Ocarina.Backends.C_Values;
43
with Ocarina.Backends.POK_C.Runtime;
44
with Ocarina.Backends.C_Common.Mapping;
45

46
with Ocarina.Instances.Queries;
47

48
with Ocarina.ME_AADL;
49
with Ocarina.ME_AADL.AADL_Tree.Nodes;
50
with Ocarina.ME_AADL.AADL_Tree.Nutils;
51
with Ocarina.ME_AADL.AADL_Tree.Entities;
52
with Ocarina.ME_AADL.AADL_Instances.Nodes;
53
with Ocarina.ME_AADL.AADL_Instances.Nutils;
54
with Ocarina.ME_AADL.AADL_Instances.Entities;
55
with Ocarina.ME_AADL.AADL_Instances.Entities.Properties;
56

57 1
package body Ocarina.Backends.POK_C.Deployment is
58

59
   use Ocarina.Namet;
60
   use Locations;
61
   use Ocarina.Backends.Properties;
62
   use Ocarina.Backends.Messages;
63
   use Ocarina.Backends.Utils;
64
   use Ocarina.Backends.C_Tree.Nutils;
65
   use Ocarina.Backends.POK_C.Runtime;
66
   use Ocarina.Backends.C_Common.Mapping;
67
   use Ocarina.Instances.Queries;
68
   use Ocarina.ME_AADL;
69
   use Ocarina.ME_AADL.AADL_Instances.Nodes;
70
   use Ocarina.ME_AADL.AADL_Instances.Entities;
71

72
   package ATE renames Ocarina.ME_AADL.AADL_Tree.Entities;
73
   package ATN renames Ocarina.ME_AADL.AADL_Tree.Nodes;
74
   package ATNU renames Ocarina.ME_AADL.AADL_Tree.Nutils;
75
   package AIE renames Ocarina.ME_AADL.AADL_Instances.Entities;
76
   package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
77
   package AIEP renames Ocarina.ME_AADL.AADL_Instances.Entities.Properties;
78
   package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
79
   package CTU renames Ocarina.Backends.C_Tree.Nutils;
80
   package CTN renames Ocarina.Backends.C_Tree.Nodes;
81
   package CV renames Ocarina.Backends.C_Values;
82

83 1
   Array_Global_Ports_Nodes          : Node_Id;
84 1
   Array_Local_Ports_To_Global_Ports : Node_Id;
85 1
   Array_Global_Ports_To_Local_Ports : Node_Id;
86 1
   Array_Global_Ports_Bus            : Node_Id;
87 1
   Array_Buses_Partitions            : Node_Id;
88 1
   All_Ports                         : List_Id;
89 1
   Used_Buses                        : List_Id;
90
   Node_Identifier                   : Unsigned_Long_Long := 0;
91
   Current_Device                    : Node_Id            := No_Node;
92

93
   --------------------
94
   -- Is_Bus_Handled --
95
   --------------------
96

97 0
   function Is_Bus_Handled (Bus : Node_Id) return Boolean is
98 0
      S : Node_Id;
99
   begin
100 0
      if not AINU.Is_Empty (Used_Buses) then
101 0
         S := AIN.First_Node (Used_Buses);
102 0
         while Present (S) loop
103 0
            if (Item (S) = Bus) then
104 0
               return True;
105
            end if;
106 0
            S := AIN.Next_Node (S);
107 0
         end loop;
108

109
      end if;
110

111 0
      return False;
112
   end Is_Bus_Handled;
113

114
   ------------------------------
115
   -- Handle_Buses_Connections --
116
   ------------------------------
117

118 1
   procedure Handle_Buses_Connections (Port : Node_Id) is
119 1
      L          : List_Id;
120 1
      S          : Node_Id;
121 1
      Connection : Node_Id;
122

123 0
      procedure Handle_Bus (My_Bus : Node_Id) is
124 0
         Bus : Node_Id;
125
      begin
126 0
         Bus := My_Bus;
127

128 0
         if AINU.Is_Bus (Bus) and then not Is_Bus_Handled (Bus) then
129 0
            AINU.Append_Node_To_List
130 0
              (AINU.Make_Node_Container (Bus),
131
               Used_Buses);
132 0
         elsif AINU.Is_Virtual_Bus (Bus) then
133

134 0
            Bus := Parent_Component (Parent_Subcomponent (Bus));
135 0
            if AINU.Is_Bus (Bus) and then not Is_Bus_Handled (Bus) then
136 0
               AINU.Append_Node_To_List
137 0
                 (AINU.Make_Node_Container (Bus),
138
                  Used_Buses);
139
            end if;
140
         end if;
141 0
      end Handle_Bus;
142
   begin
143 1
      if AIN.Is_In (Port) then
144 1
         L := Sources (Port);
145 1
         if not AINU.Is_Empty (L) then
146 1
            S := AIN.First_Node (L);
147 1
            while Present (S) loop
148 1
               Connection := Extra_Item (S);
149

150 1
               if Present (Connection)
151 1
                 and then Get_Bound_Bus (Connection, False) /= No_Node
152
               then
153 0
                  Handle_Bus (Get_Bound_Bus (Connection, False));
154
               end if;
155

156 1
               S := AIN.Next_Node (S);
157 1
            end loop;
158
         end if;
159 1
      elsif AIN.Is_Out (Port) then
160 1
         L := Destinations (Port);
161 1
         if not AINU.Is_Empty (L) then
162 1
            S := AIN.First_Node (L);
163 1
            while Present (S) loop
164 1
               Connection := Extra_Item (S);
165

166 1
               if Present (Connection)
167 1
                 and then Get_Bound_Bus (Connection, False) /= No_Node
168
               then
169 0
                  Handle_Bus (Get_Bound_Bus (Connection, False));
170
               end if;
171

172 1
               S := AIN.Next_Node (S);
173 1
            end loop;
174
         end if;
175
      end if;
176 1
   end Handle_Buses_Connections;
177

178
   -------------
179
   -- Get_Bus --
180
   -------------
181

182 0
   function Get_Bus (Port : Node_Id) return Node_Id is
183 0
      L          : List_Id;
184 0
      S          : Node_Id;
185 0
      Bus        : Node_Id;
186 0
      Connection : Node_Id;
187
   begin
188 0
      if AIN.Is_In (Port) then
189 0
         L := Sources (Port);
190 0
         if not AINU.Is_Empty (L) then
191 0
            S := AIN.First_Node (L);
192 0
            while Present (S) loop
193 0
               Connection := Extra_Item (S);
194

195 0
               if Present (Connection)
196 0
                 and then Get_Bound_Bus (Connection, False) /= No_Node
197
               then
198 0
                  Bus := Get_Bound_Bus (Connection, False);
199

200 0
                  if AINU.Is_Bus (Bus) then
201 0
                     return Bus;
202 0
                  elsif AINU.Is_Virtual_Bus (Bus) then
203 0
                     Bus := Parent_Component (Parent_Subcomponent (Bus));
204 0
                     if AINU.Is_Bus (Bus) then
205 0
                        return Bus;
206
                     end if;
207
                  end if;
208
               end if;
209

210 0
               S := AIN.Next_Node (S);
211 0
            end loop;
212
         end if;
213 0
      elsif AIN.Is_Out (Port) then
214 0
         L := Destinations (Port);
215 0
         if not AINU.Is_Empty (L) then
216 0
            S := AIN.First_Node (L);
217 0
            while Present (S) loop
218 0
               Connection := Extra_Item (S);
219

220 0
               if Present (Connection)
221 0
                 and then Get_Bound_Bus (Connection, False) /= No_Node
222
               then
223 0
                  Bus := Get_Bound_Bus (Connection, False);
224

225 0
                  if AINU.Is_Bus (Bus) then
226 0
                     return Bus;
227 0
                  elsif AINU.Is_Virtual_Bus (Bus) then
228 0
                     Bus := Parent_Component (Parent_Subcomponent (Bus));
229 0
                     if AINU.Is_Bus (Bus) then
230 0
                        return Bus;
231
                     end if;
232
                  end if;
233
               end if;
234

235 0
               S := AIN.Next_Node (S);
236 0
            end loop;
237
         end if;
238
      end if;
239

240 0
      return No_Node;
241

242
   end Get_Bus;
243

244
   -----------------
245
   -- Header_File --
246
   -----------------
247

248
   package body Header_File is
249

250
      procedure Visit_Architecture_Instance (E : Node_Id);
251
      procedure Visit_Component_Instance (E : Node_Id);
252
      procedure Visit_System_Instance (E : Node_Id);
253
      procedure Visit_Process_Instance
254
        (E                    : Node_Id;
255
         Real_Process         : Boolean := True;
256
         Associated_Component : Node_Id := No_Node);
257
      procedure Visit_Device_Instance (E : Node_Id);
258
      procedure Visit_Processor_Instance (E : Node_Id);
259
      procedure Visit_Virtual_Processor_Instance (E : Node_Id);
260
      procedure Visit_Thread_Instance (E : Node_Id);
261

262
      System_Nb_Partitions    : Unsigned_Long_Long := 0;
263
      System_Nb_Threads       : Unsigned_Long_Long := 0;
264
      Process_Nb_Threads      : Unsigned_Long_Long := 0;
265
      Process_Nb_Buffers      : Unsigned_Long_Long := 0;
266
      Process_Nb_Events       : Unsigned_Long_Long := 0;
267
      Process_Nb_Lock_Objects : Unsigned_Long_Long := 0;
268
      System_Nb_Lock_Objects  : Unsigned_Long_Long := 0;
269
      Process_Nb_Blackboards  : Unsigned_Long_Long := 0;
270
      System_Nb_Ports         : Unsigned_Long_Long := 0;
271
      System_Stacks_Size      : Unsigned_Long_Long := 0;
272
      Partition_Stacks_Size   : Unsigned_Long_Long := 0;
273

274 1
      Kernel_Unit : Node_Id;
275

276 1
      Global_Nb_Ports_Node   : Node_Id;
277 1
      Kernel_Needs_Sched_Rms : Boolean;
278 1
      Kernel_Needs_Sched_Llf : Boolean;
279 1
      Kernel_Needs_Sched_Edf : Boolean;
280 1
      Kernel_Needs_Sched_Rr  : Boolean;
281

282 1
      System_Partitions_Ports : Node_Id;
283
      --  This is an array that contain all the partitions
284
      --  identifier for each port.
285
      --  Consequently, we have an array like that:
286
      --  pok_ports_partitions_id[POK_NB_PORTS] = {....}
287

288 1
      System_Partitions_Size : Node_Id;
289
      --  This array represents the size of each partition. We
290
      --  have an array like:
291
      --  POK_PARTTIONS_SIZE {xxx,xxx}
292

293 1
      System_Partitions_Scheduler       : Node_Id;
294 1
      System_Partitions_Nb_Threads      : Node_Id;
295 1
      System_Partitions_Nb_Lock_Objects : Node_Id;
296 1
      Major_Frame                       : Node_Id;
297 1
      System_Slots                      : Node_Id;
298 1
      System_Slots_Allocation           : Node_Id;
299
      System_Nb_Slots                   : Unsigned_Long_Long := 0;
300 1
      Local_Port_List                   : List_Id;
301 1
      Global_Port_List                  : List_Id;
302 1
      Node_List                         : List_Id;
303
      Local_Port_Identifier             : Unsigned_Long_Long := 0;
304
      Global_Port_Identifier            : Unsigned_Long_Long := 0;
305 1
      System_Use_Queueing_Ports         : Boolean;
306 1
      System_Use_Sampling_Ports         : Boolean;
307 1
      System_Use_Virtual_Ports          : Boolean;
308
      System_Partition_Identifier       : Unsigned_Long_Long := 0;
309
      Partition_Use_Error_Handling      : Boolean            := False;
310
      Kernel_Use_Error_Handling         : Boolean            := False;
311
      Kernel_Use_Pci                    : Boolean            := False;
312
      Kernel_Use_Io                     : Boolean            := False;
313
      Kernel_Use_Gettick                : Boolean            := False;
314

315
      -----------
316
      -- Visit --
317
      -----------
318

319 1
      procedure Visit (E : Node_Id) is
320
      begin
321 1
         case Kind (E) is
322 1
            when K_Architecture_Instance =>
323 1
               Visit_Architecture_Instance (E);
324

325 1
            when K_Component_Instance =>
326 1
               Visit_Component_Instance (E);
327

328 0
            when others =>
329 0
               null;
330 1
         end case;
331 1
      end Visit;
332

333
      ---------------------------------
334
      -- Visit_Architecture_Instance --
335
      ---------------------------------
336

337 1
      procedure Visit_Architecture_Instance (E : Node_Id) is
338
      begin
339 1
         All_Ports        := AINU.New_List (AIN.K_List_Id, No_Location);
340 1
         Global_Port_List := New_List (CTN.K_Enumeration_Literals);
341 1
         Node_List        := New_List (CTN.K_Enumeration_Literals);
342

343 1
         Array_Global_Ports_Nodes := CTU.Make_Array_Values;
344

345 1
         Global_Nb_Ports_Node := Make_Literal (CV.New_Int_Value (0, 1, 10));
346

347 1
         Visit (Root_System (E));
348 1
      end Visit_Architecture_Instance;
349

350
      ------------------------------
351
      -- Visit_Component_Instance --
352
      ------------------------------
353

354 1
      procedure Visit_Component_Instance (E : Node_Id) is
355
         Category : constant Component_Category :=
356 1
           AIE.Get_Category_Of_Component (E);
357
      begin
358 1
         case Category is
359 1
            when CC_System =>
360 1
               Visit_System_Instance (E);
361

362 1
            when CC_Process =>
363 1
               Visit_Process_Instance (E);
364

365 1
            when CC_Processor =>
366 1
               Visit_Processor_Instance (E);
367

368 0
            when CC_Device =>
369 0
               Visit_Device_Instance (E);
370

371 1
            when CC_Virtual_Processor =>
372 1
               Visit_Virtual_Processor_Instance (E);
373

374 1
            when CC_Thread =>
375 1
               Visit_Thread_Instance (E);
376

377 0
            when others =>
378 0
               null;
379 1
         end case;
380 1
      end Visit_Component_Instance;
381

382
      --------------------------------------
383
      -- Visit_Virtual_Processor_Instance --
384
      --------------------------------------
385

386 1
      procedure Visit_Virtual_Processor_Instance (E : Node_Id) is
387 1
         N         : Node_Id;
388 1
         S         : Node_Id;
389 1
         U         : Node_Id;
390 1
         Processes : List_Id;
391
      begin
392 1
         if POK_Flavor = ARINC653 then
393 0
            CTU.Append_Node_To_List
394 0
              (RE (RE_Pok_Sched_Rr),
395 0
               CTN.Values (System_Partitions_Scheduler));
396 0
            Kernel_Needs_Sched_Rr := True;
397 1
         elsif POK_Flavor = POK then
398 0
            if Get_POK_Scheduler (E) = RR then
399 0
               Kernel_Needs_Sched_Rr := True;
400 0
               CTU.Append_Node_To_List
401 0
                 (RE (RE_Pok_Sched_Rr),
402 0
                  CTN.Values (System_Partitions_Scheduler));
403 0
            elsif Get_POK_Scheduler (E) = RMS then
404 0
               Kernel_Needs_Sched_Rms := True;
405 0
               CTU.Append_Node_To_List
406 0
                 (RE (RE_Pok_Sched_Rms),
407 0
                  CTN.Values (System_Partitions_Scheduler));
408 0
            elsif Get_POK_Scheduler (E) = EDF then
409 0
               Kernel_Needs_Sched_Edf := True;
410 0
               CTU.Append_Node_To_List
411 0
                 (RE (RE_Pok_Sched_Edf),
412 0
                  CTN.Values (System_Partitions_Scheduler));
413 0
            elsif Get_POK_Scheduler (E) = LLF then
414 0
               Kernel_Needs_Sched_Llf := True;
415 0
               CTU.Append_Node_To_List
416 0
                 (RE (RE_Pok_Sched_Llf),
417 0
                  CTN.Values (System_Partitions_Scheduler));
418
            else
419 0
               Display_Error
420
                 ("POK does not support a such scheduler in partitions",
421
                  Fatal => True);
422
            end if;
423
         end if;
424

425
         N :=
426 1
           CTU.Make_Literal
427 1
             (CV.New_Int_Value (System_Partition_Identifier, 1, 10));
428 1
         Set_Handling (E, By_Node, H_C_Deployment_Spec, N);
429

430
         N :=
431 1
           CTU.Make_Literal
432 1
             (CV.New_Int_Value (System_Partition_Identifier, 1, 10));
433

434 1
         CTN.Set_Deployment_Node (Backend_Node (Identifier (E)), N);
435

436 1
         if Present (Backend_Node (Identifier (E))) then
437 1
            Processes := CTN.Processes (Backend_Node (Identifier (E)));
438 1
            S         := AIN.First_Node (Processes);
439 1
            while Present (S) loop
440 1
               U := Current_Entity;
441 1
               Pop_Entity;
442 1
               Visit (AIN.Item (S));
443 1
               Push_Entity (U);
444 1
               S := AIN.Next_Node (S);
445 1
            end loop;
446
         end if;
447

448 1
         System_Partition_Identifier := System_Partition_Identifier + 1;
449 1
      end Visit_Virtual_Processor_Instance;
450

451
      ------------------------------
452
      -- Visit_Processor_Instance --
453
      ------------------------------
454

455 1
      procedure Visit_Processor_Instance (E : Node_Id) is
456 1
         N : Node_Id;
457 1
         S : Node_Id;
458 1
         K : Node_Id;
459 1
         L : List_Id;
460 1
         U : Node_Id;
461 1
         P : Node_Id;
462 1
         A : Node_Id;
463
      begin
464 1
         U := CTN.Naming_Node (Backend_Node (Identifier (E)));
465 1
         A := CTN.Deployment_Node (Backend_Node (Identifier (E)));
466 1
         P := CTN.Entity (U);
467

468 1
         Push_Entity (C_Root);
469 1
         Push_Entity (A);
470

471 1
         Kernel_Unit := U;
472

473 1
         Start_Recording_Handlings;
474

475 1
         Used_Buses := AINU.New_List (AIN.K_List_Id, No_Location);
476

477 1
         System_Partition_Identifier := 0;
478 1
         System_Stacks_Size          := 0;
479 1
         System_Nb_Threads           := 0;
480 1
         System_Nb_Partitions        := 0;
481 1
         System_Nb_Slots             := 0;
482 1
         System_Nb_Ports             := 0;
483 1
         System_Nb_Lock_Objects      := 0;
484 1
         Kernel_Use_Pci              := False;
485 1
         Kernel_Use_Io               := False;
486 1
         Kernel_Use_Gettick          := False;
487

488 1
         Kernel_Needs_Sched_Rms := False;
489 1
         Kernel_Needs_Sched_Edf := False;
490 1
         Kernel_Needs_Sched_Llf := False;
491 1
         Kernel_Needs_Sched_Rr  := False;
492

493 1
         Local_Port_List       := New_List (CTN.K_Enumeration_Literals);
494 1
         Local_Port_Identifier := 0;
495

496 1
         System_Partitions_Ports           := CTU.Make_Array_Values;
497 1
         System_Partitions_Size            := CTU.Make_Array_Values;
498 1
         System_Partitions_Scheduler       := CTU.Make_Array_Values;
499 1
         System_Partitions_Nb_Threads      := CTU.Make_Array_Values;
500 1
         System_Partitions_Nb_Lock_Objects := CTU.Make_Array_Values;
501 1
         System_Slots                      := CTU.Make_Array_Values;
502 1
         System_Slots_Allocation           := CTU.Make_Array_Values;
503 1
         System_Use_Queueing_Ports         := False;
504 1
         System_Use_Virtual_Ports          := False;
505 1
         System_Use_Sampling_Ports         := False;
506 1
         Major_Frame                       := No_Node;
507 1
         Kernel_Use_Error_Handling         := False;
508

509 1
         Pop_Entity;
510 1
         Push_Entity (P);
511 1
         Push_Entity (U);
512

513 1
         CTU.Set_Deployment_Header;
514

515 1
         if not AINU.Is_Empty (Subcomponents (E)) then
516 1
            S := First_Node (Subcomponents (E));
517 1
            while Present (S) loop
518 1
               Visit (Corresponding_Instance (S));
519 1
               S := Next_Node (S);
520 1
            end loop;
521
         end if;
522

523
         --
524
         --  If we are using DEOS or VxWorks, we do not need
525
         --  to write code to configure the kernel, this
526
         --  is done through the XML file of the deos_conf
527
         --  backend.
528
         --
529

530 1
         if POK_Flavor = DEOS or else POK_Flavor = VXWORKS then
531 1
            Reset_Handlings;
532

533 1
            Pop_Entity;
534 1
            Pop_Entity;
535 1
            Pop_Entity;
536 1
            return;
537
         end if;
538

539 0
         Runtime.Kernel_Mode;
540

541
         N :=
542 0
           CTU.Make_Define_Statement
543 0
             (Defining_Identifier => RE (RE_Pok_Config_Local_Node),
544
              Value               =>
545 0
                CTU.Make_Literal (CV.New_Int_Value (Node_Identifier, 1, 10)));
546

547 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
548

549
         --  Add the Local node identifier in the
550
         --  kernel/deployment.h file.
551

552
         N :=
553 0
           CTU.Make_Define_Statement
554 0
             (Defining_Identifier => RE (RE_Pok_Generated_Code),
555 0
              Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
556

557 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
558

559
         --  Define the maccro POK_GENERATED_CODE so that the runtime
560
         --  is aware that we use generated code. Consequently,
561
         --  the runtime can restrict included functions in the binary.
562
         --  Here, we do that at the kernel level.
563

564 0
         N :=
565 0
           Message_Comment
566
             ("The POK_LOCAL_NODE macro corresponds to the identifier " &
567
              "for this node in the distributed system. This identifier " &
568
              "is unique for each node" &
569
              "In this case, this identifier was deduced from the" &
570 0
              Get_Name_String
571 0
                (Display_Name (Identifier (Parent_Subcomponent (E)))) &
572
              " processor component.");
573 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
574

575
         N :=
576 0
           Make_Expression
577 0
             (CTU.Make_Defining_Identifier (Map_Node_Name (E)),
578
              Op_Equal,
579 0
              (Make_Literal (CV.New_Int_Value (Node_Identifier, 0, 10))));
580 0
         Append_Node_To_List (N, Node_List);
581

582 0
         Node_Identifier := Node_Identifier + 1;
583

584 0
         if Get_POK_Major_Frame (E) /= Null_Time then
585 0
            Major_Frame := Map_Time_To_Millisecond (Get_POK_Major_Frame (E));
586
         end if;
587

588 0
         if Get_POK_Slots (E) /= Empty_Time_Array then
589 0
            declare
590 0
               T : constant Time_Array := Get_POK_Slots (E);
591
            begin
592 0
               for I in T'Range loop
593 0
                  N := Map_Time_To_Millisecond (T (I));
594 0
                  CTU.Append_Node_To_List (N, CTN.Values (System_Slots));
595 0
                  System_Nb_Slots := System_Nb_Slots + 1;
596 0
               end loop;
597 0
            end;
598
         else
599 0
            Display_Error
600
              ("You must define partitions time slots",
601
               Fatal => True);
602
         end if;
603

604 0
         if POK_Flavor = POK and then Get_POK_Scheduler (E) /= Static then
605 0
            Display_Error
606
              ("POK systems must have a static scheduler",
607
               Fatal => True);
608
         end if;
609

610 0
         L := Get_POK_Slots_Allocation (E);
611 0
         if L /= No_List then
612 0
            S := ATN.First_Node (L);
613 0
            while Present (S) loop
614 0
               K := ATE.Get_Referenced_Entity (S);
615

616 0
               N := Get_Handling (K, By_Node, H_C_Deployment_Spec);
617

618 0
               if Present (N) then
619 0
                  CTU.Append_Node_To_List
620 0
                    (CTU.Copy_Node (N),
621 0
                     CTN.Values (System_Slots_Allocation));
622
               else
623 0
                  CTU.Append_Node_To_List
624 0
                    (Make_Literal (CV.New_Int_Value (0, 1, 10)),
625 0
                     CTN.Values (System_Slots_Allocation));
626
               end if;
627

628 0
               S := ATN.Next_Node (S);
629

630 0
            end loop;
631
         else
632 0
            Display_Error
633
              ("You must define partitions time slots allocation",
634
               Fatal => True);
635
         end if;
636

637 0
         if Kernel_Use_Error_Handling then
638
            N :=
639 0
              CTU.Make_Define_Statement
640 0
                (Defining_Identifier => RE (RE_Pok_Needs_Error_Handling),
641 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
642 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
643
         end if;
644

645 0
         if Kernel_Use_Pci then
646
            N :=
647 0
              CTU.Make_Define_Statement
648 0
                (Defining_Identifier => RE (RE_Pok_Needs_Pci),
649 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
650 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
651
         end if;
652

653 0
         if Kernel_Use_Io then
654
            N :=
655 0
              CTU.Make_Define_Statement
656 0
                (Defining_Identifier => RE (RE_Pok_Needs_Io),
657 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
658 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
659
         end if;
660

661 0
         if Kernel_Use_Gettick then
662
            N :=
663 0
              CTU.Make_Define_Statement
664 0
                (Defining_Identifier => RE (RE_Pok_Needs_Gettick),
665 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
666 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
667
         end if;
668

669 0
         if System_Nb_Threads > 0 then
670
            N :=
671 0
              CTU.Make_Define_Statement
672 0
                (Defining_Identifier => RE (RE_Pok_Needs_Threads),
673 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
674 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
675
         end if;
676

677 0
         if System_Nb_Partitions > 0 then
678
            N :=
679 0
              CTU.Make_Define_Statement
680 0
                (Defining_Identifier => RE (RE_Pok_Needs_Partitions),
681 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
682 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
683

684
            N :=
685 0
              CTU.Make_Define_Statement
686 0
                (Defining_Identifier => RE (RE_Pok_Needs_Sched),
687 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
688 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
689
         end if;
690

691
--         N := CTU.Make_Define_Statement
692
--               (Defining_Identifier => RE (RE_Pok_Needs_Debug),
693
--                  Value => CTU.Make_Literal
694
--                     (CV.New_Int_Value (1, 1, 10)));
695
--         CTU.Append_Node_To_List
696
--                  (N, CTN.Declarations (CTU.Current_File));
697

698
--         N := Message_Comment
699
--            ("The maccro POK_NEEDS_DEBUG "&
700
--             "activates debug in the kernel (not in libpok).");
701

702
--         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
703

704
--  Try to remove the debug mode, automatically added previously.
705

706 0
         N := Message_Comment ("#define POK_NEEDS_DEBUG 1");
707 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
708

709
         N :=
710 0
           Message_Comment
711
             ("If you want to activate DEBUG mode, uncomment previous line");
712 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
713

714
         --  Define useful constants that configures the kernel : partition
715
         --  names, sizes and so on.
716

717
         N :=
718 0
           CTU.Make_Define_Statement
719 0
             (Defining_Identifier => RE (RE_Pok_Config_Nb_Partitions),
720
              Value               =>
721 0
                CTU.Make_Literal
722 0
                  (CV.New_Int_Value (System_Nb_Partitions, 1, 10)));
723 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
724

725
         N :=
726 0
           Message_Comment
727
             ("The maccro POK_CONFIG_NB_PARTITIONS " &
728
              "indicates the amount of partitions in the current system." &
729
              "It corresponds to the amount of process components" &
730
              "in the system.");
731

732 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
733

734 0
         System_Nb_Threads := System_Nb_Threads + System_Nb_Partitions;
735

736
         --  We add one thread per partitions
737

738 0
         System_Nb_Threads := System_Nb_Threads + 2;
739

740
         --  We add the kernel and idle threads
741

742
         N :=
743 0
           CTU.Make_Define_Statement
744 0
             (Defining_Identifier => RE (RE_Pok_Config_Nb_Threads),
745
              Value               =>
746 0
                CTU.Make_Literal
747 0
                  (CV.New_Int_Value (System_Nb_Threads, 1, 10)));
748

749 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
750

751
         N :=
752 0
           Message_Comment
753
             ("The maccro POK_CONFIG_NB_THREADS " &
754
              "indicates the amount of threads used in the kernel." &
755
              "It comprises the tasks for the partition and the main " &
756
              "task of each partition that initialize all ressources.");
757

758 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
759

760
         N :=
761 0
           CTU.Make_Define_Statement
762 0
             (Defining_Identifier => RE (RE_Pok_Config_Partitions_Nthreads),
763
              Value               => System_Partitions_Nb_Threads);
764 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
765

766
         N :=
767 0
           Message_Comment
768
             ("The maccro POK_CONFIG_NB_PARTITIONS_NTHREADS " &
769
              "indicates the amount of threads in each partition " &
770
              "we also add an additional process that initialize " &
771
              "all partition's entities (communication, threads, ...)");
772

773 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
774

775
         --  Declare only used schedulers
776

777 0
         if Kernel_Needs_Sched_Rms then
778
            N :=
779 0
              CTU.Make_Define_Statement
780 0
                (Defining_Identifier => RE (RE_Pok_Needs_Sched_Rms),
781 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
782 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
783
         end if;
784

785 0
         if Kernel_Needs_Sched_Rr then
786
            N :=
787 0
              CTU.Make_Define_Statement
788 0
                (Defining_Identifier => RE (RE_Pok_Needs_Sched_Rr),
789 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
790 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
791
         end if;
792

793 0
         if Kernel_Needs_Sched_Llf then
794
            N :=
795 0
              CTU.Make_Define_Statement
796 0
                (Defining_Identifier => RE (RE_Pok_Needs_Sched_Llf),
797 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
798 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
799
         end if;
800

801 0
         if Kernel_Needs_Sched_Edf then
802
            N :=
803 0
              CTU.Make_Define_Statement
804 0
                (Defining_Identifier => RE (RE_Pok_Needs_Sched_Edf),
805 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
806 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
807
         end if;
808

809 0
         if System_Nb_Lock_Objects > 0 then
810
            N :=
811 0
              CTU.Make_Define_Statement
812 0
                (Defining_Identifier => RE (RE_Pok_Needs_Lockobjects),
813 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
814

815 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
816

817
            N :=
818 0
              CTU.Make_Define_Statement
819 0
                (Defining_Identifier => RE (RE_Pok_Config_Nb_Lockobjects),
820
                 Value               =>
821 0
                   CTU.Make_Literal
822 0
                     (CV.New_Int_Value (System_Nb_Lock_Objects, 1, 10)));
823

824 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
825

826
            N :=
827 0
              CTU.Make_Define_Statement
828
                (Defining_Identifier =>
829 0
                   RE (RE_Pok_Config_Partitions_Nlockobjects),
830
                 Value => System_Partitions_Nb_Lock_Objects);
831

832 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
833

834
            N :=
835 0
              Message_Comment
836
                ("The maccro POK_CONFIG_NB_PARTITIONS_NLOCKOBJECTS " &
837
                 "indicates the amount of lockobjects in each partition ");
838

839 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
840
         end if;
841

842
         N :=
843 0
           CTU.Make_Define_Statement
844 0
             (Defining_Identifier => RE (RE_Pok_Config_Partitions_Size),
845
              Value               => System_Partitions_Size);
846

847 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
848

849
         N :=
850 0
           CTU.Make_Define_Statement
851 0
             (Defining_Identifier => RE (RE_Pok_Config_Partitions_Scheduler),
852
              Value               => System_Partitions_Scheduler);
853

854 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
855

856
         N :=
857 0
           Message_Comment
858
             ("The maccro POK_CONFIG_PARTTITIONS_SIZE " &
859
              "indicates the required amount of memory for each partition." &
860
              "This value was deduced from the property " &
861
              "POK::Needed_Memory_Size of each process");
862

863 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
864

865 0
         if not CTU.Is_Empty (CTN.Values (System_Slots)) then
866
            N :=
867 0
              CTU.Make_Define_Statement
868 0
                (Defining_Identifier => RE (RE_Pok_Config_Scheduling_Slots),
869
                 Value               => System_Slots);
870

871 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
872
         end if;
873

874 0
         if not CTU.Is_Empty (CTN.Values (System_Slots_Allocation)) then
875
            N :=
876 0
              CTU.Make_Define_Statement
877
                (Defining_Identifier =>
878 0
                   RE (RE_Pok_Config_Scheduling_Slots_Allocation),
879
                 Value => System_Slots_Allocation);
880

881 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
882
         end if;
883

884
         N :=
885 0
           CTU.Make_Define_Statement
886 0
             (Defining_Identifier => RE (RE_Pok_Config_Scheduling_Nbslots),
887
              Value               =>
888 0
                CTU.Make_Literal (CV.New_Int_Value (System_Nb_Slots, 1, 10)));
889

890 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
891

892 0
         if Major_Frame /= No_Node then
893
            N :=
894 0
              CTU.Make_Define_Statement
895
                (Defining_Identifier =>
896 0
                   RE (RE_Pok_Config_Scheduling_Major_Frame),
897
                 Value => Major_Frame);
898

899 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
900
         end if;
901

902 0
         if System_Use_Sampling_Ports then
903
            N :=
904 0
              CTU.Make_Define_Statement
905 0
                (Defining_Identifier => RE (RE_Pok_Needs_Ports_Sampling),
906 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
907

908 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
909
            N :=
910 0
              Message_Comment
911
                ("The maccro POK_NEEDS_PORTS_SAMPLING indicates " &
912
                 "that we need sampling ports facilities in POK." &
913
                 "It also means that we have intra-partition " &
914
                 "communication between several processes through " &
915
                 "event data port.");
916 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
917
         end if;
918

919 0
         if System_Use_Queueing_Ports then
920
            N :=
921 0
              CTU.Make_Define_Statement
922 0
                (Defining_Identifier => RE (RE_Pok_Needs_Ports_Queueing),
923 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
924

925 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
926
            N :=
927 0
              Message_Comment
928
                ("The maccro POK_NEEDS_PORTS_QUEUEING indicates " &
929
                 "that we need queueing ports facilities in POK." &
930
                 "It also means that we have inter-partition " &
931
                 "communication between several processes through " &
932
                 "event data port.");
933 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
934
         end if;
935

936 0
         if System_Use_Virtual_Ports then
937
            N :=
938 0
              CTU.Make_Define_Statement
939 0
                (Defining_Identifier => RE (RE_Pok_Needs_Ports_Virtual),
940 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
941

942 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
943
            N :=
944 0
              Message_Comment
945
                ("The maccro POK_NEEDS_PORTS_VIRTUAL indicates " &
946
                 "that we need virtual ports facilities in POK." &
947
                 "It also means that we have inter-partition " &
948
                 "communication between several processes through " &
949
                 "[event] data port. Virtual ports are uses " &
950
                 "for device drivers interfacing");
951 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
952
         end if;
953

954
         N :=
955 0
           CTU.Make_Define_Statement
956 0
             (Defining_Identifier => RE (RE_Pok_Config_Stacks_Size),
957
              Value               =>
958 0
                CTU.Make_Literal
959 0
                  (CV.New_Int_Value (System_Stacks_Size, 1, 10)));
960 0
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
961

962 0
         if System_Nb_Ports > 0 then
963
            N :=
964 0
              CTU.Make_Define_Statement
965 0
                (Defining_Identifier => RE (RE_Pok_Config_Partitions_Ports),
966
                 Value               => System_Partitions_Ports);
967

968 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
969

970
            N :=
971 0
              CTU.Make_Define_Statement
972 0
                (Defining_Identifier => RE (RE_Pok_Config_Nb_Ports),
973
                 Value               =>
974 0
                   CTU.Make_Literal
975 0
                     (CV.New_Int_Value (System_Nb_Ports, 1, 10)));
976

977 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
978

979
            N :=
980 0
              CTU.Make_Define_Statement
981 0
                (Defining_Identifier => RE (RE_Pok_Config_Nb_Global_Ports),
982
                 Value               => Global_Nb_Ports_Node);
983

984 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
985

986
            N :=
987 0
              Message_Comment
988
                ("The maccro POK_CONFIG_NB_PORTS represent the amount " &
989
                 "of inter-partition communication in the system." &
990
                 "Sampling and Queueing ports are counted.");
991 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
992

993 0
            Set_Str_To_Name_Buffer ("invalid_local_port");
994
            N :=
995 0
              Make_Expression
996 0
                (CTU.Make_Defining_Identifier (Name_Find),
997
                 Op_Equal,
998 0
                 (Make_Literal
999 0
                    (CV.New_Int_Value (Local_Port_Identifier, 0, 10))));
1000 0
            Append_Node_To_List (N, Local_Port_List);
1001

1002
            N :=
1003 0
              Make_Full_Type_Declaration
1004 0
                (Defining_Identifier => RE (RE_Pok_Port_Local_Identifier_T),
1005 0
                 Type_Definition     => Make_Enum_Aggregate (Local_Port_List));
1006 0
            Append_Node_To_List (N, CTN.Declarations (Current_File));
1007

1008
            N :=
1009 0
              Make_Full_Type_Declaration
1010 0
                (Defining_Identifier => RE (RE_Pok_Node_Identifier_T),
1011 0
                 Type_Definition     => Make_Enum_Aggregate (Node_List));
1012 0
            Append_Node_To_List (N, CTN.Declarations (Current_File));
1013

1014
            N :=
1015 0
              Make_Full_Type_Declaration
1016 0
                (Defining_Identifier => RE (RE_Pok_Port_Identifier_T),
1017 0
                 Type_Definition => Make_Enum_Aggregate (Global_Port_List));
1018 0
            Append_Node_To_List (N, CTN.Declarations (Current_File));
1019

1020
            N :=
1021 0
              Message_Comment
1022
                ("This enumeration describes all ports on the current " &
1023
                 "nodes. It is used by the configuration arrays in " &
1024
                 "the generated file deployment.c.");
1025 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1026
         end if;
1027

1028
         declare
1029 0
            Bus_Id   : Unsigned_Long_Long := 0;
1030
            Bus_List : constant List_Id   :=
1031 0
              New_List (CTN.K_Enumeration_Literals);
1032
         begin
1033 0
            S := AIN.First_Node (Used_Buses);
1034

1035 0
            while Present (S) loop
1036
               N :=
1037 0
                 Make_Expression
1038 0
                   (CTU.Make_Defining_Identifier (Map_Bus_Name (Item (S))),
1039
                    Op_Equal,
1040 0
                    (Make_Literal (CV.New_Int_Value (Bus_Id, 0, 10))));
1041 0
               Append_Node_To_List (N, Bus_List);
1042

1043 0
               Bus_Id := Bus_Id + 1;
1044

1045 0
               S := AIN.Next_Node (S);
1046 0
            end loop;
1047

1048
            N :=
1049 0
              CTU.Make_Define_Statement
1050 0
                (Defining_Identifier => RE (RE_Pok_Config_Nb_Buses),
1051 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (Bus_Id, 1, 10)));
1052 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1053

1054
            N :=
1055 0
              Make_Expression
1056 0
                (CTU.Make_Defining_Identifier
1057 0
                   (Get_String_Name ("invalid_bus")),
1058
                 Op_Equal,
1059 0
                 (Make_Literal (CV.New_Int_Value (Bus_Id, 0, 10))));
1060 0
            Append_Node_To_List (N, Bus_List);
1061

1062
            N :=
1063 0
              Make_Full_Type_Declaration
1064 0
                (Defining_Identifier => RE (RE_Pok_Bus_Identifier_T),
1065 0
                 Type_Definition     => Make_Enum_Aggregate (Bus_List));
1066 0
            Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1067
         end;
1068

1069 0
         Reset_Handlings;
1070

1071 0
         CTN.Set_Value
1072
           (Global_Nb_Ports_Node,
1073 0
            CV.New_Int_Value (Global_Port_Identifier, 1, 10));
1074
         --  Update the value of the number of global ports,
1075
         --  taking in accounts new procesed ports.
1076

1077 0
         Runtime.User_Mode;
1078
         --  Fallback in user mode now, since we dont need
1079
         --  functionnalities dedicated to kernelland.
1080

1081 0
         Pop_Entity;
1082 0
         Pop_Entity;
1083 0
         Pop_Entity;
1084 1
      end Visit_Processor_Instance;
1085

1086
      ---------------------------
1087
      -- Visit_System_Instance --
1088
      ---------------------------
1089

1090 1
      procedure Visit_System_Instance (E : Node_Id) is
1091 1
         S                  : Node_Id;
1092 1
         Component_Instance : Node_Id;
1093
      begin
1094 1
         if not AINU.Is_Empty (Subcomponents (E)) then
1095 1
            S := First_Node (Subcomponents (E));
1096 1
            while Present (S) loop
1097 1
               Component_Instance := Corresponding_Instance (S);
1098 1
               if AINU.Is_Processor (Component_Instance) then
1099 1
                  Visit (Component_Instance);
1100
               end if;
1101 1
               S := Next_Node (S);
1102 1
            end loop;
1103
         end if;
1104 1
      end Visit_System_Instance;
1105

1106
      ----------------------------
1107
      -- Visit_Process_Instance --
1108
      ----------------------------
1109

1110 1
      procedure Visit_Process_Instance
1111
        (E                    : Node_Id;
1112
         Real_Process         : Boolean := True;
1113
         Associated_Component : Node_Id := No_Node)
1114
      is
1115 1
         C                       : Node_Id;
1116 1
         N                       : Node_Id;
1117 1
         O                       : Node_Id;
1118 1
         F                       : Node_Id;
1119 1
         U                       : Node_Id;
1120 1
         P                       : Node_Id;
1121 1
         Bound_Processor         : Node_Id;
1122 1
         Communicating_Component : Node_Id;
1123 1
         Property_Memory_Size    : Unsigned_Long_Long := 0;
1124 1
         Bound_Memory_Component  : Node_Id;
1125 1
         Bound_Memory_Size       : Unsigned_Long_Long := 0;
1126 1
         Used_Memory_Size        : Unsigned_Long_Long := 0;
1127 1
         Additional_Features     : List_Id;
1128
      begin
1129 1
         if Real_Process then
1130
            U :=
1131 1
              CTN.Distributed_Application_Unit
1132 1
                (CTN.Naming_Node (Backend_Node (Identifier (E))));
1133 1
            P := CTN.Entity (U);
1134 1
            CTU.Push_Entity (P);
1135 1
            CTU.Push_Entity (U);
1136 1
            Communicating_Component := E;
1137
         else
1138 0
            Communicating_Component := Associated_Component;
1139
            U                       :=
1140 0
              CTN.Distributed_Application_Unit
1141 0
                (CTN.Naming_Node
1142 0
                   (Backend_Node (Identifier (Communicating_Component))));
1143 0
            P := CTN.Entity (U);
1144
         end if;
1145

1146 1
         CTU.Set_Deployment_Header;
1147

1148 1
         Partition_Stacks_Size := 0;
1149

1150 1
         if Real_Process then
1151 1
            Bound_Processor := Get_Bound_Processor (E);
1152
         else
1153 0
            Bound_Processor := Get_Bound_Processor (Associated_Component);
1154
         end if;
1155

1156
         --
1157
         --  Add a maccro to specify on which platform we are deploying
1158
         --  the code. This can be used to make some adjustment in the
1159
         --  user code.
1160
         --
1161

1162 1
         case POK_Flavor is
1163 1
            when DEOS =>
1164
               N :=
1165 1
                 CTU.Make_Define_Statement
1166 1
                   (Defining_Identifier => RE (RE_Ocarina_Runtime_Deos),
1167 1
                    Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1168

1169 1
               CTU.Append_Node_To_List
1170
                 (N,
1171 1
                  CTN.Declarations (CTU.Current_File));
1172 1
            when VXWORKS =>
1173
               N :=
1174 1
                 CTU.Make_Define_Statement
1175 1
                   (Defining_Identifier => RE (RE_Ocarina_Runtime_Vxworks653),
1176 1
                    Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1177

1178 1
               CTU.Append_Node_To_List
1179
                 (N,
1180 1
                  CTN.Declarations (CTU.Current_File));
1181

1182 0
            when POK | ARINC653 =>
1183
               N :=
1184 0
                 CTU.Make_Define_Statement
1185 0
                   (Defining_Identifier => RE (RE_Ocarina_Runtime_Pok),
1186 0
                    Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1187

1188 0
               CTU.Append_Node_To_List
1189
                 (N,
1190 0
                  CTN.Declarations (CTU.Current_File));
1191 1
         end case;
1192

1193
         N :=
1194 1
           CTU.Make_Define_Statement
1195 1
             (Defining_Identifier => RE (RE_Pok_Generated_Code),
1196 1
              Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1197

1198 1
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1199

1200
         --  Define the maccro POK_GENERATED_CODE so that the runtime
1201
         --  is aware that we use generated code. Consequently,
1202
         --  the runtime can restrict included functions in the binary.
1203
         --  Here, we do that at the partition level.
1204

1205 1
         if Is_Defined_Property
1206
             (Bound_Processor,
1207
              "pok::additional_features")
1208
         then
1209
            Additional_Features :=
1210 0
              ATN.Multi_Value
1211 0
                (AIN.Property_Association_Value
1212 0
                   (AIEP.Find_Property_Association_From_Name
1213 0
                      (Property_List => AIN.Properties (Bound_Processor),
1214
                       Property_Name =>
1215 0
                         Get_String_Name ("pok::additional_features"),
1216
                       In_Mode => No_Name)));
1217

1218 0
            if not ATNU.Is_Empty (Additional_Features) then
1219
               declare
1220 0
                  S        : Node_Id;
1221 0
                  Tmp_Name : Name_Id;
1222
               begin
1223 0
                  S := ATN.First_Node (Additional_Features);
1224 0
                  while Present (S) loop
1225 0
                     Set_Str_To_Name_Buffer ("pok_needs_");
1226 0
                     Get_Name_String_And_Append
1227 0
                       (ATN.Name (ATN.Identifier (S)));
1228

1229 0
                     Tmp_Name := To_Upper (Name_Find);
1230

1231
                     N :=
1232 0
                       CTU.Make_Define_Statement
1233
                         (Defining_Identifier =>
1234 0
                            Make_Defining_Identifier
1235
                              (Tmp_Name,
1236
                               C_Conversion => False),
1237
                          Value =>
1238 0
                            CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1239 0
                     CTU.Append_Node_To_List
1240
                       (N,
1241 0
                        CTN.Declarations (CTU.Current_File));
1242

1243 0
                     if Get_Name_String (ATN.Name (ATN.Identifier (S))) =
1244
                       "console"
1245
                     then
1246 0
                        CTU.Pop_Entity;
1247 0
                        CTU.Pop_Entity;
1248

1249 0
                        Push_Entity (Kernel_Unit);
1250 0
                        Set_Deployment_Header;
1251

1252
                        N :=
1253 0
                          CTU.Make_Define_Statement
1254 0
                            (Defining_Identifier => RE (RE_Pok_Needs_Console),
1255
                             Value               =>
1256 0
                               CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1257 0
                        CTU.Append_Node_To_List
1258
                          (N,
1259 0
                           CTN.Declarations (CTU.Current_File));
1260

1261 0
                        Pop_Entity;
1262

1263 0
                        CTU.Push_Entity (P);
1264 0
                        CTU.Push_Entity (U);
1265

1266 0
                        Set_Deployment_Header;
1267
                     end if;
1268

1269 0
                     if Get_Name_String (ATN.Name (ATN.Identifier (S))) =
1270
                       "x86_vmm"
1271
                     then
1272 0
                        CTU.Pop_Entity;
1273 0
                        CTU.Pop_Entity;
1274

1275 0
                        Push_Entity (Kernel_Unit);
1276 0
                        Set_Deployment_Header;
1277

1278
                        N :=
1279 0
                          CTU.Make_Define_Statement
1280 0
                            (Defining_Identifier => RE (RE_Pok_Needs_X86_Vmm),
1281
                             Value               =>
1282 0
                               CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1283 0
                        CTU.Append_Node_To_List
1284
                          (N,
1285 0
                           CTN.Declarations (CTU.Current_File));
1286

1287 0
                        Pop_Entity;
1288

1289 0
                        CTU.Push_Entity (P);
1290 0
                        CTU.Push_Entity (U);
1291

1292 0
                        Set_Deployment_Header;
1293
                     end if;
1294

1295 0
                     S := ATN.Next_Node (S);
1296 0
                  end loop;
1297
               end;
1298
            end if;
1299
         end if;
1300

1301 1
         Partition_Use_Error_Handling := False;
1302

1303 1
         Process_Nb_Threads      := 0;
1304 1
         Process_Nb_Buffers      := 0;
1305 1
         Process_Nb_Events       := 0;
1306 1
         Process_Nb_Lock_Objects := 0;
1307 1
         Process_Nb_Blackboards  := 0;
1308 1
         System_Nb_Partitions    := System_Nb_Partitions + 1;
1309

1310
         --  The Needed_Memory_Size is required, it must be
1311
         --  declared in the model. It defines the allocated
1312
         --  size for each partition.
1313

1314 1
         Property_Memory_Size := Get_Needed_Memory_Size (E);
1315

1316 1
         if Real_Process then
1317 1
            Bound_Memory_Component := Get_Bound_Memory (E);
1318
         else
1319 0
            Bound_Memory_Component := Get_Bound_Memory (Associated_Component);
1320
         end if;
1321

1322 1
         if Bound_Memory_Component /= No_Node then
1323
            declare
1324 1
               Byte_Count : Unsigned_Long_Long := 1;
1325 1
               Word_Size  : Unsigned_Long_Long := 1;
1326
            begin
1327 1
               if Get_Byte_Count (Bound_Memory_Component) /= 0 then
1328 0
                  Byte_Count := Get_Byte_Count (Bound_Memory_Component);
1329
               end if;
1330

1331 1
               if Get_Word_Size (Bound_Memory_Component) /= Null_Size then
1332
                  Word_Size :=
1333 0
                    To_Bytes (Get_Word_Size (Bound_Memory_Component));
1334
               end if;
1335 1
               Bound_Memory_Size := Byte_Count * Word_Size;
1336

1337
               --  byte_count override other properties.
1338 1
               if Is_Defined_Property
1339
                   (Bound_Memory_Component,
1340
                    "byte_count")
1341
               then
1342
                  Bound_Memory_Size :=
1343 0
                    Get_Integer_Property
1344
                      (Bound_Memory_Component,
1345
                       "byte_count");
1346
               end if;
1347 1
            end;
1348
         end if;
1349

1350 1
         if Bound_Memory_Size /= 0 then
1351 1
            Used_Memory_Size := Bound_Memory_Size;
1352 0
         elsif Property_Memory_Size /= 0 then
1353 0
            Used_Memory_Size := Property_Memory_Size;
1354
         else
1355 0
            Display_Located_Error
1356 0
              (Loc (E),
1357
               "You must provide the size of the parttion",
1358
               Fatal => True);
1359
         end if;
1360

1361 1
         if Real_Process then
1362 1
            Communicating_Component := E;
1363
         else
1364 0
            Communicating_Component := Associated_Component;
1365
         end if;
1366

1367 1
         if not AINU.Is_Empty (Features (Communicating_Component)) then
1368 1
            F := First_Node (Features (Communicating_Component));
1369

1370 1
            while Present (F) loop
1371 1
               if Kind (F) = K_Port_Spec_Instance
1372 1
                 and then Get_Connection_Pattern (F) = Inter_Process
1373
               then
1374

1375 1
                  if Is_Defined_Property
1376
                      (F,
1377
                       "allowed_connection_binding_class")
1378
                  then
1379
                     N :=
1380 0
                       CTU.Make_Define_Statement
1381 0
                         (Defining_Identifier => RE (RE_Pok_Needs_Protocols),
1382
                          Value               =>
1383 0
                            CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1384 0
                     CTU.Append_Node_To_List
1385
                       (N,
1386 0
                        CTN.Declarations (CTU.Current_File));
1387

1388
                     N :=
1389 0
                       CTU.Make_Define_Statement
1390 0
                         (Defining_Identifier => RE (RE_Pok_Needs_Libc_String),
1391
                          Value               =>
1392 0
                            CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1393 0
                     CTU.Append_Node_To_List
1394
                       (N,
1395 0
                        CTN.Declarations (CTU.Current_File));
1396

1397 0
                     Handle_Virtual_Buses_Properties (F);
1398

1399 0
                     Set_Activity_Source;
1400 0
                     Add_Include (RH (RH_Protocols));
1401 0
                     Set_Deployment_Header;
1402
                  end if;
1403

1404 1
                  AINU.Append_Node_To_List
1405 1
                    (AINU.Make_Node_Container (F),
1406
                     All_Ports);
1407

1408 1
                  Handle_Buses_Connections (F);
1409

1410
                  N :=
1411 1
                    Make_Expression
1412 1
                      (CTU.Make_Defining_Identifier (Map_Port_Name (F)),
1413
                       Op_Equal,
1414 1
                       (Make_Literal
1415 1
                          (CV.New_Int_Value (Local_Port_Identifier, 0, 10))));
1416 1
                  Append_Node_To_List (N, Local_Port_List);
1417

1418
                  N :=
1419 1
                    Make_Expression
1420 1
                      (CTU.Make_Defining_Identifier (Map_Port_Name (F, True)),
1421
                       Op_Equal,
1422 1
                       (Make_Literal
1423 1
                          (CV.New_Int_Value (Global_Port_Identifier, 0, 10))));
1424 1
                  Append_Node_To_List (N, Global_Port_List);
1425

1426 1
                  CTU.Append_Node_To_List
1427 1
                    (CTU.Copy_Node
1428 1
                       (Get_Handling
1429
                          (Bound_Processor,
1430
                           By_Node,
1431
                           H_C_Deployment_Spec)),
1432 1
                     CTN.Values (System_Partitions_Ports));
1433
                  --  Declare which partition would use this port.
1434

1435 1
                  Local_Port_Identifier  := Local_Port_Identifier + 1;
1436 1
                  Global_Port_Identifier := Global_Port_Identifier + 1;
1437

1438 1
                  CTU.Append_Node_To_List
1439 1
                    (Make_Literal (CV.New_Int_Value (Node_Identifier, 0, 10)),
1440 1
                     CTN.Values (Array_Global_Ports_Nodes));
1441

1442 1
                  if not AIN.Is_Event (F) and then AIN.Is_Data (F) then
1443 1
                     System_Use_Sampling_Ports := True;
1444 1
                  elsif AIN.Is_Data (F) and then AIN.Is_Event (F) then
1445 1
                     System_Use_Queueing_Ports := True;
1446
                  end if;
1447

1448 1
                  System_Nb_Ports := System_Nb_Ports + 1;
1449
               end if;
1450 1
               F := Next_Node (F);
1451 1
            end loop;
1452
         end if;
1453

1454
         --  Handle subcomponents.
1455

1456 1
         if not AINU.Is_Empty (Subcomponents (E)) then
1457 1
            C := First_Node (Subcomponents (E));
1458

1459 1
            while Present (C) loop
1460
               --  If we have a protected data, we create semaphore variables.
1461 1
               if AINU.Is_Data (Corresponding_Instance (C))
1462 0
                 and then Is_Protected_Data (Corresponding_Instance (C))
1463
               then
1464

1465
                  --  If we have a protected shared data, we declare
1466
                  --  a new semaphore in the kernel and in the current
1467
                  --  partitions. This dimension resources of kernel
1468
                  --  and partition.
1469

1470 0
                  System_Nb_Lock_Objects  := System_Nb_Lock_Objects + 1;
1471 0
                  Process_Nb_Lock_Objects := Process_Nb_Lock_Objects + 1;
1472
               else
1473 1
                  Visit (Corresponding_Instance (C));
1474
               end if;
1475 1
               C := Next_Node (C);
1476 1
            end loop;
1477
         end if;
1478
         --  Append the partition name and its size to a global
1479

1480
         --  array that will configure the kernel
1481

1482 1
         O := CTU.Make_Literal (CV.New_Int_Value (Used_Memory_Size, 1, 10));
1483

1484 1
         CTU.Append_Node_To_List (O, CTN.Values (System_Partitions_Size));
1485

1486 1
         if Partition_Use_Error_Handling then
1487 0
            Process_Nb_Threads := Process_Nb_Threads + 1;
1488 0
            System_Nb_Threads  := System_Nb_Threads + 1;
1489
            --  If we have error handling in this partition, we need
1490
            --  to add one thread in the partitions so we declare
1491
            --  an additional thread in the partition and in the kernel.
1492
         end if;
1493

1494 1
         Process_Nb_Threads := Process_Nb_Threads + 1;
1495

1496 1
         CTU.Append_Node_To_List
1497 1
           (CTU.Make_Literal (CV.New_Int_Value (Process_Nb_Threads, 1, 10)),
1498 1
            CTN.Values (System_Partitions_Nb_Threads));
1499

1500 1
         CTU.Append_Node_To_List
1501 1
           (CTU.Make_Literal
1502 1
              (CV.New_Int_Value (Process_Nb_Lock_Objects, 1, 10)),
1503 1
            CTN.Values (System_Partitions_Nb_Lock_Objects));
1504

1505
         --  Finally, declare the amount of threads inside the partition
1506

1507
         N :=
1508 1
           CTU.Make_Define_Statement
1509 1
             (Defining_Identifier => RE (RE_Pok_Config_Nb_Threads),
1510
              Value               =>
1511 1
                CTU.Make_Literal
1512 1
                  (CV.New_Int_Value (Process_Nb_Threads, 1, 10)));
1513

1514 1
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1515

1516 1
         if Process_Nb_Buffers > 0 then
1517
            N :=
1518 1
              CTU.Make_Define_Statement
1519 1
                (Defining_Identifier => RE (RE_Pok_Config_Nb_Buffers),
1520
                 Value               =>
1521 1
                   CTU.Make_Literal
1522 1
                     (CV.New_Int_Value (Process_Nb_Buffers, 1, 10)));
1523 1
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1524

1525
            N :=
1526 1
              CTU.Make_Define_Statement
1527 1
                (Defining_Identifier => RE (RE_Pok_Needs_Buffers),
1528 1
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1529 1
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1530
         end if;
1531

1532 1
         if Process_Nb_Events > 0 then
1533
            N :=
1534 0
              CTU.Make_Define_Statement
1535 0
                (Defining_Identifier => RE (RE_Pok_Config_Nb_Events),
1536
                 Value               =>
1537 0
                   CTU.Make_Literal
1538 0
                     (CV.New_Int_Value (Process_Nb_Events, 1, 10)));
1539 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1540

1541
            N :=
1542 0
              CTU.Make_Define_Statement
1543 0
                (Defining_Identifier => RE (RE_Pok_Needs_Events),
1544 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1545 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1546
         end if;
1547

1548
         --  Define NB_BLACKBOARDS or NB_BUFFERS directive in the deployment.h
1549
         --  of each partition.
1550

1551 1
         if Process_Nb_Blackboards > 0 then
1552
            N :=
1553 1
              CTU.Make_Define_Statement
1554 1
                (Defining_Identifier => RE (RE_Pok_Config_Nb_Blackboards),
1555
                 Value               =>
1556 1
                   CTU.Make_Literal
1557 1
                     (CV.New_Int_Value (Process_Nb_Blackboards, 1, 10)));
1558 1
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1559

1560
            N :=
1561 1
              CTU.Make_Define_Statement
1562 1
                (Defining_Identifier => RE (RE_Pok_Needs_Blackboards),
1563 1
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1564 1
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1565
         end if;
1566

1567
         --  Define POK_NEEDS_MIDDLEWARE in each partition
1568

1569 1
         if Process_Nb_Blackboards > 0 or else Process_Nb_Buffers > 0 then
1570
            N :=
1571 1
              CTU.Make_Define_Statement
1572 1
                (Defining_Identifier => RE (RE_Pok_Needs_Middleware),
1573 1
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
1574 1
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1575
         end if;
1576

1577
         N :=
1578 1
           CTU.Make_Define_Statement
1579 1
             (Defining_Identifier => RE (RE_Pok_Config_Stacks_Size),
1580
              Value               =>
1581 1
                CTU.Make_Literal
1582 1
                  (CV.New_Int_Value (Partition_Stacks_Size, 1, 10)));
1583 1
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1584

1585 1
         if Real_Process then
1586 1
            CTU.Pop_Entity;
1587 1
            CTU.Pop_Entity;
1588
         end if;
1589 1
      end Visit_Process_Instance;
1590

1591
      ---------------------------
1592
      -- Visit_Device_Instance --
1593
      ---------------------------
1594

1595 0
      procedure Visit_Device_Instance (E : Node_Id) is
1596 0
         N : Node_Id;
1597 0
         F : Node_Id;
1598 0
         S : Node_Id;
1599
         U : constant Node_Id :=
1600 0
           CTN.Distributed_Application_Unit
1601 0
             (CTN.Naming_Node (Backend_Node (Identifier (E))));
1602 0
         P              : constant Node_Id := CTN.Entity (U);
1603 0
         Implementation : Node_Id;
1604
      begin
1605 0
         CTU.Push_Entity (P);
1606 0
         CTU.Push_Entity (U);
1607

1608 0
         CTU.Set_Deployment_Header;
1609

1610 0
         Current_Device := E;
1611

1612 0
         if Is_Defined_Property (E, "pok::hw_addr") then
1613
            N :=
1614 0
              CTU.Make_Define_Statement
1615 0
                (Defining_Identifier => RE (RE_Pok_Hw_Addr),
1616
                 Value               =>
1617 0
                   CTU.Make_Literal
1618 0
                     (CV.New_Pointed_Char_Value
1619 0
                        (Get_String_Property (E, "pok::hw_addr"))));
1620

1621 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1622
         end if;
1623

1624 0
         if Is_Defined_Property (E, "pok::pci_device_id") then
1625
            N :=
1626 0
              CTU.Make_Define_Statement
1627 0
                (Defining_Identifier => RE (RE_Pok_Pci_Device_Id),
1628
                 Value               =>
1629 0
                   CTU.Make_Literal
1630 0
                     (CV.New_Pointed_Char_Value
1631 0
                        (Get_String_Property (E, "pok::pci_device_id"))));
1632

1633 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1634
         end if;
1635

1636 0
         if Is_Defined_Property (E, "pok::device_name") then
1637
            N :=
1638 0
              CTU.Make_Define_Statement
1639
                (Defining_Identifier =>
1640 0
                   Map_Needs_Macro
1641 0
                     (Get_String_Property (E, "pok::device_name")),
1642
                 Value =>
1643 0
                   CTU.Make_Literal
1644 0
                     (CV.New_Int_Value (Process_Nb_Threads, 1, 10)));
1645

1646 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1647
         end if;
1648

1649 0
         if Is_Defined_Property (E, "pok::pci_vendor_id") then
1650 0
            Kernel_Use_Pci := True;
1651 0
            Kernel_Use_Io  := True;
1652
            N              :=
1653 0
              CTU.Make_Define_Statement
1654 0
                (Defining_Identifier => RE (RE_Pok_Pci_Vendor_Id),
1655
                 Value               =>
1656 0
                   CTU.Make_Literal
1657 0
                     (CV.New_Pointed_Char_Value
1658 0
                        (Get_String_Property (E, "pok::pci_vendor_id"))));
1659

1660 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
1661
         end if;
1662

1663 0
         if Get_String_Property (E, "pok::device_name") =
1664 0
           Get_String_Name ("rtl8029")
1665
         then
1666 0
            Kernel_Use_Pci := True;
1667 0
            Kernel_Use_Io  := True;
1668
         end if;
1669

1670 0
         if not AINU.Is_Empty (Features (E)) then
1671 0
            F := First_Node (Features (E));
1672

1673 0
            while Present (F) loop
1674 0
               if Kind (F) = K_Port_Spec_Instance
1675 0
                 and then Get_Connection_Pattern (F) = Inter_Process
1676 0
                 and then Is_Virtual (Get_Port_By_Name (F, Current_Device))
1677
               then
1678

1679 0
                  System_Use_Virtual_Ports := True;
1680
               end if;
1681

1682 0
               if Kind (F) = K_Subcomponent_Access_Instance
1683 0
                 and then AINU.Is_Bus (Corresponding_Instance (F))
1684
               then
1685
                  declare
1686 0
                     Accessed     : List_Id;
1687 0
                     Accessed_Bus : Node_Id;
1688 0
                     D            : Node_Id;
1689
                  begin
1690 0
                     if not AINU.Is_Empty (Sources (F)) then
1691 0
                        D := First_Node (Sources (F));
1692 0
                        while Present (D) loop
1693 0
                           Accessed_Bus := Item (D);
1694
                           Accessed     :=
1695 0
                             CTN.Processes
1696 0
                               (Backend_Node (Identifier (Accessed_Bus)));
1697 0
                           AINU.Append_Node_To_List
1698 0
                             (AINU.Make_Node_Container (E),
1699
                              Accessed);
1700

1701 0
                           D := Next_Node (D);
1702 0
                        end loop;
1703
                     end if;
1704
                  end;
1705
               end if;
1706 0
               F := Next_Node (F);
1707 0
            end loop;
1708
         end if;
1709

1710 0
         Implementation := Get_Classifier_Property (E, "implemented_as");
1711

1712 0
         if Implementation /= No_Node then
1713 0
            if not AINU.Is_Empty (AIN.Subcomponents (Implementation)) then
1714 0
               S := First_Node (Subcomponents (Implementation));
1715 0
               while Present (S) loop
1716 0
                  if Get_Category_Of_Component (S) = CC_Process then
1717 0
                     Visit_Process_Instance
1718 0
                       (Corresponding_Instance (S),
1719
                        False,
1720
                        E);
1721
                  else
1722 0
                     Visit (Corresponding_Instance (S));
1723
                  end if;
1724

1725 0
                  S := Next_Node (S);
1726 0
               end loop;
1727
            end if;
1728

1729
         end if;
1730

1731 0
         Current_Device := No_Node;
1732

1733 0
         CTU.Pop_Entity;
1734 0
         CTU.Pop_Entity;
1735 0
      end Visit_Device_Instance;
1736

1737
      ---------------------------
1738
      -- Visit_Thread_Instance --
1739
      ---------------------------
1740

1741 1
      procedure Visit_Thread_Instance (E : Node_Id) is
1742 1
         F : Node_Id;
1743
      begin
1744 1
         System_Nb_Threads  := System_Nb_Threads + 1;
1745 1
         Process_Nb_Threads := Process_Nb_Threads + 1;
1746

1747 1
         if Get_POK_Recovery_Errors (E) /= POK_Empty_Handled_Errors
1748 1
           or else Get_ARINC653_HM_Errors (E) /= ARINC653_Empty_Errors
1749
         then
1750 0
            Kernel_Use_Error_Handling    := True;
1751 0
            Partition_Use_Error_Handling := True;
1752
         end if;
1753

1754 1
         if Get_Thread_Stack_Size (E) /= Null_Size then
1755 1
            Partition_Stacks_Size :=
1756 1
              Partition_Stacks_Size + To_Bytes (Get_Thread_Stack_Size (E));
1757 1
            System_Stacks_Size :=
1758 1
              System_Stacks_Size + To_Bytes (Get_Thread_Stack_Size (E));
1759
         else
1760 0
            Partition_Stacks_Size := Partition_Stacks_Size + 8192;
1761 0
            System_Stacks_Size    := System_Stacks_Size + 8192;
1762
         end if;
1763

1764
         --  Fetch ports and declare correct number of intra-partitions
1765
         --  elements (buffers, blackboards and so on). Crappy hack :
1766
         --  we only handle out port since it permit us to handle
1767
         --  the whole connection in the process.
1768

1769 1
         if not AINU.Is_Empty (Features (E)) then
1770 1
            F := First_Node (Features (E));
1771

1772 1
            while Present (F) loop
1773 1
               if Kind (F) = K_Port_Spec_Instance then
1774 1
                  Kernel_Use_Gettick := True;
1775 1
                  if Get_Connection_Pattern (F) = Intra_Process
1776 1
                    and then Get_Port_By_Name (F, Current_Device) = No_Node
1777 1
                    and then Is_In (F)
1778
                  then
1779 1
                     if AIN.Is_Data (F) and then not AIN.Is_Event (F) then
1780 1
                        Process_Nb_Blackboards := Process_Nb_Blackboards + 1;
1781 1
                     elsif AIN.Is_Data (F) and then AIN.Is_Event (F) then
1782 1
                        Process_Nb_Buffers := Process_Nb_Buffers + 1;
1783 0
                     elsif AIN.Is_Event (F) and then not AIN.Is_Data (F) then
1784 0
                        Process_Nb_Events := Process_Nb_Events + 1;
1785
                     else
1786 0
                        Display_Communication_Error;
1787
                     end if;
1788

1789 1
                     Process_Nb_Lock_Objects := Process_Nb_Lock_Objects + 1;
1790 1
                     System_Nb_Lock_Objects  := System_Nb_Lock_Objects + 1;
1791
                  end if;
1792
               end if;
1793 1
               F := Next_Node (F);
1794 1
            end loop;
1795
         end if;
1796

1797 1
      end Visit_Thread_Instance;
1798

1799
   end Header_File;
1800

1801
   -----------------
1802
   -- Source_File --
1803
   -----------------
1804

1805
   package body Source_File is
1806 1
      Process_Buffers       : Node_Id;
1807 1
      Process_Blackboards   : Node_Id;
1808 1
      Nb_Ports_By_Partition : Node_Id;
1809 1
      Ports_By_Partition    : Node_Id;
1810 1
      Ports_Names           : Node_Id;
1811

1812 1
      Partition_ARINC653_Semaphores_Names : Node_Id;
1813 1
      Partition_ARINC653_Events_Names     : Node_Id;
1814
      --  Name of semaphores for ARINC653 flavor.
1815

1816
      Partition_ARINC653_Nb_Semaphores : Unsigned_Long_Long := 0;
1817
      Partition_ARINC653_Nb_Events     : Unsigned_Long_Long := 0;
1818
      --  Number of semaphores inside a partition.
1819

1820 1
      Ports_Identifiers                      : Node_Id;
1821 1
      Nb_Destinations                        : Node_Id;
1822 1
      Ports_Destinations                     : Node_Id;
1823 1
      Ports_Kind                             : Node_Id;
1824
      Kernel_Error_Handling                  : Boolean            := False;
1825
      Partition_Error_Handling               : Boolean            := False;
1826
      Partition_Error_Callback               : Boolean            := False;
1827
      Nports                                 : Unsigned_Long_Long := 0;
1828 1
      Kernel_Error_Switch_Alternatives       : List_Id;
1829 1
      Partition_Error_Switch_Alternatives    : List_Id;
1830 1
      Partitions_Error_Callback_Alternatives : List_Id;
1831
      Partition_Id                           : Unsigned_Long_Long := 0;
1832 1
      Kernel_Unit                            : Node_Id;
1833

1834
      procedure Visit_Architecture_Instance (E : Node_Id);
1835
      procedure Visit_Component_Instance (E : Node_Id);
1836
      procedure Visit_System_Instance (E : Node_Id);
1837
      procedure Visit_Process_Instance
1838
        (E                       : Node_Id;
1839
         Real_Process            : Boolean := True;
1840
         Corresponding_Component : Node_Id := No_Node);
1841
      procedure Visit_Processor_Instance (E : Node_Id);
1842
      procedure Visit_Virtual_Processor_Instance (E : Node_Id);
1843
      procedure Visit_Thread_Instance (E : Node_Id);
1844
      procedure Visit_Device_Instance (E : Node_Id);
1845

1846
      -----------
1847
      -- Visit --
1848
      -----------
1849

1850 1
      procedure Visit (E : Node_Id) is
1851
      begin
1852 1
         case Kind (E) is
1853 1
            when K_Architecture_Instance =>
1854 1
               Visit_Architecture_Instance (E);
1855

1856 1
            when K_Component_Instance =>
1857 1
               Visit_Component_Instance (E);
1858

1859 0
            when others =>
1860 0
               null;
1861 1
         end case;
1862 1
      end Visit;
1863

1864
      ---------------------------------
1865
      -- Visit_Architecture_Instance --
1866
      ---------------------------------
1867

1868 1
      procedure Visit_Architecture_Instance (E : Node_Id) is
1869
      begin
1870 1
         Visit (Root_System (E));
1871 1
      end Visit_Architecture_Instance;
1872

1873
      ------------------------------
1874
      -- Visit_Component_Instance --
1875
      ------------------------------
1876

1877 1
      procedure Visit_Component_Instance (E : Node_Id) is
1878
         Category : constant Component_Category :=
1879 1
           AIE.Get_Category_Of_Component (E);
1880
      begin
1881 1
         case Category is
1882 1
            when CC_System =>
1883 1
               Visit_System_Instance (E);
1884

1885 1
            when CC_Process =>
1886 1
               Visit_Process_Instance (E);
1887

1888 1
            when CC_Processor =>
1889 1
               Visit_Processor_Instance (E);
1890

1891 1
            when CC_Virtual_Processor =>
1892 1
               Visit_Virtual_Processor_Instance (E);
1893

1894 1
            when CC_Thread =>
1895 1
               Visit_Thread_Instance (E);
1896

1897 0
            when CC_Device =>
1898 0
               Visit_Device_Instance (E);
1899

1900 0
            when others =>
1901 0
               null;
1902 1
         end case;
1903 1
      end Visit_Component_Instance;
1904

1905
      ---------------------------
1906
      -- Visit_System_Instance --
1907
      ---------------------------
1908

1909 1
      procedure Visit_System_Instance (E : Node_Id) is
1910 1
         S : Node_Id;
1911
      begin
1912 1
         if not AINU.Is_Empty (Subcomponents (E)) then
1913 1
            S := First_Node (Subcomponents (E));
1914 1
            while Present (S) loop
1915
               --  Visit the component instance corresponding to the
1916
               --  subcomponent S.
1917 1
               if AINU.Is_Processor (Corresponding_Instance (S)) then
1918 1
                  Visit (Corresponding_Instance (S));
1919
               end if;
1920

1921 1
               S := Next_Node (S);
1922 1
            end loop;
1923
         end if;
1924 1
      end Visit_System_Instance;
1925

1926
      ----------------------------
1927
      -- Visit_Process_Instance --
1928
      ----------------------------
1929

1930 1
      procedure Visit_Process_Instance
1931
        (E                       : Node_Id;
1932
         Real_Process            : Boolean := True;
1933
         Corresponding_Component : Node_Id := No_Node)
1934
      is
1935 1
         S                       : Node_Id;
1936 1
         N                       : Node_Id;
1937 1
         F                       : Node_Id;
1938 1
         U                       : Node_Id;
1939 1
         P                       : Node_Id;
1940 1
         Nb_Ports_Partition      : Unsigned_Long_Long;
1941 1
         Nb_Ports_Destinations   : Unsigned_Long_Long;
1942 1
         Q                       : Node_Id;
1943 1
         T                       : Node_Id;
1944 1
         O                       : Node_Id;
1945 1
         Communicating_Component : Node_Id;
1946
      begin
1947

1948 1
         if Real_Process then
1949
            U :=
1950 1
              CTN.Distributed_Application_Unit
1951 1
                (CTN.Naming_Node (Backend_Node (Identifier (E))));
1952 1
            P := CTN.Entity (U);
1953

1954 1
            CTU.Push_Entity (P);
1955 1
            CTU.Push_Entity (U);
1956 1
            Communicating_Component := E;
1957
         else
1958
            U :=
1959 0
              CTN.Distributed_Application_Unit
1960 0
                (CTN.Naming_Node
1961 0
                   (Backend_Node (Identifier (Corresponding_Component))));
1962 0
            P := CTN.Entity (U);
1963

1964 0
            Communicating_Component := Corresponding_Component;
1965
         end if;
1966

1967 1
         CTU.Set_Deployment_Source;
1968

1969 1
         T := CTU.Make_Array_Values;
1970

1971 1
         Process_Buffers := CTU.Make_Array_Values;
1972

1973 1
         Process_Blackboards := CTU.Make_Array_Values;
1974

1975 1
         Partition_ARINC653_Semaphores_Names := CTU.Make_Array_Values;
1976 1
         Partition_ARINC653_Events_Names     := CTU.Make_Array_Values;
1977

1978 1
         Partition_ARINC653_Nb_Semaphores := 0;
1979 1
         Partition_ARINC653_Nb_Events     := 0;
1980

1981 1
         Nb_Ports_Partition := 0;
1982

1983
         --  Handle threads (most of subcomponents).
1984

1985 1
         if not AINU.Is_Empty (Subcomponents (E)) then
1986 1
            S := First_Node (Subcomponents (E));
1987

1988 1
            while Present (S) loop
1989 1
               Visit (Corresponding_Instance (S));
1990

1991 1
               S := Next_Node (S);
1992 1
            end loop;
1993
         end if;
1994

1995
         --  Handle shared data
1996

1997 1
         if not AINU.Is_Empty (Subcomponents (E)) then
1998 1
            S := First_Node (Subcomponents (E));
1999

2000 1
            while Present (S) loop
2001
               --  If we have a protected data, we create semaphore variables.
2002 1
               if AINU.Is_Data (Corresponding_Instance (S))
2003 0
                 and then Is_Protected_Data (Corresponding_Instance (S))
2004 0
                 and then POK_Flavor = ARINC653
2005
               then
2006

2007
                  --  If we use the ARINC653 flavor, we must configure
2008
                  --  the ARINC653 layer to handle different semaphores
2009
                  --  names.
2010

2011 0
                  Append_Node_To_List
2012 0
                    (CTU.Make_Literal
2013 0
                       (CV.New_Pointed_Char_Value
2014 0
                          (Map_Associated_Locking_Entity_Name (S))),
2015 0
                     CTN.Values (Partition_ARINC653_Semaphores_Names));
2016

2017 0
                  Partition_ARINC653_Nb_Semaphores :=
2018 0
                    Partition_ARINC653_Nb_Semaphores + 1;
2019

2020
               end if;
2021 1
               S := Next_Node (S);
2022 1
            end loop;
2023
         end if;
2024

2025
         --  Add the table pok_buffers_names[POK_CONFIG_NB_BUFFERS] = {...}
2026
         --  This variable contains the names of the buffers.
2027

2028 1
         if not CTU.Is_Empty (CTN.Values (Process_Buffers)) then
2029
            N :=
2030 1
              CTU.Make_Expression
2031
                (Left_Expr =>
2032 1
                   CTU.Make_Variable_Declaration
2033
                     (Defining_Identifier =>
2034 1
                        CTU.Make_Array_Declaration
2035 1
                          (Defining_Identifier => RE (RE_Pok_Buffers_Names),
2036 1
                           Array_Size => RE (RE_Pok_Config_Nb_Buffers)),
2037 1
                      Used_Type => CTU.Make_Pointer_Type (RE (RE_Char))),
2038
                 Operator   => CTU.Op_Equal,
2039
                 Right_Expr => Process_Buffers);
2040 1
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2041
         end if;
2042

2043 1
         if Partition_ARINC653_Nb_Semaphores > 0 then
2044
            N :=
2045 0
              CTU.Make_Expression
2046
                (Left_Expr =>
2047 0
                   CTU.Make_Variable_Declaration
2048
                     (Defining_Identifier =>
2049 0
                        CTU.Make_Array_Declaration
2050
                          (Defining_Identifier =>
2051 0
                             RE (RE_Pok_ARINC653_Semaphores_Names),
2052
                           Array_Size =>
2053 0
                             RE (RE_Pok_Config_ARINC653_Nb_Semaphores)),
2054 0
                      Used_Type => CTU.Make_Pointer_Type (RE (RE_Char))),
2055
                 Operator   => CTU.Op_Equal,
2056
                 Right_Expr => Partition_ARINC653_Semaphores_Names);
2057 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2058

2059
            N :=
2060 0
              CTU.Make_Define_Statement
2061
                (Defining_Identifier =>
2062 0
                   RE (RE_Pok_Config_ARINC653_Nb_Semaphores),
2063
                 Value =>
2064 0
                   CTU.Make_Literal
2065 0
                     (CV.New_Int_Value
2066
                        (Partition_ARINC653_Nb_Semaphores,
2067
                         1,
2068
                         10)));
2069 0
            Set_Deployment_Header;
2070 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2071 0
            Set_Deployment_Source;
2072
         end if;
2073

2074 1
         if Partition_ARINC653_Nb_Events > 0 then
2075
            N :=
2076 0
              CTU.Make_Expression
2077
                (Left_Expr =>
2078 0
                   CTU.Make_Variable_Declaration
2079
                     (Defining_Identifier =>
2080 0
                        CTU.Make_Array_Declaration
2081
                          (Defining_Identifier =>
2082 0
                             RE (RE_Pok_ARINC653_Events_Names),
2083
                           Array_Size =>
2084 0
                             RE (RE_Pok_Config_ARINC653_Nb_Events)),
2085 0
                      Used_Type => CTU.Make_Pointer_Type (RE (RE_Char))),
2086
                 Operator   => CTU.Op_Equal,
2087
                 Right_Expr => Partition_ARINC653_Events_Names);
2088 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2089

2090
            N :=
2091 0
              CTU.Make_Define_Statement
2092 0
                (Defining_Identifier => RE (RE_Pok_Config_ARINC653_Nb_Events),
2093
                 Value               =>
2094 0
                   CTU.Make_Literal
2095 0
                     (CV.New_Int_Value (Partition_ARINC653_Nb_Events, 1, 10)));
2096 0
            Set_Deployment_Header;
2097 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2098 0
            Set_Deployment_Source;
2099
         end if;
2100

2101
         --  If there is at least one blackboard for intra-partition
2102
         --  communication in this partition, we declare its name
2103
         --  in the pok_blackboards_names variable.
2104

2105 1
         if not CTU.Is_Empty (CTN.Values (Process_Blackboards)) then
2106
            N :=
2107 1
              CTU.Make_Expression
2108
                (Left_Expr =>
2109 1
                   CTU.Make_Variable_Declaration
2110
                     (Defining_Identifier =>
2111 1
                        CTU.Make_Array_Declaration
2112
                          (Defining_Identifier =>
2113 1
                             RE (RE_Pok_Blackboards_Names),
2114 1
                           Array_Size => RE (RE_Pok_Config_Nb_Blackboards)),
2115 1
                      Used_Type => CTU.Make_Pointer_Type (RE (RE_Char))),
2116
                 Operator   => CTU.Op_Equal,
2117
                 Right_Expr => Process_Blackboards);
2118 1
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2119
         end if;
2120

2121 1
         if not AINU.Is_Empty (Features (Communicating_Component)) then
2122 1
            F := First_Node (Features (Communicating_Component));
2123

2124 1
            while Present (F) loop
2125 1
               if Kind (F) = K_Port_Spec_Instance
2126 1
                 and then Get_Connection_Pattern (F) = Inter_Process
2127
               then
2128

2129
                  --  Add the port to the list of ports available
2130
                  --  inside the partition
2131

2132 1
                  CTU.Append_Node_To_List
2133 1
                    (CTU.Make_Defining_Identifier (Map_Port_Name (F)),
2134 1
                     CTN.Values (T));
2135

2136 1
                  CTU.Append_Node_To_List
2137 1
                    (CTU.Make_Defining_Identifier (Map_Port_Name (F, True)),
2138 1
                     CTN.Values (Array_Local_Ports_To_Global_Ports));
2139

2140
                  --  Add the name of the port in the variable
2141
                  --  pok_ports_names
2142

2143
                  N :=
2144 1
                    CTU.Make_Literal
2145 1
                      (CV.New_Pointed_Char_Value (Map_Port_Name (F)));
2146 1
                  CTU.Append_Node_To_List (N, CTN.Values (Ports_Names));
2147

2148
                  --  Add the identifier of the port
2149 1
                  N := CTU.Make_Defining_Identifier (Map_Port_Name (F));
2150 1
                  CTU.Append_Node_To_List (N, CTN.Values (Ports_Identifiers));
2151

2152
                  --  Add the kind of the port
2153

2154 1
                  if Is_Virtual (Get_Port_By_Name (F, Current_Device)) then
2155 0
                     CTU.Append_Node_To_List
2156 0
                       (RE (RE_Pok_Port_Kind_Virtual),
2157 0
                        CTN.Values (Ports_Kind));
2158 1
                  elsif AIN.Is_Data (F) and then not AIN.Is_Event (F) then
2159 1
                     CTU.Append_Node_To_List
2160 1
                       (RE (RE_Pok_Port_Kind_Sampling),
2161 1
                        CTN.Values (Ports_Kind));
2162 1
                  elsif AIN.Is_Event (F) and then AIN.Is_Data (F) then
2163 1
                     CTU.Append_Node_To_List
2164 1
                       (RE (RE_Pok_Port_Kind_Queueing),
2165 1
                        CTN.Values (Ports_Kind));
2166
                  end if;
2167

2168
                  --  If you have an out port, we add its destinations
2169
                  --  in the deployment.c file
2170 1
                  Nb_Ports_Destinations := 0;
2171

2172 1
                  if AIN.Is_Out (F) then
2173 1
                     Q := CTU.Make_Array_Values;
2174 1
                     O := First_Node (Destinations (F));
2175 1
                     while Present (O) loop
2176 1
                        CTU.Append_Node_To_List
2177 1
                          (CTU.Make_Defining_Identifier
2178 1
                             (Map_Port_Name (Item (O), True)),
2179 1
                           CTN.Values (Q));
2180 1
                        Nb_Ports_Destinations := Nb_Ports_Destinations + 1;
2181 1
                        O                     := Next_Node (O);
2182 1
                     end loop;
2183 1
                     CTU.Append_Node_To_List
2184 1
                       (CTU.Make_Defining_Identifier
2185 1
                          (Map_Port_Deployment_Destinations (F)),
2186 1
                        CTN.Values (Ports_Destinations));
2187

2188
                     --  Add an array which contain the destinations
2189
                     --  of the port if needed.
2190

2191
                     N :=
2192 1
                       CTU.Make_Variable_Declaration
2193
                         (Defining_Identifier =>
2194 1
                            CTU.Make_Array_Declaration
2195
                              (Defining_Identifier =>
2196 1
                                 CTU.Make_Defining_Identifier
2197 1
                                   (Map_Port_Deployment_Destinations (F)),
2198
                               Array_Size =>
2199 1
                                 CTU.Make_Literal
2200 1
                                   (CV.New_Int_Value
2201
                                      (Nb_Ports_Destinations,
2202
                                       1,
2203
                                       10))),
2204 1
                          Used_Type => RE (RE_Uint8_T));
2205
                     N :=
2206 1
                       CTU.Make_Expression
2207
                         (Left_Expr  => N,
2208
                          Operator   => CTU.Op_Equal,
2209
                          Right_Expr => Q);
2210

2211
                     --  Add new declaration inside the deployment.c
2212
                     --  inside the kernel directory.
2213

2214 1
                     CTU.Pop_Entity;
2215 1
                     CTU.Pop_Entity;
2216

2217 1
                     Push_Entity (Kernel_Unit);
2218 1
                     Set_Deployment_Source;
2219 1
                     CTU.Append_Node_To_List
2220
                       (N,
2221 1
                        CTN.Declarations (CTU.Current_File));
2222 1
                     Pop_Entity;
2223

2224 1
                     CTU.Push_Entity (P);
2225 1
                     CTU.Push_Entity (U);
2226

2227
                  else
2228 1
                     CTU.Append_Node_To_List
2229 1
                       (RE (RE_Null),
2230 1
                        CTN.Values (Ports_Destinations));
2231
                  end if;
2232

2233
                  --  Add the amount of destinations
2234
                  --  FIXME we fix the destination to one at this moment
2235

2236
                  N :=
2237 1
                    CTU.Make_Literal
2238 1
                      (CV.New_Int_Value (Nb_Ports_Destinations, 1, 10));
2239 1
                  CTU.Append_Node_To_List (N, CTN.Values (Nb_Destinations));
2240

2241 1
                  Nports             := Nports + 1;
2242 1
                  Nb_Ports_Partition := Nb_Ports_Partition + 1;
2243
               end if;
2244 1
               F := Next_Node (F);
2245 1
            end loop;
2246
         end if;
2247

2248 1
         if Has_Ports (Communicating_Component) or else Has_Ports (E) then
2249
            N :=
2250 1
              CTU.Make_Variable_Declaration
2251
                (Defining_Identifier =>
2252 1
                   CTU.Make_Array_Declaration
2253
                     (Defining_Identifier =>
2254 1
                        CTU.Make_Defining_Identifier
2255 1
                          (Map_Port_Deployment_Partition (E)),
2256
                      Array_Size =>
2257 1
                        CTU.Make_Literal
2258 1
                          (CV.New_Int_Value (Nb_Ports_Partition, 1, 10))),
2259 1
                 Used_Type => RE (RE_Uint8_T));
2260

2261
            N :=
2262 1
              CTU.Make_Expression
2263
                (Left_Expr  => N,
2264
                 Operator   => CTU.Op_Equal,
2265
                 Right_Expr => T);
2266

2267
            --  Add new declaration inside the deployment.c
2268
            --  inside the kernel directory.
2269

2270 1
            CTU.Pop_Entity;
2271 1
            CTU.Pop_Entity;
2272

2273 1
            CTU.Push_Entity (Kernel_Unit);
2274 1
            Set_Deployment_Source;
2275 1
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2276 1
            CTU.Pop_Entity;
2277

2278 1
            CTU.Push_Entity (P);
2279 1
            CTU.Push_Entity (U);
2280

2281 1
            CTU.Append_Node_To_List
2282 1
              (CTU.Make_Defining_Identifier
2283 1
                 (Map_Port_Deployment_Partition (E)),
2284 1
               CTN.Values (Ports_By_Partition));
2285
         else
2286 0
            CTU.Append_Node_To_List
2287 0
              (RE (RE_Null),
2288 0
               CTN.Values (Ports_By_Partition));
2289
         end if;
2290

2291
         --  Now, we know precisely how many ports are available for each
2292
         --  partition. So we can fill the pok_ports_nb_ports_by_partition
2293
         --  array.
2294

2295 1
         N := CTU.Make_Literal (CV.New_Int_Value (Nb_Ports_Partition, 1, 10));
2296 1
         CTU.Append_Node_To_List (N, CTN.Values (Nb_Ports_By_Partition));
2297

2298 1
         if Real_Process then
2299 1
            CTU.Pop_Entity;
2300 1
            CTU.Pop_Entity;
2301
         end if;
2302 1
      end Visit_Process_Instance;
2303

2304
      ---------------------------
2305
      -- Visit_Thread_Instance --
2306
      ---------------------------
2307

2308 1
      procedure Visit_Thread_Instance (E : Node_Id) is
2309 1
         Subcomponent : Node_Id;
2310 1
         F            : Node_Id;
2311 1
         N            : Node_Id;
2312 1
         Type_Used    : Node_Id;
2313
      begin
2314 1
         if not AINU.Is_Empty (Subcomponents (E)) then
2315 0
            Subcomponent := First_Node (Subcomponents (E));
2316 0
            while Present (Subcomponent) loop
2317
               --  Visit the component instance corresponding to the
2318
               --  subcomponent S.
2319

2320 0
               Visit (Corresponding_Instance (Subcomponent));
2321 0
               Subcomponent := Next_Node (Subcomponent);
2322 0
            end loop;
2323
         end if;
2324

2325 1
         if not AINU.Is_Empty (Features (E)) then
2326 1
            F := First_Node (Features (E));
2327

2328
            --  For each port in the thread that represent an intra partition
2329
            --  communication, we add the port name to the array
2330
            --  pok_buffers_names or pok_blackboards_names.
2331
            --  In addition, we create a variable that will contain the
2332
            --  identifier of the buffer/blackboard.
2333

2334 1
            while Present (F) loop
2335 1
               if Kind (F) = K_Port_Spec_Instance
2336 1
                 and then Is_In (F)
2337 1
                 and then Get_Port_By_Name (F, Current_Device) = No_Node
2338 1
                 and then Get_Connection_Pattern (F) = Intra_Process
2339
               then
2340 1
                  if AIN.Is_Data (F) and then not AIN.Is_Event (F) then
2341 1
                     if Use_ARINC653_API then
2342 1
                        Type_Used := RE (RE_Blackboard_Id_Type);
2343
                     else
2344 0
                        Type_Used := RE (RE_Uint8_T);
2345
                     end if;
2346

2347
                     N :=
2348 1
                       CTU.Make_Literal
2349 1
                         (CV.New_Pointed_Char_Value (Map_Port_Name (F)));
2350 1
                     CTU.Append_Node_To_List
2351
                       (N,
2352 1
                        CTN.Values (Process_Blackboards));
2353

2354
                     N :=
2355 1
                       CTU.Make_Variable_Declaration
2356
                         (Defining_Identifier =>
2357 1
                            CTU.Make_Defining_Identifier (Map_Port_Var (F)),
2358
                          Used_Type => Type_Used);
2359

2360 1
                     CTU.Append_Node_To_List
2361
                       (N,
2362 1
                        CTN.Declarations (CTU.Current_File));
2363 1
                  elsif AIN.Is_Data (F) and then AIN.Is_Event (F) then
2364 1
                     if Use_ARINC653_API then
2365 1
                        Type_Used := RE (RE_Buffer_Id_Type);
2366
                     else
2367 0
                        Type_Used := RE (RE_Uint8_T);
2368
                     end if;
2369

2370
                     N :=
2371 1
                       CTU.Make_Literal
2372 1
                         (CV.New_Pointed_Char_Value (Map_Port_Name (F)));
2373 1
                     CTU.Append_Node_To_List (N, CTN.Values (Process_Buffers));
2374

2375
                     N :=
2376 1
                       CTU.Make_Variable_Declaration
2377
                         (Defining_Identifier =>
2378 1
                            CTU.Make_Defining_Identifier (Map_Port_Var (F)),
2379
                          Used_Type => Type_Used);
2380

2381 1
                     CTU.Append_Node_To_List
2382
                       (N,
2383 1
                        CTN.Declarations (CTU.Current_File));
2384 0
                  elsif AIN.Is_Event (F) and then not AIN.Is_Data (F) then
2385 0
                     if Use_ARINC653_API then
2386 0
                        Type_Used                    := RE (RE_Event_Id_Type);
2387 0
                        Partition_ARINC653_Nb_Events :=
2388 0
                          Partition_ARINC653_Nb_Events + 1;
2389

2390 0
                        Append_Node_To_List
2391 0
                          (CTU.Make_Literal
2392 0
                             (CV.New_Pointed_Char_Value (Map_Port_Name (F))),
2393 0
                           CTN.Values (Partition_ARINC653_Events_Names));
2394
                     else
2395 0
                        Type_Used := RE (RE_Pok_Event_Id_T);
2396
                     end if;
2397

2398
                     N :=
2399 0
                       CTU.Make_Variable_Declaration
2400
                         (Defining_Identifier =>
2401 0
                            CTU.Make_Defining_Identifier (Map_Port_Var (F)),
2402
                          Used_Type => Type_Used);
2403

2404 0
                     CTU.Append_Node_To_List
2405
                       (N,
2406 0
                        CTN.Declarations (CTU.Current_File));
2407
                  end if;
2408
               end if;
2409 1
               F := Next_Node (F);
2410 1
            end loop;
2411
         end if;
2412 1
      end Visit_Thread_Instance;
2413

2414
      ------------------------------
2415
      -- Visit_Processor_Instance --
2416
      ------------------------------
2417

2418 1
      procedure Visit_Processor_Instance (E : Node_Id) is
2419 1
         S : Node_Id;
2420

2421 1
         POK_Errors : constant POK_Handled_Errors :=
2422 1
           Get_POK_Recovery_Errors (E);
2423

2424 1
         POK_Actions : constant POK_Handled_Actions :=
2425 1
           Get_POK_Recovery_Actions (E);
2426

2427 1
         POK_Error  : Supported_POK_Error;
2428 1
         POK_Action : Supported_POK_Action;
2429

2430 1
         ARINC653_Handled_Errors : constant ARINC653_Errors :=
2431 1
           Get_ARINC653_HM_Errors (E);
2432

2433 1
         ARINC653_Handled_Actions : constant ARINC653_Actions :=
2434 1
           Get_ARINC653_HM_Actions (E);
2435

2436 1
         ARINC653_Error  : Supported_ARINC653_Error;
2437 1
         ARINC653_Action : Supported_ARINC653_Action;
2438

2439 1
         Connected_Processor : Node_Id;
2440

2441 1
         U : Node_Id;
2442 1
         P : Node_Id;
2443 1
         N : Node_Id;
2444
      begin
2445 1
         U := CTN.Naming_Node (Backend_Node (Identifier (E)));
2446 1
         P := CTN.Entity (U);
2447

2448 1
         Used_Buses := AINU.New_List (AIN.K_List_Id, No_Location);
2449

2450 1
         Kernel_Unit := U;
2451

2452 1
         Array_Local_Ports_To_Global_Ports := CTU.Make_Array_Values;
2453

2454 1
         Array_Buses_Partitions := CTU.Make_Array_Values;
2455

2456 1
         Partition_Error_Callback := False;
2457

2458 1
         Partitions_Error_Callback_Alternatives :=
2459 1
           New_List (CTN.K_Alternatives_List);
2460

2461 1
         Push_Entity (C_Root);
2462 1
         Push_Entity (P);
2463 1
         Push_Entity (U);
2464

2465
         --  begin imported code
2466

2467 1
         CTU.Set_Deployment_Source;
2468

2469 1
         Kernel_Error_Switch_Alternatives :=
2470 1
           New_List (CTN.K_Alternatives_List);
2471

2472 1
         Partition_Error_Switch_Alternatives :=
2473 1
           New_List (CTN.K_Alternatives_List);
2474

2475 1
         Nb_Ports_By_Partition := CTU.Make_Array_Values;
2476 1
         Ports_By_Partition    := CTU.Make_Array_Values;
2477 1
         Ports_Names           := CTU.Make_Array_Values;
2478 1
         Ports_Identifiers     := CTU.Make_Array_Values;
2479 1
         Nb_Destinations       := CTU.Make_Array_Values;
2480 1
         Ports_Destinations    := CTU.Make_Array_Values;
2481 1
         Ports_Kind            := CTU.Make_Array_Values;
2482

2483
         --  For each system, we set this variable to 0. Then,
2484
         --  subcomponents will modify it and tell us if there is
2485
         --  some ports for inter-partition communication.
2486

2487 1
         Nports := 0;
2488

2489 1
         Set_Deployment_Source;
2490

2491 1
         Runtime.Kernel_Mode;
2492

2493 1
         Set_Deployment_Header;
2494

2495
         N :=
2496 1
           CTU.Make_Define_Statement
2497 1
             (Defining_Identifier => RE (RE_Pok_Config_Nb_Nodes),
2498
              Value               =>
2499 1
                CTU.Make_Literal (CV.New_Int_Value (Node_Identifier, 1, 10)));
2500

2501 1
         CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2502

2503 1
         Set_Deployment_Source;
2504

2505
         --  Here, we declare the number of nodes in deployment.h file
2506
         --  We do that here because doing it in the Header part
2507
         --  would imply another parsing and would consume resources.
2508

2509 1
         if not AINU.Is_Empty (Subcomponents (E)) then
2510 1
            S := First_Node (Subcomponents (E));
2511 1
            while Present (S) loop
2512
               --  Visit the component instance corresponding to the
2513
               --  subcomponent S.
2514

2515 1
               Visit (Corresponding_Instance (S));
2516 1
               S := Next_Node (S);
2517 1
            end loop;
2518
         end if;
2519

2520
         --
2521
         --  If we are using DEOS, we do not need
2522
         --  to write code to configure the kernel, this
2523
         --  is done through the XML file of the deos_conf
2524
         --  backend.
2525
         --
2526

2527 1
         if POK_Flavor = DEOS or else POK_Flavor = VXWORKS then
2528

2529 1
            Pop_Entity;
2530 1
            Pop_Entity;
2531 1
            Pop_Entity;
2532 1
            return;
2533
         end if;
2534

2535 0
         if Nports > 0 then
2536 0
            Add_Include (RH (RH_Types));
2537 0
            Add_Include (RH (RH_Port));
2538

2539 0
            Array_Global_Ports_To_Local_Ports := CTU.Make_Array_Values;
2540 0
            Array_Global_Ports_Bus            := CTU.Make_Array_Values;
2541

2542 0
            if not AINU.Is_Empty (All_Ports) then
2543 0
               S := AIN.First_Node (All_Ports);
2544 0
               while Present (S) loop
2545
                  Connected_Processor :=
2546 0
                    Parent_Component
2547 0
                      (Parent_Subcomponent
2548 0
                         (Get_Bound_Processor (Parent_Component (Item (S)))));
2549 0
                  if Connected_Processor = E then
2550 0
                     Append_Node_To_List
2551 0
                       (Make_Defining_Identifier (Map_Port_Name (Item (S))),
2552 0
                        CTN.Values (Array_Global_Ports_To_Local_Ports));
2553

2554 0
                     Set_Str_To_Name_Buffer ("invalid_bus");
2555 0
                     Append_Node_To_List
2556 0
                       (Make_Defining_Identifier (Name_Find),
2557 0
                        CTN.Values (Array_Global_Ports_Bus));
2558
                  else
2559 0
                     Set_Str_To_Name_Buffer ("invalid_local_port");
2560 0
                     Append_Node_To_List
2561 0
                       (Make_Defining_Identifier (Name_Find),
2562 0
                        CTN.Values (Array_Global_Ports_To_Local_Ports));
2563

2564 0
                     Append_Node_To_List
2565 0
                       (Make_Defining_Identifier
2566 0
                          (Map_Bus_Name (Get_Bus (Item (S)))),
2567 0
                        CTN.Values (Array_Global_Ports_Bus));
2568
                  end if;
2569 0
                  S := AIN.Next_Node (S);
2570 0
               end loop;
2571
            end if;
2572

2573
            N :=
2574 0
              CTU.Make_Expression
2575
                (Left_Expr =>
2576 0
                   CTU.Make_Variable_Declaration
2577
                     (Defining_Identifier =>
2578 0
                        CTU.Make_Array_Declaration
2579
                          (Defining_Identifier =>
2580 0
                             RE (RE_Pok_Global_Ports_To_Local_Ports),
2581 0
                           Array_Size => RE (RE_Pok_Config_Nb_Global_Ports)),
2582 0
                      Used_Type => RE (RE_Uint8_T)),
2583
                 Operator   => CTU.Op_Equal,
2584
                 Right_Expr => Array_Global_Ports_To_Local_Ports);
2585 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2586

2587
            N :=
2588 0
              CTU.Make_Expression
2589
                (Left_Expr =>
2590 0
                   CTU.Make_Variable_Declaration
2591
                     (Defining_Identifier =>
2592 0
                        CTU.Make_Array_Declaration
2593
                          (Defining_Identifier =>
2594 0
                             RE (RE_Pok_Global_Ports_To_Bus),
2595 0
                           Array_Size => RE (RE_Pok_Config_Nb_Global_Ports)),
2596 0
                      Used_Type => RE (RE_Pok_Bus_Identifier_T)),
2597
                 Operator   => CTU.Op_Equal,
2598
                 Right_Expr => Array_Global_Ports_Bus);
2599 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2600

2601
            N :=
2602 0
              CTU.Make_Expression
2603
                (Left_Expr =>
2604 0
                   CTU.Make_Variable_Declaration
2605
                     (Defining_Identifier =>
2606 0
                        CTU.Make_Array_Declaration
2607 0
                          (Defining_Identifier => RE (RE_Pok_Buses_Partitions),
2608 0
                           Array_Size          => RE (RE_Pok_Config_Nb_Buses)),
2609 0
                      Used_Type => RE (RE_Uint8_T)),
2610
                 Operator   => CTU.Op_Equal,
2611
                 Right_Expr => Array_Buses_Partitions);
2612 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2613

2614
            N :=
2615 0
              CTU.Make_Expression
2616
                (Left_Expr =>
2617 0
                   CTU.Make_Variable_Declaration
2618
                     (Defining_Identifier =>
2619 0
                        CTU.Make_Array_Declaration
2620
                          (Defining_Identifier =>
2621 0
                             RE (RE_Pok_Local_Ports_To_Global_Ports),
2622 0
                           Array_Size => RE (RE_Pok_Config_Nb_Ports)),
2623 0
                      Used_Type => RE (RE_Uint8_T)),
2624
                 Operator   => CTU.Op_Equal,
2625
                 Right_Expr => Array_Local_Ports_To_Global_Ports);
2626 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2627

2628
            N :=
2629 0
              CTU.Make_Expression
2630
                (Left_Expr =>
2631 0
                   CTU.Make_Variable_Declaration
2632
                     (Defining_Identifier =>
2633 0
                        CTU.Make_Array_Declaration
2634 0
                          (Defining_Identifier => RE (RE_Pok_Ports_Nodes),
2635 0
                           Array_Size => RE (RE_Pok_Config_Nb_Global_Ports)),
2636 0
                      Used_Type => RE (RE_Uint8_T)),
2637
                 Operator   => CTU.Op_Equal,
2638
                 Right_Expr => Array_Global_Ports_Nodes);
2639 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2640

2641
            N :=
2642 0
              Message_Comment
2643
                ("This array indicates on which node is located each port. " &
2644
                 "For example, it means that the first port is located on " &
2645
                 "the node that is represented in this array with the first " &
2646
                 "value. You can check node identifier values in the " &
2647
                 "deployment.h file");
2648

2649 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2650

2651
            --  Build the variable pok_ports_nb_ports_by_partitions.
2652
            --  It gives the amount of ports available inside a partition.
2653

2654
            N :=
2655 0
              CTU.Make_Expression
2656
                (Left_Expr =>
2657 0
                   CTU.Make_Variable_Declaration
2658
                     (Defining_Identifier =>
2659 0
                        CTU.Make_Array_Declaration
2660
                          (Defining_Identifier =>
2661 0
                             RE (RE_Pok_Ports_Nb_Ports_By_Partition),
2662 0
                           Array_Size => RE (RE_Pok_Config_Nb_Partitions)),
2663 0
                      Used_Type => RE (RE_Uint8_T)),
2664
                 Operator   => CTU.Op_Equal,
2665
                 Right_Expr => Nb_Ports_By_Partition);
2666 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2667

2668
            --  Build the varible pok_ports_by_partitions which point to all
2669
            --  accessible ports inside a partition.
2670

2671
            N :=
2672 0
              CTU.Make_Expression
2673
                (Left_Expr =>
2674 0
                   CTU.Make_Variable_Declaration
2675
                     (Defining_Identifier =>
2676 0
                        CTU.Make_Array_Declaration
2677
                          (Defining_Identifier =>
2678 0
                             RE (RE_Pok_Ports_By_Partition),
2679 0
                           Array_Size => RE (RE_Pok_Config_Nb_Partitions)),
2680 0
                      Used_Type => CTU.Make_Pointer_Type (RE (RE_Uint8_T))),
2681
                 Operator   => CTU.Op_Equal,
2682
                 Right_Expr => Ports_By_Partition);
2683 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2684

2685
            --  Build the variable pok_ports_names
2686

2687
            N :=
2688 0
              CTU.Make_Expression
2689
                (Left_Expr =>
2690 0
                   CTU.Make_Variable_Declaration
2691
                     (Defining_Identifier =>
2692 0
                        CTU.Make_Array_Declaration
2693 0
                          (Defining_Identifier => RE (RE_Pok_Ports_Names),
2694 0
                           Array_Size          => RE (RE_Pok_Config_Nb_Ports)),
2695 0
                      Used_Type => CTU.Make_Pointer_Type (RE (RE_Char))),
2696
                 Operator   => CTU.Op_Equal,
2697
                 Right_Expr => Ports_Names);
2698 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2699

2700
            N :=
2701 0
              Message_Comment
2702
                ("This array contains the identifier of each port " &
2703
                 "involved in inter-partition communication. These names " &
2704
                 "are used in pok_port_sampling_create() and " &
2705
                 "pok_port_ queueing_create");
2706 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2707

2708
            --  Now, build the variable pok_ports_identifiers
2709

2710
            N :=
2711 0
              CTU.Make_Expression
2712
                (Left_Expr =>
2713 0
                   CTU.Make_Variable_Declaration
2714
                     (Defining_Identifier =>
2715 0
                        CTU.Make_Array_Declaration
2716
                          (Defining_Identifier =>
2717 0
                             RE (RE_Pok_Ports_Identifiers),
2718 0
                           Array_Size => RE (RE_Pok_Config_Nb_Ports)),
2719 0
                      Used_Type => RE (RE_Uint8_T)),
2720
                 Operator   => CTU.Op_Equal,
2721
                 Right_Expr => Ports_Identifiers);
2722 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2723

2724
            --  Now, pok_ports_nb_destinations which give us the amount
2725
            --  of destination per port.
2726

2727
            N :=
2728 0
              CTU.Make_Expression
2729
                (Left_Expr =>
2730 0
                   CTU.Make_Variable_Declaration
2731
                     (Defining_Identifier =>
2732 0
                        CTU.Make_Array_Declaration
2733
                          (Defining_Identifier =>
2734 0
                             RE (RE_Pok_Ports_Nb_Destinations),
2735 0
                           Array_Size => RE (RE_Pok_Config_Nb_Ports)),
2736 0
                      Used_Type => RE (RE_Uint8_T)),
2737
                 Operator   => CTU.Op_Equal,
2738
                 Right_Expr => Nb_Destinations);
2739 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2740

2741
            --  Build the pok_ports_destinations which is a pointer to other
2742
            --  variable that contains the ports destination of each port.
2743

2744
            N :=
2745 0
              CTU.Make_Expression
2746
                (Left_Expr =>
2747 0
                   CTU.Make_Variable_Declaration
2748
                     (Defining_Identifier =>
2749 0
                        CTU.Make_Array_Declaration
2750
                          (Defining_Identifier =>
2751 0
                             RE (RE_Pok_Ports_Destinations),
2752 0
                           Array_Size => RE (RE_Pok_Config_Nb_Ports)),
2753 0
                      Used_Type => CTU.Make_Pointer_Type (RE (RE_Uint8_T))),
2754
                 Operator   => CTU.Op_Equal,
2755
                 Right_Expr => Ports_Destinations);
2756 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2757

2758
            --  Build the pok_ports_kind variable that tell the kernel
2759
            --  that is the kind of each port (sampling, queueing, ...)
2760

2761
            N :=
2762 0
              CTU.Make_Expression
2763
                (Left_Expr =>
2764 0
                   CTU.Make_Variable_Declaration
2765
                     (Defining_Identifier =>
2766 0
                        CTU.Make_Array_Declaration
2767 0
                          (Defining_Identifier => RE (RE_Pok_Ports_Kind),
2768 0
                           Array_Size          => RE (RE_Pok_Config_Nb_Ports)),
2769 0
                      Used_Type => RE (RE_Pok_Port_Kind_T)),
2770
                 Operator   => CTU.Op_Equal,
2771
                 Right_Expr => Ports_Kind);
2772 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2773
         end if;
2774

2775
         ----------------------------------------------------------------
2776
         --  From this line, we handle ONLY health monitoring service  --
2777
         ----------------------------------------------------------------
2778

2779 0
         if Partition_Error_Callback then
2780 0
            Set_Deployment_Header;
2781

2782
            N :=
2783 0
              CTU.Make_Define_Statement
2784
                (Defining_Identifier =>
2785 0
                   RE (RE_Pok_Use_Generated_Partition_Error_Callback),
2786 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
2787

2788 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2789

2790 0
            Set_Deployment_Source;
2791

2792
            declare
2793 0
               Spec         : Node_Id;
2794 0
               Statements   : List_Id;
2795 0
               Declarations : List_Id;
2796
            begin
2797 0
               Declarations := New_List (CTN.K_Declaration_List);
2798 0
               Statements   := New_List (CTN.K_Statement_List);
2799

2800 0
               Append_Node_To_List
2801 0
                 (Make_Switch_Statement
2802 0
                    (Make_Defining_Identifier (PN (P_Partition)),
2803
                     Partitions_Error_Callback_Alternatives),
2804
                  Statements);
2805

2806
               Spec :=
2807 0
                 Make_Function_Specification
2808
                   (Defining_Identifier =>
2809 0
                      RE (RE_Pok_Error_Partition_Callback),
2810
                    Parameters =>
2811 0
                      Make_List_Id
2812 0
                        (Make_Parameter_Specification
2813 0
                           (Make_Defining_Identifier (PN (P_Partition)),
2814 0
                            Make_Defining_Identifier (TN (T_Uint32_T)))),
2815 0
                    Return_Type => Make_Defining_Identifier (TN (T_Void)));
2816

2817
               --  Make the function that calls user-defined callback
2818
               --  for each partition.
2819

2820 0
               Append_Node_To_List
2821 0
                 (Make_Function_Implementation
2822
                    (Spec,
2823
                     Declarations,
2824
                     Statements),
2825 0
                  CTN.Declarations (Current_File));
2826

2827
               --  Append this function to deployment.c in the kernel part.
2828
            end;
2829
         end if;
2830

2831
         --  In the previous if statement, we analyse if partitions use
2832
         --  a callback mecanism. If so, we generate a dedicated function
2833
         --  called pok_error_partition_callback() that will execute
2834
         --  the health-moniroting functions defined by the user().
2835
         --  In the AADL model, the HM callback is specified using
2836
         --  The ARINC653::HM_Callback property on AADL processors or
2837
         --  virtual processors.
2838

2839 0
         if Partition_Error_Handling then
2840 0
            Set_Deployment_Header;
2841

2842
            N :=
2843 0
              CTU.Make_Define_Statement
2844
                (Defining_Identifier =>
2845 0
                   RE (RE_Pok_Use_Generated_Partition_Error_Handler),
2846 0
                 Value => CTU.Make_Literal (CV.New_Int_Value (1, 1, 10)));
2847

2848 0
            CTU.Append_Node_To_List (N, CTN.Declarations (CTU.Current_File));
2849

2850 0
            Set_Deployment_Source;
2851
            declare
2852 0
               Spec         : Node_Id;
2853 0
               Statements   : List_Id;
2854 0
               Declarations : List_Id;
2855
            begin
2856 0
               Declarations := New_List (CTN.K_Declaration_List);
2857 0
               Statements   := New_List (CTN.K_Statement_List);
2858

2859 0
               Append_Node_To_List
2860 0
                 (Make_Switch_Statement
2861 0
                    (Make_Defining_Identifier (PN (P_Partition)),
2862
                     Partition_Error_Switch_Alternatives),
2863
                  Statements);
2864

2865
               Spec :=
2866 0
                 Make_Function_Specification
2867 0
                   (Defining_Identifier => RE (RE_Pok_Partition_Error),
2868
                    Parameters          =>
2869 0
                      Make_List_Id
2870 0
                        (Make_Parameter_Specification
2871 0
                           (Make_Defining_Identifier (PN (P_Partition)),
2872 0
                            Make_Defining_Identifier (TN (T_Uint8_T))),
2873 0
                         Make_Parameter_Specification
2874 0
                           (Make_Defining_Identifier (PN (P_Error)),
2875 0
                            Make_Defining_Identifier (TN (T_Uint32_T)))),
2876

2877 0
                    Return_Type => Make_Defining_Identifier (TN (T_Void)));
2878

2879 0
               Append_Node_To_List
2880 0
                 (Make_Function_Implementation
2881
                    (Spec,
2882
                     Declarations,
2883
                     Statements),
2884 0
                  CTN.Declarations (Current_File));
2885
            end;
2886
         end if;
2887

2888
         --  We generate a function with a big switch/case statement. This
2889
         --  switch/case will execute appropriate function to recover
2890
         --  errors for each partitions. Recovery actions are different
2891
         --  for each partitions and for each error.
2892
         --  The Partition_Error_Switch_Alternatives node is filled
2893