diff options
Diffstat (limited to 'kernel/features/logger.c')
-rw-r--r-- | kernel/features/logger.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/kernel/features/logger.c b/kernel/features/logger.c new file mode 100644 index 0000000..7db9a82 --- /dev/null +++ b/kernel/features/logger.c @@ -0,0 +1,42 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#include <cpu.h> +#include <def.h> +#include <errno.h> +#include <io.h> +#include <logger.h> +#include <mem.h> +#include <print.h> +#include <serial.h> + +static res logger_write(const void *buf, u32 offset, u32 count) +{ + if (offset) + return -EINVAL; + + if (!count) + return EOK; + + print_prefix(); + + u32 i; + stac(); + for (i = 0; i < count; i++) { + if (!((const u8 *)buf)[i]) + break; + + serial_put(((const u8 *)buf)[i]); + } + clac(); + + serial_print("\x1B[0m"); + + return i; +} + +void logger_install(void) +{ + struct io_dev *dev = zalloc(sizeof(*dev)); + dev->write = logger_write; + io_add(IO_LOGGER, dev); +} |