1 /* udis86 - libudis86/syn-att.c
3 * Copyright (c) 2002-2009 Vivek Thampi
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
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.
33 /* -----------------------------------------------------------------------------
34 * opr_cast() - Prints an operand cast.
35 * -----------------------------------------------------------------------------
38 opr_cast(struct ud
* u
, struct ud_operand
* op
)
42 ud_asmprintf(u
, "*"); break;
47 /* -----------------------------------------------------------------------------
48 * gen_operand() - Generates assembly output for each operand.
49 * -----------------------------------------------------------------------------
52 gen_operand(struct ud
* u
, struct ud_operand
* op
)
56 ud_asmprintf(u
, "$0x%x", op
->lval
.udword
);
60 ud_asmprintf(u
, "%%%s", ud_reg_tab
[op
->base
- UD_R_AL
]);
68 ud_asmprintf(u
, "%%%s:", ud_reg_tab
[u
->pfx_seg
- UD_R_AL
]);
70 if (op
->offset
!= 0) {
71 ud_syn_print_mem_disp(u
, op
, 0);
74 ud_asmprintf(u
, "(%%%s", ud_reg_tab
[op
->base
- UD_R_AL
]);
82 ud_asmprintf(u
, "%%%s", ud_reg_tab
[op
->index
- UD_R_AL
]);
85 ud_asmprintf(u
, ",%d", op
->scale
);
87 if (op
->base
|| op
->index
) {
93 ud_syn_print_imm(u
, op
);
97 ud_syn_print_addr(u
, ud_syn_rel_target(u
, op
));
103 ud_asmprintf(u
, "$0x%x, $0x%x", op
->lval
.ptr
.seg
,
104 op
->lval
.ptr
.off
& 0xFFFF);
107 ud_asmprintf(u
, "$0x%x, $0x%x", op
->lval
.ptr
.seg
,
117 /* =============================================================================
118 * translates to AT&T syntax
119 * =============================================================================
122 ud_translate_att(struct ud
*u
)
127 /* check if P_OSO prefix is used */
128 if (! P_OSO(u
->itab_entry
->prefix
) && u
->pfx_opr
) {
129 switch (u
->dis_mode
) {
131 ud_asmprintf(u
, "o32 ");
135 ud_asmprintf(u
, "o16 ");
140 /* check if P_ASO prefix was used */
141 if (! P_ASO(u
->itab_entry
->prefix
) && u
->pfx_adr
) {
142 switch (u
->dis_mode
) {
144 ud_asmprintf(u
, "a32 ");
147 ud_asmprintf(u
, "a16 ");
150 ud_asmprintf(u
, "a32 ");
156 ud_asmprintf(u
, "lock ");
158 ud_asmprintf(u
, "rep ");
159 } else if (u
->pfx_rep
) {
160 ud_asmprintf(u
, "repe ");
161 } else if (u
->pfx_repne
) {
162 ud_asmprintf(u
, "repne ");
165 /* special instructions */
166 switch (u
->mnemonic
) {
168 ud_asmprintf(u
, "lret ");
171 ud_asmprintf(u
, ".byte 0x%x", u
->operand
[0].lval
.ubyte
);
175 if (u
->br_far
) ud_asmprintf(u
, "l");
176 if (u
->operand
[0].type
== UD_OP_REG
) {
179 ud_asmprintf(u
, "%s", ud_lookup_mnemonic(u
->mnemonic
));
183 if (u
->operand
[0].type
!= UD_NONE
)
184 gen_operand(u
, &u
->operand
[0]);
185 if (u
->operand
[1].type
!= UD_NONE
) {
186 ud_asmprintf(u
, ",");
187 gen_operand(u
, &u
->operand
[1]);
191 ud_asmprintf(u
, "%s", ud_lookup_mnemonic(u
->mnemonic
));
195 ud_asmprintf(u
, "b");
197 ud_asmprintf(u
, "w");
199 ud_asmprintf(u
, "q");
202 ud_asmprintf(u
, " *");
204 ud_asmprintf(u
, " ");
207 if (u
->operand
[2].type
!= UD_NONE
) {
208 gen_operand(u
, &u
->operand
[2]);
209 ud_asmprintf(u
, ", ");
212 if (u
->operand
[1].type
!= UD_NONE
) {
213 gen_operand(u
, &u
->operand
[1]);
214 ud_asmprintf(u
, ", ");
217 if (u
->operand
[0].type
!= UD_NONE
)
218 gen_operand(u
, &u
->operand
[0]);
222 vim: set ts=2 sw=2 expandtab