From ed9d22fb423f92be45e0f6c3d695728970376035 Mon Sep 17 00:00:00 2001 From: Xnoe Date: Sun, 29 Aug 2021 06:58:12 +0100 Subject: [PATCH] We now have FAT16 file loading support in the bootloader. --- boot.asm | 149 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 134 insertions(+), 15 deletions(-) diff --git a/boot.asm b/boot.asm index d3c023a..d065b37 100644 --- a/boot.asm +++ b/boot.asm @@ -1,23 +1,133 @@ [BITS 16] ;tell the assembler that its a 16 bit code -mov ax, 7c0h -mov ds, ax +jmp short bootcode +nop -mov si, _boot_msg -call _boot_print +bpOEMid db "XNOE " +bpBytesPerSector dw 512 +bpSectorsPerCluster db 1 +bpReservedSectors dw 1 +bpNoFATs db 2 +bpRootDirEntries dw 256 +bpLVSectors dw 8419 +bpMediumID db 0F0h +bpSectorsPerFat dw 9 +bpSectorsPerTrack dw 18 +bpSides dw 2 +bpHiddenSectors dd 0 +bpLargeSectors dd 0 +bpDriveNo dw 0 +bpSignature db 41 +bpVolumeID dd 00000000h +bpVolumeLabel db "XNOE OS " +bpFileSystem db "FAT16 " -mov ah, 02h -mov al, 1 -mov ch, 0 -mov cl, 2 -mov dh, 0 +bootcode: + mov ax, 7c0h + mov ds, ax -mov bx, 2000h -mov es, bx -xor bx, bx -int 13h + mov byte [drive], dl -jmp 2000h:0 + mov si, boot_msg + call _boot_print + + mov ax, ds + mov es, ax + mov bx, buffer + + mov ah, 2 + mov al, 16 + mov cl, 20 + mov ch, 0 + mov dh, 0 + mov dl, byte [drive] + + int 13h + + mov cx, [bpRootDirEntries] + mov di, buffer + + mov ax, 0 + +; jmp $ + +kernel_finder: + xchg cx, dx + + mov di, buffer + add di, ax + +; mov si, di +; call _boot_print +; mov si, new_line +; call _boot_print + + mov si, kernel_file + mov cx, 11 + rep cmpsb + je kernel_found + + add ax, 20h + + xchg cx, dx + loop kernel_finder + + mov si, kernel_nf + call _boot_print + + jmp $ + +kernel_found: + mov ax, [es:di+0fh] + mov word [cluster], ax + +fat_loader: + mov ax, ds + mov es, ax + mov bx, buffer + + mov ah, 2 + mov al, 9 + mov cl, 2 + mov ch, 0 + mov dh, 0 + mov dl, byte [drive] + + int 13h + +kernel_loader: + mov ax, 2000h + mov es, ax + mov bx, word [pointer] + + mov al, byte [cluster] + mov word [buffer+20h], ax + + add al, 34 + + mov cl, al + mov al, 1 + mov ah, 2 + mov ch, 0 + mov dh, 0 + mov dl, byte [drive] + + int 13h + + add word [pointer], 512 + + mov si, word [cluster] + add si, buffer + add si, 1 + cmp word [si], 0ffffh + je kernel_loaded + + add word [cluster], 1 + jmp kernel_loader + +kernel_loaded: + mov dword [buffer], 0xdeadbeef + jmp 2000h:0h _boot_print: mov ah, 0eh @@ -32,7 +142,16 @@ _boot_print_loop: _boot_print_exit: ret -_boot_msg db "Boot Sector OK!", 13, 10, 0 +boot_msg db "Boot Sector OK!", 13, 10, 0 +kernel_nf db "KERNEL.BIN Missing!", 13, 10, 0 +new_line db " ", 0 +kernel_file db "KERNEL BIN" + +cluster dw 0 +pointer dw 0 +drive db 0 TIMES 510 - ($ - $$) db 0 ;fill the rest of sector with 0 DW 0xAA55 ; add boot signature at the end of bootloader + +buffer: \ No newline at end of file