1 |
dpavlin |
1 |
/* |
2 |
|
|
* HT Editor |
3 |
|
|
* x86dis.h |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 1999-2002 Stefan Weyergraf |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License version 2 as |
9 |
|
|
* published by the Free Software Foundation. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#ifndef __X86DIS_H__ |
22 |
|
|
#define __X86DIS_H__ |
23 |
|
|
|
24 |
|
|
#include "asm.h" |
25 |
|
|
#include "x86opc.h" |
26 |
|
|
#include "tools/data.h" |
27 |
|
|
|
28 |
|
|
#define word uint16 |
29 |
|
|
|
30 |
|
|
#define X86DIS_OPCODE_CLASS_STD 0 /* no prefix */ |
31 |
|
|
#define X86DIS_OPCODE_CLASS_EXT 1 /* 0F */ |
32 |
|
|
#define X86DIS_OPCODE_CLASS_EXTEXT 2 /* 0F0F */ |
33 |
|
|
|
34 |
|
|
/* x86-specific styles */ |
35 |
|
|
#define X86DIS_STYLE_EXPLICIT_MEMSIZE 0x00000001 /* IF SET: mov word ptr [0000], ax ELSE: mov [0000], ax */ |
36 |
|
|
#define X86DIS_STYLE_OPTIMIZE_ADDR 0x00000002 /* IF SET: mov [eax*3], ax ELSE: mov [eax+eax*2+00000000], ax */ |
37 |
|
|
/*#define X86DIS_STYLE_USE16 0x00000004 |
38 |
|
|
#define X86DIS_STYLE_USE32 0x00000008*/ |
39 |
|
|
|
40 |
|
|
struct x86dis_insn { |
41 |
|
|
bool invalid; |
42 |
|
|
sint8 lockprefix; |
43 |
|
|
sint8 repprefix; |
44 |
|
|
sint8 segprefix; |
45 |
|
|
byte size; |
46 |
|
|
int opcode; |
47 |
|
|
int opcodeclass; |
48 |
|
|
int eopsize; |
49 |
|
|
int eaddrsize; |
50 |
|
|
char *name; |
51 |
|
|
x86_insn_op op[3]; |
52 |
|
|
}; |
53 |
|
|
|
54 |
|
|
/* |
55 |
|
|
* CLASS x86dis |
56 |
|
|
*/ |
57 |
|
|
|
58 |
|
|
class X86Disassembler: public Disassembler { |
59 |
|
|
public: |
60 |
|
|
int opsize, addrsize; |
61 |
|
|
protected: |
62 |
|
|
x86dis_insn insn; |
63 |
|
|
char insnstr[256]; |
64 |
|
|
/* initme! */ |
65 |
|
|
const byte *codep, *ocodep; |
66 |
|
|
int seg; |
67 |
|
|
int addr; // FIXME: int?? |
68 |
|
|
byte c; |
69 |
|
|
int modrm; |
70 |
|
|
int sib; |
71 |
|
|
int maxlen; |
72 |
|
|
|
73 |
|
|
/* new */ |
74 |
|
|
void decode_insn(x86opc_insn *insn); |
75 |
|
|
void decode_modrm(x86_insn_op *op, char size, int allow_reg, int allow_mem, int mmx); |
76 |
|
|
void decode_op(x86_insn_op *op, x86opc_insn_op *xop); |
77 |
|
|
void decode_sib(x86_insn_op *op, int mod); |
78 |
|
|
int esizeaddr(char c); |
79 |
|
|
int esizeop(char c); |
80 |
|
|
byte getbyte(); |
81 |
|
|
word getword(); |
82 |
|
|
dword getdword(); |
83 |
|
|
int getmodrm(); |
84 |
|
|
int getsib(); |
85 |
|
|
void invalidate(); |
86 |
|
|
int isfloat(char c); |
87 |
|
|
void prefixes(); |
88 |
|
|
int special_param_ambiguity(x86dis_insn *disasm_insn); |
89 |
|
|
void str_format(char **str, char **format, char *p, char *n, char *op[3], int oplen[3], char stopchar, int print); |
90 |
|
|
virtual void str_op(char *opstr, int *opstrlen, x86dis_insn *insn, x86_insn_op *op, bool explicit_params); |
91 |
|
|
public: |
92 |
|
|
X86Disassembler(); |
93 |
|
|
X86Disassembler(int opsize, int addrsize); |
94 |
|
|
virtual ~X86Disassembler(); |
95 |
|
|
|
96 |
|
|
/* overwritten */ |
97 |
|
|
virtual dis_insn *decode(const byte *code, int maxlen, CPU_ADDR addr); |
98 |
|
|
virtual dis_insn *duplicateInsn(dis_insn *disasm_insn); |
99 |
|
|
virtual void getOpcodeMetrics(int &min_length, int &max_length, int &min_look_ahead, int &avg_look_ahead, int &addr_align); |
100 |
|
|
virtual char *getName(); |
101 |
|
|
virtual byte getSize(dis_insn *disasm_insn); |
102 |
|
|
virtual char *str(dis_insn *disasm_insn, int options); |
103 |
|
|
virtual char *strf(dis_insn *disasm_insn, int options, char *format); |
104 |
|
|
virtual bool validInsn(dis_insn *disasm_insn); |
105 |
|
|
}; |
106 |
|
|
|
107 |
|
|
|
108 |
|
|
#endif /* __X86DIS_H__ */ |