startup_gen_22.0.0_85f5a122/src/device.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
------------------------------------------------------------------------------
--                                                                          --
--                               startup-gen                                --
--                                                                          --
--                     Copyright (C) 2019-2021, AdaCore                     --
--                                                                          --
-- This is  free  software;  you can redistribute it and/or modify it under --
-- terms of the  GNU  General Public License as published by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  This software is distributed in the hope  that it will be useful, --
-- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details.  You should have received  a copy of the  GNU  --
-- General Public License distributed with GNAT; see file  COPYING. If not, --
-- see <http://www.gnu.org/licenses/>.                                      --
--                                                                          --
------------------------------------------------------------------------------

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Hash;
with Ada.Strings.Hash;
with Ada.Containers.Vectors;
with Ada.Containers.Hashed_Maps;

with GNATCOLL.Projects;     use GNATCOLL.Projects;

with Templates_Parser;

package Device is

   type Spec is tagged private;

   procedure Get_Memory_List_From_Project
      (Self         : in out Spec;
       Spec_Project : Project_Type);

   procedure Get_Interrupt_Vector_From_Project
      (Self         : in out Spec;
       Spec_Project : Project_Type);

   procedure Get_Boot_Memory_From_Project
      (Self         : in out Spec;
       Spec_Project : Project_Type);

   procedure Get_CPU_From_Project
      (Self         : in out Spec;
       Spec_Project : Project_Type);

   procedure Get_User_Tags_From_Project
      (Self         : in out Spec;
       Spec_Project : Project_Type);

   procedure Display (Self : in out Spec);

   --  Checks that the specs are valid, IE:
   --    Validate Inputs (address, sizes, etc...)
   --    No overlapping memory_regions
   --    Boot memory exists
   --    No overlapping interrupts in the interrupt vector.
   --  return False if there is an error
   function  Valid (Self : in out Spec) return Boolean;

   procedure Dump_Linker_Script (Self : in out Spec; Filename : String);

   procedure Dump_Startup_Code (Self : in out Spec; Filename : String);

   procedure Dump_Translate_Table (Self : in out Spec);

   function To_Translate_Table
     (Self : Spec)
      return Templates_Parser.Translate_Table;

private

   type Float_Type is (Hard, Soft);

   function Convert (Str : String) return Float_Type;

   type CPU_Type is record
      Name                 : Unbounded_String;
      Float_Handling       : Float_Type;
      Number_Of_Interrupts : Natural := 0;
      Arch                 : Unbounded_String;
   end record;

   type Memory_Kind is (RAM, ROM);

   type Memory_Region is record
      Name    : Unbounded_String;
      Address : Unbounded_String;
      Size    : Unbounded_String;
      Kind    : Memory_Kind;
   end record;

   package Memory_Region_Vectors is new Ada.Containers.Vectors
      (Positive, Memory_Region);

   use Ada.Containers;
   function Identity_Integer (Key : Integer) return Hash_Type
      is (Hash_Type (Key));

   function Identity_Unbounded_String (Key : Unbounded_String) return Hash_Type
      is (Ada.Strings.Hash (To_String (Key)));

   package Interrupt_Hashed_Maps is new Ada.Containers.Hashed_Maps
      (Key_Type        => Integer,
       Element_Type    => Unbounded_String,
       Hash            => Identity_Integer,
       Equivalent_Keys => "=");

   type Interrupt_Vector is tagged record
      Interrupts  : Interrupt_Hashed_Maps.Map;
      Last_Index  : Integer := -1;
   end record;

   package User_Tags_Maps is new Ada.Containers.Hashed_Maps
     (Key_Type        => Unbounded_String,
      Element_Type    => Unbounded_String,
      Hash            => Ada.Strings.Unbounded.Hash,
      Equivalent_Keys => "=");

   type Spec is tagged record
      Memory            : Memory_Region_Vectors.Vector;
      Boot_Memory       : Unbounded_String;
      Boot_From_ROM     : Boolean;
      CPU               : CPU_Type;
      Interrupts        : Interrupt_Vector;
      Linker_Template   : Unbounded_String;
      Startup_Template  : Unbounded_String;
      Main_Stack_Size   : Unbounded_String;
      Main_Stack_Memory : Unbounded_String;
      User_Tags         : User_Tags_Maps.Map;
   end record;

   --  Private procedures  --

   procedure Add_Interrupt
      (Self  : in out Interrupt_Vector;
       Index : Integer;
       Name  : Unbounded_String);

   --  Used to check if an interrupt has been defined for a given Index.
   function Is_Index_Used
      (Self  : Interrupt_Vector;
       Index : Integer) return Boolean;

   function Get_Name
      (Self  : Interrupt_Vector;
       Index : Integer) return String;

   --  Checks that the input is coherent IE:
   --    Boot memory is a valid memory region.
   --    All memory regions have an address and a size in a relevant format.
   function Valid_Input (Self : in out Spec) return Boolean;

   --  Checks that there are no overlapping memory regions.
   function Valid_Memory_Regions (Self : in out Spec) return Boolean;

   --  Verify that two memory regions are not overlapping each other.
   function Memory_Regions_Overlap (Memory_1 : Memory_Region;
                                    Memory_2 : Memory_Region)
                                    return Boolean;

   --  Return a string of the following form
   --  <region.name> with Size = <region.size> and Address = <region.address>;
   function Get_Info_String (Region : Memory_Region) return String;

   --  Return the default linker template based on the device information
   function Default_Linker_Template (Self : Spec) return String;

   --  Return the default startup template based on the device information
   function Default_Startup_Template (Self : Spec) return String;

end Device;