amd64: serial: register tty in serial driver

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-11 23:54:15 -04:00
commit bba8fc7476
3 changed files with 23 additions and 7 deletions

View file

@ -28,7 +28,7 @@ void arch_early_init()
cr4 |= (1 << 9) | (1 << 10);
cr4_write(cr4);
tty_early.serial_ops = &tty_early_ops;
tty_early.serial_ops = tty_early_ops;
tty_early.priv = (void *)COM1;
tty_printf = &tty_early;

View file

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/common.h>
#include <kernel/device.h>
#include <kernel/slab.h>
#include <drivers/serial.h>
#include <drivers/pio.h>
@ -30,11 +31,6 @@ void init_serial_port(int port)
outb(port | 4, 0x0F); /* Enter normal operation */
}
void *arch_serial_init()
{
return (void *)COM1;
}
void arch_serial_write(struct tty *tty, char c)
{
/* Wait for line to be clear */
@ -54,3 +50,23 @@ char arch_serial_read(struct tty *tty)
return inb(port);
}
int serial_port_tty_init(struct tty **out)
{
init_serial_port(COM1);
*out = kalloc(sizeof(struct tty), ALLOC_KERN);
if (!(*out))
return -ENOMEM;
(*out)[0].priv = (void *)COM1;
(*out)[0].serial_ops.serial_getchar = arch_serial_read;
(*out)[0].serial_ops.serial_putchar = arch_serial_write;
dev_t com1 = device_create((*out + 0), DEV_CLASS_TTY, "ttyS0");
(*out)[0].dev = com1;
return 1;
}

View file

@ -7,6 +7,6 @@
#include <kernel/device.h>
void *arch_serial_init();
int serial_port_tty_init(struct tty **out);
#endif /* _SERIAL_H_ */