00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __X86ASM_H__
00022 #define __X86ASM_H__
00023
00024 #include "asm.h"
00025 #include "x86opc.h"
00026
00027 struct x86asm_insn {
00028 char lockprefix;
00029 char repprefix;
00030 char segprefix;
00031 char n[16];
00032 char *name;
00033 x86_insn_op op[3];
00034 };
00035
00036 struct x86addrcoding {
00037 int reg1;
00038 int reg2;
00039 int dispsize;
00040 };
00041
00042
00043
00044
00045
00046 #define X86ASM_NULL 0x00000000
00047 #define X86ASM_ALLOW_AMBIGUOUS 0x00000001
00048
00049 class x86asm: public Assembler {
00050 public:
00051 int opsize;
00052 int addrsize;
00053 protected:
00054 int esizes[3];
00055
00056 int modrmv;
00057 int sibv;
00058 int disp;
00059 int dispsize;
00060 int imm;
00061 int imm2;
00062 int immsize;
00063 int address;
00064 bool ambiguous;
00065 bool namefound;
00066 bool addrsize_depend;
00067
00068 void delete_nonsense();
00069 int delete_nonsense_insn(asm_code *c);
00070 void emitdisp(dword disp, int size);
00071 void emitfarptr(dword s, dword o, bool big);
00072 void emitimm(dword imm, int size);
00073 void emitmodrm(int modrm);
00074 void emitmodrm_mod(int mod);
00075 void emitmodrm_reg(int reg);
00076 void emitmodrm_rm(int rm);
00077 void emitsib_base(int base);
00078 void emitsib_index(int index);
00079 void emitsib_scale(int scale);
00080 int encode_insn(x86asm_insn *insn, x86opc_insn *opcode, int opcodeb, int additional_opcode, int prefix, int eopsize, int eaddrsize);
00081 int encode_modrm(x86_insn_op *op, char size, int allow_reg, int allow_mem, int eopsize, int eaddrsize);
00082 int encode_modrm_v(x86addrcoding (*modrmc)[3][8], x86_insn_op *op, int mindispsize, int *mod, int *rm, int *dispsize);
00083 int encode_op(x86_insn_op *op, x86opc_insn_op *xop, int *esize, int eopsize, int eaddrsize);
00084 int encode_sib_v(x86_insn_op *op, int mindispsize, int *ss, int *index, int *base, int *mod, int *dispsize, int *disp);
00085 int esizeaddr(char c, int size);
00086 int esizeop(char c, int size);
00087 int fetch_number(char **s, dword *value);
00088 char flsz2hsz(int size);
00089 char *immlsz2hsz(int size, int opsize);
00090 char *lsz2hsz(int size, int opsize);
00091 int match_allops(x86asm_insn *insn, x86opc_insn *xinsn, int opsize, int addrsize);
00092 void match_fopcodes(x86asm_insn *insn);
00093 void match_opcode(x86opc_insn *opcode, x86asm_insn *insn, int prefix, byte opcodebyte, int additional_opcode);
00094 int match_opcode_name(char *input_name, char *opcodelist_name);
00095 int match_opcode_final(x86opc_insn *opcode, x86asm_insn *insn, int prefix, byte opcodebyte, int additional_opcode, int opsize, int addrsize);
00096 void match_opcodes(x86opc_insn *opcodes, x86asm_insn *insn, int prefix);
00097 int match_size(x86_insn_op *op, x86opc_insn_op *xop, int opsize);
00098 int match_type(x86_insn_op *op, x86opc_insn_op *xop, int addrsize);
00099 int opfarptr(x86_insn_op *op, char *xop);
00100 int opimm(x86_insn_op *op, char *xop);
00101 int opplugimm(x86_insn_op *op, char *xop);
00102 int opmem(x86asm_insn *asm_insn, x86_insn_op *op, char *xop);
00103 int opreg(x86_insn_op *op, char *xop);
00104 int opseg(x86_insn_op *op, char *xop);
00105 int opspecialregs(x86_insn_op *op, char *xop);
00106 int simmsize(dword imm, int immsize);
00107 void splitstr(const char *s, char *name, char *op[3]);
00108 public:
00109 x86asm(int opsize, int addrsize);
00110 virtual ~x86asm();
00111
00112 virtual asm_insn *alloc_insn();
00113 virtual asm_code *encode(asm_insn *asm_insn, int options, CPU_ADDR cur_address);
00114 virtual char *get_name();
00115 virtual int translate_str(asm_insn *asm_insn, const char *s);
00116 };
00117
00118 #endif