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