📄 debug.asm
字号:
;
; Copyright (C) 1996-2002 Supernar Systems, Ltd. All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are
; met:
;
; 1. Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
;
; 2. Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; 3. The end-user documentation included with the redistribution, if any,
; must include the following acknowledgment:
;
; "This product uses DOS/32 Advanced DOS Extender technology."
;
; Alternately, this acknowledgment may appear in the software itself, if
; and wherever such third-party acknowledgments normally appear.
;
; 4. Products derived from this software may not be called "DOS/32A" or
; "DOS/32 Advanced".
;
; THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS" AND ANY EXPRESSED
; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
;
PushState
.386p
;=============================================================================
; IN: AL = interrupt number / extended error number
; interrupt exception
; ----------------------------
; SS:[ESP] = AX +0 AX +0
; - ec +2
; EIP +2 EIP +6
; xx:CS +6 xx:CS +10
; EFL +10 EFL +14
;
;=============================================================================
critical_handler:
cli ; immediately disable interrupts
cld ; clear direction flag
cmp esp,40h ; check if low on stack
jae critical_handler_start ; if not, proceed
lss esp,fword ptr cs:_sel_esp
critical_handler_start:
push ax
mov ax,ds
mov ds,cs:_sel_ds ; get system's DS
mov _int_temp,ax ; store application's DS
mov al,20h
out 20h,al ; send EOI to the interrupt controller
out 0A0h,al
mov ax,_pic_mask ; restore PIC mask
out 0A1h,al
mov al,ah
out 21h,al
pop ax
mov word ptr _int_number,ax ; store INT number and Last INT number
cmp al,08h ; if INT 00h-07h, no errcode
jb @@1
cmp al,09h ; if INT 09h, no errcode
jz @@1
cmp al,0Fh ; if INT 0Fh, no errcode
jz @@1
ja @@next ; if extended error, goto next handler
push ds ; check for software INT
push esi
lar si,[esp+6+6] ; get CS: rights assuming no errcode
jnz @@0 ; if CS: not valid, jump
verr word ptr [esp+6+6] ; verify selector read access
jnz @@0 ; if non-readable, jump
not si ; invert Present bit
test si,8000h ; test Present bit
jnz @@0 ; if segment was not present, jump
mov ah,al
mov al,0CDh ; AX = ##h, 0CDh (INT ##h instruction)
mov ds,[esp+6+6]
mov esi,[esp+6+2]
cmp ax,[esi-2]
@@0: pop esi
pop ds
jz @@1 ; it is software interrupt, jump
; Exception with error code
;---------------------------
pop ax ; restore application's AX
pop _int_errcode ; remove error_code from stack
mov _int_erravail,1
jmp @@2
; Exception without error code
;------------------------------
@@1: pop ax ; restore application's AX
mov _int_erravail,0
;=============================================================================
; now make stack frame look like this: (relative to EBP)
; GS -50
; FS -48
; SS -46
; ES -44
; PUSHAD -12
; EIP -8
; xx:CS -4
; EFL -0
;-----------------------------------------------------------------------------
@@2: pushad
push _int_temp ; push application's DS
push es ss fs gs
xor eax,eax
mov dr7,eax ; reset any breakpoints
mov _int_ss,ss ; store application's SS:ESP
mov _int_esp,esp
mov ax,ss
cmp ax,_sel_ss ; call from DOS/32A segment?
mov edi,esp
jz @@2a ; yes, do not copy stack
lea esi,[esp+36h] ; SS:ESI=source on stack
les edi,fword ptr _sel_esp ; ES:EDI=destination new stack
sub edi,2 ; adjust EDI (1st dec stk, then push)
mov ecx,1Ch
std
rep movs word ptr es:[edi],ss:[esi] ; move pushed regs to main stk
add edi,2
cld
mov ss,cs:_sel_ss ; switch to system's SS:ESP
lea esp,[edi-2] ; align ESP on 4 bytes boundary
@@2a: lea ebp,[edi+32h]
add dword ptr [ebp-28],0Ch ; adjust application's ESP by 12 bytes
mov al,_int_number
cmp al,1
jz trap_point
cmp al,3
jz break_point
push ax
call restore_pit
call tone
call restore_inttab
call scr_on
pop ax
mov dx,offs errmsg3 ; 'DOS/32A run-time:'
push 6001h ; manually push error code
call prints
pop bx
xor bx,bx
mov bl,al
add bx,bx
push dword ptr [ebp-08h] ; show EIP
push word ptr [ebp-04h] ; show CS:
push word ptr i_msg[bx] ; int name
push ax ; int number
mov dx,offs excmsgE ; assume 'exception'
mov bx,[ebp-04h] ; get CS:
lar cx,bx ; check if valid selector
jnz @@2b
mov es,bx
mov ah,al
mov al,0CDh
mov esi,[ebp-08h] ; get EIP
cmp ax,es:[esi-2] ; check at CS:[EIP] for INT instruct.
jnz @@2b
mov dx,offs excmsgI ; 'unexpected interrupt'
mov ax,offs excmsgS ; replace name by 'software interrupt'
mov [esp+2],ax
@@2b: push dx
mov dx,offs excmsg1 ; main string
call prints
add sp,12
mov ax,0006h ; get base of application's CS:
mov bx,[ebp-04h]
int 31h
shl ecx,16
mov cx,dx ; ECX=CS's Base
mov eax,[ebp-08h] ; EAX=offset of faulting instruction
call check_faultsel ; check if fault occured in app's seg
jc @@3 ; if not, show linear address
push eax ;******** calculate unrelocated addr
push si
mov dx,offs excmsg3 ; 'unrelocated...'
jmp @@4
@@3: push eax
push 0000h
mov dx,offs excmsg2 ; 'linear...'
@@4: call prints
add sp,6
cmp _int_erravail,0 ; if error code present, show it
jz @@5
push _int_errcode ; show error code
mov dx,offs excmsg4
call prints
pop eax
@@5: call printcr
test _misc_byte2,00010000b
jz @@6
mov dx,offs excmsgC
push _process_id
push offs start
call prints
pop eax
@@6: call show_status
@@done: mov al,-1 ; exit with error code 0FFh
jmp exit386
;
; extended error handler
;
@@next: lss esp,fword ptr cs:_sel_esp
push ax
call restore_pit
call tone ; handle extended errors
call restore_inttab
call scr_on
pop ax
mov dx,ax
mov ax,6002h
cmp dl,81h ; RM virtual stack overflow
jz @@x1
mov al,03h
cmp dl,82h ; PM virtual stack overflow
jz @@x1
rol esi,16
mov di,si
shr esi,16
mov al,04h
cmp dl,83h ; extended memory check failure
jz @@x1
mov al,05h
cmp dl,84h ; DOS/4G API call failure
jz @@x1
; mov al,06h
; cmp dl,85h ; invalid selector limit failure
; mov si,bp
; jz @@x1
mov al,00h
movzx si,byte ptr _int_number
@@x1: call report_error
jmp @@done
;-----------------------------------------------------------------------------
trap_point:
mov eax,dr6 ; check if breakpoint on one of DRs
and al,0Fh
jnz null_protect
mov dx,offs excmsg5
jmp brkpnt_common
null_protect:
call tone
call scr_on
xor eax,eax
mov dr6,eax
mov dx,offs nulmsg0
jmp brkpnt_common
break_point:
call tone
call scr_on
mov dx,offs excmsg6
brkpnt_common:
push dx
mov ax,0006h ; get base of application's CS:
mov bx,[ebp-04h]
int 31h
shl ecx,16
mov cx,dx ; ECX=CS's Base
mov eax,[ebp-08h] ; EAX=offset of faulting instruction
call check_faultsel ; check if fault occured in app's seg
pop dx
jc @@1 ; if not, show linear address
push eax ;******** calculate unrelocated addr
push si
push offs excmsgB ; unrelocated
jmp @@2
@@1: push eax
push 0000h
push offs excmsgA ; linear
@@2: push dword ptr [ebp-08h] ; show EIP
push word ptr [ebp-04h] ; show CS:
call prints
add sp,14
call show_status
mov dx,offs excmsg7
call prints
@@loop: mov bl,09h
mov ax,0200h
int 31h
push cx dx
push ds
mov ds,_sel_ss
mov si,STACKSIZE*16+9*4
mov dx,ds:[si+0]
mov cx,ds:[si+2]
pop ds
mov ax,0201h
int 31h
sti
xor ax,ax
int 16h
cli
pop dx cx
push ax
mov bl,09h
mov ax,0201h
int 31h
pop ax
and al,0DFh
cmp al,'A'
jz @@ab
cmp al,'P'
jz @@pr
cmp al,'T'
jz @@tr
mov ax,0400h
mov cx,0100h
call beep
jmp @@loop
@@ab: call restore_pit
call printc
call printcr
mov al,-1
jmp exit386
@@pr: call printc
call printcr
cli
lss esp,fword ptr _int_esp
pop gs fs ss es ds
popad
and byte ptr ss:[esp+9],0FEh
iretd
@@tr: call printc
call printcr
cli
lss esp,fword ptr _int_esp
pop gs fs ss es ds
popad
or byte ptr ss:[esp+9],001h
iretd
;=============================================================================
show_status:
call @show_status_1
mov ax,[ebp-4]
call @show_status_2
mov ebx,[ebp] ; show EFLAGS
call @show_status_3
lar ax,[ebp-4] ; check if CS: is accessible
jnz @@1
verr word ptr [ebp-4]
jnz @@1
mov fs,[ebp-4] ; show instructions at CS:EIP
mov ebx,[ebp-8]
call @show_status_4
jmp @@2
@@1: mov dx,offs selmsg1 ; invalid CS:
push word ptr [ebp-4] ; show heximal CS:
call prints
pop ax
mov dx,offs dbgmsgA ; show 'Invalid Selector'
call prints
@@2: call printcr
lar ax,[ebp-46] ; check if SS: is accessible
jnz @@3
mov es,[ebp-46] ; load ES:ESI with stack ptr
mov esi,[ebp-28]
jmp @@4
@@3: mov es,_sel_ds ; load ES:ESI with dummy ptr
xor esi,esi ; that will not trigger errors
@@4: push dword ptr es:[esi+0] ; STK[0]
mov al,_int_number+1
push ax ; Last INT
push dword ptr [ebp-36] ; EAX
push dword ptr [ebp-12] ; ESI
mov dx,offs dbgmsg4
call prints
add sp,14
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -