1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
33 #include "util/u_math.h"
34 #include "util/u_debug.h"
35 #include "lp_bld_debug.h"
41 * It is important that this check is not implemented as a macro or inlined
42 * function, as the compiler assumptions in respect to alignment of global
43 * and stack variables would often make the check a no op, defeating the
44 * whole purpose of the exercise.
47 lp_check_alignment(const void *ptr
, unsigned alignment
)
49 assert(util_is_pot(alignment
));
50 return ((uintptr_t)ptr
& (alignment
- 1)) == 0;
55 lp_disassemble(const void* func
)
63 ud_set_input_buffer(&ud_obj
, (void*)func
, 0xffff);
65 max_jmp_pc
= (uint64_t) (uintptr_t) func
;
66 ud_set_pc(&ud_obj
, max_jmp_pc
);
69 ud_set_mode(&ud_obj
, 32);
71 #ifdef PIPE_ARCH_X86_64
72 ud_set_mode(&ud_obj
, 64);
75 ud_set_syntax(&ud_obj
, UD_SYN_ATT
);
77 while (ud_disassemble(&ud_obj
)) {
80 debug_printf("%08lx: ", (unsigned long)ud_insn_off(&ud_obj
));
82 #ifdef PIPE_ARCH_X86_64
83 debug_printf("%016llx: ", (unsigned long long)ud_insn_off(&ud_obj
));
87 debug_printf("%-16s ", ud_insn_hex(&ud_obj
));
90 debug_printf("%s\n", ud_insn_asm(&ud_obj
));
92 if(ud_obj
.mnemonic
!= UD_Icall
) {
94 for(i
= 0; i
< 3; ++i
) {
95 const struct ud_operand
*op
= &ud_obj
.operand
[i
];
96 if (op
->type
== UD_OP_JIMM
){
97 uint64_t pc
= ud_obj
.pc
;
101 pc
+= op
->lval
.sbyte
;
104 pc
+= op
->lval
.sword
;
107 pc
+= op
->lval
.sdword
;
118 if (ud_insn_off(&ud_obj
) >= max_jmp_pc
&& ud_obj
.mnemonic
== UD_Iret
)