CACAO
disass.cpp
Go to the documentation of this file.
1 /* src/vm/jit/alpha/disass.cpp - primitive disassembler for Alpha machine code
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 
28 #include <dis-asm.h>
29 #include <cstdio>
30 
31 #include "vm/types.hpp"
32 
33 #include "vm/global.hpp"
34 
35 #include "vm/jit/abi.hpp"
36 #include "vm/jit/disass.hpp"
37 
38 
39 /* disassinstr *****************************************************************
40 
41  Outputs a disassembler listing of one machine code instruction on
42  'stdout'.
43 
44  code: pointer to instructions machine code
45 
46 *******************************************************************************/
47 
48 u1 *disassinstr(u1 *code)
49 {
50  s4 seqlen;
51  s4 i;
52 
53  if (!disass_initialized) {
54  INIT_DISASSEMBLE_INFO(info, NULL, disass_printf);
55 
56  /* setting the struct members must be done after
57  * INIT_DISASSEMBLE_INFO */
58  info.mach = bfd_mach_aarch64;
59  info.read_memory_func = &disass_buffer_read_memory;
60 
61  disass_initialized = true;
62  }
63 
64  printf("0x%016lx: ", (s8) code);
65 
66  disass_len = 0;
67 
68  seqlen = print_insn_aarch64((bfd_vma) code, &info);
69 
70  for (i = 0; i < seqlen; i++, code++) {
71  printf("%02x ", *code);
72  }
73 
74  for (; i < 10; i++) {
75  printf(" ");
76  }
77 
78  printf(" %s\n", disass_buf);
79 
80  return code;
81 }
82 
83 
84 /*
85  * These are local overrides for various environment variables in Emacs.
86  * Please do not remove this and leave it at the end of the file, where
87  * Emacs will automagically detect them.
88  * ---------------------------------------------------------------------
89  * Local variables:
90  * mode: c++
91  * indent-tabs-mode: t
92  * c-basic-offset: 4
93  * tab-width: 4
94  * End:
95  */
int disass_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info)
u1 * disassinstr(u1 *code)
Definition: disass.cpp:48
uint8_t u1
Definition: types.hpp:40
int64_t s8
Definition: types.hpp:48
MIIterator i
int32_t s4
Definition: types.hpp:45
void disass_printf(PTR p, const char *fmt,...)
#define printf(...)
Definition: ssa2.cpp:40