GDT finally works

This commit is contained in:
2025-08-10 21:29:16 +02:00
parent f8f00cc608
commit 8ee1ea1292
36 changed files with 868 additions and 206 deletions

View File

@ -0,0 +1,50 @@
#include <stdint.h>
#include <stdbool.h>
#define SERIAL_PORT 0x3f8
extern uint8_t serial_inb(uint16_t port);
extern void serial_outb(uint16_t port, uint8_t value);
static int serial_received(void) {
return serial_inb(SERIAL_PORT + 5) & 1;
}
static uint8_t serial_read(void) {
while (serial_received() == 0);
return serial_inb(SERIAL_PORT);
}
static int serial_trans_empty(void) {
return serial_inb(SERIAL_PORT + 5) & 0x20;
}
static void serial_write(uint8_t value) {
while (!serial_trans_empty());
serial_outb(SERIAL_PORT, value);
}
// REFERENCE: https://wiki.osdev.org/Serial_Ports
bool serial_init(void) {
serial_outb(SERIAL_PORT + 1, 0x00);
serial_outb(SERIAL_PORT + 3, 0x80);
serial_outb(SERIAL_PORT + 0, 0x03);
serial_outb(SERIAL_PORT + 1, 0x00);
serial_outb(SERIAL_PORT + 3, 0x03);
serial_outb(SERIAL_PORT + 2, 0xc7);
serial_outb(SERIAL_PORT + 4, 0x0b);
serial_outb(SERIAL_PORT + 4, 0x1e);
serial_outb(SERIAL_PORT + 0, 0xae);
if (serial_inb(SERIAL_PORT + 0) != 0xae) {
return false;
}
serial_outb(SERIAL_PORT + 4, 0x0f);
return true;
}
// For printf library
void putchar_(char c) {
serial_write(c);
}