blob: 78cc0487d0ec636b889bb11bdbe18f954d5beed0 [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
6-- the Free Software Foundation; version 2 of the License.
7--
8-- This program is distributed in the hope that it will be useful,
9-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11-- GNU General Public License for more details.
12--
13
14with HW.Debug;
15with GNAT.Source_Info;
16with System.Storage_Elements;
17with System.Address_To_Access_Conversions;
18
19package body HW.MMIO_Range
20with
21 Refined_State =>
22 (State => Range_A, -- the contents accessed
23 Base_Address => null) -- the address, so actually Range_A too
24is
25 pragma Warnings (Off, "implicit dereference",
26 Reason => "This is what this package is about.");
27
28 Debug_Reads : constant Boolean := False;
29 Debug_Writes : constant Boolean := False;
30
31 type Range_Access is access all Array_T;
32 package Conv_Range is new System.Address_To_Access_Conversions (Array_T);
33
34 Range_A : Range_Access :=
35 Range_Access (Conv_Range.To_Pointer (System'To_Address (Base_Addr)))
36 with Volatile;
37
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;