mirror of https://github.com/tailix/libkernaux.git
Implement serial console for x86_64
This commit is contained in:
parent
a793875c40
commit
67b3469318
|
@ -5,6 +5,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,6 +9,64 @@ extern "C" {
|
||||||
|
|
||||||
void kernaux_asm_x86_64_hang() __attribute__((noreturn));
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
#ifdef ASM_I386
|
#ifdef ASM_I386
|
||||||
#include <kernaux/asm/i386.h>
|
#include <kernaux/asm/i386.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ASM_X86_64
|
||||||
|
#include <kernaux/asm/x86_64.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <kernaux/console.h>
|
#include <kernaux/console.h>
|
||||||
#include <kernaux/libc.h>
|
#include <kernaux/libc.h>
|
||||||
|
@ -15,6 +18,9 @@ void kernaux_console_putc(const char c __attribute__((unused)))
|
||||||
#ifdef ASM_I386
|
#ifdef ASM_I386
|
||||||
kernaux_asm_i386_outportb(0x3F8, c);
|
kernaux_asm_i386_outportb(0x3F8, c);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ASM_X86_64
|
||||||
|
kernaux_asm_x86_64_outportb(0x3F8, c);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void kernaux_console_print(const char *const s)
|
void kernaux_console_print(const char *const s)
|
||||||
|
|
Loading…
Reference in New Issue