Nyanix

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

commit 16159327b4c968f9ce5961a349c428283aa481f6
parent 8b1284f707d59a0d5003883752977063e2bc9047
Author: Dani Frisk <dani@silverskin.fi>
Date:   Sun, 25 Nov 2018 11:29:28 +0200

Optimizing

Diffstat:
src/boot_early/a20gate.s | 3+--
src/boot_early/boot.s | 3+--
src/boot_early/second_stage.s | 40++++++++++++----------------------------
src/drivers/framebuffer.s | 168-------------------------------------------------------------------------------
src/main/main_loader.s | 6++----
5 files changed, 16 insertions(+), 204 deletions(-)

diff --git a/src/boot_early/a20gate.s b/src/boot_early/a20gate.s @@ -18,9 +18,7 @@ ; Check A20 line ; Returns to caller if A20 gate is cleared. ; Continues to A20_on if A20 line is set. -; Written by Elad Ashkcenazi check_a20gate: - xor eax, eax pushad mov esi, 0x012345 mov edi, 0x112345 @@ -29,6 +27,7 @@ check_a20gate: cmpsd popad jne .a20_isenabled + xor eax, eax ret .a20_isenabled: inc eax diff --git a/src/boot_early/boot.s b/src/boot_early/boot.s @@ -13,7 +13,7 @@ org 0x7c00 bits 16 align 4 -%define SECTOR_COUNT 3 +%define SECTOR_COUNT 1 ; clearing out CS jmp 0x0000:start @@ -129,4 +129,3 @@ dw 0xAA55 %include "src/boot_early/second_stage.s" - diff --git a/src/boot_early/second_stage.s b/src/boot_early/second_stage.s @@ -20,7 +20,6 @@ _start: ; drivers. %include "src/drivers/kbd_ctl.s" -%include "src/drivers/framebuffer.s" ; a20 gate related operations. %include "src/boot_early/a20gate.s" @@ -32,8 +31,6 @@ _start: ; Messages ; ; =========================================================================== ; msg_a20_fail db "Failed to enable A20 gate!", 0x0A, 0 -msg_main_loader_ret db "Unknown fatal error with main loader!", 0x0A, 0 -msg_panic db "[!] Panic: ", 0 ; =========================================================================== ; ; boot device backup ; @@ -44,21 +41,18 @@ boot_device_db db 0, 0 ; Main function of second stage entry. ; ; =========================================================================== ; main: - xor ebp, ebp - mov esp, 0x9c00 + xor ebp, ebp + mov esp, 0x9c00 - xor eax, eax mov al, [BOOT_DEVICE] mov [boot_device_db], al call check_a20gate - cmp eax, 0 - je .a20_is_enabled + jnz .a20_enabled call toggle_a20_status call check_a20gate - cmp eax, 0 - je .a20_is_enabled + jnz .a20_enabled ; we apparently failed to enable a20 gate. :( mov esi, msg_a20_fail @@ -66,30 +60,20 @@ main: ; we've enabled a20 gate now, time to start loading ; kernel from the disk. - .a20_is_enabled: - call main_loader - - ; we returned from main loader? - ; that means we've failed hard, and it's time - ; to panic now! - - mov esi, msg_main_loader_ret - call panic + .a20_enabled: + call main_loader ; Fancy little panic function. panic: - push ebp - mov ebp, esp - - push esi - mov esi, msg_panic - call print32dbg - - pop esi - call print32dbg + lodsb + or al, al + int 0x10 + cmp al, 0 + jne panic .hang: cli hlt jmp .hang + diff --git a/src/drivers/framebuffer.s b/src/drivers/framebuffer.s @@ -1,168 +0,0 @@ -; =========================================================================== ; -; /src/drivers/framebuffer.s ; -; Copyright (C) 2018, k4m1 <k4m1@protonmail.com> ; -; All rights reserved. ; -; See /LICENSE for whole license text ; -; ; -; This code is responsible of controlling the framebuffer. ; -; In practise, this means write-operations to memory address 0xB8000, which ; -; is directed to screen. ; -; =========================================================================== ; - -%ifndef __FRAMEBUFFER_S__ -%define __FRAMEBUFFER_S__ 1 - -__TTY_COLUMNS db 0 -__TTY_ROWS db 0 -__TTY_COLOR db 0x0F - -newline db 0x0A, 0 - -; String to print at ESI. -print32dbg: - push ebp - mov ebp, esp - - push eax - push ebx - push ecx - push edx - xor ecx, ecx - - .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 - -; Printing a 32-bit register content -print32dbg_hex: - push ebp - mov ebp, esp - - mov esi, .hex_prefix - call print32dbg - - mov ebx, eax - and eax, 0x0000ffff - and ebx, 0xffff0000 - rol ebx, 16 - and ebx, 0x0000ffff - - call __p16dbghx - mov eax, ebx - call __p16dbghx - - mov esi, newline - call print32dbg - - mov esp, ebp - pop ebp - ret - - .hex_prefix db '0x', 0 - -__p16dbghx: - push ebp - mov ebp, esp - push ebx - - mov di, .outstr16 - mov si, .hexstr - mov cx, 4 - xor bx, bx - .loop: - rol ax, 4 - mov bx, ax - and bx, 0x0f - mov bl, [si + bx] - mov [di], bl - inc di - dec cx - jnz .loop - mov esi, .outstr16 - call print32dbg - - pop ebx - mov esp, ebp - pop ebp - ret - - .hexstr db '0123456789ABCDEF' - .outstr16 db '0000', 0 - -%endif - diff --git a/src/main/main_loader.s b/src/main/main_loader.s @@ -13,8 +13,6 @@ %ifndef __LOADER_MAIN_S__ %define __LOADER_MAIN_S__ 1 -%include "src/drivers/framebuffer.s" - ; =========================================================================== ; ; Variables needed for kernel loading process. ; ; =========================================================================== ; @@ -23,8 +21,8 @@ sectors_remaining dw 1 ; the amount of sectors to load kernel_sectors_loaded dw 0 main_loader: - push ebp - mov ebp, esp + push ebp + mov ebp, esp xor eax, eax xor ebx, ebx