MentOS  0.8.0
The Mentoring Operating System
port_io.h
Go to the documentation of this file.
1 
6 #pragma once
7 
11 static inline unsigned char inportb(unsigned short port)
12 {
13  unsigned char result;
14  __asm__ __volatile__("inb %%dx, %%al"
15  : "=a"(result)
16  : "dN"(port)
17  : "memory");
18  return result;
19 }
20 
24 static inline unsigned short inports(unsigned short port)
25 {
26  unsigned short result;
27  __asm__ __volatile__("inw %1, %0"
28  : "=a"(result)
29  : "dN"(port)
30  : "memory");
31  return result;
32 }
33 
37 static inline unsigned int inportl(unsigned short port)
38 {
39  unsigned int result;
40  __asm__ __volatile__("inl %%dx, %%eax"
41  : "=a"(result)
42  : "dN"(port)
43  : "memory");
44  return result;
45 }
46 
50 static inline void outportb(unsigned short port, unsigned char value)
51 {
52  __asm__ __volatile__("outb %%al, %%dx"
53  :
54  : "a"(value), "dN"(port)
55  : "memory");
56 }
57 
61 static inline void outports(unsigned short port, unsigned short value)
62 {
63  __asm__ __volatile__("outw %1, %0"
64  :
65  : "dN"(port), "a"(value)
66  : "memory");
67 }
68 
72 static inline void outportl(unsigned short port, unsigned int value)
73 {
74  __asm__ __volatile__("outl %%eax, %%dx"
75  :
76  : "dN"(port), "a"(value)
77  : "memory");
78 }
79 
84 static inline void inportsb(unsigned short port, void *addr, unsigned long count)
85 {
86  __asm__ __volatile__(
87  "cld ; rep ; insb "
88  : "=D"(addr), "=c"(count)
89  : "d"(port), "0"(addr), "1"(count));
90 }
91 
96 static inline void inportsw(unsigned short port, void *addr, unsigned long count)
97 {
98  __asm__ __volatile__(
99  "cld ; rep ; insw "
100  : "=D"(addr), "=c"(count)
101  : "d"(port), "0"(addr), "1"(count));
102 }
103 
108 static inline void inportsl(unsigned short port, void *addr, unsigned long count)
109 {
110  __asm__ __volatile__(
111  "cld ; rep ; insl "
112  : "=D"(addr), "=c"(count)
113  : "d"(port), "0"(addr), "1"(count));
114 }
115 
120 static inline void outportsb(unsigned short port, void *addr, unsigned long count)
121 {
122  __asm__ __volatile__(
123  "cld ; rep ; outsb "
124  : "=S"(addr), "=c"(count)
125  : "d"(port), "0"(addr), "1"(count));
126 }
127 
132 static inline void outportsw(unsigned short port, void *addr, unsigned long count)
133 {
134  __asm__ __volatile__(
135  "cld ; rep ; outsw "
136  : "=S"(addr), "=c"(count)
137  : "d"(port), "0"(addr), "1"(count));
138 }
139 
144 static inline void outportsl(unsigned short port, void *addr, unsigned long count)
145 {
146  __asm__ __volatile__(
147  "cld ; rep ; outsl "
148  : "=S"(addr), "=c"(count)
149  : "d"(port), "0"(addr), "1"(count));
150 }
static void outportsl(unsigned short port, void *addr, unsigned long count)
Writes multiple 32-bit values to the given port.
Definition: port_io.h:144
static unsigned int inportl(unsigned short port)
Reads a 32-bit value from the given port.
Definition: port_io.h:37
static void outportl(unsigned short port, unsigned int value)
Writes a 32-bit value at the given port.
Definition: port_io.h:72
static void inportsl(unsigned short port, void *addr, unsigned long count)
Reads multiple 32-bit values from the given port.
Definition: port_io.h:108
static unsigned short inports(unsigned short port)
Reads a 16-bit value from the given port.
Definition: port_io.h:24
static void inportsw(unsigned short port, void *addr, unsigned long count)
Reads multiple 16-bit values from the given port.
Definition: port_io.h:96
static void outportsb(unsigned short port, void *addr, unsigned long count)
Writes multiple 8-bit values to the given port.
Definition: port_io.h:120
static void inportsb(unsigned short port, void *addr, unsigned long count)
Reads multiple 8-bit values from the given port.
Definition: port_io.h:84
static void outports(unsigned short port, unsigned short value)
Writes a 16-bit value at the given port.
Definition: port_io.h:61
static void outportb(unsigned short port, unsigned char value)
Writes a 8-bit value at the given port.
Definition: port_io.h:50
static unsigned char inportb(unsigned short port)
Reads a 8-bit value from the given port.
Definition: port_io.h:11
static void outportsw(unsigned short port, void *addr, unsigned long count)
Writes multiple 16-bit values to the given port.
Definition: port_io.h:132