blob: 86c8d1b0c628caf94bbf0abf7c898840cee86bb6 [file] [log] [blame]
Nico Huber5e9b1b52016-10-08 22:09:33 +02001--
2-- Copyright (C) 2015-2016 secunet Security Networks AG
3--
4-- This program is free software; you can redistribute it and/or modify
5-- it under the terms of the GNU General Public License as published by
Nico Huberaab715f2016-10-18 00:22:25 +02006-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
Nico Huber5e9b1b52016-10-08 22:09:33 +02008--
9-- This program is distributed in the hope that it will be useful,
10-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-- GNU General Public License for more details.
13--
14
15with HW.Debug;
16with GNAT.Source_Info;
17with System.Storage_Elements;
18with System.Address_To_Access_Conversions;
19
20package body HW.MMIO_Range
21with
22 Refined_State =>
Nico Huber5f82d1a2017-05-08 14:14:21 +020023 (State => null, -- the contents accessed, Range_A points to it
24 Base_Address => Range_A) -- the address, stored in Range_A
Nico Huber5e9b1b52016-10-08 22:09:33 +020025is
26 pragma Warnings (Off, "implicit dereference",
27 Reason => "This is what this package is about.");
28
29 Debug_Reads : constant Boolean := False;
30 Debug_Writes : constant Boolean := False;
31
32 type Range_Access is access all Array_T;
33 package Conv_Range is new System.Address_To_Access_Conversions (Array_T);
34
35 Range_A : Range_Access :=
Nico Huber5f82d1a2017-05-08 14:14:21 +020036 Range_Access (Conv_Range.To_Pointer (System'To_Address (Base_Addr)));
Nico Huber5e9b1b52016-10-08 22:09:33 +020037
38 procedure Read (Value : out Element_T; Index : in Index_T)
39 is
40 use type Word32;
41 begin
42 Value := Range_A (Index);
43 pragma Debug (Debug_Reads, Debug.Put
44 (GNAT.Source_Info.Enclosing_Entity & ": "));
45 pragma Debug (Debug_Reads, Debug.Put_Word32 (Word32 (Value)));
46 pragma Debug (Debug_Reads, Debug.Put (" <- "));
47 pragma Debug (Debug_Reads, Debug.Put_Word32
48 (Word32 (System.Storage_Elements.To_Integer
49 (Conv_Range.To_Address (Conv_Range.Object_Pointer (Range_A)))) +
50 Word32 (Index) * (Element_T'Size / 8)));
51 pragma Debug (Debug_Reads, Debug.New_Line);
52 end Read;
53
54 procedure Write (Index : in Index_T; Value : in Element_T)
55 is
56 use type Word32;
57 begin
58 pragma Debug (Debug_Writes, Debug.Put
59 (GNAT.Source_Info.Enclosing_Entity & ": "));
60 pragma Debug (Debug_Writes, Debug.Put_Word32 (Word32 (Value)));
61 pragma Debug (Debug_Writes, Debug.Put (" -> "));
62 pragma Debug (Debug_Writes, Debug.Put_Word32
63 (Word32 (System.Storage_Elements.To_Integer
64 (Conv_Range.To_Address (Conv_Range.Object_Pointer (Range_A)))) +
65 Word32 (Index) * (Element_T'Size / 8)));
66 pragma Debug (Debug_Writes, Debug.New_Line);
67 Range_A (Index) := Value;
68 end Write;
69
70 procedure Set_Base_Address (Base : Word64) is
71 begin
72 Range_A := Range_Access
73 (Conv_Range.To_Pointer (System'To_Address (Base)));
74 end Set_Base_Address;
75
76end HW.MMIO_Range;