exceptn.asm

来自「开放源码的编译器open watcom 1.6.0版的源代码」· 汇编 代码 · 共 2,536 行 · 第 1/5 页

ASM
2,536
字号
        movzx   esi,si
@@SP320:        mov     edi,offset DebugBuffer
        mov     ecx,(4+4+4+4+4+4+4)+(2+2+2+2)
        cld
        db 67h
        rep     movsb           ;copy registers off the stack.
        ;
        test    es:ExcepSystemFlags,1
        jz      @@Use32Bit17
        movzx   ebp,sp
        movzx   eax,w[ebp+(4+4+4+4+4+4+4)+(2+2+2+2)+(2+2)]
        mov     es:DebugExceptionCode,eax
        add     esi,2+2+2               ;skip return address/flags.
        db 67h
        movsw
        add     edi,2
        db 67h
        movsw
        add     edi,2
        db 67h
        movsw
        add     edi,2
        jmp     @@Use16Bit17
        ;
@@Use32Bit17:   mov     eax,[esp+(4+4+4+4+4+4+4)+(2+2+2+2)+(4+4)]
        mov     es:DebugExceptionCode,eax
        add     esi,4+4+4               ;skip return address/flags.
        mov     ecx,4+4+4
        cld
        db 67h
        rep     movsb           ;get real return address.
@@Use16Bit17:   ;
        test    es:ExcepSystemFlags,1
        jz      @@Use32Bit678
        movzx   eax,w[esi]
        mov     es:DebugESP,eax
        mov     ax,[esi+2]
        mov     es:DebugSS,ax
        jmp     @@Use16Bit678
        ;
@@Use32Bit678:  mov     eax,[esi]
        mov     es:DebugESP,eax
        mov     ax,[esi+4]
        mov     es:DebugSS,ax
@@Use16Bit678:  ;
        push    es
        pop     ds
        assume es:nothing
        assume ds:_Excep
        ;
        mov     DebugTR,0
        mov     DebugCR0,0
        mov     DebugCR2,0
        mov     DebugCR3,0
        ;
        ;Process segment registers to produce application relative base
        ;addresses.
        ;
        mov     ax,DebugCS
        mov     edi,offset DebugCSApp
        call    DebugSegmentDPMI
        mov     ax,DebugDS
        mov     edi,offset DebugDSApp
        call    DebugSegmentDPMI
        mov     ax,DebugES
        mov     edi,offset DebugESApp
        call    DebugSegmentDPMI
        mov     ax,DebugFS
        mov     edi,offset DebugFSApp
        call    DebugSegmentDPMI
        mov     ax,DebugGS
        mov     edi,offset DebugGSApp
        call    DebugSegmentDPMI
        mov     ax,DebugSS
        mov     edi,offset DebugSSApp
        call    DebugSegmentDPMI
        ;
        popm    eax,ebx,ecx,edx,esi,edi,ebp             ;save general registers.
        popm    ds,es,fs,gs
        ;
        pushm   eax,ebp,ds
        assume ds:nothing
        mov     ds,cs:ExcepDSeg
        assume ds:_cwMain
        mov     DebugDump,1
        mov     ErrorNumber,9
        ;
        mov     ebp,esp         ;make stack addresable.
        ;
        ;Now modify origional CS:EIP,SS:ESP values and return control
        ;to this code via interupt structure to restore stacks.
        ;
        test    SystemFlags,1
        jz      @@Use32_2
        mov     eax,offset @@Use0_2
        mov     w[bp+(4+4+2)+(2+2+2)+(0)],ax
        mov     w[bp+(4+4+2)+(2+2+2)+(2)],cs
        popm    eax,ebp,ds
        retf
        ;
@@Use32_2:      mov     eax,offset @@Use0_2
        mov     d[ebp+(4+4+2)+(4+4+4)+(0)],eax
        mov     w[ebp+(4+4+2)+(4+4+4)+(4)],cs
        popm    eax,ebp,ds
        db 66h
        retf
        ;
