blob: bdb6ab1a7efcd927dc49835d9fbef0bf290aa8c6 [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
Nico Huberfc2102f2021-06-10 16:36:31 +020022 SPARK_Mode => Off,
Nico Huber5e9b1b52016-10-08 22:09:33 +020023 Refined_State =>
Nico Huberfc2102f2021-06-10 16:36:31 +020024 (State => Range_A, -- the contents accessed, Range_A points to it
25 Base_Address => null) -- the address, implicitly stored in Range_A
Nico Huber5e9b1b52016-10-08 22:09:33 +020026is
27 pragma Warnings (Off, "implicit dereference",
28 Reason => "This is what this package is about.");
29
30 Debug_Reads : constant Boolean := False;
31 Debug_Writes : constant Boolean := False;
32
Nico Huberfc2102f2021-06-10 16:36:31 +020033 type Range_Access is access all Array_T with Volatile;
Nico Huber5e9b1b52016-10-08 22:09:33 +020034 package Conv_Range is new System.Address_To_Access_Conversions (Array_T);
35
36 Range_A : Range_Access :=
Nico Huber5f82d1a2017-05-08 14:14:21 +020037 Range_Access (Conv_Range.To_Pointer (System'To_Address (Base_Addr)));
Nico Huber5e9b1b52016-10-08 22:09:33 +020038
39 procedure Read (Value : out Element_T; Index : in Index_T)
40 is
41 use type Word32;
42 begin
43 Value := Range_A (Index);
44 pragma Debug (Debug_Reads, Debug.Put
45 (GNAT.Source_Info.Enclosing_Entity & ": "));
46 pragma Debug (Debug_Reads, Debug.Put_Word32 (Word32 (Value)));
47 pragma Debug (Debug_Reads, Debug.Put (" <- "));
48 pragma Debug (Debug_Reads, Debug.Put_Word32
49 (Word32 (System.Storage_Elements.To_Integer
50 (Conv_Range.To_Address (Conv_Range.Object_Pointer (Range_A)))) +
51 Word32 (Index) * (Element_T'Size / 8)));
52 pragma Debug (Debug_Reads, Debug.New_Line);
53 end Read;
54
55 procedure Write (Index : in Index_T; Value : in Element_T)
56 is
57 use type Word32;
58 begin
59 pragma Debug (Debug_Writes, Debug.Put
60 (GNAT.Source_Info.Enclosing_Entity & ": "));
61 pragma Debug (Debug_Writes, Debug.Put_Word32 (Word32 (Value)));
62 pragma Debug (Debug_Writes, Debug.Put (" -> "));
63 pragma Debug (Debug_Writes, Debug.Put_Word32
64 (Word32 (System.Storage_Elements.To_Integer
65 (Conv_Range.To_Address (Conv_Range.Object_Pointer (Range_A)))) +
66 Word32 (Index) * (Element_T'Size / 8)));
67 pragma Debug (Debug_Writes, Debug.New_Line);
68 Range_A (Index) := Value;
69 end Write;
70
71 procedure Set_Base_Address (Base : Word64) is
72 begin
73 Range_A := Range_Access
74 (Conv_Range.To_Pointer (System'To_Address (Base)));
75 end Set_Base_Address;
76
77end HW.MMIO_Range;