📄 cwhelp.asm
字号:
include system.inc
include cw.inc
; MED 1/21/2003, WASM compatibility change
; only macros left used from the once mighty EQUMAC.INC follow
;*******************************************************************************
;Lazy variable access equates.
;*******************************************************************************
b equ byte ptr
w equ word ptr
d equ dword ptr
f equ fword ptr
;*******************************************************************************
;Similar to PROC but it resets the variables needed for ESP local variable and
;stack parameter addressing.
;
;Usage: PROCS TestProc
;
; Does: TestProc PROC and some initialisation.
;
;*******************************************************************************
procs macro name
;curproc textequ <name>
curproc textequ name
curproc proc private
endm
;*******************************************************************************
;Similar to ENDP but doesn't need a name. It closes a PROCS routine.
;*******************************************************************************
endps macro
curproc endp
endm
;*******************************************************************************
;Replacement for PUSH that maintains the stack offset for PARAMS,LOCALS &
;MLOCAL and allows multiple parameters.
;*******************************************************************************
pushs macro r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16
irp x,<r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16> ;REPEAT FOR EACH PARM
ifnb <x>
push x
endif
endm
endm
;*******************************************************************************
;A replacement for POP that maintains the stack offset for PARAMS,LOCALS &
;MLOCAL and allows multiple parameters. POP's in reverse order.
;*******************************************************************************
pops macro r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16
irp x,<r16,r15,r14,r13,r12,r11,r10,r9,r8,r7,r6,r5,r4,r3,r2,r1> ;REPEAT FOR EACH PARM
ifnb <x>
pop x
endif
endm
endm
;*******************************************************************************
;Call a C routine with stacked parameters and clean the stack afterwards. Also
;preserves all registers except EAX.
;*******************************************************************************
callc macro name,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16
pushs ebx,ecx,edx,esi,edi,ebp
callsize = 0
irp x,<p16,p15,p14,p13,p12,p11,p10,p9,p8,p7,p6,p5,p4,p3,p2,p1>
ifnb <x>
callsize = callsize+4
pushs x
endif
endm
call name
if callsize
lea esp,[esp+callsize]
endif
pops ebx,ecx,edx,esi,edi,ebp
endm
;*******************************************************************************
;Add a memory region to the auto-lock list.
;*******************************************************************************
autolock macro p1,p2
extrn __autolock:near
extrn __autounlock:near
_AUTOLOCKB segment dword public 'DATA'
_AUTOLOCKB ends
_AUTOLOCK segment dword public 'DATA'
dd p1,p2
_AUTOLOCK ends
_AUTOLOCKE segment dword public 'DATA'
_AUTOLOCKE ends
endm
;
;Hardware break point table entry structure.
;
HBRK struc
HBRK_Flags dw 0 ;padding.
HBRK_Handle dw 0 ;DPMI break point handle.
HBRK_Address dd 0 ;Linear break point address.
HBRK_Size db 0 ;DPMI size code to use.
HBRK_Type db 0 ;DPMI type code to use.
HBRK ends
MaxWatches equ 256
;
;Software watch point table entry structure.
;
WATCH struc
WATCH_Flags dd 0
WATCH_Address dd 0
WATCH_Length dd 0
WATCH_Check dd 0
WATCH ends
.data
; MED 1/21/2003
; kill need for C2.INC by appropriate external declarations
EXTERN __psp:WORD, strcpy:NEAR, strcat:NEAR, strlen:NEAR
public PSPSegment,DebugLevel
dLockStart label byte
PSPSegment dw ?
public ReqTable
ReqTable label dword
dd 0 ;0
dd 0 ;1
dd 0 ;2
dd 0 ;3
dd 0 ;4
dd 0 ;5
dd 0; REQ_GET_SYS_CONFIG ;6
dd REQ_MAP_ADDR ;7
dd 0; REQ_ADDR_INFO ;8
dd REQ_CHECKSUM_MEM ;9
dd REQ_READ_MEM ;10
dd REQ_WRITE_MEM ;11
dd REQ_READ_IO ;12
dd REQ_WRITE_IO ;13
dd REQ_READ_CPU ;14
dd REQ_READ_FPU ;15
dd REQ_WRITE_CPU ;16
dd REQ_WRITE_FPU ;17
dd REQ_PROG_GO ;18
dd REQ_PROG_STEP ;19
dd REQ_PROG_LOAD ;20
dd REQ_PROG_KILL ;21
dd REQ_SET_WATCH ;22
dd REQ_CLEAR_WATCH ;23
dd REQ_SET_BREAK ;24
dd REQ_CLEAR_BREAK ;25
dd REQ_GET_NEXT_ALIAS ;26
dd 0 ;27
dd 0 ;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0
DebugSegs dd 0
DebugRegsStart label byte
DebugEAX dd 0
DebugEBX dd 0
DebugECX dd 0
DebugEDX dd 0
DebugESI dd 0
DebugEDI dd 0
DebugEBP dd 0
DebugESP dd 0
DebugEIP dd 0
DebugEFL dd 0
DebugCR0 dd 0
DebugCR2 dd 0
DebugCR3 dd 0
DebugDS dw 0
DebugES dw 0
DebugSS dw 0
DebugCS dw 0
DebugFS dw 0
DebugGS dw 0
DebugRegsEnd label byte
DebugZero dw 0
TerminationFlag db 0
TerminateCode db 0
Executing db 0
ExceptionFlag db 0
BreakFlag db 0
TraceFlag db 0
DebuggerESP dd 0
DebuggerSS dw 0
ExecuteFlags dd 0
BreakKeyFlag db 0
HBRKTable db size HBRK * 4 dup (0)
NumWatches dd 0
WatchTable db size WATCH * 256 dup (0)
ErrorNumber dd 0
ErrorMessage dd 0
ErrorList dd 0,ErrorM01,ErrorM02,ErrorM03,ErrorM04,ErrorM05,ErrorM06,ErrorM07
dd ErrorM08,ErrorM09,ErrorM10,ErrorM11,ErrorM12
ErrorM01 db "DOS reported a file access error",0
ErrorM02 db "Unknown file format",0
ErrorM03 db "Not enough memory",0
ErrorM04 db "Invalid task handle",0
ErrorM05 db "Not enough WATCH table space",0
ErrorM06 db "Function not implemented",0
ErrorM07 db "Divide by zero exception (00h)",0
ErrorM08 db "Stack access exception (0Ch)",0
ErrorM09 db "General protection exception (0Dh)",0
ErrorM10 db "Page access exception (0Eh)",0
ErrorM11 db "Unknown exception",0
ErrorM12 db "Hardware break point triggered",0
LinearAddressCheck db 0
InInt09 db 0
KeyTable db 128 dup (0) ;keypress table.
ConfigFile db "cwhelp.cfg",0
ConfigName db "cwhelp.cfg", 128 dup (0)
SetupName db "setup",0
BreakKeyVar db "BreakKeys",0
BreakKeyList dd 1dh,38h,0,0,0
ResetTimerVAR db "ResetTimer",0
ResetTimer dd 0
DebugVar db "debug",0
DebugLevel dd 0
;DebugLevel dd 1 ; MED 1/20/2003
DebugBuffer db 256 dup (0)
CarriageReturn db 13,0
SpaceText db " ",0
LogFileName db "cwhelp.log",0
LogFileHandle dd 0
dLockEnd label byte
autolock cLockStart,cLockEnd-cLockStart
autolock dLockStart,dLockEnd-dLockStart
.code
cLockStart label byte
;*******************************************************************************
;
;Convert selector number/offset into real address.
;
;On Entry:
;
;ECX - remaining request bytes.
;ESI - current request data.
;EDI - result buffer position.
;
;Returns:
;
;ECX,ESI & EDI updated.
;
;*******************************************************************************
procs REQ_MAP_ADDR
local @@incount:DWORD,@@inaddr:DWORD,@@outaddr:DWORD
; MED 1/20/2003
; cmp DebugLevel,0
; jz @@pastaddr
; call DumpReply2File
;@@pastaddr:
pushad
;
;Setup new input count/address.
;
mov @@incount,ecx
mov @@inaddr,esi
sub @@incount,1+6+4
add @@inaddr,1+6+4
;
;Setup output address and default contents.
;
mov @@outaddr,edi
add @@outaddr,6+4+4
mov eax,[esi+1]
mov [edi],eax
mov w[edi+4],0
mov d[edi+6],0
mov d[edi+6+4],0
;
;Check the module handle.
;
mov bx,DebugPSP
sys GetSelDet32
cmp edx,[esi+1+6] ;right module handle?
jnz @@9addr
;
;Convert the selector.
;
movsx ebx,w[esi+1+4]
cmp ebx,0
jge @@NotFlat0
neg ebx
@@NotFlat0:
dec ebx
shl ebx,3
add bx,[edx+EPSP_SegBase]
or bx,3
mov [edi+4],bx ;set the selector.
;
;Convert the offset.
;
movsx ebx,w[esi+1+4]
cmp ebx,0
jge @@NotFlat1
neg ebx
@@NotFlat1:
dec ebx
shl ebx,3
add ebx,DebugSegs ;point to segment details.
mov eax,[ebx] ;get base offset.
add eax,[edx+EPSP_MemBase]
add [edi],eax ;add real address.
; MED 1/23/2003
; horrible hackery to fix offset+code size passed for symbol offset in global vars
cmp WORD PTR [esi+1+4],-1
jge addrsetb ; only adjust MAP_FLAT_DATA_SELECTOR
mov ecx,DebugSegs
add ecx,8
mov ecx,[ecx] ; 2nd, hopefully DGROUP, segment base offset
add ecx,65535
xor cx,cx ; round up to next 64K
sub [edi],ecx ; subtract off rounded up DGROUP offset
addrsetb:
;
;Set the bounds.
;
mov d[edi+6],0 ;set low bound.
mov eax,[ebx+4] ;get limit.
and eax,0fffffh ;mask to 20 bits.
test d[ebx+4],1 shl 20 ;G bit set?
jz @@NoGBitaddr
shl eax,12
or eax,4095
@@NoGBitaddr:
or eax,eax
jz @@NoDecLimaddr
cmp eax,-1
jz @@NoDecLimaddr
dec eax
@@NoDecLimaddr: mov d[edi+6+4],eax ;set high bound.
;
;Return to caller.
;
@@9addr:
popad
mov ecx,@@incount
mov esi,@@inaddr
mov edi,@@outaddr
ret
endps
;*******************************************************************************
;
;Check-sum some memory.
;
;On Entry:
;
;ECX - remaining request bytes.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -