1*4882a593Smuzhiyun /**************************************************************************** 2*4882a593Smuzhiyun * 3*4882a593Smuzhiyun * Realmode X86 Emulator Library 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (C) 1991-2004 SciTech Software, Inc. 6*4882a593Smuzhiyun * Copyright (C) David Mosberger-Tang 7*4882a593Smuzhiyun * Copyright (C) 1999 Egbert Eich 8*4882a593Smuzhiyun * 9*4882a593Smuzhiyun * ======================================================================== 10*4882a593Smuzhiyun * 11*4882a593Smuzhiyun * Permission to use, copy, modify, distribute, and sell this software and 12*4882a593Smuzhiyun * its documentation for any purpose is hereby granted without fee, 13*4882a593Smuzhiyun * provided that the above copyright notice appear in all copies and that 14*4882a593Smuzhiyun * both that copyright notice and this permission notice appear in 15*4882a593Smuzhiyun * supporting documentation, and that the name of the authors not be used 16*4882a593Smuzhiyun * in advertising or publicity pertaining to distribution of the software 17*4882a593Smuzhiyun * without specific, written prior permission. The authors makes no 18*4882a593Smuzhiyun * representations about the suitability of this software for any purpose. 19*4882a593Smuzhiyun * It is provided "as is" without express or implied warranty. 20*4882a593Smuzhiyun * 21*4882a593Smuzhiyun * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 22*4882a593Smuzhiyun * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 23*4882a593Smuzhiyun * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 24*4882a593Smuzhiyun * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 25*4882a593Smuzhiyun * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 26*4882a593Smuzhiyun * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 27*4882a593Smuzhiyun * PERFORMANCE OF THIS SOFTWARE. 28*4882a593Smuzhiyun * 29*4882a593Smuzhiyun * ======================================================================== 30*4882a593Smuzhiyun * 31*4882a593Smuzhiyun * Language: ANSI C 32*4882a593Smuzhiyun * Environment: Any 33*4882a593Smuzhiyun * Developer: Kendall Bennett 34*4882a593Smuzhiyun * 35*4882a593Smuzhiyun * Description: Header file for debug definitions. 36*4882a593Smuzhiyun * 37*4882a593Smuzhiyun ****************************************************************************/ 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun #ifndef __X86EMU_DEBUG_H 40*4882a593Smuzhiyun #define __X86EMU_DEBUG_H 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun /*---------------------- Macros and type definitions ----------------------*/ 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun /* checks to be enabled for "runtime" */ 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun #define CHECK_IP_FETCH_F 0x1 47*4882a593Smuzhiyun #define CHECK_SP_ACCESS_F 0x2 48*4882a593Smuzhiyun #define CHECK_MEM_ACCESS_F 0x4 /*using regular linear pointer */ 49*4882a593Smuzhiyun #define CHECK_DATA_ACCESS_F 0x8 /*using segment:offset */ 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun #ifdef CONFIG_X86EMU_DEBUG 52*4882a593Smuzhiyun # define CHECK_IP_FETCH() (M.x86.check & CHECK_IP_FETCH_F) 53*4882a593Smuzhiyun # define CHECK_SP_ACCESS() (M.x86.check & CHECK_SP_ACCESS_F) 54*4882a593Smuzhiyun # define CHECK_MEM_ACCESS() (M.x86.check & CHECK_MEM_ACCESS_F) 55*4882a593Smuzhiyun # define CHECK_DATA_ACCESS() (M.x86.check & CHECK_DATA_ACCESS_F) 56*4882a593Smuzhiyun #else 57*4882a593Smuzhiyun # define CHECK_IP_FETCH() 58*4882a593Smuzhiyun # define CHECK_SP_ACCESS() 59*4882a593Smuzhiyun # define CHECK_MEM_ACCESS() 60*4882a593Smuzhiyun # define CHECK_DATA_ACCESS() 61*4882a593Smuzhiyun #endif 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun #ifdef CONFIG_X86EMU_DEBUG 64*4882a593Smuzhiyun # define DEBUG_INSTRUMENT() (M.x86.debug & DEBUG_INSTRUMENT_F) 65*4882a593Smuzhiyun # define DEBUG_DECODE() (M.x86.debug & DEBUG_DECODE_F) 66*4882a593Smuzhiyun # define DEBUG_TRACE() (M.x86.debug & DEBUG_TRACE_F) 67*4882a593Smuzhiyun # define DEBUG_STEP() (M.x86.debug & DEBUG_STEP_F) 68*4882a593Smuzhiyun # define DEBUG_DISASSEMBLE() (M.x86.debug & DEBUG_DISASSEMBLE_F) 69*4882a593Smuzhiyun # define DEBUG_BREAK() (M.x86.debug & DEBUG_BREAK_F) 70*4882a593Smuzhiyun # define DEBUG_SVC() (M.x86.debug & DEBUG_SVC_F) 71*4882a593Smuzhiyun # define DEBUG_SAVE_IP_CS() (M.x86.debug & DEBUG_SAVE_CS_IP) 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun # define DEBUG_FS() (M.x86.debug & DEBUG_FS_F) 74*4882a593Smuzhiyun # define DEBUG_PROC() (M.x86.debug & DEBUG_PROC_F) 75*4882a593Smuzhiyun # define DEBUG_SYSINT() (M.x86.debug & DEBUG_SYSINT_F) 76*4882a593Smuzhiyun # define DEBUG_TRACECALL() (M.x86.debug & DEBUG_TRACECALL_F) 77*4882a593Smuzhiyun # define DEBUG_TRACECALLREGS() (M.x86.debug & DEBUG_TRACECALL_REGS_F) 78*4882a593Smuzhiyun # define DEBUG_SYS() (M.x86.debug & DEBUG_SYS_F) 79*4882a593Smuzhiyun # define DEBUG_MEM_TRACE() (M.x86.debug & DEBUG_MEM_TRACE_F) 80*4882a593Smuzhiyun # define DEBUG_IO_TRACE() (M.x86.debug & DEBUG_IO_TRACE_F) 81*4882a593Smuzhiyun # define DEBUG_DECODE_NOPRINT() (M.x86.debug & DEBUG_DECODE_NOPRINT_F) 82*4882a593Smuzhiyun #else 83*4882a593Smuzhiyun # define DEBUG_INSTRUMENT() 0 84*4882a593Smuzhiyun # define DEBUG_DECODE() 0 85*4882a593Smuzhiyun # define DEBUG_TRACE() 0 86*4882a593Smuzhiyun # define DEBUG_STEP() 0 87*4882a593Smuzhiyun # define DEBUG_DISASSEMBLE() 0 88*4882a593Smuzhiyun # define DEBUG_BREAK() 0 89*4882a593Smuzhiyun # define DEBUG_SVC() 0 90*4882a593Smuzhiyun # define DEBUG_SAVE_IP_CS() 0 91*4882a593Smuzhiyun # define DEBUG_FS() 0 92*4882a593Smuzhiyun # define DEBUG_PROC() 0 93*4882a593Smuzhiyun # define DEBUG_SYSINT() 0 94*4882a593Smuzhiyun # define DEBUG_TRACECALL() 0 95*4882a593Smuzhiyun # define DEBUG_TRACECALLREGS() 0 96*4882a593Smuzhiyun # define DEBUG_SYS() 0 97*4882a593Smuzhiyun # define DEBUG_MEM_TRACE() 0 98*4882a593Smuzhiyun # define DEBUG_IO_TRACE() 0 99*4882a593Smuzhiyun # define DEBUG_DECODE_NOPRINT() 0 100*4882a593Smuzhiyun #endif 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun # define ERR_PRINTF(x) printf(x) 103*4882a593Smuzhiyun # define ERR_PRINTF2(x, y) printf(x, y) 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun #ifdef CONFIG_X86EMU_DEBUG 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun # define DECODE_PRINTF(x) if (DEBUG_DECODE()) \ 109*4882a593Smuzhiyun x86emu_decode_printf(x) 110*4882a593Smuzhiyun # define DECODE_PRINTF2(x,y) if (DEBUG_DECODE()) \ 111*4882a593Smuzhiyun x86emu_decode_printf2(x,y) 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun /* 114*4882a593Smuzhiyun * The following allow us to look at the bytes of an instruction. The 115*4882a593Smuzhiyun * first INCR_INSTRN_LEN, is called everytime bytes are consumed in 116*4882a593Smuzhiyun * the decoding process. The SAVE_IP_CS is called initially when the 117*4882a593Smuzhiyun * major opcode of the instruction is accessed. 118*4882a593Smuzhiyun */ 119*4882a593Smuzhiyun #define INC_DECODED_INST_LEN(x) \ 120*4882a593Smuzhiyun if (DEBUG_DECODE()) \ 121*4882a593Smuzhiyun x86emu_inc_decoded_inst_len(x) 122*4882a593Smuzhiyun 123*4882a593Smuzhiyun #define SAVE_IP_CS(x,y) \ 124*4882a593Smuzhiyun if (DEBUG_DECODE() | DEBUG_TRACECALL() | DEBUG_BREAK() \ 125*4882a593Smuzhiyun | DEBUG_IO_TRACE() | DEBUG_SAVE_IP_CS()) { \ 126*4882a593Smuzhiyun M.x86.saved_cs = x; \ 127*4882a593Smuzhiyun M.x86.saved_ip = y; \ 128*4882a593Smuzhiyun } 129*4882a593Smuzhiyun #else 130*4882a593Smuzhiyun # define INC_DECODED_INST_LEN(x) 131*4882a593Smuzhiyun # define DECODE_PRINTF(x) 132*4882a593Smuzhiyun # define DECODE_PRINTF2(x,y) 133*4882a593Smuzhiyun # define SAVE_IP_CS(x,y) 134*4882a593Smuzhiyun #endif 135*4882a593Smuzhiyun 136*4882a593Smuzhiyun #ifdef CONFIG_X86EMU_DEBUG 137*4882a593Smuzhiyun #define TRACE_REGS() \ 138*4882a593Smuzhiyun if (DEBUG_DISASSEMBLE()) { \ 139*4882a593Smuzhiyun x86emu_just_disassemble(); \ 140*4882a593Smuzhiyun goto EndOfTheInstructionProcedure; \ 141*4882a593Smuzhiyun } \ 142*4882a593Smuzhiyun if (DEBUG_TRACE() || DEBUG_DECODE()) X86EMU_trace_regs() 143*4882a593Smuzhiyun #else 144*4882a593Smuzhiyun # define TRACE_REGS() 145*4882a593Smuzhiyun #endif 146*4882a593Smuzhiyun 147*4882a593Smuzhiyun #ifdef CONFIG_X86EMU_DEBUG 148*4882a593Smuzhiyun # define SINGLE_STEP() if (DEBUG_STEP()) x86emu_single_step() 149*4882a593Smuzhiyun #else 150*4882a593Smuzhiyun # define SINGLE_STEP() 151*4882a593Smuzhiyun #endif 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun #define TRACE_AND_STEP() \ 154*4882a593Smuzhiyun TRACE_REGS(); \ 155*4882a593Smuzhiyun SINGLE_STEP() 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun #ifdef CONFIG_X86EMU_DEBUG 158*4882a593Smuzhiyun # define START_OF_INSTR() 159*4882a593Smuzhiyun # define END_OF_INSTR() EndOfTheInstructionProcedure: x86emu_end_instr(); 160*4882a593Smuzhiyun # define END_OF_INSTR_NO_TRACE() x86emu_end_instr(); 161*4882a593Smuzhiyun #else 162*4882a593Smuzhiyun # define START_OF_INSTR() 163*4882a593Smuzhiyun # define END_OF_INSTR() 164*4882a593Smuzhiyun # define END_OF_INSTR_NO_TRACE() 165*4882a593Smuzhiyun #endif 166*4882a593Smuzhiyun 167*4882a593Smuzhiyun #ifdef CONFIG_X86EMU_DEBUG 168*4882a593Smuzhiyun # define CALL_TRACE(u,v,w,x,s) \ 169*4882a593Smuzhiyun if (DEBUG_TRACECALLREGS()) \ 170*4882a593Smuzhiyun x86emu_dump_regs(); \ 171*4882a593Smuzhiyun if (DEBUG_TRACECALL()) \ 172*4882a593Smuzhiyun printk("%04x:%04x: CALL %s%04x:%04x\n", u , v, s, w, x); 173*4882a593Smuzhiyun # define RETURN_TRACE(n,u,v) \ 174*4882a593Smuzhiyun if (DEBUG_TRACECALLREGS()) \ 175*4882a593Smuzhiyun x86emu_dump_regs(); \ 176*4882a593Smuzhiyun if (DEBUG_TRACECALL()) \ 177*4882a593Smuzhiyun printk("%04x:%04x: %s\n",u,v,n); 178*4882a593Smuzhiyun #else 179*4882a593Smuzhiyun # define CALL_TRACE(u,v,w,x,s) 180*4882a593Smuzhiyun # define RETURN_TRACE(n,u,v) 181*4882a593Smuzhiyun #endif 182*4882a593Smuzhiyun 183*4882a593Smuzhiyun #ifdef CONFIG_X86EMU_DEBUG 184*4882a593Smuzhiyun #define DB(x) x 185*4882a593Smuzhiyun #else 186*4882a593Smuzhiyun #define DB(x) 187*4882a593Smuzhiyun #endif 188*4882a593Smuzhiyun 189*4882a593Smuzhiyun /*-------------------------- Function Prototypes --------------------------*/ 190*4882a593Smuzhiyun 191*4882a593Smuzhiyun #ifdef __cplusplus 192*4882a593Smuzhiyun extern "C" { /* Use "C" linkage when in C++ mode */ 193*4882a593Smuzhiyun #endif 194*4882a593Smuzhiyun 195*4882a593Smuzhiyun extern void x86emu_inc_decoded_inst_len(int x); 196*4882a593Smuzhiyun extern void x86emu_decode_printf(char *x); 197*4882a593Smuzhiyun extern void x86emu_decode_printf2(char *x, int y); 198*4882a593Smuzhiyun extern void x86emu_just_disassemble(void); 199*4882a593Smuzhiyun extern void x86emu_single_step(void); 200*4882a593Smuzhiyun extern void x86emu_end_instr(void); 201*4882a593Smuzhiyun extern void x86emu_dump_regs(void); 202*4882a593Smuzhiyun extern void x86emu_dump_xregs(void); 203*4882a593Smuzhiyun extern void x86emu_print_int_vect(u16 iv); 204*4882a593Smuzhiyun extern void x86emu_instrument_instruction(void); 205*4882a593Smuzhiyun extern void x86emu_check_ip_access(void); 206*4882a593Smuzhiyun extern void x86emu_check_sp_access(void); 207*4882a593Smuzhiyun extern void x86emu_check_mem_access(u32 p); 208*4882a593Smuzhiyun extern void x86emu_check_data_access(uint s, uint o); 209*4882a593Smuzhiyun 210*4882a593Smuzhiyun #ifdef __cplusplus 211*4882a593Smuzhiyun } /* End of "C" linkage for C++ */ 212*4882a593Smuzhiyun #endif 213*4882a593Smuzhiyun #endif /* __X86EMU_DEBUG_H */ 214