User:Johnburger/Demo/Ints/Debug/Regs
Stack Frame
Displaying the registers can be very useful when debugging. The only problem is getting hold of them! Luckily the default Fault handler already knows where they are - as long as this Debug handler institutes the same Stack Frame as the Fault handler.
Register Display
That didn't turn out to be too hard. The next problem was where to display the registers on the screen. The Fault handler just listed them vertically. I wanted most of the screen real estate to be taken up in memory dump, so it had to be in a few rows at the bottom of the screen. I was able to encode an (X,Y) location for each register in a single byte: a screen 'map' is reproduced below from the Ints.Name
table.
Note that I cheated a little bit: I overlapped the CS
and SS
values over the labels for EIP
and ESP
respectively. I was running out of room... and besides, they just kind of work, don't they?
; 0000000000000000111111111111111122222222222222223333333333333333
; 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
;000: _EAX:######## _EBX:######## _ECX:######## _EDX:########
;040: _ESI:######## _EDI:######## _EBP:######## Flag:########
;080: __DS:#### __ES:#### __FS:#### __GS:#### PDBR:########
;0C0: __CS:####:######## __SS:####:######### _LDT:#### Task:####
Demo/Ints/Debug/Regs.inc
;
; Ints/Debug/Regs.inc
;
; This module displays the registers stored on the stack, with the aid of
; .Names.Regs in Debug.inc.
Ints.Debug.Regs:
.Window EQU ((Debug.VGA.Top+Debug.Show.Height)*VGA.Cols+Debug.VGA.Left) * 2
PUSH CS ; Point to Ints.Names
POP DS ; With DS
CLD
MOV ESI,Ints.Names.Regs ; Register Names only
.Regs:
LODSB ; Get Debug offset
MOVZX ECX,AL ; Into two registers
MOV EDX,ECX
AND ECX,3Fh ; XLoc
SHR EDX,6 ; YLoc
IMUL EDX,VGA.Cols ; RowLoc
ADD EDX,ECX ; Combined
MOV AH,Debug.Colour.Label
MOV CL,Ints.Names.Label
LEA EDI,[.Window+EDX*2] ; Screen position
.Name:
LODSB ; Get Name
STOSW
LOOP .Name
MOV AL,':' ; Separator
STOSW
LODSB ; Get Hex width
MOV CL,AL
LODSB ; Get Stack offset
INC ESI ; (Ignore TSS offset)
MOVZX EDX,AL ; As indexable address
MOV AH,Debug.Colour.Regs
MOV EDX,[ESP+4+EDX] ; Value to display
CALL Ints.Hex
CMP ESI,Ints.Names.End
JB .Regs
RET