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