| Nico Huber | 5e9b1b5 | 2016-10-08 22:09:33 +0200 | [diff] [blame] | 1 | -- |
| 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 Huber | aab715f | 2016-10-18 00:22:25 +0200 | [diff] [blame] | 6 | -- the Free Software Foundation; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| Nico Huber | 5e9b1b5 | 2016-10-08 22:09:33 +0200 | [diff] [blame] | 8 | -- |
| 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 | |
| 15 | with HW.Debug; |
| 16 | with GNAT.Source_Info; |
| 17 | with System.Storage_Elements; |
| 18 | with System.Address_To_Access_Conversions; |
| 19 | |
| 20 | package body HW.MMIO_Range |
| 21 | with |
| 22 | Refined_State => |
| 23 | (State => Range_A, -- the contents accessed |
| 24 | Base_Address => null) -- the address, so actually Range_A too |
| 25 | is |
| 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 := |
| 36 | Range_Access (Conv_Range.To_Pointer (System'To_Address (Base_Addr))) |
| 37 | with Volatile; |
| 38 | |
| 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 | |
| 77 | end HW.MMIO_Range; |