gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
misc.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, 2012-2013 ARM Limited
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are
17  * met: redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer;
19  * redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution;
22  * neither the name of the copyright holders nor the names of its
23  * contributors may be used to endorse or promote products derived from
24  * this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *
38  * Authors: Gabe Black
39  */
40 
41 #include "arch/arm/insts/misc.hh"
42 
43 #include "cpu/reg_class.hh"
44 
45 std::string
47 {
48  std::stringstream ss;
49  printMnemonic(ss);
50  printReg(ss, dest);
51  ss << ", ";
52  bool foundPsr = false;
53  for (unsigned i = 0; i < numSrcRegs(); i++) {
54  RegIndex idx = srcRegIdx(i);
55  RegIndex rel_idx;
56  if (regIdxToClass(idx, &rel_idx) != MiscRegClass) {
57  continue;
58  }
59  if (rel_idx == MISCREG_CPSR) {
60  ss << "cpsr";
61  foundPsr = true;
62  break;
63  }
64  if (rel_idx == MISCREG_SPSR) {
65  ss << "spsr";
66  foundPsr = true;
67  break;
68  }
69  }
70  if (!foundPsr) {
71  ss << "????";
72  }
73  return ss.str();
74 }
75 
76 void
77 MsrBase::printMsrBase(std::ostream &os) const
78 {
79  printMnemonic(os);
80  bool apsr = false;
81  bool foundPsr = false;
82  for (unsigned i = 0; i < numDestRegs(); i++) {
83  int idx = destRegIdx(i);
84  if (idx < Misc_Reg_Base) {
85  continue;
86  }
87  idx -= Misc_Reg_Base;
88  if (idx == MISCREG_CPSR) {
89  os << "cpsr_";
90  foundPsr = true;
91  break;
92  }
93  if (idx == MISCREG_SPSR) {
94  if (bits(byteMask, 1, 0)) {
95  os << "spsr_";
96  } else {
97  os << "apsr_";
98  apsr = true;
99  }
100  foundPsr = true;
101  break;
102  }
103  }
104  if (!foundPsr) {
105  os << "????";
106  return;
107  }
108  if (bits(byteMask, 3)) {
109  if (apsr) {
110  os << "nzcvq";
111  } else {
112  os << "f";
113  }
114  }
115  if (bits(byteMask, 2)) {
116  if (apsr) {
117  os << "g";
118  } else {
119  os << "s";
120  }
121  }
122  if (bits(byteMask, 1)) {
123  os << "x";
124  }
125  if (bits(byteMask, 0)) {
126  os << "c";
127  }
128 }
129 
130 std::string
132 {
133  std::stringstream ss;
134  printMsrBase(ss);
135  ccprintf(ss, ", #%#x", imm);
136  return ss.str();
137 }
138 
139 std::string
141 {
142  std::stringstream ss;
143  printMsrBase(ss);
144  ss << ", ";
145  printReg(ss, op1);
146  return ss.str();
147 }
148 
149 std::string
151 {
152  std::stringstream ss;
153  printMnemonic(ss);
154  printReg(ss, dest);
155  ss << ", ";
156  printReg(ss, dest2);
157  ss << ", ";
158  printReg(ss, op1);
159  return ss.str();
160 }
161 
162 std::string
164 {
165  std::stringstream ss;
166  printMnemonic(ss);
167  printReg(ss, dest);
168  ss << ", ";
169  printReg(ss, op1);
170  ss << ", ";
171  printReg(ss, op2);
172  return ss.str();
173 }
174 
175 std::string
177 {
178  std::stringstream ss;
179  printMnemonic(ss);
180  ccprintf(ss, "#%d", imm);
181  return ss.str();
182 }
183 
184 std::string
186 {
187  std::stringstream ss;
188  printMnemonic(ss);
189  printReg(ss, dest);
190  ccprintf(ss, ", #%d", imm);
191  return ss.str();
192 }
193 
194 std::string
196 {
197  std::stringstream ss;
198  printMnemonic(ss);
199  printReg(ss, dest);
200  ss << ", ";
201  printReg(ss, op1);
202  return ss.str();
203 }
204 
205 std::string
207 {
208  std::stringstream ss;
209  printMnemonic(ss);
210  printReg(ss, dest);
211  ss << ", ";
212  printReg(ss, op1);
213  ss << ", ";
214  printReg(ss, op2);
215  ccprintf(ss, ", #%d", imm);
216  return ss.str();
217 }
218 
219 std::string
221 {
222  std::stringstream ss;
223  printMnemonic(ss);
224  printReg(ss, dest);
225  ss << ", ";
226  printReg(ss, op1);
227  ss << ", ";
228  printReg(ss, op2);
229  ss << ", ";
230  printReg(ss, op3);
231  return ss.str();
232 }
233 
234 std::string
236 {
237  std::stringstream ss;
238  printMnemonic(ss);
239  printReg(ss, dest);
240  ss << ", ";
241  printReg(ss, op1);
242  ss << ", ";
243  printReg(ss, op2);
244  return ss.str();
245 }
246 
247 std::string
249 {
250  std::stringstream ss;
251  printMnemonic(ss);
252  printReg(ss, dest);
253  ss << ", ";
254  printReg(ss, op1);
255  ccprintf(ss, ", #%d", imm);
256  return ss.str();
257 }
258 
259 std::string
261 {
262  std::stringstream ss;
263  printMnemonic(ss);
264  printReg(ss, dest);
265  ss << ", ";
266  printReg(ss, op1);
267  ccprintf(ss, ", #%d", imm);
268  return ss.str();
269 }
270 
271 std::string
273 {
274  std::stringstream ss;
275  printMnemonic(ss);
276  printReg(ss, dest);
277  ss << ", ";
278  printReg(ss, op1);
279  ccprintf(ss, ", #%d", imm);
280  return ss.str();
281 }
282 
283 std::string
285 {
286  std::stringstream ss;
287  printMnemonic(ss);
288  printReg(ss, dest);
289  ccprintf(ss, ", #%d, #%d", imm1, imm2);
290  return ss.str();
291 }
292 
293 std::string
295 {
296  std::stringstream ss;
297  printMnemonic(ss);
298  printReg(ss, dest);
299  ss << ", ";
300  printReg(ss, op1);
301  ccprintf(ss, ", #%d, #%d", imm1, imm2);
302  return ss.str();
303 }
304 
305 std::string
307 {
308  std::stringstream ss;
309  printMnemonic(ss);
310  printReg(ss, dest);
311  ccprintf(ss, ", #%d, ", imm);
312  printReg(ss, op1);
313  return ss.str();
314 }
315 
316 std::string
318 {
319  std::stringstream ss;
320  printMnemonic(ss);
321  printReg(ss, dest);
322  ccprintf(ss, ", #%d, ", imm);
324  printReg(ss, op1);
325  return ss.str();
326 }
327 
328 std::string
330 {
331  return csprintf("%-10s (inst %#08x)", "unknown", machInst);
332 }
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
void printMsrBase(std::ostream &os) const
Definition: misc.cc:77
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:329
IntRegIndex op1
Definition: misc.hh:332
uint64_t imm
Definition: misc.hh:331
IntRegIndex op1
Definition: misc.hh:246
IntRegIndex op2
Definition: misc.hh:213
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:46
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:206
Bitfield< 7 > i
Definition: miscregs.hh:1378
void printShiftOperand(std::ostream &os, IntRegIndex rm, bool immShift, uint32_t shiftAmt, IntRegIndex rs, ArmShiftType type) const
Definition: static_inst.cc:464
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:176
IntRegIndex dest
Definition: misc.hh:211
IntRegIndex dest2
Definition: misc.hh:102
IntRegIndex op1
Definition: misc.hh:118
uint64_t imm2
Definition: misc.hh:315
IntRegIndex dest
Definition: misc.hh:101
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:317
Control (misc) register.
Definition: reg_class.hh:45
uint64_t imm2
Definition: misc.hh:298
void printMnemonic(std::ostream &os, const std::string &suffix="", bool withPred=true, bool withCond64=false, ConditionCode cond64=COND_UC) const
Definition: static_inst.cc:345
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:306
void printReg(std::ostream &os, int reg) const
Print a register name for disassembly given the unique dependence tag number (FP or int)...
Definition: static_inst.cc:296
IntRegIndex op2
Definition: misc.hh:195
RegIndex destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:188
IntRegIndex dest
Definition: misc.hh:229
uint32_t imm
Definition: misc.hh:74
TheISA::RegIndex RegIndex
Logical register index type.
Definition: static_inst.hh:74
IntRegIndex op1
Definition: misc.hh:230
IntRegIndex dest
Definition: misc.hh:163
Bitfield< 17 > os
Definition: misc.hh:804
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:140
IntRegIndex dest
Definition: misc.hh:296
IntRegIndex dest
Definition: misc.hh:48
IntRegIndex op1
Definition: misc.hh:179
const ExtMachInst machInst
The binary machine instruction.
Definition: static_inst.hh:218
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:235
MiscRegIndex op1
Definition: misc.hh:280
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
IntRegIndex op1
Definition: misc.hh:313
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:284
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:150
uint64_t imm
Definition: misc.hh:247
IntRegIndex op1
Definition: misc.hh:212
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:220
IntRegIndex dest
Definition: misc.hh:330
IntRegIndex dest
Definition: misc.hh:193
IntRegIndex op1
Definition: misc.hh:87
uint64_t imm
Definition: misc.hh:178
IntRegIndex dest
Definition: misc.hh:149
MiscRegIndex dest
Definition: misc.hh:120
uint64_t imm1
Definition: misc.hh:314
Bitfield< 21 > ss
Definition: miscregs.hh:1371
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:248
IntRegIndex op1
Definition: misc.hh:164
uint64_t imm
Definition: misc.hh:281
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:272
uint64_t imm
Definition: misc.hh:150
RegIndex srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:192
IntRegIndex op2
Definition: misc.hh:231
int8_t numSrcRegs() const
Number of source registers.
Definition: static_inst.hh:112
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:185
IntRegIndex op1
Definition: misc.hh:194
uint64_t imm
Definition: misc.hh:136
IntRegIndex op3
Definition: misc.hh:214
uint8_t byteMask
Definition: misc.hh:61
uint64_t imm1
Definition: misc.hh:297
IntRegIndex dest
Definition: misc.hh:177
MiscRegIndex op1
Definition: misc.hh:100
IntRegIndex dest
Definition: misc.hh:245
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:131
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:163
MiscRegIndex dest
Definition: misc.hh:262
IntRegIndex dest
Definition: misc.hh:279
IntRegIndex dest
Definition: misc.hh:312
IntReg pc
Definition: remote_gdb.hh:91
int32_t shiftAmt
Definition: misc.hh:333
ArmShiftType shiftType
Definition: misc.hh:334
RegClass regIdxToClass(TheISA::RegIndex reg_idx, TheISA::RegIndex *rel_reg_idx=NULL)
Map a 'unified' architectural register index to its register class.
Definition: reg_class.hh:66
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:260
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:195
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
Definition: bitfield.hh:67
uint64_t imm
Definition: misc.hh:196
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: misc.cc:294
uint64_t imm
Definition: misc.hh:264
IntRegIndex op1
Definition: misc.hh:263
int8_t numDestRegs() const
Number of destination registers.
Definition: static_inst.hh:114
IntRegIndex op2
Definition: misc.hh:119

Generated on Fri Jun 9 2017 13:03:38 for gem5 by doxygen 1.8.6