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