Bootloader fixes on systems with wrong CS

This commit is contained in:
Jeremy Soller 2016-10-19 10:06:37 -06:00
parent 1aace24eba
commit f7672dbaf4
3 changed files with 53 additions and 66 deletions

View file

@ -12,6 +12,14 @@ boot: ; dl comes with disk
; initialize stack
mov sp, 0x7C00
; initialize CS
push ax
push word .set_cs
retf
.set_cs:
; save disk number
mov [disk], dl
mov si, name
@ -45,16 +53,16 @@ boot: ; dl comes with disk
; TODO rewrite to (eventually) move larger parts at once
; if that is done increase buffer_size_sectors in startup-common to that (max 0x80000 - startup_end)
load:
cmp cx, 128
cmp cx, 127
jbe .good_size
pusha
mov cx, 128
mov cx, 127
call load
popa
add ax, 128
add dx, 128 * 512 / 16
sub cx, 128
add ax, 127
add dx, 127 * 512 / 16
sub cx, 127
jmp load
.good_size:
@ -63,31 +71,7 @@ load:
mov [DAPACK.count], cx
mov [DAPACK.seg], dx
mov bx, [DAPACK.addr + 2]
call print_num
mov bx, [DAPACK.addr]
call print_num
mov al, '#'
call print_char
mov bx, [DAPACK.count]
call print_num
mov al, ' '
call print_char
mov bx, [DAPACK.seg]
call print_num
mov al, ':'
call print_char
mov bx, [DAPACK.buf]
call print_num
call print_line
call print_dapack
mov dl, [disk]
mov si, DAPACK
@ -108,16 +92,16 @@ load:
; TODO rewrite to (eventually) move larger parts at once
; if that is done increase buffer_size_sectors in startup-common to that (max 0x80000 - startup_end)
store:
cmp cx, 128
cmp cx, 127
jbe .good_size
pusha
mov cx, 128
mov cx, 127
call store
popa
add ax, 128
add dx, 128 * 512 / 16
sub cx, 128
add ax, 127
add dx, 127 * 512 / 16
sub cx, 127
jmp store
.good_size:
@ -126,31 +110,7 @@ load:
mov [DAPACK.count], cx
mov [DAPACK.seg], dx
mov bx, [DAPACK.addr + 2]
call print_num
mov bx, [DAPACK.addr]
call print_num
mov al, '#'
call print_char
mov bx, [DAPACK.count]
call print_num
mov al, ' '
call print_char
mov bx, [DAPACK.seg]
call print_num
mov al, ':'
call print_char
mov bx, [DAPACK.buf]
call print_num
call print_line
call print_dapack
mov dl, [disk]
mov si, DAPACK
@ -159,6 +119,33 @@ load:
jc error
ret
print_dapack:
mov bx, [DAPACK.addr + 2]
call print_num
mov bx, [DAPACK.addr]
call print_num
mov al, '#'
call print_char
mov bx, [DAPACK.count]
call print_num
mov al, ' '
call print_char
mov bx, [DAPACK.seg]
call print_num
mov al, ':'
call print_char
mov bx, [DAPACK.buf]
call print_num
jmp print_line
error:
mov bh, 0
mov bl, ah
@ -180,7 +167,6 @@ error:
name: db "Redox Loader - Stage One",0
errored: db "Could not read disk",0
finished: db "Redox Loader - Stage Two",0
line: db 13,10,0
disk: db 0

View file

@ -4,7 +4,7 @@ USE16
; a newline
newline: db 0xD, 0xA, 0
newline: db 13,10,0
; print a string and a newline
; IN
@ -13,8 +13,7 @@ newline: db 0xD, 0xA, 0
; ax
print_line:
mov si, newline
call print
ret
jmp print
; print a string
; IN
@ -22,11 +21,13 @@ print_line:
; CLOBBER
; ax
print:
cld
.loop:
lodsb
test al, al
jz .done
call print_char
jmp print
jmp .loop
.done:
ret

View file

@ -14,7 +14,7 @@ startup:
; buffersize in multiple of sectors (512 Bytes)
; min 1
; max (0x70000 - startup_end) / 512
buffer_size_sectors equ 128
buffer_size_sectors equ 127
; buffer size in Bytes
buffer_size_bytes equ buffer_size_sectors * 512