; ; GRDP ; ; Copyright(c) LADsoft ; ; David Lindauer, gclind01@starbase.spd.louisville.edu ; ; ; Regs.asm ; ; Function: Handle register display and input ; ;MASM MODE .model small .386 include prints.ase include mtrap.ase include input.ase include dis.ase include options.ase PUBLIC DisplayRegisters, ModifyRegisters, ReadReg .code ; ; This is a list corresponding ASCII names for general purpose regs ; with the address the value can be found at; ; peax dw offset dgroup:dreax db 13,10,"eax:",0 pebx dw offset dgroup:drebx db "ebx:",0 pecx dw offset dgroup:drecx db "ecx:",0 pedx dw offset dgroup:dredx db "edx:",0 pesi dw offset dgroup:dresi db "esi:",0 pedi dw offset dgroup:dredi db "edi:",0 pebp dw offset dgroup:drebp db 13,10,"ebp:",0 pesp dw offset dgroup:dresp db "esp:",0 peip dw offset dgroup:dreip db "eip:",0 dw 0 ; ; a list of 8-bit register names ; pal dw offset dgroup:dreax db 13,10,"al:",0 dw offset dgroup:dreax+1 db "ah:",0 dw offset dgroup:drebx db "bl:",0 dw offset dgroup:drebx+1 db "bh:",0 dw offset dgroup:drecx db "cl:",0 dw offset dgroup:drecx+1 db "ch:",0 dw offset dgroup:dredx db 13,10,"dl:",0 dw offset dgroup:dredx+1 db "dh:",0 dw 0 ; ; a list of 16-bit register names ; pax dw offset dgroup:dreax db 13,10,"ax:",0 dw offset dgroup:drebx db "bx:",0 dw offset dgroup:drecx db "cx:",0 dw offset dgroup:dredx db "dx:",0 dw offset dgroup:dresi db "si:",0 dw offset dgroup:dredi db "di:",0 dw offset dgroup:drebp db 13,10,"bp:",0 dw offset dgroup:dresp db "sp:",0 dw offset dgroup:dreip db "ip:",0 pds dw offset dgroup:drds db 13,10,"ds: ",0 PES dw offset dgroup:dres db "es:",0 pfs dw offset dgroup:drfs db "fs:",0 pgs dw offset dgroup:drgs db "gs:",0 Pss dw offset dgroup:drss db "ss:",0 pcs dw offset dgroup:drcs db "cs:",0 dw 0 peflags dw offset dgroup:reflags db "eflags:",0 dw 0 flm label byte db 11 dd "NVOV" db 10 dd "UPDN" db 9 dd "DIEI" db 7 dd "PLMI" db 6 dd "NZZR" db 4 dd "NAAC" db 2 dd "POPE" db 0 dd "NCCY" db -1 db 0 ; ; Print a general purpose reg and it's value ; PutDword PROC test [optdword],0ffh jz PutWord lods word ptr cs:[si]; Get pointer to val mov bx,ax mov eax,[bx] ; Get val push eax ; mov bx,si ; Get text pointer call olMessage pop eax ; call printdword ; Print value call printspace ; ret PutDword ENDP ; ; Print a segment reg and its value ; PutWord PROC lods word ptr cs:[si]; Get pointer to value mov bx,ax mov ax,[bx] ; Get value push ax ; mov bx,si ; Pointer to text call olMessage pop ax ; call printword ; Print value call printspace ; ret PutWord ENDP ; ; Print either the GP regs or the SEG regs ; PrintaFew PROC call dx ; Call the print routine pf_lp: lods byte ptr cs:[si]; Wade past the text or al,al ; jnz pf_lp ; test WORD PTR cs:[si],-1 ; See if trailer found jnz PrintAFew ; Go print another ret PrintAFew ENDP ; ; try to find a match for a register spec ; skimreg PROC push di push si xchg si,di add si,2 srlp: cmp byte ptr cs:[si],32 jnc oktry inc si jmp srlp oktry: cmp byte ptr cs:[si],':' jz match cmps byte ptr cs:[si],es:[di] jz oktry pop di add sp,2 srlp2: lods byte ptr cs:[si] or al,al jnz srlp2 test word ptr cs:[si],0ffffh xchg si,di jnz skimreg sub al,al inc al ret match: add sp,2 sub eax,eax xchg si,di pop di mov di,cs:[di] stc ret skimreg ENDP ; ; search all the name tables for a match ; FindRegister PROC mov di,offset _text: peax call skimreg mov cl,4 jc frnoseg mov di,offset _text: pal call skimreg mov cl,1 jc frnoseg mov di,offset _text: peflags call skimreg mov cl,4 jc frnoseg mov bl,[si+1] mov di,offset _text: pax call skimreg mov cl,2 jnc frnotfound cmp bl,'s' stc jnz frnoseg clc frnoseg: mov al,0ffH inc al pushf test [optdword],1 jnz okdword cmp cl,2 jbe okdword mov cl,2 okdword: popf ret frnotfound: sub ax,ax inc ax stc ret FindRegister ENDP ; ; read the value of a reg (used by input routines) ; ReadReg PROC push ecx call FindRegister jnz notreg pushf mov ax,[di] cmp cl,4 jz rr_exit movzx eax,ax cmp cl,2 jz rr_exit movzx eax,al rr_exit: popf notreg: pop ecx ret ReadReg ENDP ; ; Read value for a register back into memory (R) command ; ReadRegValue PROC call WadeSpace jz doregprompt inc si cmp al,':' jz ReadRegValue cmp al,'=' jz ReadRegValue dec si call ReadNumber ret doregprompt: push bx ; Else put up prompt push cx ; Msg <13,10,": "> call GetInputLine ; Get input line pop cx ; pop bx ; call WadeSpace ; Ignore spaces jz short rr_out ; Quit if so call ReadNumber ret rr_out: stc ret ReadRegValue ENDP ; ; main 'Reg' command ; ModifyRegisters PROC call wadespace ; Wade through spaces jz DisplayRegisters ; Display regs call FindRegister jnz badreg push di call ReadRegValue pop di jc badreg2 cmp cl,4 jnz wordreg mov [di],eax clc ret wordreg: cmp cl,2 jnz bytereg mov [di],ax badreg2: clc ret badreg: stc ret bytereg: mov [di],al ret ModifyRegisters ENDP putflags PROC mov si,offset _text: flm putflags2: lods byte ptr cs:[si] or al,al js pfdone movzx ax,al bt word ptr [reflags],ax lods dword ptr cs:[si] mov edx,eax jc isclr shr edx,16 isclr: xchg dh,dl call PutChar xchg dl,dh call PutChar call PrintSpace jmp putflags2 pfdone: ret putflags ENDP ; ; Display the processor regs ; DisplayRegisters PROC mov word ptr [dreip + 2],0 pushfd pop eax shr eax,16 mov word ptr [reflags+2],ax mov si, offset _text: peax ; Print GP regs mov dx,offset _text:PutDword ; with the DWORD function call PrintAFew ; Print them mov si,offset _text: peflags ; Put the flags call PutDword ; call putflags mov si,offset _text: pds ; Now put the segs mov dx,offset _Text:PutWord ; call PrintAFew ; mov bx,word ptr [dreip] ; Dissassemble at current code pointer mov dx,[drcs] ; call DisOneLine ; clc ret DisplayRegisters ENDP END