Nyanix

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

commit 6d3f065c62a3099c26de4128e68777dae9dc1774
parent 1331f4ae9913103a390894aa8626d72ea38e81a5
Author: Dani Frisk <dani@silverskin.fi>
Date:   Fri,  3 Aug 2018 10:23:39 +0300

Updated A20, and print32dbg

Diffstat:
src/2nd_stage.s | 149++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
src/boot.s | 6+++++-
2 files changed, 145 insertions(+), 10 deletions(-)

diff --git a/src/2nd_stage.s b/src/2nd_stage.s @@ -19,6 +19,7 @@ _start: jmp .hang %include "src/gdt32table.s" +msg_failed_to_switch_pm db "Failed to swap to protected mode", 0x0A, 0x0D, 0 ; Function to print debug messages in 16-bit real mode real16_dbg_print: @@ -40,14 +41,14 @@ switch_to_pm: ; 1 more instruction to execute in ; 16 bit real mode, then we'll be ; in 32-bit mode ! - jmp GDT_32_CODE:pmode_init + jmp GDT_32_CODE:main_init ; ============================================================================ ; ; 32-bit protected mode ; ; ============================================================================ ; [bits 32] -; Function to initialize pmode -pmode_init: +; Function to initialize main +main_init: mov ax, GDT_32_DATA mov ds, ax mov ss, ax @@ -61,13 +62,13 @@ pmode_init: ; disable interrupts cli - call pmode + call main ; ============================================================================ ; ; Function that's in protected 32-bit mode. ; ; This function server as the 'main' function of tthe bootloader. ; ; ============================================================================ ; -pmode: +main: push ebp mov ebp, esp @@ -76,6 +77,9 @@ pmode: xor ecx, ecx xor edx, edx + mov esi, msg_nyanix + call print32dbg + call check_a20 cmp ax, 0 je .a20_enabled @@ -83,19 +87,39 @@ pmode: call check_a20 cmp ax, 0 je .a20_enabled - - ; a20 line is not completed + ; Failed to enable a20 ! + mov esi, msg_a20fail + call print32dbg cli hlt .a20_enabled: - mov ax, 0xbeef cli hlt +.hang: + mov esi, msg_booting_failed + call print32dbg +.__hang: + cli + hlt + jmp .__hang + +; ============================================================================ ; +; Messages ; +; ============================================================================ ; +; Banner +msg_nyanix db "Nyanix 0.1 loading your kernel :) ...", 0x0A, 0x00 + +; Fatal errors, start with 'Fatal: ' prefix. +msg_a20fail db "Fatal: Failed to enable A20 line.", 0x0A, 0x00 +msg_booting_failed db "Fatal: Failed to boot the kernel!", 0x0A, 0x00 + ; ============================================================================ ; ; Functionality for enabling a20-gate ; ; ============================================================================ ; +; returns 0 if a20 is enabled, +; returns 1 if a20 is not enabled, check_a20: push ebp mov ebp, esp @@ -117,7 +141,11 @@ check_a20: pop ebp ret +; does not require arguments, +; returns nothing enable_a20: + push ebp + mov ebp, esp ; we'll enable a20-gate via keyboard controller. call kbd_wait mov al, __KBD_DISABLE @@ -138,7 +166,6 @@ enable_a20: pop eax or al, 2 call kbd_send - call kbd_wait mov esp, ebp @@ -154,12 +181,16 @@ __KBD_ENABLE equ 0xAE __KBD_READ_IN equ 0xD0 __KBD_WRITE_OUT equ 0xD1 +; does not return nor require args kbd_wait: + push eax in al, 0x64 test al, 2 jnz kbd_wait + pop eax ret +; returns one byte at al kbd_read: in al, 0x64 test al, 1 @@ -167,7 +198,107 @@ kbd_read: in al, 0x60 ret +; parameters for kbd_send: one byte at al kbd_send: out 0x64, al ret +; ============================================================================ ; +; Functionality for printing to the framebuffer ; +; ============================================================================ ; +__TTY_COLUMNS db 0 +__TTY_ROWS db 0 +__TTY_COLOR db 0x0F + +; requires null-terminated string @ esi +print32dbg: + push ebp + mov ebp, esp + + push eax + push ebx + push ecx + push edx + + .print_loop: + xor eax, eax + xor ebx, ebx + xor edx, edx + + cmp byte [esi + ecx], 0x00 + je .done + + ; VGA_ADDR = (0xB8000 + (y * 80 + x)) + mov bl, byte [__TTY_COLUMNS] + mov dl, byte [__TTY_ROWS] + + ; setting EBX = VGA-Color + ; and EDX = VGA-address + push ecx + mov ecx, 0xb8000 + imul edx, 80 + add edx, ebx + add ecx, edx + mov edx, ecx + pop ecx + + mov bh, byte [__TTY_COLOR] + + ; printing the character + xor eax, eax + mov al, byte [esi + ecx] + + inc ecx + cmp ecx, 0xffff + jge .prevent_overflow + + cmp al, 0x0A + je .newline + mov ah, bh + mov word [edx], ax + + xor ebx, ebx + mov bl, byte [__TTY_COLUMNS] + add bl, 2 + mov byte [__TTY_COLUMNS], bl + cmp bl, 80 + jl .print_loop + mov bl, byte [__TTY_ROWS] + mov byte [__TTY_COLUMNS], 0 + inc bl + mov byte [__TTY_ROWS], bl + cmp bl, 25 + jl .print_loop + + ; 80x24 lines used? what for, this is a bootloader, + ; not a fairy-tale. No need for roll-over... + .rollover: + mov byte [__TTY_COLUMNS], 0 + mov byte [__TTY_ROWS], 0 + jmp .print_loop + + .newline: + xor ebx, ebx + mov bl, byte [__TTY_ROWS] + cmp bl, 24 + je .rollover + add bl, 2 + mov byte [__TTY_ROWS], bl + mov byte [__TTY_COLUMNS], 0 + jmp .print_loop + + .prevent_overflow: + .done: + mov dl, byte [__TTY_ROWS] + mov bl, byte [__TTY_COLUMNS] + pop edx + pop ecx + pop ebx + pop eax + mov esp, ebp + pop ebp + ret + + + + diff --git a/src/boot.s b/src/boot.s @@ -17,6 +17,10 @@ _entry: ; back-uping boot device id & clearing registers mov [BOOT_DEVICE_DB], dl + ; change to text-mode (and clear the screen) + xor ah, ah + mov al, 0x03 + int 0x10 xor ax, ax xor bx, bx xor cx, cx @@ -39,7 +43,7 @@ _entry: load_2nd_stage: sti mov bx, _start - mov dh, 1 + mov dh, 2 mov dl, [BOOT_DEVICE_DB] mov byte [BL_SECTORS], dh xor ch, ch