📄 debug.asm
字号:
push dword ptr es:[esi+4] ; STK[4]
mov eax,cr0
push eax ; CR0
push dword ptr [ebp-40] ; EBX
push dword ptr [ebp-24] ; EDI
mov dx,offs dbgmsg5
call prints
add sp,16
push dword ptr es:[esi+8] ; STK[8]
mov eax,cr2
push eax ; CR2
push dword ptr [ebp-32] ; ECX
push dword ptr [ebp-16] ; EBP
mov dx,offs dbgmsg6
call prints
add sp,16
push dword ptr es:[esi+12] ; STK[12]
mov eax,cr3
push eax ; CR3
push dword ptr [ebp-28] ; EDX
push dword ptr [ebp-20] ; ESP
mov dx,offs dbgmsg7
call prints
add sp,16
mov dx,offs selmsg1
mov ax,[ebp-4] ; CS: selector
call show_selector
mov dx,offs selmsg2
mov ax,[ebp-42] ; DS: selector
call show_selector
mov dx,offs selmsg3
mov ax,[ebp-44] ; ES: selector
call show_selector
mov dx,offs selmsg4
mov ax,[ebp-46] ; SS: selector
call show_selector
mov dx,offs selmsg5
mov ax,[ebp-48] ; FS: selector
call show_selector
mov dx,offs selmsg6
mov ax,[ebp-50] ; GS: selector
jmp show_selector
;-----------------------------------------------------------------------------
show_selector:
push ax
call prints
pop ax
test ax,ax ; check if NULL selector
jnz @@1
mov dx,offs dbgmsgB
call prints
jmp printcr
@@1: sub sp,8 ; get selector info
mov es,_sel_ss
mov edi,esp
mov bx,ax
mov ax,000Bh
int 31h
jnc @@2 ; branch if selector is OK
add sp,8 ; invalid selector
mov dx,offs dbgmsgA
call prints
jmp printcr
@@2: mov ax,word ptr es:[edi+5] ; explain selector
mov dx,ax
push ax ; Acc
shr al,1
and ax,07h
push ax ; Type
mov cl,dh
shr cl,6
and cl,1
mov ax,16
shl ax,cl
push ax ; Seg: USE16/USE32
mov al,dl
shr al,3
and eax,01h
lea eax,selmsg8[eax*4+eax]
push ax ; Seg: DATA/CODE
mov al,dh
shr al,7
and eax,01h
lea eax,selmsg9[eax+eax*4]
push ax ; Granularity
mov al,dh
and eax,0Fh
shl eax,16
mov ax,word ptr es:[edi+0]
push eax ; Limit
mov ah,byte ptr es:[edi+7]
mov al,byte ptr es:[edi+4]
shl eax,16
mov ax,word ptr es:[edi+2]
push eax ; Base
mov dx,offs selmsg0
call prints
add sp,26
ret
;-----------------------------------------------------------------------------
check_faultsel:
add eax,ecx ; linear addr = CS_base+EIP_offset
push ecx
mov ecx,_app_num_objects
jcxz @@2
@@1: cmp bx,_app_buf_allocsel[ecx*2]
jz @@3
loop @@1
@@2: stc
jmp @@done
@@3: sub eax,_app_buf_allocbase[ecx*4]
mov si,cx
clc
@@done: pop ecx
ret
.8086
;=============================================================================
tone: push ax cx
mov ax,0500h
mov cx,0110h
call beep
mov ax,0300h
call beep
pop cx ax
ret
;=============================================================================
beep: test cs:_misc_byte,00000010b
jz @@done
push cx dx ax ; AX=frequency, CX=time
mov al,0B6h ; set frequency
out 43h,al
pop ax
out 42h,al ; fLow
mov al,ah
out 42h,al ; fHigh
in al,61h ; beep on
or al,03h
out 61h,al
@@loop: in al,40h
in al,40h
mov ah,al
@@0: in al,40h
in al,40h
cmp ah,al
je @@0
loop @@loop
in al,61h ; beep off
and al,not 03h
out 61h,al
pop dx cx
@@done: ret
;=============================================================================
scr_on: push ax bx cx dx
test cs:_misc_byte,01000000b
jz @@1
mov ax,0003h
int 10h ; set default videomode
@@1: mov dx,03C4h ; turn on VGA screen
mov al,01
out dx,al
inc dx
in al,dx
and al,0DFh
out dx,al
pop dx cx bx ax
ret
.386p
;=============================================================================
_exc00: push 00h
jmp _exc_common
_exc06: push 06h
jmp _exc_common
_exc0D: push 0Dh
jmp _exc_common
_exc0E: push 0Eh
_exc_common:
cli
cld
pushad ; push regs on application's stack
mov ax,ss
mov edx,esp
lss esp,fword ptr cs:_sel_esp ; switch to internal 16bit stk
push ds es fs gs ; now push the segment regs
mov es,ax
movzx ebx,ax
lar ebx,ebx
test ebx,00400000h
mov ebp,edx
jnz @@0
movzx ebp,dx
@@0: mov ds,cs:_sel_ds
call restore_pit
call tone
call scr_on
mov dx,offs errmsg3 ; 'DOS/32A run-time:'
push 6001h ; manually push error code
call prints
pop ax
mov ax,es:[ebp+20h]
mov bx,ax
add bx,bx
push dword ptr es:[ebp+2Eh] ; show EIP
push word ptr es:[ebp+32h] ; show CS:
push word ptr i_msg[bx] ; int name
push ax ; int number
push offs excmsgE ; "exception"
mov dx,offs excmsg1 ; main string
call prints
add sp,12
mov ax,0006h ; get base of application's CS:
mov bx,es:[ebp+32h]
int 31h
shl ecx,16
mov cx,dx ; ECX=CS's Base
mov eax,es:[ebp+2Eh] ; 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 0
mov dx,offs excmsg2 ; 'linear...'
@@4: call prints
add sp,6
cmp byte ptr es:[ebp+20h],08h ; if error code present, show it
jb @@5
push dword ptr es:[ebp+2Ah] ; show error code
mov dx,offs excmsg4
call prints
pop eax
@@5: call printcr
test _misc_byte2,00010000b
jz show_statusx
mov dx,offs excmsgC
push _process_id
push offs start
call prints
pop eax
show_statusx:
call @show_status_1
mov ax,es:[ebp+32h]
call @show_status_2
mov ebx,es:[ebp+36h] ; show EFLAGS
call @show_status_3
lar ax,es:[ebp+32h] ; check if CS: is accessible
jnz @@1
verr word ptr es:[ebp+32h]
jnz @@1
mov fs,es:[ebp+32h] ; show instructions at CS:EIP
mov ebx,es:[ebp+2Eh]
call @show_status_4
jmp @@2
@@1: mov dx,offs selmsg1 ; invalid CS:
push word ptr es:[ebp+32h] ; show heximal CS:
call prints
pop ax
mov dx,offs dbgmsgA ; show 'Invalid Selector'
call prints
@@2: call printcr
lar ax,es:[ebp+3Eh] ; check if SS: is accessible
jnz @@3
mov fs,es:[ebp+3Eh] ; load ES:ESI with stack ptr
mov esi,es:[ebp+3Ah]
jmp @@4
@@3: mov fs,_sel_ds ; load ES:ESI with dummy ptr
xor esi,esi ; that will not trigger errors
@@4: push dword ptr fs:[esi+0] ; STK[0]
push 0 ; Last INT
push dword ptr es:[ebp+04h] ; ESI
push dword ptr es:[ebp+1Ch] ; EAX
mov dx,offs dbgmsg4
call prints
add sp,14
push dword ptr fs:[esi+4] ; STK[4]
push large 0 ; CR0
push dword ptr es:[ebp+00h] ; EDI
push dword ptr es:[ebp+10h] ; EBX
mov dx,offs dbgmsg5
call prints
add sp,16
push dword ptr fs:[esi+8] ; STK[8]
push large 0 ; CR2
push dword ptr es:[ebp+08h] ; EBP
push dword ptr es:[ebp+18h] ; ECX
mov dx,offs dbgmsg6
call prints
add sp,16
push dword ptr fs:[esi+12] ; STK[12]
push large 0 ; CR3
push dword ptr es:[ebp+3Ah] ; ESP
push dword ptr es:[ebp+14h] ; EDX
mov dx,offs dbgmsg7
call prints
add sp,16
mov ax,es
mov fs,ax
mov dx,offs selmsg1
mov ax,fs:[ebp+32h] ; CS: selector
call show_selector
mov dx,offs selmsg2
mov ax,[esp+06h] ; DS: selector
call show_selector
mov dx,offs selmsg3
mov ax,[esp+04h] ; ES: selector
call show_selector
mov dx,offs selmsg4
mov ax,fs:[ebp+3Eh] ; SS: selector
call show_selector
mov dx,offs selmsg5
mov ax,[esp+02h] ; FS: selector
call show_selector
mov dx,offs selmsg6
mov ax,[esp+00h] ; GS: selector
call show_selector
mov al,-1
jmp exit386
;=============================================================================
@show_status_1:
mov al,'='
mov cx,72
@@0: call printc
loop @@0
ret
;-----------------------------------------------------------------------------
@show_status_2:
cmp ax,0008h ; note: kernel selector hardcoded!
mov dx,offs selmsgX ; exception came from "KERNEL"
jz @@0
cmp ax,_sel_cs
mov dx,offs selmsgY ; exception came from "CLIENT"
jz @@0
cmp ax,_sel32_cs
mov dx,offs selmsgZ ; exception came from "APP/32"
jz @@0
mov dx,offs selmsgW ; where do all they come from?
@@0: call prints
jmp printcr
;-----------------------------------------------------------------------------
@show_status_3:
mov esi,ebx
mov cl,8
xor eax,eax
xor edx,edx
@@0: shr bl,1
rcr eax,4
shr bh,1
rcr edx,4
loop @@0
push eax
push edx
push esi
mov dx,offs dbgmsg1
call prints
add sp,12
ret
;-----------------------------------------------------------------------------
@show_status_4:
mov cl,10
@@0: mov al,fs:[ebx+9]
push ax
dec ebx
loop @@0
mov dx,offs dbgmsg2
call prints
add sp,10*2
ret
PopState
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -