Nyanix

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

commit b3ebd7ccbf59309b313a5c1f34cf109cc9856e0b
parent a1ce9e3ac406a5594dc471696f49e5573ff4ddd5
Author: pwk4m1 <k4m1@protonmail.com>
Date:   Sun,  4 Nov 2018 15:33:23 +0200

Update load process

Diffstat:
src/main/main_loader.s | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 55 insertions(+), 22 deletions(-)

diff --git a/src/main/main_loader.s b/src/main/main_loader.s @@ -15,21 +15,13 @@ %include "src/drivers/framebuffer.s" -; Kernel entry signature: -; -; bytes 0 - 7 : "Nyan_hed" -; bytes 8 - 9 : Size of kernel in sectors (how many 1024 bytes chunks) -; byte 10 : padding -; byte 11 -> : code starts -; - ; =========================================================================== ; ; Variables needed for kernel loading process. ; ; =========================================================================== ; -kernel_entry_address equ 0x10000 -kernel_entry_signature db "Nyan_hed", 0 -kernel_sector_count db 0 +kernel_entry_address equ 0x1000 + +sectors_remaining db 1 ; the amount of sectors to load kernel_sectors_loaded db 0 main_loader: @@ -39,17 +31,55 @@ main_loader: xor eax, eax xor ebx, ebx xor ecx, ecx - mov eax, kernel_entry_address - mov byte [kernel_sector_count], 15 - mov bl, byte [boot_device_db] - mov cl, 1 - call load_sectors - - ; relocate kernel to address 0x10000 + ; this is a loop for loading up to 255KB kernels. + ; we'll be loading from disk in 15kb chunks. + + .load_disk_loop: + ; check if there is more than 15KB left to load + cmp byte [sectors_remaining], 15 + jle .final_iteration + + ; adjust the entry-address for load + mov eax, kernel_entry_address + xor ebx, ebx + mov bl, byte [kernel_sectors_loaded] + imul ebx, 1024 + add eax, ebx + + ; load next 15 Kb from disk. + mov bl, byte [boot_device_db] + mov cl, 15 + call load_sectors + + mov bl, byte [kernel_sectors_loaded] + add bl, 15 + mov byte [kernel_sectors_loaded], bl + + mov bl, byte [sectors_remaining] + sub bl, 15 + mov byte [sectors_remaining], bl + + jmp .load_disk_loop + + ; final iteration of disk-load loop + .final_iteration: + mov eax, kernel_entry_address + xor ebx, ebx + mov bl, byte [kernel_sectors_loaded] + imul ebx, 1024 + add eax, ebx + + mov bl, byte [boot_device_db] + mov cl, byte [sectors_remaining] + call load_sectors + + ; disk read is finished, time for relocation. mov esi, kernel_entry_address - mov edi, 0x10000 - mov ecx, (1024 * 15) + mov edi, 0x20000 + xor ecx, ecx + mov cl, byte [kernel_sectors_loaded] + imul ecx, 1024 .relocate_loop: mov al, byte [esi+ecx] @@ -63,8 +93,11 @@ main_loader: mov eax, cr0 or al, 1 mov cr0, eax - jmp edi - + jmp .hang +.hang: + cli + hlt + jmp .hang .fail: mov esi, msg_kernel_not_found