]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
2 I/O Library. This file has compiler specifics for GCC as there is no
3 ANSI C standard for doing IO.
5 GCC - uses EFIAPI assembler. __asm__ calls GAS. __volatile__ makes sure the
6 compiler puts the assembler in this exact location. The complex GNUC
7 operations are not optimzed. It would be possible to also write these
10 We don't advocate putting compiler specifics in libraries or drivers but there
11 is no other way to make this work.
13 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
14 SPDX-License-Identifier: BSD-2-Clause-Patent
19 #include "BaseIoLibIntrinsicInternal.h"
22 Reads an 8-bit I/O port.
24 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
25 This function must guarantee that all I/O read and write operations are
28 If 8-bit I/O port operations are not supported, then ASSERT().
30 @param Port The I/O port to read.
32 @return The value read.
44 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
49 Writes an 8-bit I/O port.
51 Writes the 8-bit I/O port specified by Port with the value specified by Value
52 and returns Value. This function must guarantee that all I/O read and write
53 operations are serialized.
55 If 8-bit I/O port operations are not supported, then ASSERT().
57 @param Port The I/O port to write.
58 @param Value The value to write to the I/O port.
60 @return The value written the I/O port.
71 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
76 Reads a 16-bit I/O port.
78 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
79 This function must guarantee that all I/O read and write operations are
82 If 16-bit I/O port operations are not supported, then ASSERT().
83 If Port is not aligned on a 16-bit boundary, then ASSERT().
85 @param Port The I/O port to read.
87 @return The value read.
99 ASSERT ((Port
& 1) == 0);
100 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
105 Writes a 16-bit I/O port.
107 Writes the 16-bit I/O port specified by Port with the value specified by Value
108 and returns Value. This function must guarantee that all I/O read and write
109 operations are serialized.
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 write.
115 @param Value The value to write to the I/O port.
117 @return The value written the I/O port.
128 ASSERT ((Port
& 1) == 0);
129 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
134 Reads a 32-bit I/O port.
136 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
137 This function must guarantee that all I/O read and write operations are
140 If 32-bit I/O port operations are not supported, then ASSERT().
141 If Port is not aligned on a 32-bit boundary, then ASSERT().
143 @param Port The I/O port to read.
145 @return The value read.
157 ASSERT ((Port
& 3) == 0);
158 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
163 Writes a 32-bit I/O port.
165 Writes the 32-bit I/O port specified by Port with the value specified by Value
166 and returns Value. This function must guarantee that all I/O read and write
167 operations are serialized.
169 If 32-bit I/O port operations are not supported, then ASSERT().
170 If Port is not aligned on a 32-bit boundary, then ASSERT().
172 @param Port The I/O port to write.
173 @param Value The value to write to the I/O port.
175 @return The value written the I/O port.
186 ASSERT ((Port
& 3) == 0);
187 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));