Revision 586314f2 translate-i386.c
b/translate-i386.c | ||
---|---|---|
5 | 5 |
#include <inttypes.h> |
6 | 6 |
#include <assert.h> |
7 | 7 |
|
8 |
/* dump all code */ |
|
9 | 8 |
#define DEBUG_DISAS |
10 |
#define DEBUG_LOGFILE "/tmp/gemu.log" |
|
11 | 9 |
|
10 |
#define IN_OP_I386 |
|
11 |
#include "cpu-i386.h" |
|
12 |
|
|
13 |
/* dump all code */ |
|
12 | 14 |
#ifdef DEBUG_DISAS |
13 | 15 |
#include "dis-asm.h" |
14 | 16 |
#endif |
15 | 17 |
|
16 |
#define IN_OP_I386 |
|
17 |
#include "cpu-i386.h" |
|
18 |
|
|
19 | 18 |
static uint8_t *gen_code_ptr; |
20 | 19 |
int __op_param1, __op_param2, __op_param3; |
21 | 20 |
|
22 |
#ifdef DEBUG_DISAS |
|
23 |
static FILE *logfile = NULL; |
|
24 |
#endif |
|
21 |
extern FILE *logfile; |
|
22 |
extern int loglevel; |
|
25 | 23 |
|
26 | 24 |
/* supress that */ |
27 | 25 |
static void error(const char *fmt, ...) |
... | ... | |
716 | 714 |
int reg1, reg2, opreg; |
717 | 715 |
int mod, rm, code; |
718 | 716 |
|
719 |
#ifdef DEBUG_DISAS |
|
720 |
fprintf(logfile, "modrm=0x%x\n", modrm); |
|
721 |
#endif |
|
722 | 717 |
mod = (modrm >> 6) & 3; |
723 | 718 |
rm = modrm & 7; |
724 | 719 |
|
... | ... | |
731 | 726 |
if (base == 4) { |
732 | 727 |
havesib = 1; |
733 | 728 |
code = ldub(s->pc++); |
734 |
#ifdef DEBUG_DISAS |
|
735 |
fprintf(logfile, "sib=0x%x\n", code); |
|
736 |
#endif |
|
737 | 729 |
scale = (code >> 6) & 3; |
738 | 730 |
index = (code >> 3) & 7; |
739 | 731 |
base = code & 7; |
... | ... | |
988 | 980 |
// cur_pc = s->pc; /* for insn generation */ |
989 | 981 |
next_byte: |
990 | 982 |
b = ldub(s->pc); |
991 |
#ifdef DEBUG_DISAS |
|
992 |
fprintf(logfile, "ib=0x%02x\n", b); |
|
993 |
#endif |
|
994 |
if (b < 0) |
|
995 |
return -1; |
|
996 | 983 |
s->pc++; |
997 | 984 |
/* check prefixes */ |
998 | 985 |
switch (b) { |
... | ... | |
2247 | 2234 |
gen_start(); |
2248 | 2235 |
|
2249 | 2236 |
#ifdef DEBUG_DISAS |
2250 |
if (!logfile) { |
|
2251 |
logfile = fopen(DEBUG_LOGFILE, "w"); |
|
2252 |
if (!logfile) { |
|
2253 |
perror(DEBUG_LOGFILE); |
|
2254 |
exit(1); |
|
2255 |
} |
|
2256 |
setvbuf(logfile, NULL, _IOLBF, 0); |
|
2257 |
} |
|
2258 |
|
|
2259 |
INIT_DISASSEMBLE_INFO(disasm_info, logfile, fprintf); |
|
2260 |
disasm_info.buffer = pc_start; |
|
2261 |
disasm_info.buffer_vma = (unsigned long)pc_start; |
|
2262 |
disasm_info.buffer_length = 15; |
|
2237 |
if (loglevel) { |
|
2238 |
INIT_DISASSEMBLE_INFO(disasm_info, logfile, fprintf); |
|
2239 |
disasm_info.buffer = pc_start; |
|
2240 |
disasm_info.buffer_vma = (unsigned long)pc_start; |
|
2241 |
disasm_info.buffer_length = 15; |
|
2263 | 2242 |
#if 0 |
2264 |
disasm_info.flavour = bfd_get_flavour (abfd); |
|
2265 |
disasm_info.arch = bfd_get_arch (abfd); |
|
2266 |
disasm_info.mach = bfd_get_mach (abfd); |
|
2243 |
disasm_info.flavour = bfd_get_flavour (abfd);
|
|
2244 |
disasm_info.arch = bfd_get_arch (abfd);
|
|
2245 |
disasm_info.mach = bfd_get_mach (abfd);
|
|
2267 | 2246 |
#endif |
2268 | 2247 |
#ifdef WORDS_BIGENDIAN |
2269 |
disasm_info.endian = BFD_ENDIAN_BIG; |
|
2248 |
disasm_info.endian = BFD_ENDIAN_BIG;
|
|
2270 | 2249 |
#else |
2271 |
disasm_info.endian = BFD_ENDIAN_LITTLE; |
|
2250 |
disasm_info.endian = BFD_ENDIAN_LITTLE;
|
|
2272 | 2251 |
#endif |
2273 |
fprintf(logfile, "IN:\n"); |
|
2274 |
fprintf(logfile, "0x%08lx: ", (long)pc_start); |
|
2275 |
print_insn_i386((unsigned long)pc_start, &disasm_info); |
|
2276 |
fprintf(logfile, "\n\n"); |
|
2252 |
fprintf(logfile, "IN:\n"); |
|
2253 |
fprintf(logfile, "0x%08lx: ", (long)pc_start); |
|
2254 |
print_insn_i386((unsigned long)pc_start, &disasm_info); |
|
2255 |
fprintf(logfile, "\n\n"); |
|
2256 |
} |
|
2277 | 2257 |
#endif |
2278 | 2258 |
is_jmp = 0; |
2279 | 2259 |
ret = disas_insn(dc, pc_start, &is_jmp); |
... | ... | |
2290 | 2270 |
*gen_code_size_ptr = gen_code_ptr - gen_code_buf; |
2291 | 2271 |
|
2292 | 2272 |
#ifdef DEBUG_DISAS |
2293 |
{ |
|
2273 |
if (loglevel) {
|
|
2294 | 2274 |
uint8_t *pc; |
2295 | 2275 |
int count; |
2296 | 2276 |
|
Also available in: Unified diff