20 #include "x86emu/x86emui.h" 21 #ifndef NO_SYS_HEADERS 30 static void print_encoded_bytes(u16 s, u16 o);
31 static void print_decoded_instruction(
void);
32 static int parse_line(
char *s,
int *ps,
int *n);
35 void X86EMU_trace_regs(
void)
41 if (DEBUG_DECODE() && !DEBUG_DECODE_NOPRINT())
43 printk(
"%04x:%04x ", M.x86.saved_cs, M.x86.saved_ip);
44 print_encoded_bytes(M.x86.saved_cs, M.x86.saved_ip);
45 print_decoded_instruction();
49 void X86EMU_trace_xregs(
void)
57 void x86emu_just_disassemble(
void)
63 printk(
"%04x:%04x ", M.x86.saved_cs, M.x86.saved_ip);
64 print_encoded_bytes(M.x86.saved_cs, M.x86.saved_ip);
65 print_decoded_instruction();
68 static void disassemble_forward(u16 seg, u16 off,
int n)
102 tregs.x86.enc_str_pos = 0;
103 tregs.x86.enc_pos = 0;
106 tregs.x86.debug |= DEBUG_DISASSEMBLE_F;
116 for (i = 0; i < n; i++)
118 op1 = (*sys_rdb)(((u32) M.x86.R_CS << 4) + (M.x86.R_IP++));
119 (x86emu_optab[op1])(op1);
124 void x86emu_check_ip_access(
void)
129 void x86emu_check_sp_access(
void)
133 void x86emu_check_mem_access(u32 dummy)
138 void x86emu_check_data_access(uint dummy1, uint dummy2)
143 void x86emu_inc_decoded_inst_len(
int x)
148 void x86emu_decode_printf(
char *x)
150 StringFormat(M.x86.decoded_buf + M.x86.enc_str_pos,
"%s", x);
151 M.x86.enc_str_pos += StringLength(x);
154 void x86emu_decode_printf2(
char *x,
int y)
157 StringFormat(temp, x, y);
158 StringFormat(M.x86.decoded_buf + M.x86.enc_str_pos,
"%s", temp);
159 M.x86.enc_str_pos += StringLength(temp);
162 void x86emu_end_instr(
void)
164 M.x86.enc_str_pos = 0;
168 static void print_encoded_bytes(u16 s, u16 o)
172 for (i = 0; i < M.x86.enc_pos; i++)
174 StringFormat(buf1 + 2 * i,
"%02x", fetch_data_byte_abs(s, o + i));
176 printk(
"%-20s", buf1);
179 static void print_decoded_instruction(
void)
181 printk(
"%s", M.x86.decoded_buf);
184 void x86emu_print_int_vect(u16 iv)
190 seg = fetch_data_word_abs(0, iv * 4);
191 off = fetch_data_word_abs(0, iv * 4 + 2);
192 printk(
"%04x:%04x ", seg, off);
195 void X86EMU_dump_memory(u16 seg, u16 off, u32 amt)
197 u32 start = off & 0xfffffff0;
198 u32 end = (off + 16) & 0xfffffff0;
203 while (end <= off + amt)
205 printk(
"%04x:%04x ", seg, start);
206 for (i = start; i < off; i++)
209 printk(
"%02x ", fetch_data_byte_abs(seg, i));
216 void x86emu_single_step(
void)
225 static int breakpoint;
226 static int noDecode = 1;
232 if (M.x86.saved_ip != breakpoint)
238 M.x86.debug &= ~DEBUG_DECODE_NOPRINT_F;
239 M.x86.debug |= DEBUG_TRACE_F;
240 M.x86.debug &= ~DEBUG_BREAK_F;
241 print_decoded_instruction();
246 offset = M.x86.saved_ip;
250 p = fgets(s, 1023, stdin);
251 cmd = parse_line(s, ps, &ntok);
255 disassemble_forward(M.x86.saved_cs, (u16) offset, 10);
260 segment = M.x86.saved_cs;
262 X86EMU_dump_memory(segment, (u16) offset, 16);
269 X86EMU_dump_memory(segment, (u16) offset, 16);
274 segment = M.x86.saved_cs;
275 X86EMU_dump_memory(segment, (u16) offset, 16);
280 M.x86.debug ^= DEBUG_TRACECALL_F;
283 M.x86.debug ^= DEBUG_SVC_F | DEBUG_SYS_F | DEBUG_SYSINT_F;
289 X86EMU_trace_xregs();
297 M.x86.debug |= DEBUG_DECODE_NOPRINT_F;
301 M.x86.debug &= ~DEBUG_DECODE_NOPRINT_F;
303 M.x86.debug &= ~DEBUG_TRACE_F;
304 M.x86.debug |= DEBUG_BREAK_F;
309 M.x86.debug |= DEBUG_EXIT;
312 noDecode = (noDecode) ? 0 : 1;
314 "Toggled decoding to %s\n", (noDecode) ?
"FALSE" :
"TRUE");
324 int X86EMU_trace_on(
void)
326 return M.x86.debug |= DEBUG_STEP_F | DEBUG_DECODE_F | DEBUG_TRACE_F;
329 int X86EMU_trace_off(
void)
331 return M.x86.debug &= ~(DEBUG_STEP_F | DEBUG_DECODE_F | DEBUG_TRACE_F);
334 static int parse_line(
char *s,
int *ps,
int *n)
339 while (*s ==
' ' || *s ==
'\t')
354 while (*s !=
' ' && *s !=
'\t' && *s !=
'\n')
360 while (*s ==
' ' || *s ==
'\t')
363 sscanf(s,
"%x", &ps[*n]);
370 void x86emu_dump_regs(
void)
372 printk(
"\tAX=%04x ", M.x86.R_AX);
373 printk(
"BX=%04x ", M.x86.R_BX);
374 printk(
"CX=%04x ", M.x86.R_CX);
375 printk(
"DX=%04x ", M.x86.R_DX);
376 printk(
"SP=%04x ", M.x86.R_SP);
377 printk(
"BP=%04x ", M.x86.R_BP);
378 printk(
"SI=%04x ", M.x86.R_SI);
379 printk(
"DI=%04x\n", M.x86.R_DI);
380 printk(
"\tDS=%04x ", M.x86.R_DS);
381 printk(
"ES=%04x ", M.x86.R_ES);
382 printk(
"SS=%04x ", M.x86.R_SS);
383 printk(
"CS=%04x ", M.x86.R_CS);
384 printk(
"IP=%04x ", M.x86.R_IP);
385 if (ACCESS_FLAG(F_OF))
389 if (ACCESS_FLAG(F_DF))
393 if (ACCESS_FLAG(F_IF))
397 if (ACCESS_FLAG(F_SF))
401 if (ACCESS_FLAG(F_ZF))
405 if (ACCESS_FLAG(F_AF))
409 if (ACCESS_FLAG(F_PF))
413 if (ACCESS_FLAG(F_CF))
420 void x86emu_dump_xregs(
void)
422 printk(
"\tEAX=%08x ", M.x86.R_EAX);
423 printk(
"EBX=%08x ", M.x86.R_EBX);
424 printk(
"ECX=%08x ", M.x86.R_ECX);
425 printk(
"EDX=%08x \n", M.x86.R_EDX);
426 printk(
"\tESP=%08x ", M.x86.R_ESP);
427 printk(
"EBP=%08x ", M.x86.R_EBP);
428 printk(
"ESI=%08x ", M.x86.R_ESI);
429 printk(
"EDI=%08x\n", M.x86.R_EDI);
430 printk(
"\tDS=%04x ", M.x86.R_DS);
431 printk(
"ES=%04x ", M.x86.R_ES);
432 printk(
"SS=%04x ", M.x86.R_SS);
433 printk(
"CS=%04x ", M.x86.R_CS);
434 printk(
"EIP=%08x\n\t", M.x86.R_EIP);
435 if (ACCESS_FLAG(F_OF))
439 if (ACCESS_FLAG(F_DF))
443 if (ACCESS_FLAG(F_IF))
447 if (ACCESS_FLAG(F_SF))
451 if (ACCESS_FLAG(F_ZF))
455 if (ACCESS_FLAG(F_AF))
459 if (ACCESS_FLAG(F_PF))
463 if (ACCESS_FLAG(F_CF))