trap.asm
来自「开放源码的编译器open watcom 1.6.0版的源代码」· 汇编 代码 · 共 832 行 · 第 1/3 页
ASM
832 行
;*****************************************************************************
;*
;* 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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;* DESCRIBE IT HERE!
;*
;*****************************************************************************
include struct.inc
include traps.inc
extrn _DOS_major:byte
extrn _DOS_minor:byte
extrn _BoundAppLoading:byte
CONST segment byte public 'DATA'
CONST ends
DGROUP group CONST
_TEXT segment byte public 'CODE'
extrn DebugTask :near
extrn BptTrap :near
extrn ExitDebugger :near
extrn TraceRtn :word
extrn TrapType :byte
extrn "C", FPUExpand :near
extrn "C", FPUContract :near
; these macros assume ES is pointing at the interrupt vector
; segment and that AX and BX are available for use
SaveIntr macro intr,loc
ife dummy
if intr+1
mov BX,4*intr ; get vector offset
else
xor BH,BH
add BX,BX
add BX,BX
endif
mov AX,ES:0[BX] ; get interrupt offset
mov loc+0,AX ; save it
mov AX,ES:2[BX] ; get interrupt segment
mov loc+2,AX ; save it
endif
endm
SetIntr macro intr,loc
ife dummy
if intr+1
mov BX,4*intr ; get vector offset
else
xor BH,BH
add BX,BX
add BX,BX
endif
mov word ptr ES:0[BX],offset loc; set interrupt offset
mov ES:2[BX],CS ; set interrupt segment
endif
endm
SwapIntr macro intr,loc
ife dummy
if intr+1
mov BX,4*intr ; get vector offset
else
xor BH,BH
add BX,BX
add BX,BX
endif
mov AX,word ptr loc+0 ; get new interrupt offset
xchg ES:0[BX],AX ; swap offsets
mov word ptr loc+0, AX ; . . .
mov AX,word ptr loc+2 ; get new interrupt segment
xchg ES:2[BX],AX ; swap segments
mov word ptr loc+2,AX ; . . .
endif
endm
RestIntr macro intr,loc
ife dummy
if intr+1
mov BX,4*intr ; get vector offset
else
xor BH,BH
add BX,BX
add BX,BX
endif
mov AX,loc+0 ; get old interrupt offset
mov ES:0[BX],AX ; restore it
mov AX,loc+2 ; get old interrupt segment
mov ES:2[BX],AX ; restore it
endif
endm
assume CS:_TEXT
WATCH_DEPTH equ 6+2+2 ; additional stack in watch point rtn
; Code Segment variables
public _SegmentChain
_SegmentChain dw ?
OurSP dw ?
OurSS dw ?
DbgPSP dw ?
CurrPSP dw ?
TaskPSP dw 0
SaveIntSP dw ?
SaveIntSS dw ?
InDos dd ?
SaveBrkHndlr dw ?,?
SaveCrtErrHndlr dw ?,?
SaveBusyWait dw ?,?
SaveVects db 1024 dup(?)
TraceVec equ word ptr cs:(SaveVects+01H*4)
BptVec equ word ptr cs:(SaveVects+03H*4)
PrgIntVec equ word ptr cs:(SaveVects+05H*4)
TimerIntVec equ word ptr cs:(SaveVects+08H*4)
KbdIntVec equ word ptr cs:(SaveVects+09H*4)
SysServVec equ word ptr cs:(SaveVects+15H*4)
BrkVec equ word ptr cs:(SaveVects+1bH*4)
PrgTermVec equ word ptr cs:(SaveVects+20H*4)
OSIntVec equ word ptr cs:(SaveVects+21H*4)
DOSBrkVec equ word ptr cs:(SaveVects+23H*4)
CrtErrVec equ word ptr cs:(SaveVects+24H*4)
ResTermVec equ word ptr cs:(SaveVects+27H*4)
BusyWaitVec equ word ptr cs:(SaveVects+28H*4)
UsrInt db 0
DOSCount db 0
BrkStatus db ?
public InitVectors_
InitVectors_ proc near
push es ; save registers
push ds
push si
push di
push dx
push cx
push bx
mov ax,seg DGROUP
mov ds,ax
assume DS:DGROUP
mov AH,30H ; get version number
int 21H
mov DS:_DOS_major,AL ; and save it away
mov DS:_DOS_minor,AH
; save interrupt vectors
mov si,cs
mov es,si
sub si,si
mov ds,si
mov di,offset SaveVects
mov cx,1024/2
cli
rep movsw
sti
mov ax,BusyWaitVec ; set up busy wait
mov CS:SaveBusyWait,ax ; swap location
mov ax,BusyWaitVec+2 ; ...
mov CS:SaveBusyWait+2,ax ; ...
call GetPSP ; get debugger PSP
mov CS:DbgPSP,AX ; and save it away
call near ptr ClrIntVecs_
mov AH,34H ; get InDos flag
int 21H ; ...
mov word ptr CS:InDos+0,BX; save flag pointer away
mov word ptr CS:InDos+2,ES; ...
mov AX,3300H ; request Ctrl/Brk checking status
int 21H
mov CS:BrkStatus,DL
mov AX,3301H ; set to check for all DOS calls
mov DL,1
int 21H
pop bx ; restore registers
pop cx
pop dx
pop di
pop si
pop ds
pop es
ret
InitVectors_ endp
; DX:AX has load regs pointer & CX:BX has save regs pointer
public RunProg_ ; run the program and return termination condition
RunProg_ proc near
push ES
push DS
push SI
push DI
push BP
mov CS:UsrInt,0 ; no pending user interrupts
mov CS:OurSS,SS ; save SS
mov CS:OurSP,SP ; save SP
jmp ExitDebugger ; run program
public EnterDebugger
EnterDebugger: cli ; interrupts off
mov SS,OurSS ; restore stack segment
mov SP,CS:OurSP ; restore stack pointer
sti
cld
pop BP ; restore everything
pop DI
pop SI
pop DS
pop ES
mov AL,TRAP_SKIP
xchg AL,CS:TrapType ; get cause of termination
cbw
ret ; return to caller
RunProg_ endp
public FiniVectors_
FiniVectors_ proc near
push es ; save registers
push ds
push si
push di
push dx
push cx
mov AX,3301H ; restore Ctrl/Brk checking state
mov DL,CS:BrkStatus
int 21H
; restore interrupt vectors
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?