diff --git a/include/kernaux/arch/x86_64.h b/include/kernaux/arch/x86_64.h index 73afd64..7127d4e 100644 --- a/include/kernaux/arch/x86_64.h +++ b/include/kernaux/arch/x86_64.h @@ -5,6 +5,8 @@ extern "C" { #endif +#include + #ifdef __cplusplus } #endif diff --git a/include/kernaux/asm/x86_64.h b/include/kernaux/asm/x86_64.h index 6f71e0c..fcf3564 100644 --- a/include/kernaux/asm/x86_64.h +++ b/include/kernaux/asm/x86_64.h @@ -9,6 +9,64 @@ extern "C" { void kernaux_asm_x86_64_hang() __attribute__((noreturn)); +inline static uint8_t kernaux_asm_x86_64_inportb(uint16_t port); +inline static uint16_t kernaux_asm_x86_64_inportw(uint16_t port); +inline static uint32_t kernaux_asm_x86_64_inportd(uint16_t port); +inline static uint64_t kernaux_asm_x86_64_inportq(uint16_t port); + +inline static void kernaux_asm_x86_64_outportb(uint16_t port, uint8_t value); +inline static void kernaux_asm_x86_64_outportw(uint16_t port, uint16_t value); +inline static void kernaux_asm_x86_64_outportd(uint16_t port, uint32_t value); +inline static void kernaux_asm_x86_64_outportq(uint16_t port, uint64_t value); + +uint8_t kernaux_asm_x86_64_inportb(const uint16_t port) +{ + register uint8_t result; + __asm__ volatile("inb %1, %0" : "=a" (result) : "dN" (port)); + return result; +} + +uint16_t kernaux_asm_x86_64_inportw(const uint16_t port) +{ + register uint16_t result; + __asm__ volatile("inw %1, %0" : "=a" (result) : "dN" (port)); + return result; +} + +uint32_t kernaux_asm_x86_64_inportd(const uint16_t port) +{ + register uint32_t result; + __asm__ volatile("ind %1, %0" : "=a" (result) : "dN" (port)); + return result; +} + +uint64_t kernaux_asm_x86_64_inportq(const uint16_t port) +{ + register uint64_t result; + __asm__ volatile("inq %1, %0" : "=a" (result) : "dN" (port)); + return result; +} + +void kernaux_asm_x86_64_outportb(const uint16_t port, const uint8_t value) +{ + __asm__ volatile("outb %1, %0" : : "dN" (port), "a" (value)); +} + +void kernaux_asm_x86_64_outportw(const uint16_t port, const uint16_t value) +{ + __asm__ volatile("outw %1, %0" : : "dN" (port), "a" (value)); +} + +void kernaux_asm_x86_64_outportd(const uint16_t port, const uint32_t value) +{ + __asm__ volatile("outd %1, %0" : : "dN" (port), "a" (value)); +} + +void kernaux_asm_x86_64_outportq(const uint16_t port, const uint64_t value) +{ + __asm__ volatile("outq %1, %0" : : "dN" (port), "a" (value)); +} + #ifdef __cplusplus } #endif diff --git a/src/console.c b/src/console.c index cff793b..85dc606 100644 --- a/src/console.c +++ b/src/console.c @@ -5,6 +5,9 @@ #ifdef ASM_I386 #include #endif +#ifdef ASM_X86_64 +#include +#endif #include #include @@ -15,6 +18,9 @@ void kernaux_console_putc(const char c __attribute__((unused))) #ifdef ASM_I386 kernaux_asm_i386_outportb(0x3F8, c); #endif +#ifdef ASM_X86_64 + kernaux_asm_x86_64_outportb(0x3F8, c); +#endif } void kernaux_console_print(const char *const s)