From 9b22a6965579ea1867aea291d910c96f386b518b Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Tue, 24 Aug 2021 14:09:29 -0500 Subject: major backup 8.24.21 --- src/bootloader/bootloader.asm | 95 +++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 58 deletions(-) (limited to 'src/bootloader/bootloader.asm') diff --git a/src/bootloader/bootloader.asm b/src/bootloader/bootloader.asm index 3ac10f3..f912e49 100644 --- a/src/bootloader/bootloader.asm +++ b/src/bootloader/bootloader.asm @@ -1,11 +1,11 @@ [bits 16] -[extern _kernel_size] +[extern _kernel_sector_size] [extern _bootloader_stage1_size] -[extern _kernel_loc] +[extern _kernel_s1_loc] jmp stage0 -times 3-($-$$) db 0x90 ; a temporary dirty fix to emulate a floppy disk insted of a hard risk -times 59 db 0 ; (TODO support hard disks) +times 3-($-$$) db 0x90 +times 59 db 0 stage0: @@ -13,44 +13,49 @@ jmp 0:.entry .entry: mov ax, 0 -mov ds, ax -mov bp, ax - mov ds, ax mov es, ax -mov ax, 0x8fc0 +;stack segments +mov ax, 0x7000 mov ss, ax -mov ax, 0xfffe +mov ax, 0xfff0 mov sp, ax +mov bp, 0 mov al, 0x92 or al, 2 out 0x92, al -mov [.boot_device], dl + +call bios_disk.init + mov bx, .loadstage2_msg -mov cx, 0 call bios_print -; TODO put in an error message and a maximum fail count .load_stage1: -mov al, _bootloader_stage1_size -mov cl, 0x2 ; read sector 2 -mov dx, 0x0 ; dest segment 0 -mov bx, 0x7e00 ; dest offst 0 -call bios_disk.load_sectors +;TODO LOAD STAGE ONE HERE + +; we start on 0x100000 +; esi: sector start +; cx: sector count +; edi: memory desination + +mov esi, 1 ; 2nt sector +mov ecx, _bootloader_stage1_size +mov edi, 0x7e00 ; desination +call bios_disk.load_sectors_v2 + jmp mbr_end.entry -.boot_device: db 0 .loadstage2_msg: db "Loading (stage 2) bootloader...", 0 -%include "bootloader/bios_functions/bios_disk.asm" -%include "bootloader/bios_functions/print.asm" +%include "bootloader/bios_disk.asm" +%include "bootloader/print.asm" times 510 - ($-$$) db 0 dw 0xaa55 @@ -66,15 +71,12 @@ boot_msg: mbr_end: .entry: +cli ; entering unreal mode mov bx, boot_msg.stage2_loaded -mov cx, 0 call bios_print -cli -push ds - lgdt [protected_gdt.descriptor] mov eax, cr0 @@ -83,52 +85,29 @@ mov cr0, eax jmp $+2 -mov bx, 0x10 ; descriptor 2, the data descriptor -mov ds, bx ; put it into the segment register -mov es, bx ; +mov bx, 0x10 +mov ds, bx +mov es, bx and al, 0xfe mov cr0, eax -pop ds +mov bx, 0 +mov ds, bx +mov es, bx sti -;we are now in unreal mode - -mov cl, 5 -mov edi, _kernel_loc -.loop: -mov al, 0x1 ; sector count -mov dx, 0x0 ; dest addr segment -mov bx, 0x500 ; dest addr offset -call bios_disk.load_sectors - - -inc cl - -push cx - -mov esi, 0x500 -mov ecx, 512 -a32 rep movsb -nop - -pop cx - -cmp cl, _kernel_size+2 -je .loop_end - -jmp .loop - -.loop_end: +mov esi, _bootloader_stage1_size +mov edi, 0x100000 +mov ecx, _kernel_sector_size +call bios_disk.load_sectors_v2 mov bx, boot_msg.kernel_loaded -mov cx, 0 call bios_print call detect_arch -call vbe_init +;call vbe_init done: call enter_longmode -- cgit v1.2.3