summaryrefslogtreecommitdiff
path: root/src/bootloader/bootloader.asm
diff options
context:
space:
mode:
authorBrett Weiland <brett_weiland@bpcspace.com>2021-08-24 14:09:29 -0500
committerBrett Weiland <brett_weiland@bpcspace.com>2021-08-24 14:09:29 -0500
commit9b22a6965579ea1867aea291d910c96f386b518b (patch)
treed06dbb9c4708f1cc713bcb115b32ff9bce4cf9b9 /src/bootloader/bootloader.asm
parentbad4b0e9bdfee336bfc1c23761408279eaec1558 (diff)
major backup 8.24.21
Diffstat (limited to 'src/bootloader/bootloader.asm')
-rw-r--r--src/bootloader/bootloader.asm95
1 files changed, 37 insertions, 58 deletions
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:
@@ -14,43 +14,48 @@ jmp 0:.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