1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-10-30 11:54:01 -04:00
libkernaux/include/kernaux/arch/x86.h

77 lines
2 KiB
C
Raw Normal View History

2020-11-30 05:46:35 -05:00
#ifndef KERNAUX_INCLUDED_ARCH_X86
#define KERNAUX_INCLUDED_ARCH_X86 1
#ifdef __cplusplus
extern "C" {
#endif
inline static unsigned char kernaux_arch_x86_inportb(unsigned short port);
inline static unsigned short kernaux_arch_x86_inportw(unsigned short port);
inline static unsigned int kernaux_arch_x86_inportd(unsigned short port);
inline static void
kernaux_arch_x86_outportb(unsigned short port, unsigned char value);
inline static void
kernaux_arch_x86_outportw(unsigned short port, unsigned short value);
inline static void
kernaux_arch_x86_outportd(unsigned short port, unsigned int value);
void kernaux_arch_x86_hang() __attribute__((noreturn));
unsigned long kernaux_arch_x86_read_cr0();
unsigned long kernaux_arch_x86_read_cr4();
void kernaux_arch_x86_write_cr0(volatile unsigned long value);
void kernaux_arch_x86_write_cr3(volatile unsigned long value);
void kernaux_arch_x86_write_cr4(volatile unsigned long value);
unsigned char kernaux_arch_x86_inportb(const unsigned short port)
{
register unsigned char result;
2020-11-30 06:40:33 -05:00
__asm__ volatile("inb %1, %0" : "=a" (result) : "dN" (port));
2020-11-30 05:46:35 -05:00
return result;
}
unsigned short kernaux_arch_x86_inportw(const unsigned short port)
{
register unsigned short result;
2020-11-30 06:40:33 -05:00
__asm__ volatile("inw %1, %0" : "=a" (result) : "dN" (port));
2020-11-30 05:46:35 -05:00
return result;
}
unsigned int kernaux_arch_x86_inportd(const unsigned short port)
{
register unsigned int result;
2020-11-30 06:40:33 -05:00
__asm__ volatile("ind %1, %0" : "=a" (result) : "dN" (port));
2020-11-30 05:46:35 -05:00
return result;
}
void kernaux_arch_x86_outportb(
const unsigned short port,
const unsigned char value
) {
2020-11-30 06:40:33 -05:00
__asm__ volatile("outb %1, %0" : : "dN" (port), "a" (value));
2020-11-30 05:46:35 -05:00
}
void kernaux_arch_x86_outportw(
const unsigned short port,
const unsigned short value
) {
2020-11-30 06:40:33 -05:00
__asm__ volatile("outw %1, %0" : : "dN" (port), "a" (value));
2020-11-30 05:46:35 -05:00
}
void kernaux_arch_x86_outportd(
const unsigned short port,
const unsigned int value
) {
2020-11-30 06:40:33 -05:00
__asm__ volatile("outd %1, %0" : : "dN" (port), "a" (value));
2020-11-30 05:46:35 -05:00
}
#ifdef __cplusplus
}
#endif
#endif