kv2: initialize memory manager, early pci devices

Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
Michael Shaw 2026-05-12 02:59:37 -04:00
commit a252a3f8e9
58 changed files with 1270 additions and 505 deletions

View file

@ -9,15 +9,9 @@
#include <lib/stdio.h>
struct serial_port {
dev_t dev;
int port;
};
static int num_serial_ports = 0;
static struct serial_port serial_ports[32];
static dev_t init_serial_port(int port)
void init_serial_port(int port)
{
outb(port | 1, 0x00);
outb(port | 3, 0x80);
@ -31,49 +25,36 @@ static dev_t init_serial_port(int port)
outb(port | 0, 0xAE); /* Enable loopback mode */
if (inb(port | 0) != 0xAE) { /* Loopback test */
kwarn("Serial port 0x%04x loopback test failed\n", port);
return 1;
return;
}
outb(port | 1, 0x01); /* Enable interrupts */
outb(port | 4, 0x0F); /* Enter normal operation */
char name[256];
snprintf(name, sizeof(name) - 1, "tty%04x", port);
name[sizeof(name) - 1] = 0;
dev_t serial_device = device_create(&serial_ports[num_serial_ports], DEV_CLASS_NATIVE_SERIAL, name);
if (num_serial_ports + 1 < ARRAY_SIZE(serial_ports)) {
serial_ports[num_serial_ports].dev = serial_device;
serial_ports[num_serial_ports].port = port;
num_serial_ports += 1;
}
return serial_device;
}
dev_t arch_serial_init()
void *arch_serial_init()
{
dev_t com1 = init_serial_port(COM1);
return com1;
return (void *)COM1;
}
void arch_serial_write(struct tty *tty, char c)
{
/* Wait for line to be clear */
struct serial_port *serial_port = tty->serial_device_private;
while ((inb(serial_port->port + 5) & 0x20) == 0)
size_t port = (size_t)tty->priv;
while ((inb(port + 5) & 0x20) == 0)
;
outb(serial_port->port, c);
outb(port, c);
}
char arch_serial_read(struct tty *tty)
{
struct serial_port *serial_port = tty->serial_device_private;
size_t port = (size_t)tty->priv;
while ((inb(serial_port->port + 5) & 1) == 0)
while ((inb(port + 5) & 1) == 0)
;
return inb(serial_port->port);
return inb(port);
}