2020-05-12 22:47:34 +02:00
|
|
|
cpu 8086
|
|
|
|
org 0x0000
|
|
|
|
|
2020-05-17 18:09:50 +02:00
|
|
|
; interrupt vector we store addr of data segment in
|
2020-05-16 15:10:21 +02:00
|
|
|
bssvec: equ 0xB6
|
|
|
|
|
2020-05-12 22:47:34 +02:00
|
|
|
db 0x55, 0xAA
|
|
|
|
db 0x00
|
|
|
|
jmp init
|
|
|
|
nop
|
|
|
|
|
|
|
|
times (0x18 - ($-$$)) db 0
|
|
|
|
dw 0
|
|
|
|
dw pnp
|
|
|
|
|
|
|
|
pnp: db "$PnP"
|
|
|
|
db 1 ; version 1
|
|
|
|
db 2 ; 2 * 16 length
|
|
|
|
dw 0 ; offset of next header
|
|
|
|
db 0
|
|
|
|
db 0 ; checksum (filled by fix-rom)
|
|
|
|
dd 0 ; device identifier
|
|
|
|
dw 0 ; manufacturer string
|
|
|
|
dw name ; product name string
|
|
|
|
db 0,0,0 ; device type string
|
|
|
|
db 0x20 ; device indicator, bit for "read cacheable" set
|
|
|
|
dw 0 ; boot connection vector
|
|
|
|
dw 0 ; boot disconnect vector
|
|
|
|
dw 0 ; bootstrap entry point
|
|
|
|
dw 0 ; reserved
|
2020-05-18 18:23:37 +02:00
|
|
|
zero: dw 0
|
2020-05-12 22:47:34 +02:00
|
|
|
|
2020-05-17 18:09:50 +02:00
|
|
|
name: db "rdos debug", 0
|
2020-05-12 22:47:34 +02:00
|
|
|
|
|
|
|
init: push ds
|
|
|
|
push ax
|
|
|
|
push cx
|
2020-05-16 15:10:21 +02:00
|
|
|
|
|
|
|
; DS := 0
|
2020-05-12 22:47:34 +02:00
|
|
|
xor ax, ax
|
|
|
|
mov ds, ax
|
2020-05-16 15:10:21 +02:00
|
|
|
; allocate a single kilobyte from end of lowmem
|
|
|
|
dec word [0x413]
|
2020-05-12 22:47:34 +02:00
|
|
|
; calculate segment from kilobytes
|
|
|
|
mov ax, [0x413]
|
|
|
|
mov cl, 6
|
|
|
|
shl ax, cl
|
2020-05-16 15:10:21 +02:00
|
|
|
; store ptr to our data segment in B6h vector
|
|
|
|
mov word [bssvec*4], ax
|
|
|
|
; set entry points vectors
|
2020-05-13 23:30:43 +02:00
|
|
|
mov word [1*4], int3entry
|
2020-05-16 15:10:21 +02:00
|
|
|
mov word [1*4+2], cs
|
2020-05-12 22:47:34 +02:00
|
|
|
mov word [3*4], int3entry
|
2020-05-16 15:10:21 +02:00
|
|
|
mov word [3*4+2], cs
|
2020-05-12 22:47:34 +02:00
|
|
|
|
|
|
|
pop cx
|
|
|
|
pop ax
|
|
|
|
pop ds
|
|
|
|
retf
|
|
|
|
|
2020-05-17 22:46:11 +02:00
|
|
|
; Print AL
|
|
|
|
space: mov al, ' '
|
|
|
|
putc: xor bx, bx
|
|
|
|
mov ah, 0x0e
|
2020-05-12 23:27:48 +02:00
|
|
|
int 0x10
|
|
|
|
ret
|
|
|
|
|
2020-05-17 22:46:11 +02:00
|
|
|
; Print CS:SI
|
|
|
|
puts: push ds
|
|
|
|
push cs
|
|
|
|
pop ds
|
|
|
|
.loop: lodsb
|
|
|
|
test al, al
|
|
|
|
jz .ret
|
|
|
|
call putc
|
|
|
|
jmp .loop
|
|
|
|
.ret: pop ds
|
2020-05-12 23:27:48 +02:00
|
|
|
ret
|
|
|
|
|
2020-05-17 22:46:11 +02:00
|
|
|
crlf: mov al, 0x0A
|
|
|
|
call putc
|
|
|
|
mov al, 0x0D
|
|
|
|
jmp putc
|
|
|
|
|
2020-05-12 22:47:34 +02:00
|
|
|
print16:
|
|
|
|
; setup bx and ah for int 10h call
|
|
|
|
xor bx, bx
|
|
|
|
mov ah, 0x0e
|
|
|
|
mov cl, 4
|
|
|
|
; this double-call is essentially a 4 times repeating loop
|
|
|
|
call .c1
|
|
|
|
.c1: call .c2
|
|
|
|
.c2: ; 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
|
|
|
|
; 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: int 0x10
|
|
|
|
ret
|
|
|
|
|
|
|
|
int3entry:
|
2020-05-18 18:23:37 +02:00
|
|
|
; save DS and load bss segment from IVT
|
2020-05-16 15:10:21 +02:00
|
|
|
push ds
|
2020-05-18 18:23:37 +02:00
|
|
|
mov ds, [cs:zero]
|
2020-05-16 15:10:21 +02:00
|
|
|
mov ds, [bssvec*4]
|
2020-05-18 18:23:37 +02:00
|
|
|
; save AX so we can work with it
|
2020-05-16 15:10:21 +02:00
|
|
|
mov [reg_ax], ax
|
2020-05-18 18:23:37 +02:00
|
|
|
; pop DS, IP, CS and flags from stack
|
2020-05-16 15:10:21 +02:00
|
|
|
pop ax
|
|
|
|
mov [reg_ds], ax
|
2020-05-12 22:47:34 +02:00
|
|
|
pop ax
|
|
|
|
mov [reg_ip], ax
|
|
|
|
pop ax
|
|
|
|
mov [reg_cs], ax
|
|
|
|
pop ax
|
|
|
|
mov [reg_fl], ax
|
|
|
|
; save the other registers
|
|
|
|
mov [reg_cx], cx
|
|
|
|
mov [reg_dx], dx
|
|
|
|
mov [reg_bx], bx
|
|
|
|
mov [reg_sp], sp
|
|
|
|
mov [reg_bp], bp
|
|
|
|
mov [reg_si], si
|
|
|
|
mov [reg_di], di
|
|
|
|
; save other segment registers we can access
|
|
|
|
mov [reg_ss], ss
|
|
|
|
mov [reg_es], es
|
|
|
|
; initialize other segments and setup stack
|
2020-05-16 15:10:21 +02:00
|
|
|
mov ax, ds
|
2020-05-12 22:47:34 +02:00
|
|
|
mov es, ax
|
|
|
|
mov ss, ax
|
2020-05-16 15:10:21 +02:00
|
|
|
mov sp, stack
|
2020-05-12 23:27:48 +02:00
|
|
|
call crlf
|
2020-05-12 22:47:34 +02:00
|
|
|
call printregs
|
|
|
|
|
2020-05-17 22:46:11 +02:00
|
|
|
loop: ; show prompt
|
2020-05-13 21:48:57 +02:00
|
|
|
mov al, '-'
|
|
|
|
int 0x10
|
|
|
|
; read data
|
|
|
|
call read
|
2020-05-17 22:46:11 +02:00
|
|
|
pushf
|
|
|
|
call crlf
|
|
|
|
popf
|
2020-05-13 21:48:57 +02:00
|
|
|
jc loop
|
|
|
|
; execute
|
|
|
|
call runcmd
|
|
|
|
jmp loop
|
|
|
|
|
2020-05-12 23:27:48 +02:00
|
|
|
return: ; restore stack pointer
|
|
|
|
mov ss, [reg_ss]
|
|
|
|
mov sp, [reg_sp]
|
|
|
|
; push flags, CS and IP
|
|
|
|
mov ax, [reg_fl]
|
|
|
|
push ax
|
|
|
|
mov ax, [reg_cs]
|
|
|
|
push ax
|
|
|
|
mov ax, [reg_ip]
|
|
|
|
push ax
|
|
|
|
; restore GPR
|
|
|
|
mov ax, [reg_ax]
|
|
|
|
mov cx, [reg_cx]
|
|
|
|
mov dx, [reg_dx]
|
|
|
|
mov bx, [reg_bx]
|
|
|
|
mov bp, [reg_bp]
|
|
|
|
mov si, [reg_si]
|
|
|
|
mov di, [reg_di]
|
|
|
|
; restore segment registers
|
2020-05-16 15:10:21 +02:00
|
|
|
; DS must be last
|
2020-05-12 23:27:48 +02:00
|
|
|
mov es, [reg_es]
|
|
|
|
mov ds, [reg_ds]
|
|
|
|
; final jump back
|
|
|
|
iret
|
2020-05-12 22:47:34 +02:00
|
|
|
|
2020-05-16 15:10:21 +02:00
|
|
|
names: ; general purpose regs
|
|
|
|
db "AXCXDXBXSPBPSIDI"
|
|
|
|
; segment regs
|
|
|
|
db "ESCSSSDS"
|
|
|
|
; special regs
|
|
|
|
db "IPFL"
|
|
|
|
fnames: ; control flags
|
|
|
|
db "++++ODIT"
|
|
|
|
; status flags
|
2020-05-12 23:27:48 +02:00
|
|
|
db "SZ+A+P+C"
|
|
|
|
|
2020-05-13 21:48:57 +02:00
|
|
|
getc: xor ax, ax
|
|
|
|
int 0x16
|
|
|
|
test al, al
|
|
|
|
jz getc
|
|
|
|
ret
|
|
|
|
|
|
|
|
read: mov di, cmdbuf
|
|
|
|
.loop: call getc
|
|
|
|
cmp al, 0x03
|
|
|
|
je .can
|
|
|
|
cmp al, 0x0D
|
|
|
|
je .enter
|
|
|
|
cmp al, 0x08
|
|
|
|
je .bs
|
|
|
|
cmp di, cmdbuf+cmdlen
|
|
|
|
jnc .loop
|
|
|
|
stosb
|
|
|
|
mov ah, 0x0e
|
|
|
|
xor bx, bx
|
|
|
|
int 0x10
|
|
|
|
jmp .loop
|
|
|
|
ret
|
|
|
|
.bs: cmp di, cmdbuf
|
|
|
|
jbe .loop
|
|
|
|
xor bx, bx
|
|
|
|
mov ax, 0x0e08
|
|
|
|
int 0x10
|
|
|
|
mov al, 0x20
|
|
|
|
int 0x10
|
|
|
|
mov al, 0x08
|
|
|
|
int 0x10
|
|
|
|
dec di
|
|
|
|
jmp .loop
|
|
|
|
.can: stc
|
|
|
|
.enter: ret
|
|
|
|
|
2020-05-17 22:46:11 +02:00
|
|
|
runcmd: mov al, [cmdbuf]
|
|
|
|
cmp al, 'g'
|
|
|
|
je cmd_g
|
|
|
|
cmp al, 'r'
|
|
|
|
je cmd_r
|
|
|
|
cmp al, 't'
|
|
|
|
je cmd_t
|
|
|
|
cmp al, '?'
|
|
|
|
je cmd_?
|
|
|
|
mov al, '?'
|
|
|
|
call putc
|
|
|
|
jmp crlf
|
|
|
|
|
|
|
|
cmd_?: mov si, .txt
|
|
|
|
jmp puts
|
|
|
|
.txt: db "g Go", 0x0A, 0x0D
|
|
|
|
db "r Print register values", 0x0A, 0x0D
|
|
|
|
db "t Single-Step", 0x0A, 0x0D
|
|
|
|
db 0
|
|
|
|
|
|
|
|
cmd_g: and word [reg_fl+1], 0xfe
|
|
|
|
jmp return
|
|
|
|
|
|
|
|
cmd_r: jmp printregs
|
|
|
|
|
|
|
|
cmd_t: or word [reg_fl+1], 0x03
|
|
|
|
jmp return
|
|
|
|
|
|
|
|
printregs:
|
|
|
|
mov cx, 13
|
|
|
|
xor bx, bx
|
|
|
|
mov ah, 0x0e
|
|
|
|
mov si, reg_ax
|
|
|
|
.loop: push cx
|
|
|
|
mov dx, [cs:si+names]
|
|
|
|
lodsw
|
|
|
|
call printreg
|
|
|
|
pop cx
|
|
|
|
loop .loop
|
|
|
|
|
|
|
|
mov dx, [reg_fl]
|
|
|
|
mov si, fnames
|
|
|
|
mov cx, 16
|
|
|
|
.floop: mov al, [cs:si]
|
|
|
|
inc si
|
|
|
|
cmp al, '+'
|
|
|
|
je .fskip
|
|
|
|
test dx, 0x8000
|
|
|
|
jnz .fprnt
|
|
|
|
mov al, '-'
|
|
|
|
.fprnt: int 0x10
|
|
|
|
.fskip: shl dx, 1
|
|
|
|
loop .floop
|
|
|
|
call crlf
|
|
|
|
ret
|
|
|
|
|
|
|
|
printreg:
|
|
|
|
push ax
|
|
|
|
mov al, dl
|
|
|
|
call putc
|
|
|
|
mov al, dh
|
|
|
|
call putc
|
|
|
|
mov al, '='
|
|
|
|
call putc
|
|
|
|
pop dx
|
|
|
|
call print16
|
|
|
|
call space
|
|
|
|
ret
|
|
|
|
|
2020-05-16 15:10:21 +02:00
|
|
|
align 512
|
2020-05-12 22:47:34 +02:00
|
|
|
|
2020-05-16 15:10:21 +02:00
|
|
|
absolute 0
|
|
|
|
reg_ax: resw 1
|
|
|
|
reg_cx: resw 1
|
|
|
|
reg_dx: resw 1
|
|
|
|
reg_bx: resw 1
|
|
|
|
reg_sp: resw 1
|
|
|
|
reg_bp: resw 1
|
|
|
|
reg_si: resw 1
|
|
|
|
reg_di: resw 1
|
2020-05-12 22:47:34 +02:00
|
|
|
|
2020-05-16 15:10:21 +02:00
|
|
|
reg_es: resw 1
|
|
|
|
reg_cs: resw 1
|
|
|
|
reg_ss: resw 1
|
|
|
|
reg_ds: resw 1
|
2020-05-12 22:47:34 +02:00
|
|
|
|
2020-05-16 15:10:21 +02:00
|
|
|
reg_ip: resw 1
|
|
|
|
reg_fl: resw 1
|
2020-05-12 22:47:34 +02:00
|
|
|
|
2020-05-13 21:48:57 +02:00
|
|
|
cmdlen: equ 16
|
2020-05-16 15:10:21 +02:00
|
|
|
cmdbuf: resb cmdlen
|
2020-03-01 13:03:35 +01:00
|
|
|
|
2020-05-16 15:10:21 +02:00
|
|
|
; reserve at least 80h words for stack
|
|
|
|
resw 0x80
|
|
|
|
alignb 1024
|
|
|
|
stack:
|