-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.h
More file actions
55 lines (44 loc) · 1.13 KB
/
io.h
File metadata and controls
55 lines (44 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* io.h - I/O Port Operations for GegOS
* Low-level hardware access functions
*/
#ifndef IO_H
#define IO_H
#include <stdint.h>
/* Output a byte to a port */
static inline void outb(uint16_t port, uint8_t value) {
__asm__ volatile ("outb %0, %1" : : "a"(value), "Nd"(port));
}
/* Input a byte from a port */
static inline uint8_t inb(uint16_t port) {
uint8_t value;
__asm__ volatile ("inb %1, %0" : "=a"(value) : "Nd"(port));
return value;
}
/* Output a word to a port */
static inline void outw(uint16_t port, uint16_t value) {
__asm__ volatile ("outw %0, %1" : : "a"(value), "Nd"(port));
}
/* Input a word from a port */
static inline uint16_t inw(uint16_t port) {
uint16_t value;
__asm__ volatile ("inw %1, %0" : "=a"(value) : "Nd"(port));
return value;
}
/* I/O wait (small delay) */
static inline void io_wait(void) {
outb(0x80, 0);
}
/* Enable interrupts */
static inline void sti(void) {
__asm__ volatile ("sti");
}
/* Disable interrupts */
static inline void cli(void) {
__asm__ volatile ("cli");
}
/* Halt CPU */
static inline void hlt(void) {
__asm__ volatile ("hlt");
}
#endif /* IO_H */