Nyanix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 5da69eb4b1b97eec7dbc10c2db1022fa1c477a8b
parent e3330369a3c6220d233cebb937ce59304622a9b7
Author: Dani Frisk <dani@silverskin.fi>
Date:   Fri,  3 Aug 2018 13:41:45 +0300

Fixed silly stack bug

Diffstat:
src/2nd_stage.s | 63++++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 48 insertions(+), 15 deletions(-)

diff --git a/src/2nd_stage.s b/src/2nd_stage.s @@ -1,11 +1,21 @@ -; Entry of 2nd stage of the bootloader +; ========================================================================== ; +; Entry of 2nd stage of the bootloader ; +; ========================================================================== ; global _start _start: ; disable interrupts, adjust Stack pointer cli xor bp, bp - mov sp, 0x7e00 + add sp, 0x200 + + ; Back uping Realmode segment & boot device from + ; 1st 512 byte sector. + + mov dl, [BOOT_DEVICE_DB] + mov [BOOT_DEV_DB], dl + mov ds, [REALMODE] + mov [REALMODE_DB], ds ; we'll jump to protected mode now. ; after that, we should _never_ return to real 16-bit mode. @@ -18,10 +28,22 @@ _start: hlt jmp .hang +; ========================================================================== ; +; GDT & few variables ; +; ========================================================================== ; %include "src/gdt32table.s" msg_failed_to_switch_pm db "Failed to swap to protected mode", 0x0A, 0x0D, 0 +BOOT_DEV_DB db 0 +REALMODE_DB db 0 + +MEMORY_LOWER dw 0 +MEMORY_HIGHER dw 0 -; Function to print debug messages in 16-bit real mode +; ========================================================================== ; +; Function to print debug messages in 16-bit real mode. ; +; ; +; param message_in (DI), String to print. ; +; ========================================================================== ; real16_dbg_print: lodsb or al, al @@ -32,7 +54,9 @@ real16_dbg_print: int 0x10 jmp real16_dbg_print -; Function to switch to protected mode +; ========================================================================== ; +; Function to switch to protected mode ; +; ========================================================================== ; switch_to_pm: lgdt [GDT_32_PTR] mov eax, cr0 @@ -57,7 +81,7 @@ main_init: mov gs, ax ; Setting up new stack - mov ebp, 0x90000 + mov ebp, 0x7e00 mov esp, ebp ; disable interrupts @@ -93,10 +117,16 @@ main: cli hlt +; ============================================================================ ; +; We now have enabled A-20 gate. It's time to read the kernel from the disk. ; +; First we'll swap to unreal v8086 mode, load the kernel with BIOS interrupts, ; +; and then swap back to protected 32 bit mode. ; +; We never return from kernel_loader. If we somehow do due error, we'll jump ; +; to the hang. ; +; ============================================================================ ; .a20_enabled: - cli - hlt - + call kernel_loader + jmp .hang .hang: mov esi, msg_booting_failed call print32dbg @@ -108,7 +138,6 @@ main: ; ============================================================================ ; ; Messages ; ; ============================================================================ ; -; Banner msg_nyanix db "Nyanix 0.1 loading your kernel :) ...", 0x0A, 0x00 ; Fatal errors, start with 'Fatal: ' prefix. @@ -140,9 +169,10 @@ check_a20: mov esp, ebp pop ebp ret - -; does not require arguments, -; returns nothing + +; ========================================================================== ; +; Function to enable A20 ; +; ========================================================================== ; enable_a20: push ebp mov ebp, esp @@ -205,12 +235,12 @@ kbd_send: ; ============================================================================ ; ; Functionality for printing to the framebuffer ; +; ; +; Requires a null-terminated string at DI ; ; ============================================================================ ; __TTY_COLUMNS db 0 __TTY_ROWS db 0 __TTY_COLOR db 0x0F - -; requires null-terminated string @ esi print32dbg: push ebp mov ebp, esp @@ -299,6 +329,9 @@ print32dbg: pop ebp ret - +; ========================================================================== ; +; Include of the next part of the bootloader (kernel_load). ; +; ========================================================================== ; +%include "src/kernel_loader.s"