The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1#pragma once
2
3#include "common/stdint.h"
4
5/**
6 * write a byte to the specified I/O port.
7 * @param port the I/O port number.
8 * @param value the byte value to write.
9 */
10static inline void io_outb(uint16_t port, uint8_t value)
11{
12 __asm__ __volatile__("outb %0, %1" : : "a"(value), "Nd"(port));
13}
14
15/**
16 * read a byte from the specified I/O port.
17 * @param port the I/O port number.
18 * @return the byte value read from the port.
19 */
20static inline uint8_t io_inb(uint16_t port)
21{
22 uint8_t value;
23 __asm__ __volatile__("inb %1, %0" : "=a"(value) : "Nd"(port));
24 return value;
25}
26
27/**
28 * read a 16-bit word from the specified I/O port.
29 * @param port the I/O port number.
30 * @return the word value read from the port.
31 */
32static inline uint16_t io_inw(uint16_t port)
33{
34 uint16_t value;
35 __asm__ __volatile__("inw %1, %0" : "=a"(value) : "Nd"(port));
36 return value;
37}
38
39/**
40 * write a 16-bit word to an I/O port.
41 * @param port the I/O port number.
42 * @param value the value to write.
43 */
44static inline void io_outw(uint16_t port, uint16_t value)
45{
46 __asm__ __volatile__("outw %0, %1" : : "a"(value), "Nd"(port));
47}
48
49/**
50 * write a 32-bit value to an I/O port.
51 * @param port the I/O port number.
52 * @param value the value to write.
53 */
54static inline void io_outl(uint16_t port, uint32_t value)
55{
56 __asm__ __volatile__("outl %0, %1" : : "a"(value), "Nd"(port));
57}
58
59/**
60 * read a 32-bit value from an I/O port.
61 * @param port the I/O port number.
62 * @return the value read from the port.
63 */
64static inline uint32_t io_inl(uint16_t port)
65{
66 uint32_t value;
67 __asm__ __volatile__("inl %1, %0" : "=a"(value) : "Nd"(port));
68 return value;
69}
70
71/**
72 * read count 16-bit words from an I/O port into a buffer (string I/O).
73 * @param port the I/O port to read from.
74 * @param buffer destination buffer (must be at least word_count * 2 bytes).
75 * @param word_count number of 16-bit words to read.
76 */
77static inline void io_insw(uint16_t port, void *buffer, uint32_t word_count)
78{
79 __asm__ __volatile__("cld; rep insw"
80 : "+D"(buffer), "+c"(word_count)
81 : "d"(port)
82 : "memory");
83}
84
85/**
86 * write count 16-bit words from a buffer to an I/O port (string I/O).
87 * @param port the I/O port to write to.
88 * @param buffer source buffer.
89 * @param word_count number of 16-bit words to write.
90 */
91static inline void io_outsw(uint16_t port, const void *buffer, uint32_t word_count)
92{
93 __asm__ __volatile__("cld; rep outsw"
94 : "+S"(buffer), "+c"(word_count)
95 : "d"(port));
96}
97
98/**
99 * brief delay by writing to an unused I/O port (0x80).
100 * used to give slow devices time to catch up after a port write.
101 */
102void io_wait(void);
103
104/**
105 * enable hardware interrupts by executing the STI instruction.
106 */
107static inline void io_enable_interrupts(void)
108{
109 __asm__ __volatile__("sti");
110}
111
112/**
113 * disable hardware interrupts by executing the CLI instruction.
114 */
115static inline void io_disable_interrupts(void)
116{
117 __asm__ __volatile__("cli");
118}
void io_wait(void)
brief delay by writing to an unused I/O port (0x80).
Definition io.c:6
unsigned int uint32_t
Definition fb.h:17
unsigned char uint8_t
Definition fb.h:18
unsigned short uint16_t
Definition stdint.h:13