]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibMsc.c
769dddfce2073c7c482f34a56d515b6e59e2f22e
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 - 2018, Intel Corporation. All rights reserved.<BR>
12 SPDX-License-Identifier: BSD-2-Clause-Patent
18 #include "BaseIoLibIntrinsicInternal.h"
21 // Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.
24 int _inp (unsigned short port
);
25 unsigned short _inpw (unsigned short port
);
26 unsigned long _inpd (unsigned short port
);
27 int _outp (unsigned short port
, int databyte
);
28 unsigned short _outpw (unsigned short port
, unsigned short dataword
);
29 unsigned long _outpd (unsigned short port
, unsigned long dataword
);
30 void _ReadWriteBarrier (void);
32 #pragma intrinsic(_inp)
33 #pragma intrinsic(_inpw)
34 #pragma intrinsic(_inpd)
35 #pragma intrinsic(_outp)
36 #pragma intrinsic(_outpw)
37 #pragma intrinsic(_outpd)
38 #pragma intrinsic(_ReadWriteBarrier)
41 // _ReadWriteBarrier() forces memory reads and writes to complete at the point
42 // in the call. This is only a hint to the compiler and does emit code.
43 // In past versions of the compiler, _ReadWriteBarrier was enforced only
44 // locally and did not affect functions up the call tree. In Visual C++
45 // 2005, _ReadWriteBarrier is enforced all the way up the call tree.
49 Reads an 8-bit I/O port.
51 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
52 This function must guarantee that all I/O read and write operations are
55 If 8-bit I/O port operations are not supported, then ASSERT().
57 @param Port The I/O port to read.
59 @return The value read.
71 Value
= (UINT8
)_inp ((UINT16
)Port
);
77 Writes an 8-bit I/O port.
79 Writes the 8-bit I/O port specified by Port with the value specified by Value
80 and returns Value. This function must guarantee that all I/O read and write
81 operations are serialized.
83 If 8-bit I/O port operations are not supported, then ASSERT().
85 @param Port The I/O port to write.
86 @param Value The value to write to the I/O port.
88 @return The value written to the I/O port.
99 (UINT8
)_outp ((UINT16
)Port
, Value
);
100 _ReadWriteBarrier ();
105 Reads a 16-bit I/O port.
107 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
108 This function must guarantee that all I/O read and write operations are
111 If 16-bit I/O port operations are not supported, then ASSERT().
112 If Port is not aligned on a 16-bit boundary, then ASSERT().
114 @param Port The I/O port to read.
116 @return The value read.
127 ASSERT ((Port
& 1) == 0);
128 _ReadWriteBarrier ();
129 Value
= _inpw ((UINT16
)Port
);
130 _ReadWriteBarrier ();
135 Writes a 16-bit I/O port.
137 Writes the 16-bit I/O port specified by Port with the value specified by Value
138 and returns Value. This function must guarantee that all I/O read and write
139 operations are serialized.
141 If 16-bit I/O port operations are not supported, then ASSERT().
142 If Port is not aligned on a 16-bit boundary, then ASSERT().
144 @param Port The I/O port to write.
145 @param Value The value to write to the I/O port.
147 @return The value written to the I/O port.
157 ASSERT ((Port
& 1) == 0);
158 _ReadWriteBarrier ();
159 _outpw ((UINT16
)Port
, Value
);
160 _ReadWriteBarrier ();
165 Reads a 32-bit I/O port.
167 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
168 This function must guarantee that all I/O read and write operations are
171 If 32-bit I/O port operations are not supported, then ASSERT().
172 If Port is not aligned on a 32-bit boundary, then ASSERT().
174 @param Port The I/O port to read.
176 @return The value read.
187 ASSERT ((Port
& 3) == 0);
188 _ReadWriteBarrier ();
189 Value
= _inpd ((UINT16
)Port
);
190 _ReadWriteBarrier ();
195 Writes a 32-bit I/O port.
197 Writes the 32-bit I/O port specified by Port with the value specified by Value
198 and returns Value. This function must guarantee that all I/O read and write
199 operations are serialized.
201 If 32-bit I/O port operations are not supported, then ASSERT().
202 If Port is not aligned on a 32-bit boundary, then ASSERT().
204 @param Port The I/O port to write.
205 @param Value The value to write to the I/O port.
207 @return The value written to the I/O port.
217 ASSERT ((Port
& 3) == 0);
218 _ReadWriteBarrier ();
219 _outpd ((UINT16
)Port
, Value
);
220 _ReadWriteBarrier ();