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

📄 trace.inc

📁 DOS下的调试工具
💻 INC
📖 第 1 页 / 共 2 页
字号:
;=============================================================================
; Insight, real-mode debugger for MS DOS / PC DOS / FreeDOS.
; Copyright (c) Victor M. Gamayunov, Sergey Pimenov, 1993, 96, 97, 2002.
; Modifications by Oleg O. Chukaev (2006, 2007).
;-----------------------------------------------------------------------------
; trace.inc
; Trace-related procedures.
;-----------------------------------------------------------------------------
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
; 
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
; 02111-1307, USA.
;=============================================================================

;=============================================================================
; Changelog
;-----------------------------------------------------------------------------
; 2007-02-06 (Oleg O. Chukaev)
;	`animate' added
;
; 2007-03-01 (Oleg O. Chukaev)
;	user_push, user_pop optimized
;
;=============================================================================


%macro		save_act_regs		0
		mov	[save_sp],sp
%endmacro


%macro		restore_act_regs	0
		mov	ax,cs
		mov	ds,ax
		mov	es,ax
		mov	ss,ax
		mov	sp,[save_sp]
%endmacro


%macro		save_user_regs		0
		cmp	byte [cs:zz_cpu],3
		jb	@@skip_esp
		db	66h
@@skip_esp:
		mov	[cs:cpu_regs+REG_SP],sp
		call	_save_user_regs
%endmacro


%macro		restore_user_regs	0
		call	_restore_user_regs
%endmacro


;=============================================================================
; _save_user_regs
;-----------------------------------------------------------------------------
_save_user_regs:
first_prefix:
prefix_01:
		nop
		mov	[cs:cpu_regs+REG_AX],ax

		mov	[cs:cpu_regs+REG_DS],ds
		mov	ax,cs
		mov	ds,ax
		pop	word [keep_ip]

prefix_02:
		nop
		mov	[cpu_regs+REG_BX],bx

prefix_03:
		nop
		mov	[cpu_regs+REG_CX],cx

prefix_04:
		nop
		mov	[cpu_regs+REG_DX],dx

prefix_05:
		nop
		mov	[cpu_regs+REG_SI],si

prefix_06:
		nop
		mov	[cpu_regs+REG_DI],di

prefix_07:
		nop
		mov	[cpu_regs+REG_BP],bp

		cmp	byte [zz_cpu],3
		jb	@@skip
cpu	386
		mov	[cpu_regs+REG_GS],gs
		mov	[cpu_regs+REG_FS],fs
cpu	8086
@@skip:
		mov	[cpu_regs+REG_ES],es
		mov	[cpu_regs+REG_SS],ss
		mov	es,ax
		mov	ss,ax

prefix_16:
		nop
		mov	ax,[cpu_regs+REG_IP]

prefix_17:
		nop
		mov	[save_cpu_regs+REG_IP],ax

prefix_18:
		nop
		mov	ax,[cpu_regs+REG_CS]

prefix_19:
		nop
		mov	[save_cpu_regs+REG_CS],ax

		mov	byte [regs_saved],0
		mov	sp,[save_sp]
		jmp     word [keep_ip]
;=============================================================================
; _restore_user_regs
;-----------------------------------------------------------------------------
_restore_user_regs:
		pop	word [keep_ip]
		call	save_regs

prefix_08:
		nop
		mov	ax,[cpu_regs+REG_AX]

prefix_09:
		nop
		mov	bx,[cpu_regs+REG_BX]

prefix_10:
		nop
		mov	cx,[cpu_regs+REG_CX]

prefix_11:
		nop
		mov	dx,[cpu_regs+REG_DX]

prefix_12:
		nop
		mov	si,[cpu_regs+REG_SI]

prefix_13:
		nop
		mov	di,[cpu_regs+REG_DI]

prefix_14:
		nop
		mov	sp,[cpu_regs+REG_SP]

prefix_15:
		nop
		mov	bp,[cpu_regs+REG_BP]
		cmp	byte [zz_cpu],3
		jb	@@skip
cpu	386
		mov	gs,[cpu_regs+REG_GS]
		mov	fs,[cpu_regs+REG_FS]
cpu	8086
@@skip:
		mov	es,[cpu_regs+REG_ES]
		mov	ss,[cpu_regs+REG_SS]
		mov	ds,[cpu_regs+REG_DS]
		jmp     word [cs:keep_ip]
;=============================================================================
; save_regs
;-----------------------------------------------------------------------------
save_regs:
		push	ds
		pop	es
		mov	si,cpu_regs
		mov	di,save_cpu_regs
		mov	cx,SIZEOF_REGISTERS_32
		cld
	rep	movsb
		ret
;=============================================================================
; restore_regs
;-----------------------------------------------------------------------------
restore_regs:
		push	ds
		pop	es
		push	word [cpu_regs+REG_FL]
		push	word [cpu_regs+REG_CS]
		push	word [cpu_regs+REG_IP]
		mov	di,cpu_regs
		mov	si,save_cpu_regs
		mov	cx,SIZEOF_REGISTERS_32
		cld
	rep	movsb
		pop	word [cpu_regs+REG_IP]
		pop	word [cpu_regs+REG_CS]
		pop	word [cpu_regs+REG_FL]
		ret
;=============================================================================
; single_step
;-----------------------------------------------------------------------------
single_step:
		mov	dl,0
		call	emulate
		jnc	@@1
		call	save_regs
		jmp	trace_update
@@1:		call	check_swap
		cmp	byte [swap_flag],0
		je	@@n1
		call	restore_screen
@@n1:
		cli
;		call	set_09_vector
		mov	dx,@@int_01_entry
		call	set_01_vector
		mov	al,[user_port_21]
		or	al,3
		out	21h,al
		save_act_regs
		restore_user_regs
		or	word [cs:cpu_regs+REG_FL],100h
		push	word [cs:cpu_regs+REG_FL]
		push	word [cs:cpu_regs+REG_CS]
		push	word [cs:cpu_regs+REG_IP]
		iret
@@int_01_entry:
		pop	word [cs:cpu_regs+REG_IP]
		pop	word [cs:cpu_regs+REG_CS]
		pop	word [cs:cpu_regs+REG_FL]
		save_user_regs
		in	al,21h
		and	al,~3
		and	byte [user_port_21],3
		or	[user_port_21],al
		mov	al,[my_port_21]
		out	21h,al
		and	word [cpu_regs+REG_FL],~100h
		call	restore_01_vector
		call	clear_breakpoints
		sti
		cmp	byte [user_screen_mode],0
		je	trace_update
		call	save_screen
		call	draw_cpu_window
trace_update:
		call	update_screen
		cmp	word [cur_ip_line],-1
		jne	@@2
		jmp	go_to_origin
@@2:
		mov	ax,[cur_ip_line]
		cmp	ax,CPU_HEIGHT-4
		ja	@@adjust
@@ok:
		mov	[cur_line],ax
		jmp	update_commands
@@adjust:
		mov	si,[cur_ip]
		sub	ax,6
		mov	cx,ax
@@next:
		call	unassemble
		loop	@@next
		mov	[cur_ip],si
		mov	ax,6
		jmp	@@ok
;=============================================================================
; proc_trace
;-----------------------------------------------------------------------------
proc_trace:
		call	check_jump
		jnc	@@3
		jmp	single_step
@@3:
		xor	bp,bp
		mov	ax,[cpu_regs+REG_CS]
		mov	[unasm_seg],ax
		mov	si,[cpu_regs+REG_IP]
		call	check_bp
		jc	@@a
		mov	bp,bx
@@a:
		cli
		mov	es,ax
		call	unassemble
		call	check_bp
		jnc	@@ok
		mov	bx,bp0
		call	set_breakpoint
		jnc	@@ok
		mov	si,code_not_in_ram
		call	error_message
		call	clear_breakpoint
		jmp	trace_update
@@ok:
		mov	dl,1
		call	check_swap
		cmp	byte [swap_flag],0
		je	@@1
		call	restore_screen
@@1:
		call	set_09_vector
		mov	dx,@@int_03_entry
		call	set_03_vector
		call	set_breakpoints
		or	bp,bp
		jz	@@b
		mov	bx,bp
		call	clear_breakpoint
@@b:
		mov	al,[user_port_21]
		and	al,11111110b
		out	21h,al
		save_act_regs
		restore_user_regs
		push	word [cs:cpu_regs+REG_FL]
		push	word [cs:cpu_regs+REG_CS]
		push	word [cs:cpu_regs+REG_IP]
		iret

@@int_03_entry:
		pop	word [cs:cpu_regs+REG_IP]
		pop	word [cs:cpu_regs+REG_CS]
		pop	word [cs:cpu_regs+REG_FL]
		save_user_regs
		mov	ax,[cpu_regs+REG_IP]
		dec	ax
		mov	[cpu_regs+REG_IP],ax
		mov	[save_cpu_regs+REG_IP],ax
		call	clear_breakpoints
		in	al,21h
		mov	[user_port_21],al
		mov	al,[my_port_21]
		out	21h,al
		sti
@@skip:
		cmp	byte [user_screen_mode],0
		je	@@2
		call	save_screen
		call	draw_cpu_window
@@2:
		jmp	trace_update
;=============================================================================
; animate
;-----------------------------------------------------------------------------
animate:
		call	pushr
		mov	si,animate_dialog
		call	init_dialog

		mov	byte [anim_dlg_item],0
@@again:
		call	exec_dialog_
		jz	@@exit

		call	get_delay
		mov	byte [anim_dlg_item],0
		jc	@@again

		call	draw_screen

		cmp	word [delay_value],0
		jne	@@ok
		inc	word [delay_value]
@@ok:

		call	display_focus
@@loop:
		call	single_step
		push	ds
		xor	ax,ax
		mov	ds,ax
		mov	bx,[46ch]
		mov	cx,[46eh]
		pop	ds
		add	bx,[delay_value]
		adc	cx,0
@@wait:
		mov	ah,1
		int	16h
		jnz	@@quit
		push	ds
		xor	ax,ax
		mov	ds,ax
		cmp	[46eh],cx
		ja	@@end
		cmp	[46ch],bx
		jae	@@end
		pop	ds
		jmp	@@wait
@@end:
		pop	ds
		jmp	@@loop
@@quit:
		mov	ah,0
		int	16h
		call	hide_focus
@@exit:
		call	draw_screen
		call	popr

⌨️ 快捷键说明

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