1 /* This file is derived from source code used in MIT's 6.828
2 course. The original copyright notice is reproduced in full
6 * Copyright (C) 1997 Massachusetts Institute of Technology
8 * This software is being provided by the copyright holders under the
9 * following license. By obtaining, using and/or copying this software,
10 * you agree that you have read, understood, and will comply with the
11 * following terms and conditions:
13 * Permission to use, copy, modify, distribute, and sell this software
14 * and its documentation for any purpose and without fee or royalty is
15 * hereby granted, provided that the full text of this NOTICE appears on
16 * ALL copies of the software and documentation or portions thereof,
17 * including modifications, that you make.
19 * THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
20 * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
21 * BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
22 * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
23 * THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
24 * THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. COPYRIGHT
25 * HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE OR
28 * The name and trademarks of copyright holders may NOT be used in
29 * advertising or publicity pertaining to the software without specific,
30 * written prior permission. Title to copyright in this software and any
31 * associated documentation will at all times remain with copyright
32 * holders. See the file AUTHORS which should have accompanied this software
33 * for a list of all copyright holders.
35 * This file may be derived from previously copyrighted software. This
36 * copyright applies only to those changes made by the copyright
37 * holders listed in the AUTHORS file. The rest of this file is covered by
38 * the copyright notices, if any, listed below.
47 /* Reads and returns a byte from PORT. */
51 /* See [IA32-v2a] "IN". */
53 asm volatile ("inb %w1,%0" : "=a" (data
) : "d" (port
));
57 /* Reads CNT bytes from PORT, one after another, and stores them
58 into the buffer starting at ADDR. */
60 insb (uint16_t port
, void *addr
, size_t cnt
)
62 /* See [IA32-v2a] "INS". */
63 asm volatile ("cld; repne; insb"
64 : "=D" (addr
), "=c" (cnt
)
65 : "d" (port
), "0" (addr
), "1" (cnt
)
69 /* Reads and returns 16 bits from PORT. */
70 static inline uint16_t
74 /* See [IA32-v2a] "IN". */
75 asm volatile ("inw %w1,%0" : "=a" (data
) : "d" (port
));
79 /* Reads CNT 16-bit (halfword) units from PORT, one after
80 another, and stores them into the buffer starting at ADDR. */
82 insw (uint16_t port
, void *addr
, size_t cnt
)
84 /* See [IA32-v2a] "INS". */
85 asm volatile ("cld; repne; insw"
86 : "=D" (addr
), "=c" (cnt
)
87 : "d" (port
), "0" (addr
), "1" (cnt
)
91 /* Reads and returns 32 bits from PORT. */
92 static inline uint32_t
95 /* See [IA32-v2a] "IN". */
97 asm volatile ("inl %w1,%0" : "=a" (data
) : "d" (port
));
101 /* Reads CNT 32-bit (word) units from PORT, one after another,
102 and stores them into the buffer starting at ADDR. */
104 insl (uint16_t port
, void *addr
, size_t cnt
)
106 /* See [IA32-v2a] "INS". */
107 asm volatile ("cld; repne; insl"
108 : "=D" (addr
), "=c" (cnt
)
109 : "d" (port
), "0" (addr
), "1" (cnt
)
113 /* Writes byte DATA to PORT. */
115 outb (uint16_t port
, uint8_t data
)
117 /* See [IA32-v2b] "OUT". */
118 asm volatile ("outb %0,%w1" : : "a" (data
), "d" (port
));
121 /* Writes to PORT each byte of data in the CNT-byte buffer
124 outsb (uint16_t port
, const void *addr
, size_t cnt
)
126 /* See [IA32-v2b] "OUTS". */
127 asm volatile ("cld; repne; outsb"
128 : "=S" (addr
), "=c" (cnt
)
129 : "d" (port
), "0" (addr
), "1" (cnt
)
133 /* Writes the 16-bit DATA to PORT. */
135 outw (uint16_t port
, uint16_t data
)
137 /* See [IA32-v2b] "OUT". */
138 asm volatile ("outw %0,%w1" : : "a" (data
), "d" (port
));
141 /* Writes to PORT each 16-bit unit (halfword) of data in the
142 CNT-halfword buffer starting at ADDR. */
144 outsw (uint16_t port
, const void *addr
, size_t cnt
)
146 /* See [IA32-v2b] "OUTS". */
147 asm volatile ("cld; repne; outsw"
148 : "=S" (addr
), "=c" (cnt
)
149 : "d" (port
), "0" (addr
), "1" (cnt
)
153 /* Writes the 32-bit DATA to PORT. */
155 outl (uint16_t port
, uint32_t data
)
157 /* See [IA32-v2b] "OUT". */
158 asm volatile ("outl %0,%w1" : : "a" (data
), "d" (port
));
161 /* Writes to PORT each 32-bit unit (word) of data in the CNT-word
162 buffer starting at ADDR. */
164 outsl (uint16_t port
, const void *addr
, size_t cnt
)
166 /* See [IA32-v2b] "OUTS". */
167 asm volatile ("cld; repne; outsl"
168 : "=S" (addr
), "=c" (cnt
)
169 : "d" (port
), "0" (addr
), "1" (cnt
)
173 #endif /* threads/io.h */