@@Use0_2:       assume ds:nothing
        mov     ds,cs:ExcepDSeg
        assume ds:_cwMain
        mov     ss,StackSegment
        mov     esp,offset _cwStackEnd-256
        pushm   ds,ds,ds
        popm    es,fs,gs
        jmp     f[TerminationHandler]
        assume ds:_Excep
DPMIExcPatch    endp


;-------------------------------------------------------------------------
;
;Convert segment value into real & application relative.
;
;On Entry:-
;
;AX     - Selector.
;DS:EDI - Buffer address.
;
DebugSegmentDPMI proc near
        push    ds
        assume ds:nothing
        mov     ds,cs:ExcepDSeg
        assume ds:_cwMain
        push    fs
        mov     fs,PSPSegment
        mov     ebx,-1
        ;
        push    eax
        mov     ax,fs
        movzx   eax,ax
        lsl     eax,eax
        cmp     eax,(size PSP_Struc)+(size EPSP_Struc)
        pop     eax
        jc      @@9
        ;
        mov     dx,ax
        cmp     ax,fs:w[EPSP_SegBase]   ;inside application selector space?
        jc      @@9
        mov     cx,fs:w[EPSP_SegSize]
;       shl     cx,3            ;8 bytes per selector.
        add     cx,fs:w[EPSP_SegBase]   ;add in base selector.
        cmp     ax,cx
        jnc     @@9             ;outside application startup selectors.
        mov     bx,dx
        pushm   cx,dx
        mov     ax,0006h
        int     31h
        mov     ax,cx
        shl     eax,16
        mov     ax,dx
        popm    cx,dx
        sub     eax,fs:d[EPSP_MemBase]  ;get offset within application.
        mov     ebx,eax
@@9:    pop     fs
        pop     ds
        mov     [edi],ebx               ;store generated value.
        assume ds:_Excep
        ret
DebugSegmentDPMI endp


;-------------------------------------------------------------------------
;
;Do a debug dump. Very rough but it works for now....
;
DebugDisplay    proc    far

IFDEF DEBUG4
        push    eax
        push    ebx
        push    ecx
        push    edx
        push    ds
        push    cs
        pop     ds
        mov     edx,OFFSET debuggtext1
debuggloop2:
        cmp     BYTE PTR ds:[edx],0
        je      debuggb
        mov     ecx,1
        mov     bx,1
        mov     ah,40h
        int     21h
        inc     edx
        jmp     debuggloop2
debuggb:
        mov     edx,OFFSET debuggtext2
        push    cs
        pop     ds
        mov     ecx,2
        mov     bx,1
        mov     ah,40h
        int     21h
        pop     ds
        pop     edx
        pop     ecx
        pop     ebx
        pop     eax
        jmp     debuggout

debuggtext1     DB      'Entering DebugDisplay...',0
debuggtext2     DB      13,10

debuggout:
        push    ecx
        mov     ecx,100000h
debuggloop:
;       dec     ecx
;       jne     debugaloop
        pop     ecx
ENDIF

        push    ds
        mov     ds,cs:ExcepDSeg
        assume ds:_cwMain
        cmp     UserTermFlag,0  ; see if user termination routine
        je      dd2                             ; no

INFOLISTSIZE    EQU     104

        xor     ecx,ecx
        mov     esi,OFFSET cs:DebugBuffer
        mov     edi,DWORD PTR UserTermDump
        cmp     UserTermFlag,1  ; see if 16-bit termination routine
        mov     UserTermFlag,0  ; reset flag, KEEP CPU FLAG STATUS
        jne     ut32                    ; not
        mov     ax,WORD PTR UserTermDump+2
        mov     cx,ax
        lsl     ecx,ecx
        jnz     utsi                    ; invalid selector
        mov     es,ax
        mov     cx,INFOLISTSIZE

uttrans16:
        mov     al,cs:[si]
        mov     es:[di],al
        inc     si
        inc     di
        dec     cx
        jne     uttrans16

utsi:
        mov     si,sp
        call    DWORD PTR ds:[UserTermRoutine]
        mov     ds,cs:ExcepDSeg ; restore ds if used
        jmp     dd2

ut32:
        mov     ax,WORD PTR UserTermDump+4
        mov     cx,ax
        lsl     ecx,ecx
        jnz     utesi                   ; invalid selector
        mov     es,ax
        mov     cx,INFOLISTSIZE

uttrans32:
        mov     al,cs:[esi]
        mov     es:[edi],al
        inc     esi
        inc     edi
        dec     cx
        jne     uttrans32

utesi:
        mov     esi,esp
        call    FWORD PTR ds:[UserTermRoutine]
        mov     ds,cs:ExcepDSeg ; restore ds if used

dd2:
        cmp     DebugDump,0             ;register dump needed?
        jz      @@9
        mov     DebugDump,0

        cmp     EnableDebugDump,0       ; see if debug dumping enabled
        je      @@9

        mov     ds,cs:ExcepDDSeg
        assume ds:_Excep
        ;
        mov     ah,0fh
        int     10h
        cmp     al,3
        jz      @@ModeOk
        cmp     al,2
        jz      @@ModeOk
        cmp     al,7
        jz      @@ModeOk
        mov     ax,3
        int     10h
@@ModeOk:       ;
        mov     d[@@Handle],0
        xor     cx,cx
        mov     ah,3ch

; MED 06/18/96
        mov     ds,cs:ExcepDSeg
        assume ds:_cwMain
        mov     edx,OFFSET NewCWErrName ; try new error file name
        cmp     ds:[edx],al
        je      oldcwerr                ; no new error file name
        int     21h
        mov     ds,cs:ExcepDDSeg
        assume ds:_Excep
        jnc     debhand                 ; successfully created new error file

oldcwerr:
        mov     ds,cs:ExcepDDSeg
        assume ds:_Excep
        mov     edx,offset DebugName
        xor     cx,cx
        mov     ah,3ch
        int     21h
        jc      @@NoFile

debhand:
        mov     d[@@Handle],eax

@@NoFile:       ;Display debug info.
        ;
        push    ds
        mov     ds,ExcepDseg
        assume ds:_cwMain
        mov     esi,offset Copyright
        xor     ecx,ecx
@@LookCEnd:     cmp     b[esi],0
        jz      @@AtCEnd
        cmp     b[si],"$"
        jz      @@AtCEnd
        inc     ecx
        inc     esi
        jmp     @@LookCEnd
@@AtCEnd:       mov     edx,offset Copyright
        mov     ebx,d[@@Handle]
        mov     ah,40h
        int     21h
        assume ds:_Excep
        pop     ds
        ;
        mov     ax,DebugExceptionIndex
        mov     cx,2
        mov     edi,offset DebugINum
        call    Bin2Hex
        mov     ax,w[DebugExceptionCode]        ;high word undefined upto 486.
        mov     cx,4
        mov     edi,offset DebugENum
        call    Bin2Hex
        ;
        mov     ax,DebugTR
        mov     cx,4
        mov     edi,offset DebugTRt
        call    Bin2Hex
        mov     eax,DebugCR0
        mov     cx,8
        mov     edi,offset DebugCR0t
        call    Bin2Hex
        mov     eax,DebugCR2
        mov     cx,8
        mov     edi,offset DebugCR2t
        call    Bin2Hex
        mov     eax,DebugCR3
        mov     cx,8
        mov     edi,offset DebugCR3t
        call    Bin2Hex
        ;
        mov     eax,DebugEAX
        mov     cx,8
        mov     edi,offset DebugEAXt
        call    Bin2Hex
        mov     eax,DebugEBX
        mov     cx,8
        mov     edi,offset DebugEBXt
        call    Bin2Hex
        mov     eax,DebugECX
        mov     cx,8
        mov     edi,offset DebugECXt
        call    Bin2Hex
        mov     eax,DebugEDX
        mov     cx,8
        mov     edi,offset DebugEDXt
        call    Bin2Hex
        mov     eax,DebugESI
        mov     cx,8
        mov     edi,offset DebugESIt
        call    Bin2Hex
        mov     eax,DebugEDI
        mov     cx,8
        mov     edi,offset DebugEDIt
        call    Bin2Hex
        mov     eax,DebugEBP
        mov     cx,8
        mov     edi,offset DebugEBPt
        call    Bin2Hex
        mov     eax,DebugESP
        mov     cx,8
        mov     edi,offset DebugESPt
        call    Bin2Hex
        mov     eax,DebugEIP
        mov     cx,8
        mov     edi,offset DebugEIPt
        call    Bin2Hex
        mov     eax,DebugEFL
        mov     cx,8
        mov     edi,offset DebugEFLt
        call    Bin2Hex
        ;
        mov     ax,DebugCS
        mov     cx,4
        mov     edi,offset DebugCSt
        call    Bin2Hex
        mov     eax,DebugCSApp
        mov     cx,8
        mov     edi,offset DebugCSAppt
        cmp     eax,-1
        jnz     @@0
        mov     d[edi],'xxxx'
        mov     d[edi+4],'xxxx'
        add     edi,8
        jmp     @@1
