blob: 0ae03f19f4d0ef726727b5049eab9375982055e5 [file] [log] [blame]
Nico Huber5e9b1b52016-10-08 22:09:33 +02001--
2-- Copyright (C) 2015 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 System;
16with System.Machine_Code;
17
18package body HW.Port_IO
19with
20 Refined_State => (State => null),
21 SPARK_Mode => Off
22is
23
24 generic
25 type Word is private;
26 procedure Port_In (Value : out Word; Port : Port_Type);
27
28 procedure Port_In (Value : out Word; Port : Port_Type) is
29 begin
30 System.Machine_Code.Asm
31 ("in %1, %0",
32 Inputs => (Port_Type'Asm_Input ("Nd", Port)),
33 Outputs => (Word'Asm_Output ("=a", Value)),
34 Volatile => True);
35 end Port_In;
36
37 procedure InB_Body is new Port_In (Word => Word8);
38 procedure InB (Value : out Word8; Port : Port_Type) renames InB_Body;
39
40 procedure InW_Body is new Port_In (Word => Word16);
41 procedure InW (Value : out Word16; Port : Port_Type) renames InW_Body;
42
43 procedure InL_Body is new Port_In (Word => Word32);
44 procedure InL (Value : out Word32; Port : Port_Type) renames InL_Body;
45
46 ----------------------------------------------------------------------------
47
48 generic
49 type Word is private;
50 procedure Port_Out (Port : Port_Type; Value : Word);
51
52 procedure Port_Out (Port : Port_Type; Value : Word) is
53 begin
54 System.Machine_Code.Asm
55 ("out %1, %0",
56 Inputs => (Port_Type'Asm_Input ("Nd", Port),
57 Word'Asm_Input ("a", Value)),
58 Volatile => True);
59 end Port_Out;
60
61 procedure OutB_Body is new Port_Out (Word => Word8);
62 procedure OutB (Port : Port_Type; Value : Word8) renames OutB_Body;
63
64 procedure OutW_Body is new Port_Out (Word => Word16);
65 procedure OutW (Port : Port_Type; Value : Word16) renames OutW_Body;
66
67 procedure OutL_Body is new Port_Out (Word => Word32);
68 procedure OutL (Port : Port_Type; Value : Word32) renames OutL_Body;
69
70end HW.Port_IO;
71
72-- vim: set ts=8 sts=3 sw=3 et: