📄 cwhelp.asm
字号:
;Get current value.
;
xor eax,eax
mov al,[edx]
mov [edi],eax
add edi,4
;
;Set break point
;
mov b[edx],0cch
;
;Update input values.
;
add esi,6
sub ecx,6
;
ret
endps
;*******************************************************************************
;
;Clear a break point.
;
;On Entry:
;
;ECX - remaining request bytes.
;ESI - current request data.
;EDI - result buffer position.
;
;Returns:
;
;ECX,ESI & EDI updated.
;
;*******************************************************************************
procs REQ_CLEAR_BREAK
inc esi
dec ecx ;skip REQ_CLEAR_BREAK
;
;Get selector base.
;
mov bx,[esi+4]
push ecx
sys GetSelDet32
pop ecx
;
;Include offset.
;
add edx,[esi]
;
;Restore value.
;
mov al,[esi+6]
mov [edx],al
;
;Update input values.
;
add esi,6+4
sub ecx,6+4
;
ret
endps
;*******************************************************************************
;
;Return the alias of a selector.
;
;On Entry:
;
;ECX - remaining request bytes.
;ESI - current request data.
;EDI - result buffer position.
;
;Returns:
;
;ECX,ESI & EDI updated.
;
;*******************************************************************************
procs REQ_GET_NEXT_ALIAS
movzx eax,w[esi+1] ;get alias requested
add esi,1+2
sub ecx,1+2
mov w[edi],0
add edi,2
mov w[edi],0
add edi,2
ret
endps
;*******************************************************************************
;
;Return the name of a module.
;
;On Entry:
;
;ECX - remaining request bytes.
;ESI - current request data.
;EDI - result buffer position.
;
;Returns:
;
;ECX,ESI & EDI updated.
;
;*******************************************************************************
procs REQ_GET_LIB_NAME
add esi,1+4
sub ecx,1+4
mov d[edi],0
add edi,4
mov b[edi],0
inc edi
ret
endps
;*******************************************************************************
;
;Return the text for an error number.
;
;On Entry:
;
;ECX - remaining request bytes.
;ESI - current request data.
;EDI - result buffer position.
;
;Returns:
;
;ECX,ESI & EDI updated.
;
;*******************************************************************************
procs REQ_GET_ERR_TEXT
mov edx,[esi+1]
mov edx,[ErrorList+edx*4]
add esi,1+4
sub ecx,1+4
@@0text:
mov al,[edx]
mov [edi],al
inc edx
inc edi
or al,al
jnz @@0text
ret
endps
;*******************************************************************************
;
;Return current message/error text.
;
;On Entry:
;
;ECX - remaining request bytes.
;ESI - current request data.
;EDI - result buffer position.
;
;Returns:
;
;ECX,ESI & EDI updated.
;
;*******************************************************************************
procs REQ_GET_MESSAGE_TEXT
mov edx,ErrorMessage
add esi,1
sub ecx,1
mov b[edi],0 ;set flags.
inc edi
@@0mtext: mov al,[edx]
mov [edi],al
inc edx
inc edi
or al,al
jnz @@0mtext
ret
endps
;*******************************************************************************
;
;Redirect standard input.
;
;On Entry:
;
;ECX - remaining request bytes.
;ESI - current request data.
;EDI - result buffer position.
;
;Returns:
;
;ECX,ESI & EDI updated.
;
;*******************************************************************************
procs REQ_REDIRECT_STDIN
add esi,ecx
xor ecx,ecx
mov d[edi],6
mov ErrorNumber,6
call SetErrorText
add edi,4
ret
endps
;*******************************************************************************
;
;Redirect standard output.
;
;On Entry:
;
;ECX - remaining request bytes.
;ESI - current request data.
;EDI - result buffer position.
;
;Returns:
;
;ECX,ESI & EDI updated.
;
;*******************************************************************************
procs REQ_REDIRECT_STDOUT
add esi,ecx
xor ecx,ecx
mov d[edi],6
mov ErrorNumber,6
call SetErrorText
add edi,4
ret
endps
;*******************************************************************************
;
;Setup ErrorMessage with text for ErrorNumber.
;
;*******************************************************************************
procs SetErrorText
push eax
mov eax,ErrorNumber
mov eax,d[ErrorList+eax*4]
mov ErrorMessage,eax
pops eax
ret
endps
;*******************************************************************************
;
;Execute the debugee.
;
;On Entry:
;
;EAX - mode, 0=go, 1=step.
;
;Returns:
;
;EAX - status (see REQ_PROG_GO/STEP return flags)
;
;*******************************************************************************
procs Execute
pushs ebx,ecx,edx,esi,edi,ebp
mov ExecuteFlags,eax
;
;Switch to debuggee's PSP.
;
mov bx,DebugPSP
mov ah,50h
int 21h
;
;Install hardware break points.
;
mov esi,offset HBRKTable
mov ebp,4
@@hbrk0: test HBRK_Flags[esi],1
jz @@hbrk1
mov ax,0b00h
mov ebx,HBRK_Address[esi]
mov cx,bx
shr ebx,16
mov dl,HBRK_Size[esi]
mov dh,HBRK_Type[esi]
int 31h
jc @@hbrk1
mov HBRK_Handle[esi],bx
or HBRK_Flags[esi],2
mov ax,0b03h
int 31h
@@hbrk1: add esi,size HBRK
dec ebp
jnz @@hbrk0
;
;Force watch point checking if watches are present.
;
cmp NumWatches,0
jz @@7exec
or ExecuteFlags,2 ;force single steping.
;
;Set debuggee trap flag if it's a single instruction trace else clear it if
;not.
;
@@7exec:
cmp ExecuteFlags,0
jz @@0exec
or DebugEFL,256
jmp @@11exec
@@0exec: and DebugEFL,not 256
;
;Set flags ready for execution.
;
@@11exec:
mov Executing,1
mov ExceptionFlag,-1
mov BreakFlag,0
mov TraceFlag,0
mov BreakKeyFlag,0
;
;Put return address on the stack.
;
mov eax,offset @@backexec ;store return address for int 3.
push eax
mov w[DebuggerSS],ss
mov d[DebuggerESP],esp
;
;Execute the program.
;
mov ss,DebugSS
mov esp,DebugESP
push d[DebugEFL]
push w[DebugZero]
push w[DebugCS]
push d[DebugEIP]
mov eax,DebugEAX
mov ebx,DebugEBX
mov ecx,DebugECX
mov edx,DebugEDX
mov esi,DebugESI
mov edi,DebugEDI
mov ebp,DebugEBP
mov gs,DebugGS
mov fs,DebugFS
mov es,DebugES
mov ds,DebugDS
iretd
;
;Clear execution flag.
;
@@backexec:
mov Executing,0
;
;Check if we're single stepping to allow for watches.
;
test ExecuteFlags,2
jz @@8exec
cmp TerminationFlag,0 ;terminated?
jnz @@8exec
cmp ExceptionFlag,-1 ;exception triggered?
jnz @@8exec
cmp BreakKeyFlag,0
jnz @@8exec
;
;Check state of all watches.
;
mov esi,offset WatchTable
mov ebp,MaxWatches
@@hbrk6: test WATCH_Flags[esi],1 ;in use?
jz @@hbrk7
;
;Check if this watch changed.
;
mov edi,WATCH_Address[esi]
mov ecx,WATCH_Length[esi]
xor eax,eax
xor ebx,ebx
@@hbrk8: mov bl,[edi]
add eax,ebx
inc edi
dec ecx
jnz @@hbrk8
cmp eax,WATCH_Check[esi]
jnz @@10exec ;signal COND_WATCH
@@hbrk7: add esi,size WATCH
dec ebp
jnz @@hbrk6
;
;Check it wasn't a single step anyway.
;
test ExecuteFlags,1 ;single steping anyway?
jnz @@8exec
jmp @@7exec
;
;Set vars to trigger COND_WATCH
;
@@10exec: mov ExceptionFlag,1 ;force trace flag setting.
or TraceFlag,-1
;
;Remove HBRK's
;
@@8exec:
mov al,20h ; MED 08/06/96, re-enable interrupts
out 20h,al
mov esi,offset HBRKTable
mov ebp,4
@@hbrk4: test HBRK_Flags[esi],2
jz @@hbrk5
and HBRK_Flags[esi],not 2
mov bx,HBRK_Handle[esi]
mov ax,0b01h
int 31h
@@hbrk5: add esi,size HBRK
dec ebp
jnz @@hbrk4
;
;Store PSP incase it changed.
;
mov ah,62h
int 21h
mov DebugPSP,bx
;
;Switch back to helpers PSP.
;
mov bx,PSPSegment
mov ah,50h
int 21h
;
;Now setup return value to reflect why we stopped execution.
;
xor eax,eax
cmp TerminationFlag,0 ;program terminated?
jz @@1exec
or eax,1 shl 10 ;COND_TERMINATE
jmp @@9exec
@@1exec: cmp BreakKeyFlag,0
jz @@20exec
or eax,1 shl 9 ;COND_USER
jmp @@9exec
@@20exec: cmp BreakFlag,0 ;break point?
jz @@2exec
or eax,1 shl 7 ;COND_BREAK
jmp @@9exec
@@2exec: cmp TraceFlag,0 ;trace point?
jz @@3exec
cmp ExceptionFlag,1 ;hardware break point?
jnz @@5exec
or eax,1 shl 8 ;COND_WATCH
or eax,1 shl 11 ;COND_EXCEPTION
mov ErrorNumber,12
call SetErrorText
jmp @@9exec
@@5exec: or eax,1 shl 6 ;COND_TRACE
jmp @@9exec
@@3exec: cmp ExceptionFlag,-1 ;exception?
jz @@4exec
or eax,1 shl 11 ;COND_EXCEPTION
mov ErrorNumber,7
cmp ExceptionFlag,0 ;div zero?
jz @@12exec
mov ErrorNumber,8
cmp ExceptionFlag,12 ;stack?
jz @@12exec
mov ErrorNumber,9
cmp ExceptionFlag,13 ;general?
jz @@12exec
mov ErrorNumber,10
cmp ExceptionFlag,14 ;page?
jz @@12exec
mov ErrorNumber,11
@@12exec: call SetErrorText
jmp @@9exec
@@4exec: or eax,1 shl 8 ;COND_WATCH = dunno!
;
;Return to caller.
;
@@9exec:
pops ebx,ecx,edx,esi,edi,ebp
ret
endps
;*******************************************************************************
;
;Check if hardware break point executed.
;
;*******************************************************************************
IsHardBreak proc near private
pushad
push ds
mov ax,DGROUP
mov ds,ax
mov esi,offset HBRKTable
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -