LumaOS  v0.1.116
An experimental x86-64 OS
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1
9
10#ifndef KERNEL_ARCH_X86_64_IO_H
11#define KERNEL_ARCH_X86_64_IO_H
12
13#define COM1 0x3F8
14
15#include <stdint.h>
16
22inline void outb(uint16_t port, uint8_t value) {
23 asm volatile ("out %1, %0" : : "d"(port), "a"(value) : "memory"); // Output data to the serial port
24}
25
31inline uint8_t inb(uint16_t port) {
32 uint8_t value;
33 asm volatile ("in %1, %0" : "=a"(value) : "d"(port) : "memory");
34 return value;
35}
36
37
43inline void outw(uint32_t port, uint16_t value) {
44 asm volatile ("out %1, %0" : : "d"(port), "a"(value) : "memory"); // Output data to the serial port
45}
46
52inline uint16_t inw(uint32_t port) {
53 uint16_t value;
54 asm volatile ("in %1, %0" : "=a"(value) : "d"(port) : "memory");
55 return value;
56}
57
58
59
65inline void outl(uint32_t port, uint32_t value) {
66 asm volatile ("out %1, %0" : : "d"(port), "a"(value) : "memory"); // Output data to the serial port
67}
68
74inline uint32_t inl(uint32_t port) {
75 uint32_t value;
76 asm volatile ("in %1, %0" : "=a"(value) : "d"(port) : "memory");
77 return value;
78}
79
83inline void io_wait(void)
84{
85 outb(0x80, 0x00);
86}
87
88static inline uint64_t rdmsr(uint32_t msr)
89{
90 uint32_t lo, hi;
91 __asm__ volatile("rdmsr" : "=a"(lo), "=d"(hi) : "c"(msr));
92 return ((uint64_t)hi << 32) | lo;
93}
94
95static inline void wrmsr(uint32_t msr, uint64_t value)
96{
97 uint32_t lo = (uint32_t)value;
98 uint32_t hi = (uint32_t)(value >> 32);
99 __asm__ volatile("wrmsr" :: "c"(msr), "a"(lo), "d"(hi) : "memory");
100}
101
102#endif
uint32_t inl(uint32_t port)
Inputs 4 bytes from the specified port.
Definition io.h:74
uint16_t inw(uint32_t port)
Inputs 2 bytes from the specified port.
Definition io.h:52
void outw(uint32_t port, uint16_t value)
Outputs 2 bytes to the specified port.
Definition io.h:43
uint8_t inb(uint16_t port)
Inputs a byte from the specified port.
Definition io.h:31
void outb(uint16_t port, uint8_t value)
Outputs a byte to the specified port.
Definition io.h:22
void outl(uint32_t port, uint32_t value)
Outputs 4 bytes to the specified port.
Definition io.h:65
void io_wait(void)
Write 0 to unused port 0x80 to perform a short pause.
Definition io.h:83