2021-01-28 22:16:52 +01:00
|
|
|
; monitor program that fits in a boot sector
|
|
|
|
; for debugging disk i/o and bootstrapping
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
%define base (0x10000 - 0x200)
|
2021-01-28 22:16:52 +01:00
|
|
|
|
|
|
|
org base
|
2021-01-29 00:32:31 +01:00
|
|
|
cpu 8086
|
2021-01-28 22:16:52 +01:00
|
|
|
|
|
|
|
; relocate to end of memory
|
|
|
|
init: ; set up src addr
|
|
|
|
xor ax, ax
|
|
|
|
mov ds, ax
|
|
|
|
mov si, 0x7C00
|
|
|
|
; calculate target segment
|
|
|
|
mov ax, [0x413]
|
|
|
|
mov cl, 6
|
|
|
|
shl ax, cl
|
|
|
|
sub ax, 0x1000
|
|
|
|
; set up dst addr
|
|
|
|
mov es, ax
|
|
|
|
mov di, base
|
|
|
|
; set up stack
|
|
|
|
mov ss, ax
|
|
|
|
mov sp, di
|
2021-01-29 00:32:31 +01:00
|
|
|
; push defptr
|
|
|
|
push ds
|
|
|
|
push si
|
2021-01-28 22:16:52 +01:00
|
|
|
; relocate
|
|
|
|
mov cx, 0x100
|
|
|
|
rep movsw
|
|
|
|
; set up intr vectors
|
|
|
|
mov bx, 1*4
|
|
|
|
call .l02
|
|
|
|
; enter
|
|
|
|
mov si, 0x7C00-1
|
|
|
|
mov byte [si], 0xCC
|
|
|
|
push cs
|
|
|
|
push si
|
2021-01-29 00:32:31 +01:00
|
|
|
sti
|
2021-01-28 22:16:52 +01:00
|
|
|
retf
|
|
|
|
|
|
|
|
; call here = run proc tail twice
|
|
|
|
.l02: call .l01
|
|
|
|
.l01: mov word [bx], entry
|
2021-01-29 00:32:31 +01:00
|
|
|
mov word [bx+2], ss
|
2021-01-28 22:16:52 +01:00
|
|
|
add bx, 2*4
|
|
|
|
ret
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
nl: mov ax, 0x0e0A
|
|
|
|
int 0x10
|
2021-01-28 22:16:52 +01:00
|
|
|
mov al, 0x0D
|
|
|
|
jmp putc
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
space: mov al, ' '
|
|
|
|
putc: mov ah, 0x0e
|
|
|
|
int 0x10
|
|
|
|
ret
|
|
|
|
|
|
|
|
; print register set
|
2021-01-28 22:16:52 +01:00
|
|
|
printr: call nl
|
|
|
|
xor si, si
|
|
|
|
.l02: mov ah, 0x0e
|
|
|
|
mov al, [cs:lbls+si]
|
|
|
|
int 0x10
|
|
|
|
mov al, [cs:lbls+si+1]
|
|
|
|
int 0x10
|
|
|
|
mov al, '='
|
|
|
|
int 0x10
|
2021-01-29 00:32:31 +01:00
|
|
|
mov dx, [bp+si]
|
|
|
|
mov ch, ' '
|
|
|
|
call prints
|
|
|
|
add si, 2
|
|
|
|
cmp si, 24
|
|
|
|
jc .l02
|
|
|
|
les bx, [bp+18]
|
|
|
|
jmp dump
|
2021-01-28 22:16:52 +01:00
|
|
|
|
|
|
|
; print 16 bytes from ES:BX
|
2021-01-29 00:32:31 +01:00
|
|
|
dump: mov dx, es
|
|
|
|
mov ch, ':'
|
|
|
|
call prints
|
|
|
|
mov dx, bx
|
|
|
|
mov ch, ' '
|
|
|
|
call prints
|
2021-01-28 22:16:52 +01:00
|
|
|
push bx
|
|
|
|
mov cx, 0x10
|
|
|
|
.l01: mov dh, [es:bx]
|
|
|
|
inc bx
|
|
|
|
push cx
|
|
|
|
call printb
|
|
|
|
call space
|
|
|
|
pop cx
|
|
|
|
loop .l01
|
|
|
|
pop bx
|
|
|
|
ret
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
printw: call printb ; print dx
|
2021-01-28 22:16:52 +01:00
|
|
|
printb: call .l01 ; print dh
|
|
|
|
.l01: mov cl, 4
|
|
|
|
; grab highest nibble from dx
|
|
|
|
mov al, dh
|
|
|
|
; remove highest nibble from dx
|
|
|
|
shl dx, cl
|
|
|
|
; shift away second-highest nibble that we accidentally copied
|
|
|
|
shr al, cl
|
|
|
|
printn: ; map 0-9 to ascii codes for '0' to '9'
|
|
|
|
add al, 0x30
|
|
|
|
; if result is larger than '9', ...
|
|
|
|
cmp al, 0x3a
|
|
|
|
jl .noadj
|
|
|
|
; ... add 7 so we continue at 'A'
|
|
|
|
add al, 7
|
|
|
|
.noadj: mov ah, 0x0e
|
|
|
|
int 0x10
|
|
|
|
ret
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
; print dx and char ch
|
|
|
|
prints: call printw
|
|
|
|
mov al, ch
|
|
|
|
int 0x10
|
|
|
|
ret
|
|
|
|
|
2021-01-28 22:16:52 +01:00
|
|
|
getc: xor ax, ax
|
|
|
|
int 0x16
|
|
|
|
test al, al
|
|
|
|
jz getc
|
2021-01-29 00:32:31 +01:00
|
|
|
; to uppercase
|
2021-01-28 22:16:52 +01:00
|
|
|
cmp al, 0x60
|
|
|
|
jc .ret
|
|
|
|
sub al, 0x20
|
|
|
|
.ret: ret
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
inputw: call inputb
|
|
|
|
inputb: call inputn
|
|
|
|
inputn: jc .ret
|
|
|
|
call getc
|
2021-01-28 22:16:52 +01:00
|
|
|
cmp al, 0x20
|
2021-01-29 00:32:31 +01:00
|
|
|
stc
|
|
|
|
je .ret
|
2021-01-28 22:16:52 +01:00
|
|
|
sub al, 0x30
|
|
|
|
; if >9, turn 'A' to A
|
|
|
|
cmp al, 0x0A
|
|
|
|
jc .noadj
|
|
|
|
sub al, 7
|
|
|
|
.noadj: ; must be smaller than 'F'
|
|
|
|
cmp al, 0x10
|
2021-01-29 00:32:31 +01:00
|
|
|
jnc inputn
|
|
|
|
; append to dx
|
2021-01-28 22:16:52 +01:00
|
|
|
mov cl, 4
|
|
|
|
shl dx, cl
|
|
|
|
or dl, al
|
|
|
|
; print, loop & clear exit
|
|
|
|
call printn
|
|
|
|
clc
|
2021-01-29 00:32:31 +01:00
|
|
|
.ret: ret
|
2021-01-28 22:16:52 +01:00
|
|
|
|
|
|
|
; edit word at ES:BX
|
|
|
|
; space exits with carry
|
|
|
|
editw: mov dx, [es:bx]
|
2021-01-29 00:32:31 +01:00
|
|
|
mov ch, '.'
|
|
|
|
call prints
|
|
|
|
clc
|
|
|
|
call inputw
|
2021-01-28 22:16:52 +01:00
|
|
|
jc .err
|
|
|
|
mov [es:bx], dx
|
|
|
|
.err: ret
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
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
|
|
|
|
|
2021-01-28 22:16:52 +01:00
|
|
|
entry: push es
|
|
|
|
push ds
|
|
|
|
push di
|
|
|
|
push si
|
|
|
|
push bp
|
|
|
|
push bx
|
|
|
|
push dx
|
|
|
|
push cx
|
|
|
|
push ax
|
|
|
|
mov bp, sp
|
|
|
|
|
|
|
|
cmd_r: call printr
|
2021-01-29 00:32:31 +01:00
|
|
|
cmd: ; display prompt
|
2021-01-28 22:16:52 +01:00
|
|
|
call nl
|
|
|
|
mov al, '-'
|
|
|
|
call putc
|
|
|
|
.l01: call getc
|
|
|
|
cmp al, 0x41
|
|
|
|
jc .l01
|
|
|
|
; process input char
|
|
|
|
call putc
|
|
|
|
push ax
|
|
|
|
call space
|
|
|
|
pop ax
|
2021-01-29 00:32:31 +01:00
|
|
|
; set up default for cmds
|
|
|
|
mov dx, cs
|
|
|
|
mov ds, dx
|
|
|
|
mov es, dx
|
|
|
|
mov di, defptr
|
|
|
|
; show and edit mem
|
2021-01-28 22:16:52 +01:00
|
|
|
cmp al, 'D'
|
|
|
|
je cmd_d
|
2021-01-29 00:32:31 +01:00
|
|
|
cmp al, 'E'
|
|
|
|
je cmd_e
|
|
|
|
; show and edit regs
|
2021-01-28 22:16:52 +01:00
|
|
|
cmp al, 'R'
|
|
|
|
je cmd_r
|
2021-01-29 00:32:31 +01:00
|
|
|
cmp al, 'V'
|
|
|
|
je cmd_v
|
|
|
|
; actions
|
|
|
|
cmp al, 'G'
|
|
|
|
je cmd_g
|
|
|
|
cmp al, 'T'
|
|
|
|
je cmd_t
|
2021-01-28 22:16:52 +01:00
|
|
|
; set working ptr
|
|
|
|
cmp al, 'S'
|
|
|
|
je cmd_s
|
|
|
|
cmp al, 'O'
|
|
|
|
je cmd_o
|
|
|
|
|
|
|
|
err: mov al, '?'
|
|
|
|
call putc
|
|
|
|
jmp cmd
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
cmd_d: les bx, [di]
|
|
|
|
mov cx, 8
|
2021-01-28 22:16:52 +01:00
|
|
|
.l01: push cx
|
|
|
|
call nl
|
|
|
|
call dump
|
|
|
|
pop cx
|
|
|
|
add bx, 0x10
|
2021-01-29 00:32:31 +01:00
|
|
|
mov [cs:di], bx
|
2021-01-28 22:16:52 +01:00
|
|
|
loop .l01
|
|
|
|
jmp cmd
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
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
|
2021-01-28 22:16:52 +01:00
|
|
|
jmp cmd
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
regn: call .l01
|
|
|
|
xchg dh, dl
|
|
|
|
.l01: call getc
|
|
|
|
call putc
|
|
|
|
mov dh, al
|
|
|
|
ret
|
2021-01-28 22:16:52 +01:00
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
cmd_t: or byte [bp+23], 1
|
|
|
|
jmp exit
|
|
|
|
cmd_g: and byte [bp+23], 0xFE
|
2021-01-28 22:16:52 +01:00
|
|
|
exit: pop ax
|
|
|
|
pop cx
|
|
|
|
pop dx
|
|
|
|
pop bx
|
|
|
|
pop bp
|
|
|
|
pop si
|
|
|
|
pop di
|
|
|
|
pop ds
|
|
|
|
pop es
|
|
|
|
iret
|
|
|
|
|
|
|
|
; names for registers
|
|
|
|
lbls: db "AXCXDXBXBPSIDI" ; gpr
|
|
|
|
db "DSES" ; seg regs
|
|
|
|
db "IPCSFL" ; iret frmae
|
|
|
|
|
2021-01-29 00:32:31 +01:00
|
|
|
defptr: equ (base-4)
|
2021-01-28 22:16:52 +01:00
|
|
|
|
|
|
|
times 510-($-$$) db 0x00
|
|
|
|
db 0x55,0xaa
|