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

View File

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