feat(drivers): add port I/O helpers and serial COM1 driver

This commit is contained in:
dualfroz committed 2026-08-23 23:10:38 +02:00
1 parent c111550d0e
commit 803eeab7ec
3 files changed
+111

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
#ifndef FROSTBYTE_PORTS_H
#define FROSTBYTE_PORTS_H
#include "types.h"
static inline void outb(uint16 port, uint8 value)
{
__asm__ volatile("outb %0, %1" : : "a"(value), "Nd"(port));
}
static inline uint8 inb(uint16 port)
{
uint8 value;
__asm__ volatile("inb %1, %0" : "=a"(value) : "Nd"(port));
return value;
}
static inline void outw(uint16 port, uint16 value)
{
__asm__ volatile("outw %0, %1" : : "a"(value), "Nd"(port));
}
static inline uint16 inw(uint16 port)
{
uint16 value;
__asm__ volatile("inw %1, %0" : "=a"(value) : "Nd"(port));
return value;
}
static inline void ioWait(void)
{
outb(0x80, 0);
}
static inline uint64 readFlags(void)
{
uint64 flags;
__asm__ volatile("pushfq; popq %0" : "=r"(flags));
return flags;
}
static inline void enableInterrupts(void)
{
__asm__ volatile("sti");
}
static inline uint64 saveAndDisableInterrupts(void)
{
uint64 flags = readFlags();
__asm__ volatile("cli");
return flags;
}
static inline void restoreInterrupts(uint64 flags)
{
if (flags & (1u << 9))
__asm__ volatile("sti");
}
static inline void halt(void)
{
__asm__ volatile("hlt");
}
#endif
+10
View File
@@ -0,0 +1,10 @@
#ifndef FROSTBYTE_SERIAL_H
#define FROSTBYTE_SERIAL_H
#include "types.h"
void serialInit(void);
void serialWrite(char c);
void serialWriteString(const char* str);
#endif