Nyanix

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

commit ec78209dfde3d806de2339a661a06ccf2e13af3e
parent 2d747461350e2f177f0b9e5da0cad8c572c10747
Author: Dani Frisk <dani@silverskin.fi>
Date:   Mon, 20 Aug 2018 13:42:18 +0300

update with a fancy commit message

Diffstat:
src/boot_early/a20gate.s | 50++++++++++++++++++++++----------------------------
src/boot_early/boot.s | 4++--
src/boot_early/second_stage.s | 8++++----
src/main/main_loader.s | 35++++++++++++++++++++++++++++++-----
4 files changed, 58 insertions(+), 39 deletions(-)

diff --git a/src/boot_early/a20gate.s b/src/boot_early/a20gate.s @@ -1,43 +1,37 @@ -; ============================================================================= ; -; /boot_early/a20gate.s ; -; Copyright (C) 2018, k4m1 <k4m1@protonmail.com> ; -; See /LICENSE for full license text. ; -; ; -; This file provides functionality for checking the status of a20 gate, and ; -; toggling the a20 gate. ; -; ============================================================================= ; +; =========================================================================== ; +; /boot_early/a20gate.s ; +; Copyright (C) 2018, k4m1 <k4m1@protonmail.com> ; +; See /LICENSE for full license text. ; +; ; +; This file provides functionality for checking the status of a20 gate, and ; +; toggling the a20 gate. ; +; =========================================================================== ; [ BITS 16 ] + %ifndef __a20_gate_h__ %define __a20_gate_h__ 1 check_a20gate: - mov eax, 0x112345 - mov ebx, 0x012345 - - mov byte [eax], 0xFA - mov byte [ebx], 0xFF - - push ecx - push edx - mov ecx, dword [eax] - mov edx, dword [ebx] - cmp ecx, edx - pop edx - pop ecx - xor eax, eax - jne .a20_isenabled + pushad + mov esi, 0x012345 + mov edi, 0x112345 + mov [esi], esi + mov [edi], edi + cmpsd + popad + jne .a20_isenabled ret .a20_isenabled: inc eax ret -; ============================================================================= ; -; This function is used for togglin the a20 gate. ; -; Not returning anythin, nor requiring arguments. ; -; ============================================================================= ; +; =========================================================================== ; +; This function is used for togglin the a20 gate. ; +; Not returning anythin, nor requiring arguments. ; +; =========================================================================== ; toggle_a20_status: push ebp mov ebp, esp @@ -53,7 +47,7 @@ toggle_a20_status: call __kbdctl_wait call __kbdctl_inb - push eax + push eax call __kbdctl_wait mov eax, KBD_WRITE 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 2 +%define SECTOR_COUNT 5 ; clearing out CS jmp 0x0000:start @@ -91,7 +91,7 @@ load_second_stage: .read_done: jmp _start -msg_disk_read_failed db "Failed to read boot disk.", 0x0A, 0x0D, 0 +msg_disk_read_failed db "Failed to read boot disk.", 0x0A, 0 hang: cli diff --git a/src/boot_early/second_stage.s b/src/boot_early/second_stage.s @@ -51,13 +51,13 @@ main: mov [boot_device_db], al call check_a20gate - test eax, eax - jnz .a20_is_enabled + cmp eax, 0 + je .a20_is_enabled call toggle_a20_status call check_a20gate - test eax, eax - jnz .a20_is_enabled + cmp eax, 0 + je .a20_is_enabled ; we apparently failed to enable a20 gate. :( mov esi, msg_a20_fail diff --git a/src/main/main_loader.s b/src/main/main_loader.s @@ -17,13 +17,15 @@ ; ; bytes 0 - 7 : "Nyan_hed" ; bytes 8 - 9 : Size of kernel in sectors (how many 1024 bytes chunks) -; may be adding some more stuff +; byte 10 : padding +; byte 11 -> : code starts +; ; =========================================================================== ; ; Variables needed for kernel loading process. ; ; =========================================================================== ; -kernel_entry_address db 0x10000 +kernel_entry_address equ 0x10000 kernel_entry_signature db "Nyan_hed", 0 kernel_sector_count db 0 kernel_sectors_loaded db 0 @@ -35,7 +37,7 @@ main_loader: ; loading 1 sector from 0x10000 -> ; to see if we have a valid kernel at disk. mov eax, kernel_entry_address - mov kernel_sector_count 1 + mov byte [kernel_sector_count], 1 mov bl, boot_device_db mov cl, 1 call load_sectors @@ -43,10 +45,22 @@ main_loader: mov eax, 0x10000 call search_kernel_header + cmp eax, 0 + je .fail + mov eax, 0xbeef + cli + hlt + mov esp, ebp pop ebp ret +.fail: + mov esi, msg_kernel_not_found + call panic + +msg_kernel_not_found db "Kernel not found.", 0x0A, 0 + ; =========================================================================== ; ; Helper functions for kernel loading process. ; ; =========================================================================== ; @@ -84,7 +98,7 @@ load_sectors: mov cl, 0x01 xor dh, 1 jnz .read_start - inc ch, 1 + inc ch jmp .read_start .retry: ; reset disk @@ -109,6 +123,9 @@ load_sectors: ; Returns: ; code entry: EAX ; sector count: EBX +; on success or : +; EAX = 0, EBX = 0 +; on error. search_kernel_header: push ebp mov ebp, esp @@ -127,7 +144,15 @@ search_kernel_header: ; we found the header :) add ecx, 8 ; stepping over kenrel_entry_signature. - + xor ebx, ebx + mov bx, word [eax + ecx] + add ecx, 3 + add eax, ecx + jmp .ret +.not_found: + xor ebx, ebx + xor eax, eax +.ret: mov esp, ebp pop ebp ret