Make UEFI boot-platform build again
[haiku.git] / headers / libs / udis86 / libudis86 / types.h
blob84b3ac8c6262864b9dac73c62a7d41970bde00b4
1 /* udis86 - libudis86/types.h
3 * Copyright (c) 2002-2013 Vivek Thampi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 *
9 * * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef UD_TYPES_H
27 #define UD_TYPES_H
29 #ifdef __KERNEL__
30 /* -D__KERNEL__ is automatically passed on the command line when
31 building something as part of the Linux kernel */
32 # include <linux/kernel.h>
33 # include <linux/string.h>
34 # ifndef __UD_STANDALONE__
35 # define __UD_STANDALONE__ 1
36 #endif
37 #endif /* __KERNEL__ */
39 #if defined(_MSC_VER) || defined(__BORLANDC__)
40 # include <stdint.h>
41 # include <stdio.h>
42 # define inline __inline /* MS Visual Studio requires __inline
43 instead of inline for C code */
44 #elif !defined(__UD_STANDALONE__) || defined(__HAIKU__)
45 # include <stdio.h>
46 # include <inttypes.h>
47 #endif /* !__UD_STANDALONE__ */
49 /* gcc specific extensions */
50 #if defined(__GNUC__) && __GNUC__ > 2
51 # define UD_ATTR_PACKED __attribute__((packed))
52 #else
53 # define UD_ATTR_PACKED
54 #endif /* UD_ATTR_PACKED */
57 /* -----------------------------------------------------------------------------
58 * All possible "types" of objects in udis86. Order is Important!
59 * -----------------------------------------------------------------------------
61 enum ud_type
63 UD_NONE,
65 /* 8 bit GPRs */
66 UD_R_AL, UD_R_CL, UD_R_DL, UD_R_BL,
67 UD_R_AH, UD_R_CH, UD_R_DH, UD_R_BH,
68 UD_R_SPL, UD_R_BPL, UD_R_SIL, UD_R_DIL,
69 UD_R_R8B, UD_R_R9B, UD_R_R10B, UD_R_R11B,
70 UD_R_R12B, UD_R_R13B, UD_R_R14B, UD_R_R15B,
72 /* 16 bit GPRs */
73 UD_R_AX, UD_R_CX, UD_R_DX, UD_R_BX,
74 UD_R_SP, UD_R_BP, UD_R_SI, UD_R_DI,
75 UD_R_R8W, UD_R_R9W, UD_R_R10W, UD_R_R11W,
76 UD_R_R12W, UD_R_R13W, UD_R_R14W, UD_R_R15W,
78 /* 32 bit GPRs */
79 UD_R_EAX, UD_R_ECX, UD_R_EDX, UD_R_EBX,
80 UD_R_ESP, UD_R_EBP, UD_R_ESI, UD_R_EDI,
81 UD_R_R8D, UD_R_R9D, UD_R_R10D, UD_R_R11D,
82 UD_R_R12D, UD_R_R13D, UD_R_R14D, UD_R_R15D,
84 /* 64 bit GPRs */
85 UD_R_RAX, UD_R_RCX, UD_R_RDX, UD_R_RBX,
86 UD_R_RSP, UD_R_RBP, UD_R_RSI, UD_R_RDI,
87 UD_R_R8, UD_R_R9, UD_R_R10, UD_R_R11,
88 UD_R_R12, UD_R_R13, UD_R_R14, UD_R_R15,
90 /* segment registers */
91 UD_R_ES, UD_R_CS, UD_R_SS, UD_R_DS,
92 UD_R_FS, UD_R_GS,
94 /* control registers*/
95 UD_R_CR0, UD_R_CR1, UD_R_CR2, UD_R_CR3,
96 UD_R_CR4, UD_R_CR5, UD_R_CR6, UD_R_CR7,
97 UD_R_CR8, UD_R_CR9, UD_R_CR10, UD_R_CR11,
98 UD_R_CR12, UD_R_CR13, UD_R_CR14, UD_R_CR15,
100 /* debug registers */
101 UD_R_DR0, UD_R_DR1, UD_R_DR2, UD_R_DR3,
102 UD_R_DR4, UD_R_DR5, UD_R_DR6, UD_R_DR7,
103 UD_R_DR8, UD_R_DR9, UD_R_DR10, UD_R_DR11,
104 UD_R_DR12, UD_R_DR13, UD_R_DR14, UD_R_DR15,
106 /* mmx registers */
107 UD_R_MM0, UD_R_MM1, UD_R_MM2, UD_R_MM3,
108 UD_R_MM4, UD_R_MM5, UD_R_MM6, UD_R_MM7,
110 /* x87 registers */
111 UD_R_ST0, UD_R_ST1, UD_R_ST2, UD_R_ST3,
112 UD_R_ST4, UD_R_ST5, UD_R_ST6, UD_R_ST7,
114 /* extended multimedia registers */
115 UD_R_XMM0, UD_R_XMM1, UD_R_XMM2, UD_R_XMM3,
116 UD_R_XMM4, UD_R_XMM5, UD_R_XMM6, UD_R_XMM7,
117 UD_R_XMM8, UD_R_XMM9, UD_R_XMM10, UD_R_XMM11,
118 UD_R_XMM12, UD_R_XMM13, UD_R_XMM14, UD_R_XMM15,
120 UD_R_RIP,
122 /* Operand Types */
123 UD_OP_REG, UD_OP_MEM, UD_OP_PTR, UD_OP_IMM,
124 UD_OP_JIMM, UD_OP_CONST
127 #include "itab.h"
129 union ud_lval {
130 int8_t sbyte;
131 uint8_t ubyte;
132 int16_t sword;
133 uint16_t uword;
134 int32_t sdword;
135 uint32_t udword;
136 int64_t sqword;
137 uint64_t uqword;
138 struct {
139 uint16_t seg;
140 uint32_t off;
141 } ptr;
144 /* -----------------------------------------------------------------------------
145 * struct ud_operand - Disassembled instruction Operand.
146 * -----------------------------------------------------------------------------
148 struct ud_operand {
149 enum ud_type type;
150 uint8_t size;
151 enum ud_type base;
152 enum ud_type index;
153 uint8_t scale;
154 uint8_t offset;
155 union ud_lval lval;
157 * internal use only
159 uint64_t _legacy; /* this will be removed in 1.8 */
160 uint8_t _oprcode;
163 /* -----------------------------------------------------------------------------
164 * struct ud - The udis86 object.
165 * -----------------------------------------------------------------------------
167 struct ud
170 * input buffering
172 int (*inp_hook) (struct ud*);
173 #ifndef __UD_STANDALONE__
174 FILE* inp_file;
175 #endif
176 const uint8_t* inp_buf;
177 size_t inp_buf_size;
178 size_t inp_buf_index;
179 uint8_t inp_curr;
180 size_t inp_ctr;
181 uint8_t inp_sess[64];
182 int inp_end;
184 void (*translator)(struct ud*);
185 uint64_t insn_offset;
186 char insn_hexcode[64];
189 * Assembly output buffer
191 char *asm_buf;
192 size_t asm_buf_size;
193 size_t asm_buf_fill;
194 char asm_buf_int[128];
197 * Symbol resolver for use in the translation phase.
199 const char* (*sym_resolver)(struct ud*, uint64_t addr, int64_t *offset);
201 uint8_t dis_mode;
202 uint64_t pc;
203 uint8_t vendor;
204 enum ud_mnemonic_code mnemonic;
205 struct ud_operand operand[3];
206 uint8_t error;
207 uint8_t pfx_rex;
208 uint8_t pfx_seg;
209 uint8_t pfx_opr;
210 uint8_t pfx_adr;
211 uint8_t pfx_lock;
212 uint8_t pfx_str;
213 uint8_t pfx_rep;
214 uint8_t pfx_repe;
215 uint8_t pfx_repne;
216 uint8_t opr_mode;
217 uint8_t adr_mode;
218 uint8_t br_far;
219 uint8_t br_near;
220 uint8_t have_modrm;
221 uint8_t modrm;
222 uint8_t primary_opcode;
223 void * user_opaque_data;
224 struct ud_itab_entry * itab_entry;
225 struct ud_lookup_table_list_entry *le;
228 /* -----------------------------------------------------------------------------
229 * Type-definitions
230 * -----------------------------------------------------------------------------
232 typedef enum ud_type ud_type_t;
233 typedef enum ud_mnemonic_code ud_mnemonic_code_t;
235 typedef struct ud ud_t;
236 typedef struct ud_operand ud_operand_t;
238 #define UD_SYN_INTEL ud_translate_intel
239 #define UD_SYN_ATT ud_translate_att
240 #define UD_EOI (-1)
241 #define UD_INP_CACHE_SZ 32
242 #define UD_VENDOR_AMD 0
243 #define UD_VENDOR_INTEL 1
244 #define UD_VENDOR_ANY 2
246 #endif
249 vim: set ts=2 sw=2 expandtab