]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibIcc.c
0a61f76c4a2e0d78c4d9ce972ce9304527687bcf
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibIcc.c
1 /** @file
2 I/O Library. This file has compiler specifics for ICC as there
3 is no ANSI C standard for doing IO.
4
5 Copyright (c) 2006 - 2008, Intel Corporation<BR> All rights
6 reserved. This program and the accompanying materials are
7 licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "BaseIoLibIntrinsicInternal.h"
17
18 /**
19 Reads an 8-bit I/O port.
20
21 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
22 This function must guarantee that all I/O read and write operations are
23 serialized.
24
25 If 8-bit I/O port operations are not supported, then ASSERT().
26
27 @param Port The I/O port to read.
28
29 @return The value read.
30
31 **/
32 UINT8
33 EFIAPI
34 IoRead8 (
35 IN UINTN Port
36 )
37 {
38 UINT8 Data;
39
40 __asm {
41 mov dx, word ptr [Port]
42 in al, dx
43
44 mov Data, al
45 }
46 return Data;
47 }
48
49 /**
50 Writes an 8-bit I/O port.
51
52 Writes the 8-bit I/O port specified by Port with the value specified by Value
53 and returns Value. This function must guarantee that all I/O read and write
54 operations are serialized.
55
56 If 8-bit I/O port operations are not supported, then ASSERT().
57
58 @param Port The I/O port to write.
59 @param Value The value to write to the I/O port.
60
61 @return The value written the I/O port.
62
63 **/
64 UINT8
65 EFIAPI
66 IoWrite8 (
67 IN UINTN Port,
68 IN UINT8 Value
69 )
70 {
71 __asm {
72 mov al, byte ptr [Value]
73 mov dx, word ptr [Port]
74 out dx, al
75 }
76 return Value;
77 }
78
79 /**
80 Reads a 16-bit I/O port.
81
82 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
83 This function must guarantee that all I/O read and write operations are
84 serialized.
85
86 If 16-bit I/O port operations are not supported, then ASSERT().
87 If Port is not aligned on a 16-bit boundary, then ASSERT().
88
89 @param Port The I/O port to read.
90
91 @return The value read.
92
93 **/
94 UINT16
95 EFIAPI
96 IoRead16 (
97 IN UINTN Port
98 )
99 {
100 UINT16 Data;
101
102 ASSERT ((Port & 1) == 0);
103
104 __asm {
105 mov dx, word ptr [Port]
106 in ax, dx
107 mov word ptr [Data], ax
108 }
109
110 return Data;
111 }
112
113 /**
114 Writes a 16-bit I/O port.
115
116 Writes the 16-bit I/O port specified by Port with the value specified by Value
117 and returns Value. This function must guarantee that all I/O read and write
118 operations are serialized.
119
120 If 16-bit I/O port operations are not supported, then ASSERT().
121 If Port is not aligned on a 16-bit boundary, then ASSERT().
122
123 @param Port The I/O port to write.
124 @param Value The value to write to the I/O port.
125
126 @return The value written the I/O port.
127
128 **/
129 UINT16
130 EFIAPI
131 IoWrite16 (
132 IN UINTN Port,
133 IN UINT16 Value
134 )
135 {
136 ASSERT ((Port & 1) == 0);
137
138 __asm {
139 mov ax, word ptr [Value]
140 mov dx, word ptr [Port]
141 out dx, ax
142 }
143
144 return Value;
145 }
146
147 /**
148 Reads a 32-bit I/O port.
149
150 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
151 This function must guarantee that all I/O read and write operations are
152 serialized.
153
154 If 32-bit I/O port operations are not supported, then ASSERT().
155 If Port is not aligned on a 32-bit boundary, then ASSERT().
156
157 @param Port The I/O port to read.
158
159 @return The value read.
160
161 **/
162 UINT32
163 EFIAPI
164 IoRead32 (
165 IN UINTN Port
166 )
167 {
168 UINT32 Data;
169
170 ASSERT ((Port & 3) == 0);
171
172 __asm {
173 mov dx, word ptr [Port]
174 in eax, dx
175 mov dword ptr [Data], eax
176 }
177
178 return Data;
179 }
180
181 /**
182 Writes a 32-bit I/O port.
183
184 Writes the 32-bit I/O port specified by Port with the value specified by Value
185 and returns Value. This function must guarantee that all I/O read and write
186 operations are serialized.
187
188 If 32-bit I/O port operations are not supported, then ASSERT().
189 If Port is not aligned on a 32-bit boundary, then ASSERT().
190
191 @param Port The I/O port to write.
192 @param Value The value to write to the I/O port.
193
194 @return The value written the I/O port.
195
196 **/
197 UINT32
198 EFIAPI
199 IoWrite32 (
200 IN UINTN Port,
201 IN UINT32 Value
202 )
203 {
204 ASSERT ((Port & 3) == 0);
205
206 __asm {
207 mov eax, dword ptr [Value]
208 mov dx, word ptr [Port]
209 out dx, eax
210 }
211
212 return Value;
213 }
214