]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseIoLibIntrinsic/IoLibGcc.c
Initial import.
[mirror_edk2.git] / MdePkg / Library / BaseIoLibIntrinsic / IoLibGcc.c
CommitLineData
878ddf1f 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, Intel Corporation<BR>\r
14 All rights reserved. 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 Module Name: IoLibGcc.c\r
23\r
24**/\r
25\r
26#ifdef __GNUC__\r
27\r
28/**\r
29 Reads an 8-bit I/O port.\r
30\r
31 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r
32 This function must guarantee that all I/O read and write operations are\r
33 serialized.\r
34\r
35 If 8-bit I/O port operations are not supported, then ASSERT().\r
36\r
37 @param Port The I/O port to read.\r
38\r
39 @return The value read.\r
40\r
41**/\r
42__inline__\r
43UINT8\r
44EFIAPI\r
45IoRead8 (\r
46 IN UINTN Port\r
47 )\r
48{\r
49 UINT8 Data;\r
50\r
51 __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));\r
52 return Data;\r
53}\r
54\r
55/**\r
56 Writes an 8-bit I/O port.\r
57\r
58 Writes the 8-bit I/O port specified by Port with the value specified by Value\r
59 and returns Value. This function must guarantee that all I/O read and write\r
60 operations are serialized.\r
61\r
62 If 8-bit I/O port operations are not supported, then ASSERT().\r
63\r
64 @param Port The I/O port to write.\r
65 @param Value The value to write to the I/O port.\r
66\r
67 @return The value written the I/O port.\r
68\r
69**/\r
70__inline__\r
71UINT8\r
72EFIAPI\r
73IoWrite8 (\r
74 IN UINTN Port,\r
75 IN UINT8 Value\r
76 )\r
77{\r
78 __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r
79 return Value;;\r
80}\r
81\r
82/**\r
83 Reads a 16-bit I/O port.\r
84\r
85 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r
86 This function must guarantee that all I/O read and write operations are\r
87 serialized.\r
88\r
89 If 16-bit I/O port operations are not supported, 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\r
119 @param Port The I/O port to write.\r
120 @param Value The value to write to the I/O port.\r
121\r
122 @return The value written the I/O port.\r
123\r
124**/\r
125__inline__\r
126UINT16\r
127EFIAPI\r
128IoWrite16 (\r
129 IN UINTN Port,\r
130 IN UINT16 Value\r
131 )\r
132{\r
133 ASSERT ((Port & 1) == 0);\r
134 __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r
135 return Value;;\r
136}\r
137\r
138/**\r
139 Reads a 32-bit I/O port.\r
140\r
141 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r
142 This function must guarantee that all I/O read and write operations are\r
143 serialized.\r
144\r
145 If 32-bit I/O port operations are not supported, then ASSERT().\r
146\r
147 @param Port The I/O port to read.\r
148\r
149 @return The value read.\r
150\r
151**/\r
152__inline__\r
153UINT32\r
154EFIAPI\r
155IoRead32 (\r
156 IN UINTN Port\r
157 )\r
158{\r
159 UINT32 Data;\r
160\r
161 ASSERT ((Port & 3) == 0);\r
162 __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));\r
163 return Data;\r
164}\r
165\r
166/**\r
167 Writes a 32-bit I/O port.\r
168\r
169 Writes the 32-bit I/O port specified by Port with the value specified by Value\r
170 and returns Value. This function must guarantee that all I/O read and write\r
171 operations are serialized.\r
172\r
173 If 32-bit I/O port operations are not supported, then ASSERT().\r
174\r
175 @param Port The I/O port to write.\r
176 @param Value The value to write to the I/O port.\r
177\r
178 @return The value written the I/O port.\r
179\r
180**/\r
181__inline__\r
182UINT32\r
183EFIAPI\r
184IoWrite32 (\r
185 IN UINTN Port,\r
186 IN UINT32 Value\r
187 )\r
188{\r
189 ASSERT ((Port & 3) == 0);\r
190 __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r
191 return Value;\r
192}\r
193\r
194#endif\r