[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1/* This file is derived from source code used in MIT's 6.828
2 course. The original copyright notice is reproduced in full
3 below. */
4
5/*
6 * Copyright (C) 1997 Massachusetts Institute of Technology
7 *
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:
12 *
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.
18 *
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
26 * DOCUMENTATION.
27 *
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.
34 *
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.
39 */
40
41#ifndef THREADS_IO_H
42#define THREADS_IO_H
43
44#include <stddef.h>
45#include <stdint.h>
46
47/* Reads and returns a byte from PORT. */
48static inline uint8_t
49inb (uint16_t port) {
50 /* See [IA32-v2a] "IN". */
51 uint8_t data;
52 asm volatile ("inb %w1,%0" : "=a" (data) : "d" (port));
53 return data;
54}
55
56/* Reads CNT bytes from PORT, one after another, and stores them
57 into the buffer starting at ADDR. */
58static inline void
59insb (uint16_t port, void *addr, size_t cnt) {
60 /* See [IA32-v2a] "INS". */
61 asm volatile ("cld; repne; insb"
62 : "=D" (addr), "=c" (cnt)
63 : "d" (port), "0" (addr), "1" (cnt)
64 : "memory", "cc");
65}
66
67/* Reads and returns 16 bits from PORT. */
68static inline uint16_t
69inw (uint16_t port) {
70 uint16_t data;
71 /* See [IA32-v2a] "IN". */
72 asm volatile ("inw %w1,%0" : "=a" (data) : "d" (port));
73 return data;
74}
75
76/* Reads CNT 16-bit (halfword) units from PORT, one after
77 another, and stores them into the buffer starting at ADDR. */
78static inline void
79insw (uint16_t port, void *addr, size_t cnt) {
80 /* See [IA32-v2a] "INS". */
81 asm volatile ("cld; repne; insw"
82 : "=D" (addr), "=c" (cnt)
83 : "d" (port), "0" (addr), "1" (cnt)
84 : "memory", "cc");
85}
86
87/* Reads and returns 32 bits from PORT. */
88static inline uint32_t
89inl (uint16_t port) {
90 /* See [IA32-v2a] "IN". */
91 uint32_t data;
92 asm volatile ("inl %w1,%0" : "=a" (data) : "d" (port));
93 return data;
94}
95
96/* Reads CNT 32-bit (word) units from PORT, one after another,
97 and stores them into the buffer starting at ADDR. */
98static inline void
99insl (uint16_t port, void *addr, size_t cnt) {
100 /* See [IA32-v2a] "INS". */
101 asm volatile ("cld; repne; insl"
102 : "=D" (addr), "=c" (cnt)
103 : "d" (port), "0" (addr), "1" (cnt)
104 : "memory", "cc");
105}
106
107/* Writes byte DATA to PORT. */
108static inline void
109outb (uint16_t port, uint8_t data) {
110 /* See [IA32-v2b] "OUT". */
111 asm volatile ("outb %0,%w1" : : "a" (data), "d" (port));
112}
113
114/* Writes to PORT each byte of data in the CNT-byte buffer
115 starting at ADDR. */
116static inline void
117outsb (uint16_t port, const void *addr, size_t cnt) {
118 /* See [IA32-v2b] "OUTS". */
119 asm volatile ("cld; repne; outsb"
120 : "=S" (addr), "=c" (cnt)
121 : "d" (port), "0" (addr), "1" (cnt)
122 : "cc");
123}
124
125/* Writes the 16-bit DATA to PORT. */
126static inline void
127outw (uint16_t port, uint16_t data) {
128 /* See [IA32-v2b] "OUT". */
129 asm volatile ("outw %0,%w1" : : "a" (data), "d" (port));
130}
131
132/* Writes to PORT each 16-bit unit (halfword) of data in the
133 CNT-halfword buffer starting at ADDR. */
134static inline void
135outsw (uint16_t port, const void *addr, size_t cnt) {
136 /* See [IA32-v2b] "OUTS". */
137 asm volatile ("cld; repne; outsw"
138 : "=S" (addr), "=c" (cnt)
139 : "d" (port), "0" (addr), "1" (cnt)
140 : "cc");
141}
142
143/* Writes the 32-bit DATA to PORT. */
144static inline void
145outl (uint16_t port, uint32_t data) {
146 /* See [IA32-v2b] "OUT". */
147 asm volatile ("outl %0,%w1" : : "a" (data), "d" (port));
148}
149
150/* Writes to PORT each 32-bit unit (word) of data in the CNT-word
151 buffer starting at ADDR. */
152static inline void
153outsl (uint16_t port, const void *addr, size_t cnt) {
154 /* See [IA32-v2b] "OUTS". */
155 asm volatile ("cld; repne; outsl"
156 : "=S" (addr), "=c" (cnt)
157 : "d" (port), "0" (addr), "1" (cnt)
158 : "cc");
159}
160
161#endif /* threads/io.h */
static uint8_t inb(uint16_t port)
Definition: io.h:49
static void outsw(uint16_t port, const void *addr, size_t cnt)
Definition: io.h:135
static void outw(uint16_t port, uint16_t data)
Definition: io.h:127
static void insl(uint16_t port, void *addr, size_t cnt)
Definition: io.h:99
static void outsb(uint16_t port, const void *addr, size_t cnt)
Definition: io.h:117
static void insw(uint16_t port, void *addr, size_t cnt)
Definition: io.h:79
static void outb(uint16_t port, uint8_t data)
Definition: io.h:109
static uint32_t inl(uint16_t port)
Definition: io.h:89
static void outl(uint16_t port, uint32_t data)
Definition: io.h:145
static uint16_t inw(uint16_t port)
Definition: io.h:69
static void outsl(uint16_t port, const void *addr, size_t cnt)
Definition: io.h:153
static void insb(uint16_t port, void *addr, size_t cnt)
Definition: io.h:59
unsigned int uint32_t
Definition: stdint.h:26
unsigned char uint8_t
Definition: stdint.h:20
unsigned short int uint16_t
Definition: stdint.h:23