vbos/amd64/drivers/serial.c
Michael Shaw a252a3f8e9 kv2: initialize memory manager, early pci devices
Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
2026-05-12 03:00:45 -04:00

60 lines
1.1 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/common.h>
#include <kernel/device.h>
#include <drivers/serial.h>
#include <drivers/pio.h>
#include <drivers/tty.h>
#include <lib/stdio.h>
static int num_serial_ports = 0;
void init_serial_port(int port)
{
outb(port | 1, 0x00);
outb(port | 3, 0x80);
outb(port | 0, 0x01);
outb(port | 1, 0x00);
outb(port | 3, 0x03);
outb(port | 2, 0xC7);
outb(port | 4, 0x0B);
outb(port | 4, 0x1E);
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;
}
outb(port | 1, 0x01); /* Enable interrupts */
outb(port | 4, 0x0F); /* Enter normal operation */
char name[256];
}
void *arch_serial_init()
{
return (void *)COM1;
}
void arch_serial_write(struct tty *tty, char c)
{
/* Wait for line to be clear */
size_t port = (size_t)tty->priv;
while ((inb(port + 5) & 0x20) == 0)
;
outb(port, c);
}
char arch_serial_read(struct tty *tty)
{
size_t port = (size_t)tty->priv;
while ((inb(port + 5) & 1) == 0)
;
return inb(port);
}