From 6a020aeeee7ce01875f0632a6f31a316b320e3a5 Mon Sep 17 00:00:00 2001 From: Nocturn9x Date: Fri, 18 Nov 2022 02:40:46 +0100 Subject: [PATCH] Added kprintln and memset --- include/kernel/drivers/vga/screen.h | 1 + include/kernel/types.h | 8 +++++++- include/kernel/util.h | 3 ++- src/boot/mbr.s | 2 +- src/kernel/drivers/vga/screen.c | 9 +++++++++ src/kernel/main.c | 6 +++--- src/kernel/util.c | 13 +++++++++++++ 7 files changed, 36 insertions(+), 6 deletions(-) diff --git a/include/kernel/drivers/vga/screen.h b/include/kernel/drivers/vga/screen.h index 8f7b4f8..5200000 100644 --- a/include/kernel/drivers/vga/screen.h +++ b/include/kernel/drivers/vga/screen.h @@ -41,6 +41,7 @@ limitations under the License. void clearScreen(void); void kprintAt(char* message, i32 col, i32 row); void kprint(char* message); +void kprintln(char* message); #endif \ No newline at end of file diff --git a/include/kernel/types.h b/include/kernel/types.h index 2fbf3a5..890fd58 100644 --- a/include/kernel/types.h +++ b/include/kernel/types.h @@ -22,7 +22,13 @@ limitations under the License. #define true 1 #define false 0 -typedef unsigned char byte; +// Some of these are duplicates, but their meaning +// is purely contextual (to make it clearer what is +// what in a given function) + +typedef char i8; +typedef char byte; +typedef unsigned char u8; typedef unsigned short int u16; typedef short int i16; typedef unsigned int u32; diff --git a/include/kernel/util.h b/include/kernel/util.h index 4823221..0654017 100644 --- a/include/kernel/util.h +++ b/include/kernel/util.h @@ -20,6 +20,7 @@ limitations under the License. #include "kernel/types.h" void copystr(const char* source, char* dest, i32 n); -void itoa(i32 i, char* a); +void memset(u8* dest, u8 val, u32 len); +void itoa(const i32 i, char* a); #endif \ No newline at end of file diff --git a/src/boot/mbr.s b/src/boot/mbr.s index 6a129c4..8fde586 100644 --- a/src/boot/mbr.s +++ b/src/boot/mbr.s @@ -58,7 +58,7 @@ load_kernel: ; Loads the kernel into memory mov si, loading_kernel_msg call bios_println mov bx, kernel_offset - mov dh, 3 + mov dh, 4 mov dl, [boot_drive] call load_disk ret diff --git a/src/kernel/drivers/vga/screen.c b/src/kernel/drivers/vga/screen.c index e12d360..b4295a4 100644 --- a/src/kernel/drivers/vga/screen.c +++ b/src/kernel/drivers/vga/screen.c @@ -68,6 +68,15 @@ void kprint(char* message) { } +void inline kprintln(char* message) { + /* + Identical to kprint, but calls + kprint("\n") afterwards + */ + kprint(message); + kprint("\n"); +} + // Private API below i32 putchar(byte ch, i32 col, i32 row, byte attr) { diff --git a/src/kernel/main.c b/src/kernel/main.c index f1af790..7cfbfeb 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -24,9 +24,9 @@ i32 kmain(void) { The kernel entry point of TSOS */ - // Newline so we skip the log - // messages from the bootloader - kprint("\nTSOS: Kernel load OK"); + // We skip the log messages from + // the bootloader + kprintln("\n\n\n\nTSOS: Kernel load OK"); // TODO... return 0x022172; // :D } \ No newline at end of file diff --git a/src/kernel/util.c b/src/kernel/util.c index e237d29..8b0cb3a 100644 --- a/src/kernel/util.c +++ b/src/kernel/util.c @@ -17,6 +17,7 @@ limitations under the License. #include "kernel/types.h" #include "kernel/util.h" + void copystr(const char* restrict source, char* restrict dest, i32 n) { /* Copies n bytes from source to dest. The two memory locations may @@ -34,6 +35,18 @@ void copystr(const char* restrict source, char* restrict dest, i32 n) { } +void memset(u8* dest, u8 val, u32 len) { + /* + Implementation for memset + */ + u8* temp = (u8*)dest; + while (len) { + *temp++ = val; + len--; + } +} + + i32 countDigits(i32 n) { /* Returns the number of digits