hirtos_1.0.0_e7372ec1/sample_apps/hello_partitions/src/app_partitions.adb

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
--
--  Copyright (c) 2022-2023, German Rivera
--
--
--  SPDX-License-Identifier: Apache-2.0
--

with HiRTOS.Separation_Kernel.Partition;
with HiRTOS_Platform_Parameters;
with HiRTOS_Cpu_Arch_Parameters;
with System.Storage_Elements;
with Interfaces;
with HiRTOS.Debug; --???

package body App_Partitions is
   use System.Storage_Elements;
   use type System.Address;

   Hello_Partition1_Image_Address : constant System.Address
      with Import,
           Convention => Asm,
           External_Name => "hello_partition1_image_addr";

   Hello_Partition1_Image_Size_Bytes : constant System.Storage_Elements.Integer_Address
      with Import,
           Convention => Asm,
           External_Name => "hello_partition1_size";

   Hello_Partition1_Load_Address : constant System.Address
      with Import,
           Convention => Asm,
           External_Name => "hello_partition1_load_addr";

   Hello_Partition2_Image_Address : constant System.Address
      with Import,
           Convention => Asm,
           External_Name => "hello_partition2_image_addr";

   Hello_Partition2_Image_Size_Bytes : constant System.Storage_Elements.Integer_Address
      with Import,
           Convention => Asm,
           External_Name => "hello_partition2_size";

   Hello_Partition2_Load_Address : constant System.Address
      with Import,
           Convention => Asm,
           External_Name => "hello_partition2_load_addr";

   Per_Partittion_TCM_Size_Bytes : constant := 512 * 1024;

   -----------------------------------------------------------------------------
   --  Private Subprograms Specifications                                     --
   -----------------------------------------------------------------------------

   procedure Load_Partition (Image_Address : System.Address;
                             Image_Size_Bytes : System.Storage_Elements.Integer_Address;
                             Load_Address : System.Address)
      with Pre => Image_Size_Bytes /= 0 and then
                  Image_Size_Bytes mod HiRTOS_Cpu_Arch_Parameters.Memory_Region_Alignment = 0 and then
                  Load_Address /= Image_Address and then
                  To_Integer (Image_Address) mod HiRTOS_Cpu_Arch_Parameters.Memory_Region_Alignment = 0 and then
                  To_Integer (Load_Address) mod HiRTOS_Cpu_Arch_Parameters.Memory_Region_Alignment = 0 and then
                  Load_Address >= HiRTOS_Platform_Parameters.Stacks_Section_End_Address;

   -----------------------------------------------------------------------------
   --  Public Subprograms                                                     --
   -----------------------------------------------------------------------------

   procedure Initialize is
      use type HiRTOS.Separation_Kernel.Partition_Id_Type;
      Partition1_Id : HiRTOS.Separation_Kernel.Valid_Partition_Id_Type;
      Partition2_Id : HiRTOS.Separation_Kernel.Valid_Partition_Id_Type;
      Global_Mmio_Region_Size_In_Bytes : constant Integer_Address :=
         To_Integer (HiRTOS_Platform_Parameters.Global_Mmio_Region_End_Address) -
         To_Integer (HiRTOS_Platform_Parameters.Global_Mmio_Region_Start_Address);

   begin
      Load_Partition (Hello_Partition1_Image_Address,
                      Hello_Partition1_Image_Size_Bytes,
                      Hello_Partition1_Load_Address);

      pragma Assert (To_Integer (Hello_Partition2_Load_Address) >=
                     To_Integer (Hello_Partition1_Load_Address) + Hello_Partition1_Image_Size_Bytes);

      Load_Partition (Hello_Partition2_Image_Address,
                      Hello_Partition2_Image_Size_Bytes,
                      Hello_Partition2_Load_Address);

      HiRTOS.Separation_Kernel.Partition.Create_Partition (
         Reset_Handler_Address => Hello_Partition1_Load_Address,
         Interrupt_Vector_Table_Address => Hello_Partition1_Load_Address,
         TCM_Base_Address => Hello_Partition1_Load_Address,
         TCM_Size_In_Bytes => Per_Partittion_TCM_Size_Bytes,
         SRAM_Base_Address => System.Null_Address,
         SRAM_Size_In_Bytes => 0,
         --  TODO: Use only a subrange of MMIO space
         MMIO_Base_Address => HiRTOS_Platform_Parameters.Global_Mmio_Region_Start_Address,
         MMIO_Size_In_Bytes => Global_Mmio_Region_Size_In_Bytes,
         Partition_Id => Partition1_Id);

      pragma Assert (Partition1_Id /= HiRTOS.Separation_Kernel.Invalid_Partition_Id);

      HiRTOS.Separation_Kernel.Partition.Create_Partition (
         Reset_Handler_Address => Hello_Partition2_Load_Address,
         Interrupt_Vector_Table_Address => Hello_Partition2_Load_Address,
         TCM_Base_Address => Hello_Partition2_Load_Address,
         TCM_Size_In_Bytes => Per_Partittion_TCM_Size_Bytes,
         SRAM_Base_Address => System.Null_Address,
         SRAM_Size_In_Bytes => 0,
         --  TODO: Use only a subrange of MMIO space
         MMIO_Base_Address => HiRTOS_Platform_Parameters.Global_Mmio_Region_Start_Address,
         MMIO_Size_In_Bytes => Global_Mmio_Region_Size_In_Bytes,
         Partition_Id => Partition2_Id);

         pragma Assert (Partition2_Id /= HiRTOS.Separation_Kernel.Invalid_Partition_Id);
   end Initialize;

   -----------------------------------------------------------------------------
   --  Private Subprograms                                                    --
   -----------------------------------------------------------------------------

   procedure Load_Partition (Image_Address : System.Address;
                             Image_Size_Bytes : System.Storage_Elements.Integer_Address;
                             Load_Address : System.Address) is
      Num_Words : constant Integer_Address :=
         Image_Size_Bytes / (Interfaces.Unsigned_32'Size / System.Storage_Unit);
      type Image_Type is array (1 .. Num_Words) of Interfaces.Unsigned_32;

      Source_Image : Image_Type with Import, Address => Image_Address;
      Dest_Image : Image_Type with Import, Address => Load_Address;
   begin
      Dest_Image := Source_Image;
   end Load_Partition;

end App_Partitions;