From e92cc8877f0467fb8ec961a601aa9c1edb876c07 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Mon, 12 Jul 2021 20:03:55 +0200 Subject: [PATCH] feat(serial): add write Signed-off-by: Julien CLEMENT --- k/serial.c | 12 +++++++++++- k/serial.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/k/serial.c b/k/serial.c index 1ef073d..79cab30 100644 --- a/k/serial.c +++ b/k/serial.c @@ -22,5 +22,15 @@ void serial_init(void) int write(const char *buf, size_t count) { - return 0; + int sent; + + for(sent = 0; sent < count; ++sent) + { + u8 line_status = inb(COM1 + 5); + if (!line_status & EMPTY_TRANSMITTER) + break; + outb(COM1, buf[sent]); + } + + return sent; } diff --git a/k/serial.h b/k/serial.h index d3b1f71..65e83c1 100644 --- a/k/serial.h +++ b/k/serial.h @@ -18,6 +18,8 @@ #define DLAB (0x1 << 7) +#define EMPTY_TRANSMITTER (0x1 << 5) + void serial_init(void); int write(const char *buf, size_t count);