Work monitor program up to usable state

This commit is contained in:
Nero 2021-01-28 23:32:31 +00:00
parent daeb3891dd
commit 19f598251d

View File

@ -1,9 +1,10 @@
; monitor program that fits in a boot sector
; for debugging disk i/o and bootstrapping
%define base (0x10000 - 0x400)
%define base (0x10000 - 0x200)
org base
cpu 8086
; relocate to end of memory
init: ; set up src addr
@ -21,6 +22,9 @@ init: ; set up src addr
; set up stack
mov ss, ax
mov sp, di
; push defptr
push ds
push si
; relocate
mov cx, 0x100
rep movsw
@ -32,32 +36,29 @@ init: ; set up src addr
mov byte [si], 0xCC
push cs
push si
sti
retf
; call here = run proc tail twice
.l02: call .l01
.l01: mov word [bx], entry
mov word [bx+2], es
mov word [bx+2], ss
add bx, 2*4
ret
nl: mov al, 0x0A
call putc
nl: mov ax, 0x0e0A
int 0x10
mov al, 0x0D
jmp putc
; print full register set
space: mov al, ' '
putc: mov ah, 0x0e
int 0x10
ret
; print register set
printr: call nl
xor si, si
.l01: call .l02
add si, 2
cmp si, 18
jc .l01
mov si, 22
call .l02
les bx, [ss:bp+18]
jmp dump
.l02: mov ah, 0x0e
mov al, [cs:lbls+si]
int 0x10
@ -65,24 +66,22 @@ printr: call nl
int 0x10
mov al, '='
int 0x10
mov dx, [ss:bp+si]
call printd
space: mov al, ' '
putc: mov ah, 0x0e
int 0x10
ret
; print far ptr ES:BX
printf: mov dx, es
call printd
mov al, ':'
call putc
mov dx, bx
call printd
jmp space
mov dx, [bp+si]
mov ch, ' '
call prints
add si, 2
cmp si, 24
jc .l02
les bx, [bp+18]
jmp dump
; print 16 bytes from ES:BX
dump: call printf
dump: mov dx, es
mov ch, ':'
call prints
mov dx, bx
mov ch, ' '
call prints
push bx
mov cx, 0x10
.l01: mov dh, [es:bx]
@ -95,7 +94,7 @@ dump: call printf
pop bx
ret
printd: call printb ; print dx
printw: call printb ; print dx
printb: call .l01 ; print dh
.l01: mov cl, 4
; grab highest nibble from dx
@ -115,60 +114,78 @@ printn: ; map 0-9 to ascii codes for '0' to '9'
int 0x10
ret
; print dx and char ch
prints: call printw
mov al, ch
int 0x10
ret
getc: xor ax, ax
int 0x16
test al, al
jz getc
test al, 0x80
jnz getc
; to uppercase
cmp al, 0x60
jc .ret
sub al, 0x20
.ret: ret
; reads CX hex digits into DX
; DX needs to be zero on entry
input: call getc
inputw: call inputb
inputb: call inputn
inputn: jc .ret
call getc
cmp al, 0x20
je .err
; must be above '0'
stc
je .ret
sub al, 0x30
jc input
; if >9, turn 'A' to A
cmp al, 0x0A
jc .noadj
sub al, 7
.noadj: ; must be smaller than 'F'
cmp al, 0x10
jnc input
; append to DX
push cx
jnc inputn
; append to dx
mov cl, 4
shl dx, cl
or dl, al
pop cx
; print, loop & clear exit
call printn
loop input
call space
clc
ret
.err: call space
stc
ret
.ret: ret
; edit word at ES:BX
; space exits with carry
editw: mov dx, [es:bx]
call printd
mov al, '.'
call putc
mov cx, 4
call input
mov ch, '.'
call prints
clc
call inputw
jc .err
mov [es:bx], dx
.err: ret
cmd_o: mov bx, di
jmp cmd_s.l01
cmd_s: lea bx, [di+2]
.l01: call editw
jmp cmd
cmd_e: les bx, [cs:di]
mov dh, [es:bx]
call printb
mov al, '.'
int 0x10
mov cx, 2
clc
call inputb
jc cmd
mov [es:bx], dl
inc word [cs:di]
call space
jmp cmd_e
entry: push es
push ds
push di
@ -181,11 +198,7 @@ entry: push es
mov bp, sp
cmd_r: call printr
; reset segment register
cmd: mov ax, cs
mov ds, ax
mov es, ax
; display prompt
cmd: ; display prompt
call nl
mov al, '-'
call putc
@ -197,14 +210,26 @@ cmd: mov ax, cs
push ax
call space
pop ax
; branch out into commands
les bx, [defptr]
; set up default for cmds
mov dx, cs
mov ds, dx
mov es, dx
mov di, defptr
; show and edit mem
cmp al, 'D'
je cmd_d
cmp al, 'G'
je exit
cmp al, 'E'
je cmd_e
; show and edit regs
cmp al, 'R'
je cmd_r
cmp al, 'V'
je cmd_v
; actions
cmp al, 'G'
je cmd_g
cmp al, 'T'
je cmd_t
; set working ptr
cmp al, 'S'
je cmd_s
@ -215,26 +240,39 @@ err: mov al, '?'
call putc
jmp cmd
cmd_d: mov cx, 8
cmd_d: les bx, [di]
mov cx, 8
.l01: push cx
call nl
call dump
pop cx
add bx, 0x10
mov [defptr], bx
mov [cs:di], bx
loop .l01
jmp cmd
cmd_o: mov bx, defptr
jmp cmd_s.l01
cmd_s: mov bx, defptr+2
.l01: call editw
cmd_v: call regn
mov ax, dx
mov di, lbls
mov cx, 11
repne scasw
jne err
sub di, lbls+2
lea bx, [bp+di]
call space
call editw
jmp cmd
hlt: hlt
jmp hlt
regn: call .l01
xchg dh, dl
.l01: call getc
call putc
mov dh, al
ret
cmd_t: or byte [bp+23], 1
jmp exit
cmd_g: and byte [bp+23], 0xFE
exit: pop ax
pop cx
pop dx
@ -251,11 +289,7 @@ lbls: db "AXCXDXBXBPSIDI" ; gpr
db "DSES" ; seg regs
db "IPCSFL" ; iret frmae
defptr: dw 0x7C00, 0
defptr: equ (base-4)
times 510-($-$$) db 0x00
db 0x55,0xaa
section .bss
line: resb 0x100