]>
git.saurik.com Git - apple/javascriptcore.git/blob - disassembler/udis86/udis86_syn-att.c
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.
30 #include "udis86_types.h"
31 #include "udis86_extern.h"
32 #include "udis86_decode.h"
33 #include "udis86_itab.h"
34 #include "udis86_syn.h"
36 /* -----------------------------------------------------------------------------
37 * opr_cast() - Prints an operand cast.
38 * -----------------------------------------------------------------------------
41 opr_cast(struct ud
* u
, struct ud_operand
* op
)
50 /* -----------------------------------------------------------------------------
51 * gen_operand() - Generates assembly output for each operand.
52 * -----------------------------------------------------------------------------
55 gen_operand(struct ud
* u
, struct ud_operand
* op
)
59 mkasm(u
, "%%%s", ud_reg_tab
[op
->base
- UD_R_AL
]);
63 if (u
->br_far
) opr_cast(u
, op
);
65 mkasm(u
, "%%%s:", ud_reg_tab
[u
->pfx_seg
- UD_R_AL
]);
66 if (op
->offset
== 8) {
67 if (op
->lval
.sbyte
< 0)
68 mkasm(u
, "-0x%x", (-op
->lval
.sbyte
) & 0xff);
70 mkasm(u
, "0x%x", op
->lval
.sbyte
);
72 else if (op
->offset
== 16) {
73 if (op
->lval
.sword
< 0)
74 mkasm(u
, "-0x%x", (-op
->lval
.sword
) & 0xffff);
76 mkasm(u
, "0x%x", op
->lval
.sword
);
77 } else if (op
->offset
== 32) {
78 if (op
->lval
.sdword
< 0)
79 mkasm(u
, "-0x%x", (-op
->lval
.sdword
) & 0xffffffff);
81 mkasm(u
, "0x%x", op
->lval
.sdword
);
82 } else if (op
->offset
== 64) {
83 if (op
->lval
.sdword
< 0)
84 mkasm(u
, "-0x" FMT64
"x", (uint64_t)-op
->lval
.sqword
);
86 mkasm(u
, "0x" FMT64
"x", (uint64_t)op
->lval
.sqword
);
90 mkasm(u
, "(%%%s", ud_reg_tab
[op
->base
- UD_R_AL
]);
95 mkasm(u
, "%%%s", ud_reg_tab
[op
->index
- UD_R_AL
]);
98 mkasm(u
, ",%d", op
->scale
);
99 if (op
->base
|| op
->index
)
105 uint64_t sext_mask
= 0xffffffffffffffffull
;
106 unsigned sext_size
= op
->size
;
109 case 8: imm
= op
->lval
.sbyte
; break;
110 case 16: imm
= op
->lval
.sword
; break;
111 case 32: imm
= op
->lval
.sdword
; break;
112 case 64: imm
= op
->lval
.sqword
; break;
114 if ( P_SEXT( u
->itab_entry
->prefix
) ) {
115 sext_size
= u
->operand
[ 0 ].size
;
116 if ( u
->mnemonic
== UD_Ipush
)
117 /* push sign-extends to operand size */
118 sext_size
= u
->opr_mode
;
120 if ( sext_size
< 64 )
121 sext_mask
= ( 1ull << sext_size
) - 1;
122 mkasm( u
, "$0x" FMT64
"x", (uint64_t)(imm
& sext_mask
) );
130 mkasm(u
, "0x" FMT64
"x", (uint64_t)(u
->pc
+ op
->lval
.sbyte
));
133 mkasm(u
, "0x" FMT64
"x", (uint64_t)((u
->pc
+ op
->lval
.sword
) & 0xffff) );
136 if (u
->dis_mode
== 32)
137 mkasm(u
, "0x" FMT64
"x", (uint64_t)((u
->pc
+ op
->lval
.sdword
) & 0xffffffff));
139 mkasm(u
, "0x" FMT64
"x", (uint64_t)(u
->pc
+ op
->lval
.sdword
));
148 mkasm(u
, "$0x%x, $0x%x", op
->lval
.ptr
.seg
,
149 op
->lval
.ptr
.off
& 0xFFFF);
152 mkasm(u
, "$0x%x, $0x%lx", op
->lval
.ptr
.seg
,
153 (unsigned long)op
->lval
.ptr
.off
);
162 /* =============================================================================
163 * translates to AT&T syntax
164 * =============================================================================
167 ud_translate_att(struct ud
*u
)
171 /* check if P_OSO prefix is used */
172 if (! P_OSO(u
->itab_entry
->prefix
) && u
->pfx_opr
) {
173 switch (u
->dis_mode
) {
184 /* check if P_ASO prefix was used */
185 if (! P_ASO(u
->itab_entry
->prefix
) && u
->pfx_adr
) {
186 switch (u
->dis_mode
) {
206 /* special instructions */
207 switch (u
->mnemonic
) {
212 mkasm(u
, ".byte 0x%x", u
->operand
[0].lval
.ubyte
);
216 if (u
->br_far
) mkasm(u
, "l");
217 mkasm(u
, "%s", ud_lookup_mnemonic(u
->mnemonic
));
221 if (u
->operand
[0].type
!= UD_NONE
)
222 gen_operand(u
, &u
->operand
[0]);
223 if (u
->operand
[1].type
!= UD_NONE
) {
225 gen_operand(u
, &u
->operand
[1]);
229 mkasm(u
, "%s", ud_lookup_mnemonic(u
->mnemonic
));
233 size
= u
->operand
[0].size
;
235 size
= u
->operand
[1].size
;
237 size
= u
->operand
[2].size
;
248 if (u
->operand
[2].type
!= UD_NONE
) {
249 gen_operand(u
, &u
->operand
[2]);
253 if (u
->operand
[1].type
!= UD_NONE
) {
254 gen_operand(u
, &u
->operand
[1]);
258 if (u
->operand
[0].type
!= UD_NONE
)
259 gen_operand(u
, &u
->operand
[0]);
262 #endif // USE(UDIS86)