debug.rom: Allocate lowmem segment instead of full relocate

This commit is contained in:
Nero 2020-05-16 13:10:21 +00:00
parent e217b70bb7
commit e30f99c1a7
1 changed files with 63 additions and 56 deletions

View File

@ -1,6 +1,9 @@
cpu 8086
org 0x0000
; interrupt vector we store add of data segment in
bssvec: equ 0xB6
db 0x55, 0xAA
db 0x00
jmp init
@ -30,42 +33,28 @@ pnp: db "$PnP"
name: db "rdos debug"
init: push ds
push es
push si
push di
push ax
push cx
xor ax, ax
mov si, ax
mov di, ax
; load DS for
mov ds, ax
; move down int 0x12 ptr to make space for us
sub word [0x413], ((end - $$) >> 10)
; DS := 0
xor ax, ax
mov ds, ax
; allocate a single kilobyte from end of lowmem
dec word [0x413]
; calculate segment from kilobytes
mov ax, [0x413]
mov cl, 6
shl ax, cl
; load ES for relocate
mov es, ax
; store interrupt vectors
; store ptr to our data segment in B6h vector
mov word [bssvec*4], ax
; set entry points vectors
mov word [1*4], int3entry
mov word [1*4+2], es
mov word [1*4+2], cs
mov word [3*4], int3entry
mov word [3*4+2], es
; load DS for relocate
push cs
pop ds
; calculate our length
mov cx, codeend
rep movsb
mov word [3*4+2], cs
pop cx
pop ax
pop di
pop si
pop es
pop ds
retf
@ -111,7 +100,7 @@ printregs:
mov ah, 0x0e
mov si, reg_ax
.loop: push cx
mov dx, [si+(names-reg_ax)]
mov dx, [cs:si+names]
mov al, dl
int 0x10
mov al, dh
@ -128,7 +117,8 @@ printregs:
mov dx, [reg_fl]
mov si, fnames
mov cx, 16
.floop: lodsb
.floop: mov al, [cs:si]
inc si
cmp al, '+'
je .fskip
test dx, 0x8000
@ -142,11 +132,18 @@ printregs:
int3entry:
; save DS and AX
mov [cs:reg_ds], ds
mov [cs:reg_ax], ax
; use AX to load DS=CS
mov ax, cs
push ds
push ax
; DS=0
xor ax, ax
mov ds, ax
; load bss segment
mov ds, [bssvec*4]
; pop AX and DX
pop ax
mov [reg_ax], ax
pop ax
mov [reg_ds], ax
; pop IP, CS and flags from stack
pop ax
mov [reg_ip], ax
@ -166,14 +163,17 @@ int3entry:
mov [reg_ss], ss
mov [reg_es], es
; initialize other segments and setup stack
mov ax, cs
mov ax, ds
mov es, ax
mov ss, ax
mov sp, end
mov sp, stack
call crlf
call printregs
mov dx, ds
call print16
loop: ; new line & show prompt
call crlf
mov al, '-'
@ -223,15 +223,21 @@ return: ; restore stack pointer
mov si, [reg_si]
mov di, [reg_di]
; restore segment registers
; DS must be last
mov es, [reg_es]
mov ds, [reg_ds]
; final jump back
iret
names: db "AXCXDXBXSPBPSIDI"
db "ESCSSSDSIPFL"
fnames: db "++++ODIT"
names: ; general purpose regs
db "AXCXDXBXSPBPSIDI"
; segment regs
db "ESCSSSDS"
; special regs
db "IPFL"
fnames: ; control flags
db "++++ODIT"
; status flags
db "SZ+A+P+C"
getc: xor ax, ax
@ -270,29 +276,30 @@ read: mov di, cmdbuf
.can: stc
.enter: ret
codeend:
align 512
reg_ax: dw 0
reg_cx: dw 0
reg_dx: dw 0
reg_bx: dw 0
reg_sp: dw 0
reg_bp: dw 0
reg_si: dw 0
reg_di: dw 0
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
reg_es: dw 0
reg_cs: dw 0
reg_ss: dw 0
reg_ds: dw 0
reg_es: resw 1
reg_cs: resw 1
reg_ss: resw 1
reg_ds: resw 1
reg_ip: dw 0
reg_fl: dw 0
reg_ip: resw 1
reg_fl: resw 1
cmdlen: equ 16
cmdbuf: times cmdlen dw 0
cmdbuf: resb cmdlen
stack: times 0x80 dw 0
align 1024
end:
; reserve at least 80h words for stack
resw 0x80
alignb 1024
stack: