1#ifndef KERNEL_ARCH_I686_UTILS_CPU_OPS_H
2#define KERNEL_ARCH_I686_UTILS_CPU_OPS_H
4#include <kernel/types.h>
6#include <utils/compiler.h>
10#define READ_REGISTER_OPS(_reg) \
11 static ALWAYS_INLINE u32 read_##_reg() \
14 ASM("movl %%" #_reg ", %0" : "=r"(res)); \
19#define WRITE_REGISTER_OPS(_reg) \
20 static ALWAYS_INLINE void write_##_reg(u32 value) \
22 ASM("movl %0, %%" #_reg : : "r"(value)); \
25#define CPU_32BIT_REGISTERS \
26 cr0, cr1, cr2, cr3, cr4, esp, cs, ds, es, fs, gs, ss, eax
28MAP(READ_REGISTER_OPS, CPU_32BIT_REGISTERS)
29MAP(WRITE_REGISTER_OPS, CPU_32BIT_REGISTERS)
31#undef CPU_32BIT_REGISTERS
32#undef WRITE_REGISTER_OPS
33#undef READ_REGISTER_OPS
36static ALWAYS_INLINE
void outb(uint16_t port, uint8_t val)
38 ASM(
"out %0,%1" : :
"a"(val),
"Nd"(port) :
"memory");
42static ALWAYS_INLINE
void outw(uint16_t port, uint16_t val)
44 ASM(
"out %0,%1" : :
"a"(val),
"Nd"(port) :
"memory");
48static ALWAYS_INLINE
void outl(uint16_t port, uint32_t val)
50 ASM(
"out %0,%1" : :
"a"(val),
"Nd"(port) :
"memory");
54static ALWAYS_INLINE uint8_t inb(uint16_t port)
57 ASM(
"in %1, %0" :
"=a"(val) :
"Nd"(port) :
"memory");
62static ALWAYS_INLINE uint16_t inw(uint16_t port)
65 ASM(
"in %1, %0" :
"=a"(val) :
"Nd"(port) :
"memory");
70static ALWAYS_INLINE uint32_t inl(uint16_t port)
73 ASM(
"in %1,%0" :
"=a"(val) :
"Nd"(port) :
"memory");
77static ALWAYS_INLINE
void hlt(
void)
82static ALWAYS_INLINE
void insb(uint16_t port, uint8_t *buffer,
size_t size)
84 size_t count = size /
sizeof(*buffer);
86 asm volatile(
"cld; rep insb"
87 :
"+D"(buffer),
"+c"(count)
92static ALWAYS_INLINE
void insw(uint16_t port, uint16_t *buffer,
size_t size)
94 size_t count = size /
sizeof(*buffer);
96 asm volatile(
"cld; rep insw"
97 :
"+D"(buffer),
"+c"(count)
102static ALWAYS_INLINE
void insl(uint16_t port, uint32_t *buffer,
size_t size)
104 size_t count = size /
sizeof(*buffer);
106 asm volatile(
"cld; rep insl"
107 :
"+D"(buffer),
"+c"(count)
#define MAP(f,...)
Applies the function macro f to each of the remaining parameters.
Definition: map.h:60