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 c5bc72d..8629a26 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,7 +1,10 @@ -// VGA base address: 0xb8000 -// Charpos = 0xb8000 + 2(row*80 + col) +#include "lib/vga.c" void main() { - char* video_mem = (char*)0xb8000; // VGA Video Memory location - *video_mem = 'X'; + // Do kernel stuff + char* vidmem = (char*)0xb8000; + *vidmem = 'X'; + for( int i = 0; i < 16; i++ ) { + println("C-Printing test!", 16); + } } diff --git a/src/lib/vga.c b/src/lib/vga.c new file mode 100644 index 0000000..d951031 --- /dev/null +++ b/src/lib/vga.c @@ -0,0 +1,22 @@ +// VGA Graphics Library + +// VGA base address: 0xb8000 +// Charpos = 0xb8000 + 2(row*80 + col) + +#define VIDEO_MEM (char*)0xb8000 +#define GET_INDEX(s, c) (int)(c-s) +static int cursor_y = 0; + +char* get_cursor_pos(unsigned int col, unsigned int row) { + return (char*)(VIDEO_MEM + 2*((row*80) + col)); +} + +void print(char* str, unsigned int str_len) { + for( char* c = str; *c != '\0'; c++ ) + *get_cursor_pos( GET_INDEX(str, c), cursor_y ) = 'Y'; +} + +void println(char* str, unsigned int str_len) { + print(str, str_len); + cursor_y++; // Increment to next y-pos (newline) +}