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