gem5  v22.1.0.0
mem.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 The University of Edinburgh
3  * Copyright (c) 2021 IBM Corporation
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "arch/power/insts/mem.hh"
31 
32 #include "base/loader/symtab.hh"
33 
34 namespace gem5
35 {
36 
37 using namespace PowerISA;
38 
39 std::string
41 {
42  return csprintf("%-10s", mnemonic);
43 }
44 
45 
46 std::string
48  Addr pc, const loader::SymbolTable *symtab) const
49 {
50  std::stringstream ss;
51 
52  ccprintf(ss, "%-10s ", mnemonic);
53 
54  // Print the destination only for a load
55  if (!flags[IsStore]) {
56  if (_numDestRegs > 0) {
57 
58  // If the instruction updates the source register with the
59  // EA, then this source register is placed in position 0,
60  // therefore we print the last destination register.
62  }
63  }
64 
65  // Print the data register for a store
66  else {
67  if (_numSrcRegs > 0) {
68  printReg(ss, srcRegIdx(0));
69  }
70  }
71 
72  // Print the displacement
73  ss << ", " << d;
74  ss << "(";
75 
76  // Print the address register for a load
77  if (!flags[IsStore]) {
78  if (_numSrcRegs > 0) {
79  printReg(ss, srcRegIdx(0));
80  }
81 
82  // The address register is skipped if it is R0
83  else {
84  ss << "0";
85  }
86  }
87 
88  // Print the address register for a store
89  else {
90  if (_numSrcRegs > 1) {
91  printReg(ss, srcRegIdx(1));
92  }
93 
94  // The address register is skipped if it is R0
95  else {
96  ss << "0";
97  }
98  }
99 
100  ss << ")";
101 
102  return ss.str();
103 }
104 
105 
106 std::string
108  Addr pc, const loader::SymbolTable *symtab) const
109 {
110  std::stringstream ss;
111 
112  ccprintf(ss, "%-10s ", mnemonic);
113 
114  // Print the destination only for a load
115  if (!flags[IsStore]) {
116  if (_numDestRegs > 0) {
117 
118  // If the instruction updates the source register with the
119  // EA, then this source register is placed in position 0,
120  // therefore we print the last destination register.
122  }
123  }
124 
125  // Print the data register for a store
126  else {
127  if (_numSrcRegs > 0) {
128  printReg(ss, srcRegIdx(0));
129  }
130  }
131 
132  // Print the displacement
133  ss << ", " << (ds << 2);
134  ss << "(";
135 
136  // Print the address register for a load
137  if (!flags[IsStore]) {
138  if (_numSrcRegs > 0) {
139  printReg(ss, srcRegIdx(0));
140  }
141 
142  // The address register is skipped if it is R0
143  else {
144  ss << "0";
145  }
146  }
147 
148  // Print the address register for a store
149  else {
150  if (_numSrcRegs > 1) {
151  printReg(ss, srcRegIdx(1));
152  }
153 
154  // The address register is skipped if it is R0
155  else {
156  ss << "0";
157  }
158  }
159 
160  ss << ")";
161 
162  return ss.str();
163 }
164 
165 std::string
167  Addr pc, const loader::SymbolTable *symtab) const
168 {
169  std::stringstream ss;
170 
171  ccprintf(ss, "%-10s ", mnemonic);
172 
173  // Print the destination only for a load
174  if (!flags[IsStore]) {
175  if (_numDestRegs > 0) {
176 
177  // If the instruction updates the source register with the
178  // EA, then this source register is placed in position 0,
179  // therefore we print the last destination register.
181  }
182  }
183 
184  // Print the data register for a store
185  else {
186  if (_numSrcRegs > 0) {
187  printReg(ss, srcRegIdx(0));
188  }
189  }
190 
191  ss << ", ";
192 
193  // Print the address registers for a load
194  if (!flags[IsStore]) {
195  if (_numSrcRegs > 1) {
196  printReg(ss, srcRegIdx(0));
197  ss << ", ";
198  printReg(ss, srcRegIdx(1));
199  }
200 
201  // The first address register is skipped if it is R0
202  else if (_numSrcRegs > 0) {
203  ss << "0, ";
204  printReg(ss, srcRegIdx(0));
205  }
206  }
207 
208  // Print the address registers for a store
209  else {
210  if (_numSrcRegs > 2) {
211  printReg(ss, srcRegIdx(1));
212  ss << ", ";
213  printReg(ss, srcRegIdx(2));
214  }
215 
216  // The first address register is skipped if it is R0
217  else if (_numSrcRegs > 1) {
218  ss << "0, ";
219  printReg(ss, srcRegIdx(1));
220  }
221  }
222 
223  return ss.str();
224 }
225 
226 } // namespace gem5
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: mem.cc:47
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: mem.cc:107
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: mem.cc:166
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: mem.cc:40
void printReg(std::ostream &os, RegId reg) const
Print a register name for disassembly given the unique dependence tag number (FP or int).
Definition: static_inst.cc:40
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:225
uint8_t _numSrcRegs
See numSrcRegs().
Definition: static_inst.hh:109
uint8_t _numDestRegs
See numDestRegs().
Definition: static_inst.hh:112
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:259
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:215
std::bitset< Num_Flags > flags
Flag values for this instruction.
Definition: static_inst.hh:103
Bitfield< 4 > pc
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
std::stringstream ss
Definition: trace.test.cc:45

Generated on Wed Dec 21 2022 10:22:25 for gem5 by doxygen 1.9.1