diff --git a/.gitignore b/.gitignore index ac4d450..aab04f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin/ *.bin +*.o diff --git a/compile.sh b/compile.sh index b009096..ccdc9cd 100755 --- a/compile.sh +++ b/compile.sh @@ -1,6 +1,16 @@ #!/usr/bin/bash +done="[OK]" +fail="[FAIL]" + srcDir=src binDir=bin -nasm -f bin $srcDir/bootloader.asm -i $srcDir -o $binDir/bootloader.bin +echo -n "Compiling bootloader... " +nasm -f bin $srcDir/bootloader.asm -i $srcDir -o $binDir/bootloader.bin && echo $done + +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 -n "Creating kernel image... " +cat $binDir/bootloader.bin $binDir/kernel.bin > $binDir/os-image && echo $done diff --git a/src/bootloader.asm b/src/bootloader.asm index bcf841c..c66640c 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -1,12 +1,21 @@ [org 0x7c00] ; bootsector + KERNEL_OFFSET equ 0x1000 + ; Save the boot drive index mov [BOOT_DRIVE], dl ; Move the stack pointer somewhere safe - mov bp, 0x8000 ; move it to 0x8000 + mov bp, 0x9000 ; move it to 0x8000 mov sp, bp + ; Load kernel into memory + mov bx, stat_kernel_load + call println + call load_kernel + ; Switching to PM + mov bx, stat_pm_init + call println call pm_preinit jmp $ ; inf loop @@ -16,12 +25,25 @@ %include "pm.asm" BEGIN_PM: - mov ebx, welcome_string + mov ebx, stat_pm_init call vga_print jmp $ -welcome_string: db "e Operating-System (eOS): Version 2021 0.0", ASCII_END +[bits 16] + +load_kernel: + mov bx, KERNEL_OFFSET ; Load kernel at the kernel offset + mov dh, 15 ; Read 15 sectors + mov dl, [BOOT_DRIVE] ; Drive index + call disk_read ; Load the kernel + + ret + +stat_pm_init: db "Entering 32bit Protected Mode...", ASCII_END +stat_kernel_load: db "Loading kernel into memory...", ASCII_END +stat_boot_success: db "Booting complete!", ASCII_END + BOOT_DRIVE: db 0 ; Bootsector diff --git a/src/kernel.c b/src/kernel.c new file mode 100644 index 0000000..c5bc72d --- /dev/null +++ b/src/kernel.c @@ -0,0 +1,7 @@ +// VGA base address: 0xb8000 +// Charpos = 0xb8000 + 2(row*80 + col) + +void main() { + char* video_mem = (char*)0xb8000; // VGA Video Memory location + *video_mem = 'X'; +} diff --git a/src/pm/gdt.asm b/src/pm/gdt.asm index 4023658..4c73f1d 100644 --- a/src/pm/gdt.asm +++ b/src/pm/gdt.asm @@ -34,8 +34,8 @@ gdt_end: ; Mark the end so we can get the delta-memory (size of GDT) ; GDT descriptor gdt_descriptor: - dw gdt_end - gdt_start - 1 ; Size of GDT is always -1 of actual size (WHY?!?!?!?!??!) - dd gdt_start ; Pointer to the GDT + dw gdt_end - gdt_start - 1 ; GDT size + dd gdt_start ; GDT pointer ; Lazy constants