Nyanix

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

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

Going on...

Diffstat:
src/2nd_stage.s | 57++++++++++++++++++++++++++++++++++++++-------------------
src/boot.s | 4+++-
src/kernel_loader.s | 3++-
3 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/src/2nd_stage.s b/src/2nd_stage.s @@ -9,32 +9,51 @@ _start: xor bp, bp add sp, 0x200 - ; Back uping Realmode segment & boot device from + ; Back uping 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. - ; closest to that we'll get is virtual 8086 mode, aka - ; emulated 16-bit mode. - ; If we return, we'll hang. - call switch_to_pm -.hang: - cli - hlt - jmp .hang + + ; Getting the amount of RAM + clc + sti + xor cx, cx + xor dx, dx + mov ax, 0xE801 ; get memory interrupt + int 0x15 + jc .fail + cmp ah, 0x86 ; Unsupported function, pre 1994 machine + je .fail ; or bad BIOS + cmp ah, 0x80 + je .fail + jcxz .continue + mov ax, cx + mov bx, dx + + .continue: + ; we'll jump to protected mode now. + ; after that, we should _never_ return to real 16-bit mode. + ; closest to that we'll get is virtual 8086 mode, aka + ; emulated 16-bit mode. + ; If we return, we'll hang. + call switch_to_pm + + .fail: + mov si, msg_failed_to_get_memory + call real16_dbg_print + .hang: + cli + 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 +msg_failed_to_get_memory db "Failed to get amount of RAM avail.", 0x0A, 0x0D, 0 BOOT_DEV_DB db 0 -REALMODE_DB db 0 MEMORY_LOWER dw 0 MEMORY_HIGHER dw 0 @@ -49,10 +68,10 @@ real16_dbg_print: or al, al jnz .continue ret -.continue: - mov ah, 0x0E - int 0x10 - jmp real16_dbg_print + .continue: + mov ah, 0x0E + int 0x10 + jmp real16_dbg_print ; ========================================================================== ; ; Function to switch to protected mode ; diff --git a/src/boot.s b/src/boot.s @@ -11,6 +11,8 @@ section .text ; by setting CS=0x7c00 instead of just jmp 0x0000:0x7c00 jmp 0x0000:_entry +%define SECTOR_COUNT 3 + _entry: cld cli @@ -43,7 +45,7 @@ _entry: load_2nd_stage: sti mov bx, _start - mov dh, 2 + mov dh, SECTOR_COUNT mov dl, [BOOT_DEVICE_DB] mov byte [BL_SECTORS], dh xor ch, ch diff --git a/src/kernel_loader.s b/src/kernel_loader.s @@ -26,7 +26,8 @@ kernel_loader: push ebp mov ebp, esp - + cli + hlt mov esp, ebp pop ebp