feat: cleanup init code, small other refactors

This commit is contained in:
2021-09-01 21:43:21 +02:00
parent e693b12915
commit 073051c99e
21 changed files with 118 additions and 76 deletions

View File

@@ -2,9 +2,10 @@
// Created by rick on 28-01-21.
//
#include <myke/drivers/serial.h>
#include <sys/types.h>
#include <myke/drivers/ports.h>
#include <myke/libk/kprint.h>
#include <myke/util/init.h>
#define SERIAL_INTERRUPT_DATA_AVAILABLE (1 << 0)
#define SERIAL_INTERRUPT_TRANSMITTER_EMPTY (1 << 1)
@@ -51,7 +52,7 @@
#define MODEM_CONTROL_LOOPBACK_MODE (1 << 4)
#define MODEM_CONTROL_AUTOFLOW_CONTROL_ENABLED (1 << 5)
int serial_init() {
int serial_init_hw() {
port_byte_out(PORT_SERIAL_0 + PORT_SERIAL_INTERRUPT, 0); // Disable all interrupts
port_byte_out(PORT_SERIAL_0 + PORT_SERIAL_LINE_CONTROL,
LINE_CONTROL_DIVISOR); // Enable DLAB (set baud rate divisor)
@@ -114,4 +115,17 @@ void serial_kprint(const char *msg) {
write_serial(c);
i++;
}
}
}
void serial_init() {
if (serial_init_hw() != 0) {
return;
}
kprint_register(serial_kprint);
}
INIT_FUNCTION(100) = {
.name = "serial",
.stage = INIT_STAGE_EARLY_BOOT_0,
.init = serial_init,
};