From d1659e68ad49af2cb00a45d2f287ab1a631630cc Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 9 Aug 2021 18:46:01 +0200 Subject: [PATCH 1/6] Comment cleanup --- src/pm/gdt.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 34a4d93970e15af3f015833d509ddc5fde9493ea Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Mon, 9 Aug 2021 20:31:44 +0200 Subject: [PATCH 2/6] gitignore update --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ac4d450..aab04f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin/ *.bin +*.o From fe69547f2df151b371acdd99adb7167842382136 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 10 Aug 2021 23:07:19 +0200 Subject: [PATCH 3/6] Kernel & compiling script rework --- compile.sh | 12 +++++++++++- src/kernel.c | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/kernel.c 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/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'; +} From e7adf5528ece442df38998bd2267f484de8773a6 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 10 Aug 2021 23:18:44 +0200 Subject: [PATCH 4/6] Status strings --- src/bootloader.asm | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index bcf841c..b7149f9 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -1,11 +1,16 @@ [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 + call load_kernel + ; Switching to PM call pm_preinit @@ -21,7 +26,23 @@ BEGIN_PM: 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 + +welcome_string: db "e Operating-System (eOS): Version 2021 0.0", ASCII_END + +stat_realmode: db "Entering 16bit Real Mode...", ASCII_END +stat_pm_init: db "Entering 32bit Protected Mode...", ASCII_END + +stat_success: db " [OK]", ASCII_CARRIAGE_RETURN, ASCII_NEWLINE, ASCII_END + BOOT_DRIVE: db 0 ; Bootsector From 1bba97155d63134defda98642466922d917c07b4 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 10 Aug 2021 23:31:36 +0200 Subject: [PATCH 5/6] Kernel loading --- src/bootloader.asm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index b7149f9..9b16829 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -9,9 +9,13 @@ 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 @@ -21,13 +25,14 @@ %include "pm.asm" BEGIN_PM: - mov ebx, welcome_string + mov ebx, stat_pm_init call vga_print jmp $ [bits 16] + load_kernel: mov bx, KERNEL_OFFSET ; Load kernel at the kernel offset mov dh, 15 ; Read 15 sectors @@ -36,12 +41,9 @@ load_kernel: ret -welcome_string: db "e Operating-System (eOS): Version 2021 0.0", ASCII_END - -stat_realmode: db "Entering 16bit Real Mode...", ASCII_END stat_pm_init: db "Entering 32bit Protected Mode...", ASCII_END - -stat_success: db " [OK]", ASCII_CARRIAGE_RETURN, ASCII_NEWLINE, ASCII_END +stat_kernel_load: db "Loading kernel into memory...", ASCII_END +stat_boot_success: db "Booting complete!", ASCII_END BOOT_DRIVE: db 0 From dbedf6f6c1b17d354b74ca640fff6b1c15ff35d6 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Tue, 10 Aug 2021 23:40:25 +0200 Subject: [PATCH 6/6] More kernel stuff --- src/bootloader.asm | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index 9b16829..c66640c 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -30,7 +30,6 @@ BEGIN_PM: jmp $ - [bits 16] load_kernel: