⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbgtrap.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;*****************************************************************************
;*
;*                            Open Watcom Project
;*
;*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;*  ========================================================================
;*
;*    This file contains Original Code and/or Modifications of Original
;*    Code as defined in and that are subject to the Sybase Open Watcom
;*    Public License version 1.0 (the 'License'). You may not use this file
;*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;*    provided with the Original Code and Modifications, and is also
;*    available at www.sybase.com/developer/opensource.
;*
;*    The Original Code and all software distributed under the License are
;*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;*    NON-INFRINGEMENT. Please see the License for the specific language
;*    governing rights and limitations under the License.
;*
;*  ========================================================================
;*
;* Description:  DOS real mode Trap routines for WATCOM Debugger
;*
;*****************************************************************************


include traps.inc

                NAME    DBGTRAP


        extrn   EnterDebugger:near   ; enter the debugger
        extrn   SetIntVecs_:near     ; set int vectors while in user's program
        extrn   ClrIntVecs_:near     ; clear int vectors while in debugger
        extrn   ChkInt:near          ; check the interrupt number


_text segment byte public 'CODE'

WatchTbl   dw   ?,?             ; watch point table address
WatchCnt   dw   ?               ; number of watch points
SaveRegs   dw   ?,?             ; save regs pointer
AreWatching db  0               ; have we got watch points

public  TrapType
TrapType   db   TRAP_NONE       ; trap type
public  TraceRtn
TraceRtn   dw   0               ; routine for int 1 vector


REG_GROUP       struc
        RAX     dw ?
        _EAX    dw ?
        RBX     dw ?
        _EBX    dw ?
        RCX     dw ?
        _ECX    dw ?
        RDX     dw ?
        _EDX    dw ?
        RSI     dw ?
        _ESI    dw ?
        RDI     dw ?
        _EDI    dw ?
        RBP     dw ?
        _EBP    dw ?
        RSP     dw ?
        _ESP    dw ?
        RIP     dw ?
        _EIP    dw ?
        RFL     dw ?
        _EFL    dw ?
                dd ?    ; CR0
                dd ?    ; CR2
                dd ?    ; CR3
        RDS     dw ?
        RES     dw ?
        RSS     dw ?
        RCS     dw ?
        RFS     dw ?
        RGS     dw ?
REG_GROUP       ends



assume  cs:_text


; These offsets must match the struct in DOSACC.C
WP_ADDR         equ     0       ; offset of watch point address
WP_VALUE        equ     4       ; offset of watch point value
WP_SIZE         equ     16      ; size of the watch point structure

VALID   equ     1234H           ; value used to validate debugger data segment

public  TrapTypeInit_
TrapTypeInit_ proc       near           ; initialize trap information
        mov     byte ptr CS:TrapType,TRAP_NONE ; no trap at startup time

        ; fall into SetSingleStep
TrapTypeInit_ endp

public  SetSingle386_
SetSingle386_   proc near
        mov     CS:TraceRtn,offset _text:TraceTrap386
        ret
SetSingle386_   endp

public  SetSingleStep_
SetSingleStep_  proc near       ; set interrupt vector 1 at single step routine
        mov     CS:TraceRtn,offset _text:TraceTrap
        ret                     ; return to caller
SetSingleStep_  endp


public  SetWatchPnt_
SetWatchPnt_    proc near       ; set interrupt vector 1 at watch point routine
        mov     CS:TraceRtn,offset _text:WatchTrap
        mov     CS:WatchTbl+0,BX; point at watch point table;
        mov     CS:WatchTbl+2,CX; . . .
        mov     CS:WatchCnt,AX  ; set number of watch points
        ret                     ; return to caller
SetWatchPnt_    endp


public  SetWatch386_
SetWatch386_    proc near       ; set interrupt vector 1 at watch point routine
        call    SetWatchPnt_
        mov     CS:TraceRtn,offset _text:WatchTrap386
        ret                     ; return to caller
SetWatch386_    endp


RetAddr dw  ?,?

public  OvlTrap_
OvlTrap_:                       ; Overlay state change trap
        mov     byte ptr CS:TrapType,TRAP_OVL_CHANGE_LOAD
        pop     CS:RetAddr+0    ; save return offset
        pop     CS:RetAddr+2    ; save return segment
        pushf                   ; fake up an interrupt stack frame
        push    CS:RetAddr+2    ; . . .
        push    CS:RetAddr+0    ; . . .
        test    dl,1
        jz      short DebugTask ; invoke the debugger
        mov     byte ptr CS:TrapType,TRAP_OVL_CHANGE_RET
        jmp     short DebugTask ; invoke the debugger



w386_e: mov     byte ptr CS:TrapType,al                 ; set trap type
        pop     ax                                      ; restore ax
        jmp     short DebugTask                         ; enter debugger

TraceTrap386:
        push    ax                                      ; save ax
        db      00FH,021H,0F0H                          ; mov eax,dr6
        test    ax,04000H                               ; if trace trap
        je      w386_1                                  ; then
        mov     al,TRAP_TRACE_POINT                     ; - indicate trace trap
        jmp     short w386_e                            ; -
w386_1: test    ax,0Fh                                  ; else if watch trap
        je      w386_2                                  ; - then
        mov     al,TRAP_WATCH_POINT                     ; - indicate watch point
        jmp     short w386_e                            ; -
w386_2:
        pop     ax
        ; no indicator in DR6, fall into TraceTrap and check T-bit

TraceTrap:                      ; T-trap trap
        mov     byte ptr CS:TrapType,TRAP_TRACE_POINT ; indicate T-bit trap
        push    BP              ; save BP
        mov     BP,SP           ; get access to stack
        test    byte ptr 7[BP],1; check to see if the T-bit's off
        pop     BP              ; restore BP
        jnz     DebugTask       ; if T-bit is on then DebugTask

        ; At this point we have just encountered a bug in the 8088
        ; trace trap processing. The return address on the stack is
        ; actually the first instruction of a hardware interrupt handler.
        ; There is another stack frame on top of that indicating where the
        ; handler wants to return to (which is when this routine should really
        ; have been invoked). We are going return to the hardware handler
        ; routine which will eventually return and cause another trace trap.
        ; This second trace trap will come back here and be properly handled.

        iret                  ; return to hardware interrupt handler


public  BptTrap
BptTrap:                        ; come here for breakpoint trap
        mov     byte ptr CS:TrapType,TRAP_BREAK_POINT
        push    BP              ; save BP
        mov     BP,SP           ; get access to stack
        dec     word ptr 2[BP]  ; decrement IP
        pop     BP              ; restore BP

        ; fall into DebugTask

public  DebugTask
DebugTask:
        push    BX              ; save BX

⌨️ 快捷键说明

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