From 4b028524f01ba53f39e13805c782956d5f9e60c1 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 11 Aug 2021 23:18:43 +0200 Subject: [PATCH] Fixed kernel compiling & linking problems --- compile.sh | 12 ++++++------ src/bootloader.asm | 2 +- src/kernel.c | 6 ++---- src/lib/vga.c | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/compile.sh b/compile.sh index 57f142e..a1a90f3 100755 --- a/compile.sh +++ b/compile.sh @@ -6,11 +6,11 @@ fail="[FAIL]" srcDir=src binDir=bin -echo -n "Compiling bootloader... " -nasm -f bin $srcDir/bootloader.asm -i $srcDir -o $binDir/bootloader.bin && echo $done +echo "Compiling bootloader... " +nasm -f bin $srcDir/bootloader.asm -i $srcDir -o $binDir/bootloader.bin -echo -n "Compiling kernel... " -gcc -ffreestanding -c $srcDir/kernel.c -o $binDir/kernel.o && ld -o $binDir/kernel.bin -Ttext 0x1000 $binDir/kernel.o --oformat binary 2>/dev/null && echo $done +echo "Compiling kernel... " +gcc -fno-pie -m32 -Os -ffreestanding -c $srcDir/kernel.c -o $binDir/kernel.o && gcc -o $binDir/kernel.bin $binDir/kernel.o -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 -echo -n "Creating OS image... " -cat $binDir/bootloader.bin $binDir/kernel.bin > $binDir/os-image && echo $done +echo "Creating OS image... " +cat $binDir/bootloader.bin $binDir/kernel.bin > $binDir/os-image diff --git a/src/bootloader.asm b/src/bootloader.asm index b477677..c568288 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -38,7 +38,7 @@ BEGIN_PM: load_kernel: mov bx, KERNEL_OFFSET ; Load kernel at the kernel offset - mov dh, 15 ; Read 15 sectors + mov dh, 7 ; Read 15 sectors mov dl, [BOOT_DRIVE] ; Drive index call disk_read ; Load the kernel diff --git a/src/kernel.c b/src/kernel.c index 4fbba34..b4a3ac0 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,8 +1,6 @@ -//#include "lib/vga.c" +#include "lib/vga.c" void main() { // Do kernel stuff - char* vidmem = (char*)(0xb8000); - *vidmem = 'X'; - //println("C-Printing test!", 16); + println("C-Printing test!", 16); } diff --git a/src/lib/vga.c b/src/lib/vga.c index ae2407a..7a65b68 100644 --- a/src/lib/vga.c +++ b/src/lib/vga.c @@ -10,11 +10,11 @@ char* get_cursor_pos(unsigned int row, unsigned int col) { return (char*)(VIDEO_ void print(char* str, unsigned int str_len) { for( unsigned int i = 0; i < str_len; i++ ) { - *get_cursor_pos(i, cursor_y) = str[i]; // write to video memory + *get_cursor_pos(cursor_y, i) = 'X'; // write to video memory } } void println(char* str, unsigned int str_len) { print(str, str_len); - cursor_y++; // Increment to next y-pos (newline) + cursor_y++; // Increment to next y-pos (newline) }