]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
2 I/O Library. This file has compiler specifics for Microsft C as there is no
3 ANSI C standard for doing IO.
5 MSC - uses intrinsic functions and the optimize will remove the function call
8 We don't advocate putting compiler specifics in libraries or drivers but there
9 is no other way to make this work.
11 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
12 This program and the accompanying materials
13 are licensed and made available under the terms and conditions of the BSD License
14 which accompanies this distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php.
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 #include "BaseIoLibIntrinsicInternal.h"
27 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.
30 int _inp (unsigned short port
);
31 unsigned short _inpw (unsigned short port
);
32 unsigned long _inpd (unsigned short port
);
33 int _outp (unsigned short port
, int databyte
);
34 unsigned short _outpw (unsigned short port
, unsigned short dataword
);
35 unsigned long _outpd (unsigned short port
, unsigned long dataword
);
36 void _ReadWriteBarrier (void);
38 #pragma intrinsic(_inp)
39 #pragma intrinsic(_inpw)
40 #pragma intrinsic(_inpd)
41 #pragma intrinsic(_outp)
42 #pragma intrinsic(_outpw)
43 #pragma intrinsic(_outpd)
44 #pragma intrinsic(_ReadWriteBarrier)
47 // _ReadWriteBarrier() forces memory reads and writes to complete at the point
48 // in the call. This is only a hint to the compiler and does emit code.
49 // In past versions of the compiler, _ReadWriteBarrier was enforced only
50 // locally and did not affect functions up the call tree. In Visual C++
51 // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
55 Reads an 8-bit I/O port.
57 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
58 This function must guarantee that all I/O read and write operations are
61 If 8-bit I/O port operations are not supported, then ASSERT().
63 @param Port The I/O port to read.
65 @return The value read.
77 Value
= (UINT8
)_inp ((UINT16
)Port
);
83 Writes an 8-bit I/O port.
85 Writes the 8-bit I/O port specified by Port with the value specified by Value
86 and returns Value. This function must guarantee that all I/O read and write
87 operations are serialized.
89 If 8-bit I/O port operations are not supported, then ASSERT().
91 @param Port The I/O port to write.
92 @param Value The value to write to the I/O port.
94 @return The value written to the I/O port.
104 _ReadWriteBarrier ();
105 (UINT8
)_outp ((UINT16
)Port
, Value
);
106 _ReadWriteBarrier ();
111 Reads a 16-bit I/O port.
113 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
114 This function must guarantee that all I/O read and write operations are
117 If 16-bit I/O port operations are not supported, then ASSERT().
118 If Port is not aligned on a 16-bit boundary, then ASSERT().
120 @param Port The I/O port to read.
122 @return The value read.
133 ASSERT ((Port
& 1) == 0);
134 _ReadWriteBarrier ();
135 Value
= _inpw ((UINT16
)Port
);
136 _ReadWriteBarrier ();
141 Writes a 16-bit I/O port.
143 Writes the 16-bit I/O port specified by Port with the value specified by Value
144 and returns Value. This function must guarantee that all I/O read and write
145 operations are serialized.
147 If 16-bit I/O port operations are not supported, then ASSERT().
148 If Port is not aligned on a 16-bit boundary, then ASSERT().
150 @param Port The I/O port to write.
151 @param Value The value to write to the I/O port.
153 @return The value written to the I/O port.
163 ASSERT ((Port
& 1) == 0);
164 _ReadWriteBarrier ();
165 _outpw ((UINT16
)Port
, Value
);
166 _ReadWriteBarrier ();
171 Reads a 32-bit I/O port.
173 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
174 This function must guarantee that all I/O read and write operations are
177 If 32-bit I/O port operations are not supported, then ASSERT().
178 If Port is not aligned on a 32-bit boundary, then ASSERT().
180 @param Port The I/O port to read.
182 @return The value read.
193 ASSERT ((Port
& 3) == 0);
194 _ReadWriteBarrier ();
195 Value
= _inpd ((UINT16
)Port
);
196 _ReadWriteBarrier ();
201 Writes a 32-bit I/O port.
203 Writes the 32-bit I/O port specified by Port with the value specified by Value
204 and returns Value. This function must guarantee that all I/O read and write
205 operations are serialized.
207 If 32-bit I/O port operations are not supported, then ASSERT().
208 If Port is not aligned on a 32-bit boundary, then ASSERT().
210 @param Port The I/O port to write.
211 @param Value The value to write to the I/O port.
213 @return The value written to the I/O port.
223 ASSERT ((Port
& 3) == 0);
224 _ReadWriteBarrier ();
225 _outpd ((UINT16
)Port
, Value
);
226 _ReadWriteBarrier ();