]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
b3a1a2025663ba970a9362a2da3624ed330cb487
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.
43 __asm__
__volatile__ ("inb %w1,%b0" : "=a" (Data
) : "d" ((UINT16
)Port
));
48 Writes an 8-bit I/O port.
50 Writes the 8-bit I/O port specified by Port with the value specified by Value
51 and returns Value. This function must guarantee that all I/O read and write
52 operations are serialized.
54 If 8-bit I/O port operations are not supported, then ASSERT().
56 @param Port The I/O port to write.
57 @param Value The value to write to the I/O port.
59 @return The value written the I/O port.
69 __asm__
__volatile__ ("outb %b0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
74 Reads a 16-bit I/O port.
76 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
77 This function must guarantee that all I/O read and write operations are
80 If 16-bit I/O port operations are not supported, then ASSERT().
81 If Port is not aligned on a 16-bit boundary, then ASSERT().
83 @param Port The I/O port to read.
85 @return The value read.
96 ASSERT ((Port
& 1) == 0);
97 __asm__
__volatile__ ("inw %w1,%w0" : "=a" (Data
) : "d" ((UINT16
)Port
));
102 Writes a 16-bit I/O port.
104 Writes the 16-bit I/O port specified by Port with the value specified by Value
105 and returns Value. This function must guarantee that all I/O read and write
106 operations are serialized.
108 If 16-bit I/O port operations are not supported, then ASSERT().
109 If Port is not aligned on a 16-bit boundary, then ASSERT().
111 @param Port The I/O port to write.
112 @param Value The value to write to the I/O port.
114 @return The value written the I/O port.
124 ASSERT ((Port
& 1) == 0);
125 __asm__
__volatile__ ("outw %w0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));
130 Reads a 32-bit I/O port.
132 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
133 This function must guarantee that all I/O read and write operations are
136 If 32-bit I/O port operations are not supported, then ASSERT().
137 If Port is not aligned on a 32-bit boundary, then ASSERT().
139 @param Port The I/O port to read.
141 @return The value read.
152 ASSERT ((Port
& 3) == 0);
153 __asm__
__volatile__ ("inl %w1,%0" : "=a" (Data
) : "d" ((UINT16
)Port
));
158 Writes a 32-bit I/O port.
160 Writes the 32-bit I/O port specified by Port with the value specified by Value
161 and returns Value. This function must guarantee that all I/O read and write
162 operations are serialized.
164 If 32-bit I/O port operations are not supported, then ASSERT().
165 If Port is not aligned on a 32-bit boundary, then ASSERT().
167 @param Port The I/O port to write.
168 @param Value The value to write to the I/O port.
170 @return The value written the I/O port.
180 ASSERT ((Port
& 3) == 0);
181 __asm__
__volatile__ ("outl %0,%w1" : : "a" (Value
), "d" ((UINT16
)Port
));