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