Nyanix

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

commit 1271e5c48fc99db01acd349142730c5327c2e331
parent b5a384fd18cf3bf4c4de10233092a8460e679f89
Author: k4m1 <k4m1@proton.intra.silverskin.com>
Date:   Fri, 29 Jun 2018 12:53:34 +0300

Continued developement again

Diffstat:
src/boot.s | 204++++++++++++++++++++-----------------------------------------------------------
1 file changed, 50 insertions(+), 154 deletions(-)

diff --git a/src/boot.s b/src/boot.s @@ -1,179 +1,75 @@ -;*****************************************************************************; -; Nyanix ; -; ; -; Nyanix is a simple bootloader aiming for fastest possible boot time. ; -; Other goals are being as bloat-free as possible, and as clean as possible. ; -; ; -; If you wish to contribute to developement of Nyanix bootloader, do git fork ; -; of the current stable version of the bootloader, add your changes, and do a ; -; pull request. The developer(s) will verify, and accept/reject your code ; -; as soon as humanly possible :) ; -; ; -; Copyright 2018 k4m1 <k4m1@protonmail.com> ; -; ; -; Redistribution and use in source and binary forms, ; -; with or without modification, are permitted provided that the following ; -; conditions are met: ; -; ; -; 1. Redistributions of source code must retain the above copyright notice, ; -; this list of conditions and the following disclaimer. ; -; ; -; 2. Redistributions in binary form must reproduce ; -; the above copyright notice, this list of conditions and ; -; the following disclaimer in the documentation and/or other materials ; -; provided with the distribution. ; -; ; -; 3. Neither the name of the copyright holder nor the names of its ; -; contributors may be used to endorse or promote products derived from ; -; this software without specific prior written permission. ; -; ; -; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ; -; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ; -; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ; -; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ; -; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ; -; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ; -; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ; -; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ; -; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR ; -; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ; -; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ; -; ; -; ~ Enjoy ; -; ; -; vim: set tw=80 ; -;*****************************************************************************; - -[BITS 16] -org 0x7c00 +;*** +; The entrypoint for bootloader. +;*** +bits 16 +align 4 +org 0x7c00 section .text +global _entry +jmp 0x0000:_entry -; We'll start by jumping to 0x0000:stage1 -; in order to clean CS. This is needed as some BIOSes -; do entry to here by setting CS instead of IP. -jmp 0x0000:stage1 - -; Here live all the global variables & definitions needed by 1st stage -; of the bootloader. - -BOOT_DEVICE db 0 ; One byte of memory reserved for boot device ident - -NYANIX_VERSION db "Nyanix 0.1", 0x0A, 0x0D, 0 ; Current version of loader. - -; Our first function label *-* -stage1: - cli +_entry: cld - ; Clear rest of segments - xor ax, ax - mov ds, ax - mov fs, ax - mov gs, ax - mov es, ax - mov ss, ax - - ; Store boot-device id from BIOS (dl) to - ; BOOT_DEVICE. - mov dl, [BOOT_DEVICE] + cli - ; Clear rest of registers + mov [BOOT_DEVICE_DB], dl + xor ax, ax xor bx, bx xor cx, cx - xor dx, dx - xor di, di + xor si, si + xor di, di - ; set stack ptr + xor bp, bp + mov ss, ax + mov es, ax + mov fs, ax mov sp, 0x7c00 - mov bp, 0 - ; Start loading 2nd stage of boot-loader. +load_2nd_stage: sti - mov bx, second_stage_entry - mov dh, 2 - mov dl, [BOOT_DEVICE] - xor ch, ch + mov bx, _start + mov dh, 2 + mov dl, [BOOT_DEVICE_DB] + mov byte [BL_SECTORS], dh + xor ch, ch xor dh, dh - mov cl, 2 -read_start: + mov cl, 0x02 +.read_start: mov di, 5 .read: - mov ah, 0x02 ; int 13h, ah=2. Disk read - mov al, 1 ; sectors to read + mov ah, 0x02 + mov al, [BL_SECTORS] int 0x13 jc .retry - ; we apparently loaded the sector! Great! - ; check for signature - lea bx, [second_stage_entry] - cmp byte [bx], 'N' - jne .corrupted - cmp byte [bx+1], 'y' - jne .corrupted - cmp byte [bx+2], 'a' - jne .corrupted - cmp byte [bx+3], 'n' - jne .corrupted - - ; Rest of the code seems fine, let's jump! - add bx, 4 - jmp bx - + sub [BL_SECTORS], al + jz .read_done + mov cl, 0x01 + xor dh, 1 + jnz .read_start + inc ch + jmp .read_start .retry: - cmp di, 0 + xor ah, ah + int 0x13 dec di - jg .read - mov si, msg_diskread_failed - call real16_print - jmp .hang - -.corrupted: - mov si, msg_disk_corrupted - call real16_print -.hang: + jnz .read + mov si, msg_loader_failed + call real16_dbg_print +.error_hang: cli hlt - jmp .hang - -real16_print: - lodsb - or al, al - jz .done - mov ah, 0x0E - int 0x10 - jmp real16_print -.done: - ret - -times 510-($-$$) db 0x00 -db 0x55 -db 0xAA +.read_done: + jmp 0x0000:_start -; The entrypoint for second stage bootloader -; This is basicly just signature + nop. -second_stage_entry: - db 'N' - db 'y' - db 'a' - db 'n' - nop -second_stage: - add sp, 0x200 ; adjusting stack ptr - ; Next thing to do is to swap to unreal v8086 mode. - ; after that, we can start loading the kernel. + msg_loader_failed db "Failed to load bootloader.", 0x0A, 0x0D, 0 + BOOT_DEVICE_DB db 0 + BL_SECTORS db 0 - ; procedure should be as follows: - ; - ; swapto v8086 - ; enable/toggle a20 - ; load 64-kilos of kernel - ; toggle a20 - ; load next 64 kb of kernel - ; ... - ; swapto 32-bit protected mode - ; load dummy GDT - ; validate kernel - ; jump to kernel. + times 510-($-$$) db 0x00 + db 0x55 + db 0xAA - +%include "src/2nd_stage.s"