1 // $Id: arch-ia32.h,v 1.4 2002/06/17 17:04:04 gaburici Exp $
2 // VG(02/06/2002): configurable IA-32 decoder
4 #if !(defined(i386_unknown_linux2_0) || defined(i386_unknown_nt4_0))
5 #error "invalid architecture-os inclusion"
15 #define PREFIX_LOCK 0xF0
16 #define PREFIX_REPNZ 0xF2
17 #define PREFIX_REP 0xF3
19 #define PREFIX_SEGCS 0x2E
20 #define PREFIX_SEGSS 0x36
21 #define PREFIX_SEGDS 0x3E
22 #define PREFIX_SEGES 0x26
23 #define PREFIX_SEGFS 0x64
24 #define PREFIX_SEGGS 0x65
26 #define PREFIX_BRANCH0 0x2E
27 #define PREFIX_BRANCH1 0x3E
29 #define PREFIX_SZOPER 0x66
30 #define PREFIX_SZADDR 0x67
35 friend ia32_prefixes& ia32_decode_prefixes(const unsigned char* addr, ia32_prefixes&);
38 // At most 4 prefixes are allowed for Intel 32-bit CPUs
39 // There also 4 groups, so this array is 0 if no prefix
40 // from that group is present, otherwise it contains the
42 unsigned char prfx[4];
44 unsigned int const getCount() const { return count; }
45 unsigned char getPrefix(unsigned char group) const { return prfx[group]; }
49 ia32_prefixes& ia32_decode_prefixes(const unsigned char* addr, ia32_prefixes&);
54 class ia32_instruction {
55 friend unsigned int ia32_decode_operands (const ia32_prefixes& pref, const ia32_entry& gotit,
56 const char* addr, ia32_instruction& instruct);
57 #if defined(i386_unknown_nt4_0) && _MSC_VER < 1300
58 friend ia32_instruction& ia32_decode(unsigned int capa, const unsigned char* addr,
59 ia32_instruction& instruct);
61 template <unsigned int capa>
62 friend ia32_instruction& ia32_decode(const unsigned char* addr, ia32_instruction& instruct);
64 friend unsigned int ia32_decode_operands (const ia32_prefixes& pref, const ia32_entry& gotit,
65 const unsigned char* addr, ia32_instruction& instruct);
66 friend ia32_instruction& ia32_decode_FP(const ia32_prefixes& pref, const unsigned char* addr,
67 ia32_instruction& instruct);
68 friend unsigned int ia32_emulate_old_type(ia32_instruction& instruct);
71 unsigned int legacy_type;
74 unsigned int getSize() const { return size; }
75 unsigned int getLegacyType() const { return legacy_type; }
79 // VG(02/07/2002): Information that the decoder can return is
80 // #defined below. The decoder always returns the size of the
81 // instruction because that has to be determined anyway.
82 // Please don't add things that should be external to the
83 // decoder, e.g.: how may bytes a relocated instruction needs
84 // IMHO that stuff should go into inst-x86...
86 #define IA32_DECODE_PREFIXES (1<<0)
87 #define IA32_DECODE_MNEMONICS (1<<1)
88 #define IA32_DECODE_OPERANDS (1<<2)
89 #define IA32_DECODE_JMPS (1<<3)
90 #define IA32_DECODE_MOVS (1<<4)
91 #define IA32_DECODE_CONDITIONS (1<<5)
93 #define IA32_FULL_DECODER 0xffffffffffffffffu
94 #define IA32_SIZE_DECODER 0
96 // old broken MS compiler cannot do this properly, so we revert to args
97 #if defined(i386_unknown_nt4_0) && _MSC_VER < 1300
99 ia32_instruction& ia32_decode(unsigned int capabilities, const unsigned char* addr, ia32_instruction&);
103 template <unsigned int capabilities>
104 ia32_instruction& ia32_decode(const unsigned char* addr, ia32_instruction&);
105 // If typing the template every time is a pain, the following should help:
106 #define ia32_decode_all ia32_decode<IA32_FULL_DECODER>
107 #define ia32_decode_size ia32_decode<IA32_SIZE_DECODER>
108 #define ia32_size(a,i) ia32_decode_size((a),(i)).size