@@0:    call    Bin2Hex
@@1:    mov     ax,DebugDS
        mov     cx,4
        mov     edi,offset DebugDSt
        call    Bin2Hex
        mov     eax,DebugDSApp
        mov     cx,8
        mov     edi,offset DebugDSAppt
        cmp     eax,-1
        jnz     @@2
        mov     d[edi],'xxxx'
        mov     d[edi+4],'xxxx'
        add     edi,8
        jmp     @@3
@@2:    call    Bin2Hex
@@3:    mov     ax,DebugES
        mov     cx,4
        mov     edi,offset DebugESt
        call    Bin2Hex
        mov     eax,DebugESApp
        mov     cx,8
        mov     edi,offset DebugESAppt
        cmp     eax,-1
        jnz     @@4
        mov     d[edi],'xxxx'
        mov     d[edi+4],'xxxx'
        add     edi,8
        jmp     @@5
@@4:    call    Bin2Hex
@@5:    mov     ax,DebugFS
        mov     cx,4
        mov     edi,offset DebugFSt
        call    Bin2Hex
        mov     eax,DebugFSApp
        mov     cx,8
        mov     edi,offset DebugFSAppt
        cmp     eax,-1
        jnz     @@6
        mov     d[edi],'xxxx'
        mov     d[edi+4],'xxxx'
        add     edi,8
        jmp     @@7
@@6:    call    Bin2Hex
@@7:    mov     ax,DebugGS
        mov     cx,4
        mov     edi,offset DebugGSt
        call    Bin2Hex
        mov     eax,DebugGSApp
        mov     cx,8
        mov     edi,offset DebugGSAppt
        cmp     eax,-1
        jnz     @@10
        mov     d[edi],'xxxx'
        mov     d[edi+4],'xxxx'
        add     edi,8
        jmp     @@11
@@10:   call    Bin2Hex
@@11:   mov     ax,DebugSS
        mov     cx,4
        mov     edi,offset DebugSSt
        call    Bin2Hex
        mov     eax,DebugSSApp
        mov     cx,8
        mov     edi,offset DebugSSAppt
        cmp     eax,-1
        jnz     @@12
        mov     d[edi],'xxxx'
        mov     d[edi+4],'xxxx'
        add     edi,8
        jmp     @@13
@@12:   call    Bin2Hex
@@13:   ;
        mov     edi,offset DebugSysFlags
        push    ds
        mov     ds,ExcepDSeg
        assume ds:_cwMain
        movzx   eax,w[SystemFlags]
        assume ds:_Excep
        pop     ds
        mov     cx,8

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?