CACAO
disass.cpp
Go to the documentation of this file.
1 /* src/vm/jit/arm/disass.cpp - wrapper functions for GNU binutils disassembler
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 <stdio.h>
30 
31 #include "vm/types.hpp"
32 
33 #include "vm/global.hpp"
34 
35 #include "vm/jit/disass.hpp"
36 
37 
38 /* disass_pseudo_instr *********************************************************
39 
40  Outputs the disassembler listing of one pseudo instruction on
41  'stdout'. Trap instructions fall under this category.
42 
43  Returns true if the instruction really was a pseudo instruction
44 
45  code: pointer to machine code
46 
47 *******************************************************************************/
48 
49 static bool disass_pseudo_instr(u1 *code)
50 {
51  s4 mcode;
52 
53  mcode = *((s4 *) code);
54 
55  if ((mcode & 0x0ff000f0) == 0x07f000f0) {
56  printf("ill\t#%d, #%d (condition:0x%x) (pseudo)", ((mcode >> 8) & 0x0fff), ((mcode >> 0) & 0x0f), ((mcode >> 28) & 0x0f));
57  return true;
58  }
59  else
60  return false;
61 }
62 
63 
64 /* disassinstr *****************************************************************
65 
66  Outputs a disassembler listing of one machine code instruction on
67  'stdout'.
68 
69  code: pointer to instructions machine code
70 
71 *******************************************************************************/
72 
73 u1 *disassinstr(u1 *code)
74 {
75  if (!disass_initialized) {
76  INIT_DISASSEMBLE_INFO(info, stdout, disass_printf);
77 
78  /* setting the struct members must be done after
79  INIT_DISASSEMBLE_INFO */
80 
81  info.read_memory_func = &disass_buffer_read_memory;
82 
83  disass_initialized = true;
84  }
85 
86  printf("0x%08x: %08x ", (u4) code, *((s4 *) code));
87 
88  if (!disass_pseudo_instr(code))
89 #if defined(__ARMEL__)
90  print_insn_little_arm((bfd_vma) code, &info);
91 #else
92  print_insn_big_arm((bfd_vma) code, &info);
93 #endif
94 
95  printf("\n");
96 
97  /* 1 instruction is 4-bytes long */
98  return code + 4;
99 }
100 
101 
102 /*
103  * These are local overrides for various environment variables in Emacs.
104  * Please do not remove this and leave it at the end of the file, where
105  * Emacs will automagically detect them.
106  * ---------------------------------------------------------------------
107  * Local variables:
108  * mode: c++
109  * indent-tabs-mode: t
110  * c-basic-offset: 4
111  * tab-width: 4
112  * End:
113  */
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
static bool disass_pseudo_instr(u1 *code)
Definition: disass.cpp:49
uint8_t u1
Definition: types.hpp:40
int32_t s4
Definition: types.hpp:45
uint32_t u4
Definition: types.hpp:46
void disass_printf(PTR p, const char *fmt,...)
#define printf(...)
Definition: ssa2.cpp:40