From 5180348c39b5237c9afbc99d42320d1b7f6a4361 Mon Sep 17 00:00:00 2001 From: Eric-Paul Ickhorn Date: Sun, 16 Jun 2024 23:07:51 +0200 Subject: [PATCH] Add stage 2 loader entry point This commit adds the entry point for the second stage of the loader. It currently doesn't contain a lot of code, but it will have to expand in the next bit of time. --- i386/bootsector/bootsector.asm | 2 +- i386/loader/src-asm/entry.asm | 88 ++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100755 i386/loader/src-asm/entry.asm diff --git a/i386/bootsector/bootsector.asm b/i386/bootsector/bootsector.asm index 1ca9116..45ce4fe 100644 --- a/i386/bootsector/bootsector.asm +++ b/i386/bootsector/bootsector.asm @@ -180,7 +180,7 @@ load_partition: jump_to_partition: - jmp 0x0000:0xa000 + jmp 0x0a00:0x0000 cli hlt diff --git a/i386/loader/src-asm/entry.asm b/i386/loader/src-asm/entry.asm new file mode 100755 index 0000000..3fde6c1 --- /dev/null +++ b/i386/loader/src-asm/entry.asm @@ -0,0 +1,88 @@ +; entry.asm: Entrypoint for the loader partition of the Nightloader. + +; WARNING: Never import at the top of this file! +; If something has to be included, include it at the bottom! + +STACK_SIZE equ 32768 +UPPER_STACK_POINTER equ 0x100000 +LOWER_STACK_POINTER equ (UPPER_STACK_POINTER - STACK_SIZE) + +bits 16 +org 0xa000 +entry: + mov ebx, LOWER_STACK_POINTER + mov ss, ebx + mov esp, STACK_SIZE + mov ebp, STACK_SIZE + push dx + +.check_a20: + push ebp + mov ebp, esp + call check_a20_wraparound + mov esp, ebp + pop ebp + cmp eax, 1 + je .a20_is_enabled + + cli + hlt + +.a20_is_enabled: + ; jmp .flat_gdt_loaded + + ; Reset Display + mov ah, 0x00 + mov al, 0x03 + int 0x10 + + ; mov ah, 0x05 + ; mov al, 0 + ; int 0x10 + + mov ah, 0x0b + mov bh, 0x00 + mov bl, 0 + int 0x10 + + push ebp + mov ebp, esp + call setup_drivers + mov esp, ebp + pop ebp + + mov edi, ebp + mov esi, esp + push ebp + mov ebp, esp + push .flat_gdt_loaded + call load_flat_gdt + mov esp, ebp + pop ebp +.flat_gdt_loaded: + mov ebp, edi + mov esp, esi + + mov ebx, some_text + push ebp + mov ebp, esp + push dword ebx + call dword write_text + mov esp, ebp + pop ebp + + cli + hlt +some_text: + db "This is some text.", 0x00 + +; Utilities +%include "utility/math.asm" +%include "utility/memory.asm" + +; Memory Management +%include "memory/a20.asm" +%include "memory/gdt.asm" + +; Driver Manager +; %include "drivers/manager.asm"