debug.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /****************************************************************************
  2. *
  3. * Realmode X86 Emulator Library
  4. *
  5. * Copyright (C) 1991-2004 SciTech Software, Inc.
  6. * Copyright (C) David Mosberger-Tang
  7. * Copyright (C) 1999 Egbert Eich
  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
  17. * without specific, written prior permission. The authors makes no
  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. *
  31. * Language: ANSI C
  32. * Environment: Any
  33. * Developer: Kendall Bennett
  34. *
  35. * Description: Header file for debug definitions.
  36. *
  37. ****************************************************************************/
  38. #ifndef __X86EMU_DEBUG_H
  39. #define __X86EMU_DEBUG_H
  40. /*---------------------- Macros and type definitions ----------------------*/
  41. /* checks to be enabled for "runtime" */
  42. #define CHECK_IP_FETCH_F 0x1
  43. #define CHECK_SP_ACCESS_F 0x2
  44. #define CHECK_MEM_ACCESS_F 0x4 /*using regular linear pointer */
  45. #define CHECK_DATA_ACCESS_F 0x8 /*using segment:offset */
  46. #ifdef CONFIG_X86EMU_DEBUG
  47. # define CHECK_IP_FETCH() (M.x86.check & CHECK_IP_FETCH_F)
  48. # define CHECK_SP_ACCESS() (M.x86.check & CHECK_SP_ACCESS_F)
  49. # define CHECK_MEM_ACCESS() (M.x86.check & CHECK_MEM_ACCESS_F)
  50. # define CHECK_DATA_ACCESS() (M.x86.check & CHECK_DATA_ACCESS_F)
  51. #else
  52. # define CHECK_IP_FETCH()
  53. # define CHECK_SP_ACCESS()
  54. # define CHECK_MEM_ACCESS()
  55. # define CHECK_DATA_ACCESS()
  56. #endif
  57. #ifdef CONFIG_X86EMU_DEBUG
  58. # define DEBUG_INSTRUMENT() (M.x86.debug & DEBUG_INSTRUMENT_F)
  59. # define DEBUG_DECODE() (M.x86.debug & DEBUG_DECODE_F)
  60. # define DEBUG_TRACE() (M.x86.debug & DEBUG_TRACE_F)
  61. # define DEBUG_STEP() (M.x86.debug & DEBUG_STEP_F)
  62. # define DEBUG_DISASSEMBLE() (M.x86.debug & DEBUG_DISASSEMBLE_F)
  63. # define DEBUG_BREAK() (M.x86.debug & DEBUG_BREAK_F)
  64. # define DEBUG_SVC() (M.x86.debug & DEBUG_SVC_F)
  65. # define DEBUG_SAVE_IP_CS() (M.x86.debug & DEBUG_SAVE_CS_IP)
  66. # define DEBUG_FS() (M.x86.debug & DEBUG_FS_F)
  67. # define DEBUG_PROC() (M.x86.debug & DEBUG_PROC_F)
  68. # define DEBUG_SYSINT() (M.x86.debug & DEBUG_SYSINT_F)
  69. # define DEBUG_TRACECALL() (M.x86.debug & DEBUG_TRACECALL_F)
  70. # define DEBUG_TRACECALLREGS() (M.x86.debug & DEBUG_TRACECALL_REGS_F)
  71. # define DEBUG_SYS() (M.x86.debug & DEBUG_SYS_F)
  72. # define DEBUG_MEM_TRACE() (M.x86.debug & DEBUG_MEM_TRACE_F)
  73. # define DEBUG_IO_TRACE() (M.x86.debug & DEBUG_IO_TRACE_F)
  74. # define DEBUG_DECODE_NOPRINT() (M.x86.debug & DEBUG_DECODE_NOPRINT_F)
  75. #else
  76. # define DEBUG_INSTRUMENT() 0
  77. # define DEBUG_DECODE() 0
  78. # define DEBUG_TRACE() 0
  79. # define DEBUG_STEP() 0
  80. # define DEBUG_DISASSEMBLE() 0
  81. # define DEBUG_BREAK() 0
  82. # define DEBUG_SVC() 0
  83. # define DEBUG_SAVE_IP_CS() 0
  84. # define DEBUG_FS() 0
  85. # define DEBUG_PROC() 0
  86. # define DEBUG_SYSINT() 0
  87. # define DEBUG_TRACECALL() 0
  88. # define DEBUG_TRACECALLREGS() 0
  89. # define DEBUG_SYS() 0
  90. # define DEBUG_MEM_TRACE() 0
  91. # define DEBUG_IO_TRACE() 0
  92. # define DEBUG_DECODE_NOPRINT() 0
  93. #endif
  94. # define ERR_PRINTF(x) printf(x)
  95. # define ERR_PRINTF2(x, y) printf(x, y)
  96. #ifdef CONFIG_X86EMU_DEBUG
  97. # define DECODE_PRINTF(x) if (DEBUG_DECODE()) \
  98. x86emu_decode_printf(x)
  99. # define DECODE_PRINTF2(x,y) if (DEBUG_DECODE()) \
  100. x86emu_decode_printf2(x,y)
  101. /*
  102. * The following allow us to look at the bytes of an instruction. The
  103. * first INCR_INSTRN_LEN, is called everytime bytes are consumed in
  104. * the decoding process. The SAVE_IP_CS is called initially when the
  105. * major opcode of the instruction is accessed.
  106. */
  107. #define INC_DECODED_INST_LEN(x) \
  108. if (DEBUG_DECODE()) \
  109. x86emu_inc_decoded_inst_len(x)
  110. #define SAVE_IP_CS(x,y) \
  111. if (DEBUG_DECODE() | DEBUG_TRACECALL() | DEBUG_BREAK() \
  112. | DEBUG_IO_TRACE() | DEBUG_SAVE_IP_CS()) { \
  113. M.x86.saved_cs = x; \
  114. M.x86.saved_ip = y; \
  115. }
  116. #else
  117. # define INC_DECODED_INST_LEN(x)
  118. # define DECODE_PRINTF(x)
  119. # define DECODE_PRINTF2(x,y)
  120. # define SAVE_IP_CS(x,y)
  121. #endif
  122. #ifdef CONFIG_X86EMU_DEBUG
  123. #define TRACE_REGS() \
  124. if (DEBUG_DISASSEMBLE()) { \
  125. x86emu_just_disassemble(); \
  126. goto EndOfTheInstructionProcedure; \
  127. } \
  128. if (DEBUG_TRACE() || DEBUG_DECODE()) X86EMU_trace_regs()
  129. #else
  130. # define TRACE_REGS()
  131. #endif
  132. #ifdef CONFIG_X86EMU_DEBUG
  133. # define SINGLE_STEP() if (DEBUG_STEP()) x86emu_single_step()
  134. #else
  135. # define SINGLE_STEP()
  136. #endif
  137. #define TRACE_AND_STEP() \
  138. TRACE_REGS(); \
  139. SINGLE_STEP()
  140. #ifdef CONFIG_X86EMU_DEBUG
  141. # define START_OF_INSTR()
  142. # define END_OF_INSTR() EndOfTheInstructionProcedure: x86emu_end_instr();
  143. # define END_OF_INSTR_NO_TRACE() x86emu_end_instr();
  144. #else
  145. # define START_OF_INSTR()
  146. # define END_OF_INSTR()
  147. # define END_OF_INSTR_NO_TRACE()
  148. #endif
  149. #ifdef CONFIG_X86EMU_DEBUG
  150. # define CALL_TRACE(u,v,w,x,s) \
  151. if (DEBUG_TRACECALLREGS()) \
  152. x86emu_dump_regs(); \
  153. if (DEBUG_TRACECALL()) \
  154. printk("%04x:%04x: CALL %s%04x:%04x\n", u , v, s, w, x);
  155. # define RETURN_TRACE(n,u,v) \
  156. if (DEBUG_TRACECALLREGS()) \
  157. x86emu_dump_regs(); \
  158. if (DEBUG_TRACECALL()) \
  159. printk("%04x:%04x: %s\n",u,v,n);
  160. #else
  161. # define CALL_TRACE(u,v,w,x,s)
  162. # define RETURN_TRACE(n,u,v)
  163. #endif
  164. #ifdef CONFIG_X86EMU_DEBUG
  165. #define DB(x) x
  166. #else
  167. #define DB(x)
  168. #endif
  169. /*-------------------------- Function Prototypes --------------------------*/
  170. #ifdef __cplusplus
  171. extern "C" { /* Use "C" linkage when in C++ mode */
  172. #endif
  173. extern void x86emu_inc_decoded_inst_len(int x);
  174. extern void x86emu_decode_printf(char *x);
  175. extern void x86emu_decode_printf2(char *x, int y);
  176. extern void x86emu_just_disassemble(void);
  177. extern void x86emu_single_step(void);
  178. extern void x86emu_end_instr(void);
  179. extern void x86emu_dump_regs(void);
  180. extern void x86emu_dump_xregs(void);
  181. extern void x86emu_print_int_vect(u16 iv);
  182. extern void x86emu_instrument_instruction(void);
  183. extern void x86emu_check_ip_access(void);
  184. extern void x86emu_check_sp_access(void);
  185. extern void x86emu_check_mem_access(u32 p);
  186. extern void x86emu_check_data_access(uint s, uint o);
  187. #ifdef __cplusplus
  188. } /* End of "C" linkage for C++ */
  189. #endif
  190. #endif /* __X86EMU_DEBUG_H */