diff --git a/build.sh b/build.sh index 4fd8744..5eb6822 100755 --- a/build.sh +++ b/build.sh @@ -58,7 +58,7 @@ generate_image() { } emulate() { - qemu-system-x86_64 -cdrom build/noxos.iso + qemu-system-x86_64 -cdrom build/noxos.iso -chardev stdio,id=log,logfile=noxos.log -serial chardev:log } echo "!=====[ NoxOS build script ]=====!" diff --git a/kernel/inc/utils/io.h b/kernel/inc/utils/io.h new file mode 100644 index 0000000..a3f5e1a --- /dev/null +++ b/kernel/inc/utils/io.h @@ -0,0 +1,25 @@ +/* Copyright (C) Antifallobst + * + * NoxOS is free software: + * you can redistribute it and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * NoxOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. + * If not, see . + */ + +#ifndef NOX_IO_H +#define NOX_IO_H + +#include "stdtypes.h" + +// sends one byte to a port +void io_out_byte (uint16_t port, uint8_t data); +uint8_t io_in_byte (uint16_t port); + +#endif //NOX_IO_H diff --git a/kernel/inc/utils/logger.h b/kernel/inc/utils/logger.h new file mode 100644 index 0000000..f118f9f --- /dev/null +++ b/kernel/inc/utils/logger.h @@ -0,0 +1,35 @@ +/* Copyright (C) Antifallobst + * + * NoxOS is free software: + * you can redistribute it and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * NoxOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. + * If not, see . + */ + +#ifndef NOX_LOGGER_H +#define NOX_LOGGER_H + +#include "string.h" + +#define LOG_PORT 0x3F8 + +typedef enum { + LOG_INFO, + LOG_DEBUG, + LOG_WARNING, + LOG_ERROR, + + LOG_ENUM_END +} log_level_E; + +// logs a string to qemu's serial port +void log(log_level_E log_level, string_t string); + +#endif //NOX_LOGGER_H diff --git a/kernel/src/kmain.c b/kernel/src/kmain.c index 33a40c1..f21c933 100644 --- a/kernel/src/kmain.c +++ b/kernel/src/kmain.c @@ -14,6 +14,7 @@ */ #include "utils/stdtypes.h" +#include "utils/logger.h" #include "boot/limine.h" static volatile struct limine_terminal_request terminal_request = { @@ -30,6 +31,7 @@ void _start() { struct limine_terminal* terminal = terminal_request.response->terminals[0]; terminal_request.response->write(terminal, "Booting NoxOS...", 16); + log(LOG_DEBUG, "Booting NoxOS"); while(true) asm("hlt"); } diff --git a/kernel/src/utils/io.c b/kernel/src/utils/io.c new file mode 100644 index 0000000..6cfb015 --- /dev/null +++ b/kernel/src/utils/io.c @@ -0,0 +1,26 @@ +/* Copyright (C) Antifallobst + * + * NoxOS is free software: + * you can redistribute it and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * NoxOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. + * If not, see . + */ + +#include "utils/io.h" + +void io_out_byte(uint16_t port, uint8_t data) { + asm volatile ("outb %0, %1" : : "a"(data), "Nd"(port)); +} + +uint8_t io_in_byte(uint16_t port) { + uint8_t data; + asm volatile ("inb %1, %0" : "=a"(data) : "Nd"(port)); + return data; +} \ No newline at end of file diff --git a/kernel/src/utils/logger.c b/kernel/src/utils/logger.c new file mode 100644 index 0000000..fadf915 --- /dev/null +++ b/kernel/src/utils/logger.c @@ -0,0 +1,38 @@ +/* Copyright (C) Antifallobst + * + * NoxOS is free software: + * you can redistribute it and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * NoxOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. + * If not, see . + */ + +#include "utils/logger.h" +#include "utils/io.h" + +string_t log_prefixes[LOG_ENUM_END] = { + "[ Info ] ", + "[ Debug ] ", + "[ Warning ] ", + "[ Error ] ", +}; + +void log_send_string_to_port(string_t str) { + char* c = (char*)str; + while (*c != '\0') { + io_out_byte(LOG_PORT, *c); + c++; + } +} + +void log(log_level_E log_level, string_t str) { + log_send_string_to_port(log_prefixes[log_level]); + log_send_string_to_port(str); + log_send_string_to_port("\n"); +} \ No newline at end of file