blob: ae0792b2d55c3c50493a93f933b36938137d6b97 [file] [log] [blame]
Nico Huberf03ef4f2017-03-04 13:57:09 +01001--
2-- Copyright (C) 2017 Nico Huber <nico.h@gmx.de>
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; either version 2 of the License, or
7-- (at your option) any later version.
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
15with Interfaces.C;
16with Interfaces.C.Strings;
17
18with HW.Debug;
19
20use Interfaces.C;
21use Interfaces.C.Strings;
22
23package body HW.File is
24
25 READ : constant := 16#01#;
26 WRITE : constant := 16#02#;
27
28 function c_map
29 (path : chars_ptr;
30 addr : Word64;
31 len : Word32;
32 mode : Word32;
33 copy : int)
34 return int;
35 pragma Import (C, c_map, "hw_file_map");
36
37 procedure Map
38 (Path : in String;
39 Addr : in Word64;
40 Len : in Natural;
41 Readable : in Boolean := False;
42 Writable : in Boolean := False;
43 Map_Copy : in Boolean := False;
44 Success : out Boolean)
45 is
46 use type HW.Word32;
47
48 cpath : chars_ptr := New_String (Path);
49 ret : constant int := c_map
50 (path => cpath,
51 addr => Addr,
52 len => Word32 (Len),
53 mode => (if Readable then READ else 0) or
54 (if Writable then WRITE else 0),
55 copy => (if Map_Copy then 1 else 0));
56 begin
57 pragma Warnings(GNAT, Off, """cpath"" modified*, but* never referenced",
58 Reason => "Free() demands to set it to null_ptr");
59 Free (cpath);
60 pragma Warnings(GNAT, On, """cpath"" modified*, but* never referenced");
61 Success := ret = 0;
62
63 pragma Debug (not Success, Debug.Put ("Mapping failed: "));
64 pragma Debug (not Success, Debug.Put_Int32 (Int32 (ret)));
65 pragma Debug (not Success, Debug.New_Line);
66 end Map;
67
68end HW.File;