blob: 859b54d860007e0f3f323277b9d7aa869f1351c2 [file] [log] [blame]
Jason Jina63ce952007-07-06 08:34:56 +08001/****************************************************************************
2*
Wolfgang Denk96bb2e02007-08-06 02:17:36 +02003* Realmode X86 Emulator Library
Jason Jina63ce952007-07-06 08:34:56 +08004*
Wolfgang Denk96bb2e02007-08-06 02:17:36 +02005* Copyright (C) 1991-2004 SciTech Software, Inc.
6* Copyright (C) David Mosberger-Tang
7* Copyright (C) 1999 Egbert Eich
Jason Jina63ce952007-07-06 08:34:56 +08008*
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 Denk96bb2e02007-08-06 02:17:36 +020017* without specific, written prior permission. The authors makes no
Jason Jina63ce952007-07-06 08:34:56 +080018* 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 Denk96bb2e02007-08-06 02:17:36 +020031* Language: ANSI C
32* Environment: Any
33* Developer: Kendall Bennett
Jason Jina63ce952007-07-06 08:34:56 +080034*
Wolfgang Denk96bb2e02007-08-06 02:17:36 +020035* Description: Header file for debug definitions.
Jason Jina63ce952007-07-06 08:34:56 +080036*
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
Simon Glassbdd5f812023-09-14 18:21:46 -060046#include <linux/printk.h>
Wolfgang Denk96bb2e02007-08-06 02:17:36 +020047#define CHECK_IP_FETCH_F 0x1
48#define CHECK_SP_ACCESS_F 0x2
49#define CHECK_MEM_ACCESS_F 0x4 /*using regular linear pointer */
50#define CHECK_DATA_ACCESS_F 0x8 /*using segment:offset */
Jason Jina63ce952007-07-06 08:34:56 +080051
Simon Glassd8414fc2014-11-14 20:56:42 -070052#ifdef CONFIG_X86EMU_DEBUG
Wolfgang Denk96bb2e02007-08-06 02:17:36 +020053# define CHECK_IP_FETCH() (M.x86.check & CHECK_IP_FETCH_F)
54# define CHECK_SP_ACCESS() (M.x86.check & CHECK_SP_ACCESS_F)
55# define CHECK_MEM_ACCESS() (M.x86.check & CHECK_MEM_ACCESS_F)
56# define CHECK_DATA_ACCESS() (M.x86.check & CHECK_DATA_ACCESS_F)
Jason Jina63ce952007-07-06 08:34:56 +080057#else
58# define CHECK_IP_FETCH()
59# define CHECK_SP_ACCESS()
60# define CHECK_MEM_ACCESS()
61# define CHECK_DATA_ACCESS()
62#endif
63
Simon Glassd8414fc2014-11-14 20:56:42 -070064#ifdef CONFIG_X86EMU_DEBUG
Wolfgang Denk96bb2e02007-08-06 02:17:36 +020065# define DEBUG_INSTRUMENT() (M.x86.debug & DEBUG_INSTRUMENT_F)
66# define DEBUG_DECODE() (M.x86.debug & DEBUG_DECODE_F)
67# define DEBUG_TRACE() (M.x86.debug & DEBUG_TRACE_F)
68# define DEBUG_STEP() (M.x86.debug & DEBUG_STEP_F)
69# define DEBUG_DISASSEMBLE() (M.x86.debug & DEBUG_DISASSEMBLE_F)
70# define DEBUG_BREAK() (M.x86.debug & DEBUG_BREAK_F)
71# define DEBUG_SVC() (M.x86.debug & DEBUG_SVC_F)
72# define DEBUG_SAVE_IP_CS() (M.x86.debug & DEBUG_SAVE_CS_IP)
Jason Jina63ce952007-07-06 08:34:56 +080073
Wolfgang Denk96bb2e02007-08-06 02:17:36 +020074# define DEBUG_FS() (M.x86.debug & DEBUG_FS_F)
75# define DEBUG_PROC() (M.x86.debug & DEBUG_PROC_F)
76# define DEBUG_SYSINT() (M.x86.debug & DEBUG_SYSINT_F)
77# define DEBUG_TRACECALL() (M.x86.debug & DEBUG_TRACECALL_F)
78# define DEBUG_TRACECALLREGS() (M.x86.debug & DEBUG_TRACECALL_REGS_F)
79# define DEBUG_SYS() (M.x86.debug & DEBUG_SYS_F)
80# define DEBUG_MEM_TRACE() (M.x86.debug & DEBUG_MEM_TRACE_F)
81# define DEBUG_IO_TRACE() (M.x86.debug & DEBUG_IO_TRACE_F)
Jason Jina63ce952007-07-06 08:34:56 +080082# define DEBUG_DECODE_NOPRINT() (M.x86.debug & DEBUG_DECODE_NOPRINT_F)
83#else
Wolfgang Denk96bb2e02007-08-06 02:17:36 +020084# define DEBUG_INSTRUMENT() 0
85# define DEBUG_DECODE() 0
86# define DEBUG_TRACE() 0
87# define DEBUG_STEP() 0
88# define DEBUG_DISASSEMBLE() 0
89# define DEBUG_BREAK() 0
90# define DEBUG_SVC() 0
91# define DEBUG_SAVE_IP_CS() 0
92# define DEBUG_FS() 0
93# define DEBUG_PROC() 0
94# define DEBUG_SYSINT() 0
95# define DEBUG_TRACECALL() 0
96# define DEBUG_TRACECALLREGS() 0
97# define DEBUG_SYS() 0
98# define DEBUG_MEM_TRACE() 0
99# define DEBUG_IO_TRACE() 0
Jason Jina63ce952007-07-06 08:34:56 +0800100# define DEBUG_DECODE_NOPRINT() 0
101#endif
102
Simon Glassb91ea302014-11-14 20:56:43 -0700103# define ERR_PRINTF(x) printf(x)
104# define ERR_PRINTF2(x, y) printf(x, y)
105
Simon Glass769852f2014-12-29 19:32:22 -0700106#ifdef CONFIG_X86EMU_DEBUG
Simon Glassb91ea302014-11-14 20:56:43 -0700107
Jason Jina63ce952007-07-06 08:34:56 +0800108
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200109# define DECODE_PRINTF(x) if (DEBUG_DECODE()) \
110 x86emu_decode_printf(x)
111# define DECODE_PRINTF2(x,y) if (DEBUG_DECODE()) \
112 x86emu_decode_printf2(x,y)
Jason Jina63ce952007-07-06 08:34:56 +0800113
114/*
115 * The following allow us to look at the bytes of an instruction. The
116 * first INCR_INSTRN_LEN, is called everytime bytes are consumed in
117 * the decoding process. The SAVE_IP_CS is called initially when the
118 * major opcode of the instruction is accessed.
119 */
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200120#define INC_DECODED_INST_LEN(x) \
121 if (DEBUG_DECODE()) \
122 x86emu_inc_decoded_inst_len(x)
Jason Jina63ce952007-07-06 08:34:56 +0800123
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200124#define SAVE_IP_CS(x,y) \
Jason Jina63ce952007-07-06 08:34:56 +0800125 if (DEBUG_DECODE() | DEBUG_TRACECALL() | DEBUG_BREAK() \
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200126 | DEBUG_IO_TRACE() | DEBUG_SAVE_IP_CS()) { \
127 M.x86.saved_cs = x; \
128 M.x86.saved_ip = y; \
Jason Jina63ce952007-07-06 08:34:56 +0800129 }
130#else
131# define INC_DECODED_INST_LEN(x)
132# define DECODE_PRINTF(x)
133# define DECODE_PRINTF2(x,y)
134# define SAVE_IP_CS(x,y)
135#endif
136
Simon Glassd8414fc2014-11-14 20:56:42 -0700137#ifdef CONFIG_X86EMU_DEBUG
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200138#define TRACE_REGS() \
139 if (DEBUG_DISASSEMBLE()) { \
140 x86emu_just_disassemble(); \
141 goto EndOfTheInstructionProcedure; \
142 } \
Jason Jina63ce952007-07-06 08:34:56 +0800143 if (DEBUG_TRACE() || DEBUG_DECODE()) X86EMU_trace_regs()
144#else
145# define TRACE_REGS()
146#endif
147
Simon Glassd8414fc2014-11-14 20:56:42 -0700148#ifdef CONFIG_X86EMU_DEBUG
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200149# define SINGLE_STEP() if (DEBUG_STEP()) x86emu_single_step()
Jason Jina63ce952007-07-06 08:34:56 +0800150#else
151# define SINGLE_STEP()
152#endif
153
154#define TRACE_AND_STEP() \
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200155 TRACE_REGS(); \
Jason Jina63ce952007-07-06 08:34:56 +0800156 SINGLE_STEP()
157
Simon Glassd8414fc2014-11-14 20:56:42 -0700158#ifdef CONFIG_X86EMU_DEBUG
Jason Jina63ce952007-07-06 08:34:56 +0800159# define START_OF_INSTR()
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200160# define END_OF_INSTR() EndOfTheInstructionProcedure: x86emu_end_instr();
Jason Jina63ce952007-07-06 08:34:56 +0800161# define END_OF_INSTR_NO_TRACE() x86emu_end_instr();
162#else
163# define START_OF_INSTR()
164# define END_OF_INSTR()
165# define END_OF_INSTR_NO_TRACE()
166#endif
167
Simon Glassd8414fc2014-11-14 20:56:42 -0700168#ifdef CONFIG_X86EMU_DEBUG
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200169# define CALL_TRACE(u,v,w,x,s) \
170 if (DEBUG_TRACECALLREGS()) \
171 x86emu_dump_regs(); \
172 if (DEBUG_TRACECALL()) \
173 printk("%04x:%04x: CALL %s%04x:%04x\n", u , v, s, w, x);
174# define RETURN_TRACE(n,u,v) \
175 if (DEBUG_TRACECALLREGS()) \
176 x86emu_dump_regs(); \
177 if (DEBUG_TRACECALL()) \
178 printk("%04x:%04x: %s\n",u,v,n);
Jason Jina63ce952007-07-06 08:34:56 +0800179#else
180# define CALL_TRACE(u,v,w,x,s)
181# define RETURN_TRACE(n,u,v)
182#endif
183
Simon Glassd8414fc2014-11-14 20:56:42 -0700184#ifdef CONFIG_X86EMU_DEBUG
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200185#define DB(x) x
Jason Jina63ce952007-07-06 08:34:56 +0800186#else
187#define DB(x)
188#endif
189
190/*-------------------------- Function Prototypes --------------------------*/
191
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200192#ifdef __cplusplus
Jason Jina63ce952007-07-06 08:34:56 +0800193extern "C" { /* Use "C" linkage when in C++ mode */
194#endif
195
196 extern void x86emu_inc_decoded_inst_len(int x);
197 extern void x86emu_decode_printf(char *x);
198 extern void x86emu_decode_printf2(char *x, int y);
199 extern void x86emu_just_disassemble(void);
200 extern void x86emu_single_step(void);
201 extern void x86emu_end_instr(void);
202 extern void x86emu_dump_regs(void);
203 extern void x86emu_dump_xregs(void);
204 extern void x86emu_print_int_vect(u16 iv);
205 extern void x86emu_instrument_instruction(void);
206 extern void x86emu_check_ip_access(void);
207 extern void x86emu_check_sp_access(void);
208 extern void x86emu_check_mem_access(u32 p);
209 extern void x86emu_check_data_access(uint s, uint o);
210
Wolfgang Denk96bb2e02007-08-06 02:17:36 +0200211#ifdef __cplusplus
212} /* End of "C" linkage for C++ */
Jason Jina63ce952007-07-06 08:34:56 +0800213#endif
214#endif /* __X86EMU_DEBUG_H */