f78b12e570284aa8291f4ca1add24937fd107403vboxsync/****************************************************************************
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Realmode X86 Emulator Library
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Copyright (C) 1996-1999 SciTech Software, Inc.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Copyright (C) David Mosberger-Tang
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Copyright (C) 1999 Egbert Eich
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* ========================================================================
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Permission to use, copy, modify, distribute, and sell this software and
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* its documentation for any purpose is hereby granted without fee,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* provided that the above copyright notice appear in all copies and that
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* both that copyright notice and this permission notice appear in
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* supporting documentation, and that the name of the authors not be used
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* in advertising or publicity pertaining to distribution of the software
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* without specific, written prior permission. The authors makes no
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* representations about the suitability of this software for any purpose.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* It is provided "as is" without express or implied warranty.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* PERFORMANCE OF THIS SOFTWARE.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* ========================================================================
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Language: ANSI C
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Environment: Any
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Developer: Kendall Bennett
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Description: Header file for debug definitions.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync****************************************************************************/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifndef __X86EMU_DEBUG_H
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define __X86EMU_DEBUG_H
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*---------------------- Macros and type definitions ----------------------*/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/* checks to be enabled for "runtime" */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define CHECK_IP_FETCH_F 0x1
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define CHECK_SP_ACCESS_F 0x2
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define CHECK_MEM_ACCESS_F 0x4 /*using regular linear pointer */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define CHECK_DATA_ACCESS_F 0x8 /*using segment:offset*/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef DEBUG
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define CHECK_IP_FETCH() (M.x86.check & CHECK_IP_FETCH_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define CHECK_SP_ACCESS() (M.x86.check & CHECK_SP_ACCESS_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define CHECK_MEM_ACCESS() (M.x86.check & CHECK_MEM_ACCESS_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define CHECK_DATA_ACCESS() (M.x86.check & CHECK_DATA_ACCESS_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define CHECK_IP_FETCH()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define CHECK_SP_ACCESS()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define CHECK_MEM_ACCESS()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define CHECK_DATA_ACCESS()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef DEBUG
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_INSTRUMENT() (M.x86.debug & DEBUG_INSTRUMENT_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_DECODE() (M.x86.debug & DEBUG_DECODE_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_TRACE() (M.x86.debug & DEBUG_TRACE_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_STEP() (M.x86.debug & DEBUG_STEP_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_DISASSEMBLE() (M.x86.debug & DEBUG_DISASSEMBLE_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_BREAK() (M.x86.debug & DEBUG_BREAK_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_SVC() (M.x86.debug & DEBUG_SVC_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_SAVE_IP_CS() (M.x86.debug & DEBUG_SAVE_IP_CS_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_FS() (M.x86.debug & DEBUG_FS_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_PROC() (M.x86.debug & DEBUG_PROC_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_SYSINT() (M.x86.debug & DEBUG_SYSINT_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_TRACECALL() (M.x86.debug & DEBUG_TRACECALL_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_TRACECALLREGS() (M.x86.debug & DEBUG_TRACECALL_REGS_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_SYS() (M.x86.debug & DEBUG_SYS_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_MEM_TRACE() (M.x86.debug & DEBUG_MEM_TRACE_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_IO_TRACE() (M.x86.debug & DEBUG_IO_TRACE_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_DECODE_NOPRINT() (M.x86.debug & DEBUG_DECODE_NOPRINT_F)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_INSTRUMENT() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_DECODE() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_TRACE() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_STEP() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_DISASSEMBLE() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_BREAK() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_SVC() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_SAVE_IP_CS() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_FS() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_PROC() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_SYSINT() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_TRACECALL() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_TRACECALLREGS() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_SYS() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_MEM_TRACE() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_IO_TRACE() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DEBUG_DECODE_NOPRINT() 0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef DEBUG
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DECODE_PRINTF(x) if (DEBUG_DECODE()) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync x86emu_decode_printf(x)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DECODE_PRINTF2(x,y) if (DEBUG_DECODE()) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync x86emu_decode_printf2(x,y)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * The following allow us to look at the bytes of an instruction. The
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * first INCR_INSTRN_LEN, is called everytime bytes are consumed in
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * the decoding process. The SAVE_IP_CS is called initially when the
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * major opcode of the instruction is accessed.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define INC_DECODED_INST_LEN(x) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (DEBUG_DECODE()) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync x86emu_inc_decoded_inst_len(x)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define SAVE_IP_CS(x,y) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (DEBUG_DECODE() | DEBUG_TRACECALL() | DEBUG_BREAK() \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync | DEBUG_IO_TRACE() | DEBUG_SAVE_IP_CS()) { \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync M.x86.saved_cs = x; \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync M.x86.saved_ip = y; \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync }
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define INC_DECODED_INST_LEN(x)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DECODE_PRINTF(x)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define DECODE_PRINTF2(x,y)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define SAVE_IP_CS(x,y)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef DEBUG
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define TRACE_REGS() \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (DEBUG_DISASSEMBLE()) { \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync x86emu_just_disassemble(); \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync goto EndOfTheInstructionProcedure; \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync } \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (DEBUG_TRACE() || DEBUG_DECODE()) X86EMU_trace_regs()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define TRACE_REGS()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef DEBUG
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define SINGLE_STEP() if (DEBUG_STEP()) x86emu_single_step()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define SINGLE_STEP()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define TRACE_AND_STEP() \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync TRACE_REGS(); \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync SINGLE_STEP()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef DEBUG
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define START_OF_INSTR()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define END_OF_INSTR() EndOfTheInstructionProcedure: x86emu_end_instr();
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define END_OF_INSTR_NO_TRACE() x86emu_end_instr();
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define START_OF_INSTR()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define END_OF_INSTR()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define END_OF_INSTR_NO_TRACE()
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef DEBUG
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define CALL_TRACE(u,v,w,x,s) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (DEBUG_TRACECALLREGS()) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync x86emu_dump_regs(); \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (DEBUG_TRACECALL()) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync printk("%04x:%04x: CALL %s%04x:%04x\n", u , v, s, w, x);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define RETURN_TRACE(n,u,v) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (DEBUG_TRACECALLREGS()) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync x86emu_dump_regs(); \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync if (DEBUG_TRACECALL()) \
f78b12e570284aa8291f4ca1add24937fd107403vboxsync printk("%04x:%04x: %s\n",u,v,n);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define CALL_TRACE(u,v,w,x,s)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# define RETURN_TRACE(n,u,v)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef DEBUG
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define DB(x) x
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#define DB(x)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*-------------------------- Function Prototypes --------------------------*/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef __cplusplus
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern "C" { /* Use "C" linkage when in C++ mode */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_inc_decoded_inst_len (int x);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_decode_printf (char *x);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_decode_printf2 (char *x, int y);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_just_disassemble (void);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_single_step (void);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_end_instr (void);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_dump_regs (void);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_dump_xregs (void);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_print_int_vect (u16 iv);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_instrument_instruction (void);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_check_ip_access (void);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_check_sp_access (void);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_check_mem_access (u32 p);
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncextern void x86emu_check_data_access (uint s, uint o);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#ifdef __cplusplus
f78b12e570284aa8291f4ca1add24937fd107403vboxsync} /* End of "C" linkage for C++ */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif
f78b12e570284aa8291f4ca1add24937fd107403vboxsync
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif /* __X86EMU_DEBUG_H */