implemented a logger

This commit is contained in:
antifallobst 2023-01-25 22:36:34 +01:00
parent a49a17b22c
commit 44f5ceaeaa
6 changed files with 127 additions and 1 deletions

View File

@ -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 ]=====!"

25
kernel/inc/utils/io.h Normal file
View File

@ -0,0 +1,25 @@
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#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

35
kernel/inc/utils/logger.h Normal file
View File

@ -0,0 +1,35 @@
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#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

View File

@ -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");
}

26
kernel/src/utils/io.c Normal file
View File

@ -0,0 +1,26 @@
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#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;
}

38
kernel/src/utils/logger.c Normal file
View File

@ -0,0 +1,38 @@
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#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");
}