gem5  v21.1.0.2
static_inst.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 The Hewlett-Packard Development Company
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 
40 
41 #include "arch/x86/regs/segment.hh"
42 #include "cpu/reg_class.hh"
43 
44 namespace gem5
45 {
46 
47 namespace X86ISA
48 {
49 
50 void
51 X86StaticInst::printMnemonic(std::ostream &os, const char *mnemonic)
52 {
53  ccprintf(os, " %s ", mnemonic);
54 }
55 
56 void
57 X86StaticInst::printMnemonic(std::ostream &os, const char *instMnemonic,
58  const char *mnemonic)
59 {
60  ccprintf(os, " %s : %s ", instMnemonic, mnemonic);
61 }
62 
63 void X86StaticInst::printSegment(std::ostream &os, int segment)
64 {
65  switch (segment)
66  {
67  case SEGMENT_REG_ES:
68  ccprintf(os, "ES");
69  break;
70  case SEGMENT_REG_CS:
71  ccprintf(os, "CS");
72  break;
73  case SEGMENT_REG_SS:
74  ccprintf(os, "SS");
75  break;
76  case SEGMENT_REG_DS:
77  ccprintf(os, "DS");
78  break;
79  case SEGMENT_REG_FS:
80  ccprintf(os, "FS");
81  break;
82  case SEGMENT_REG_GS:
83  ccprintf(os, "GS");
84  break;
85  case SEGMENT_REG_HS:
86  ccprintf(os, "HS");
87  break;
88  case SEGMENT_REG_TSL:
89  ccprintf(os, "TSL");
90  break;
91  case SEGMENT_REG_TSG:
92  ccprintf(os, "TSG");
93  break;
94  case SEGMENT_REG_LS:
95  ccprintf(os, "LS");
96  break;
97  case SEGMENT_REG_MS:
98  ccprintf(os, "MS");
99  break;
100  case SYS_SEGMENT_REG_TR:
101  ccprintf(os, "TR");
102  break;
104  ccprintf(os, "IDTR");
105  break;
106  default:
107  panic("Unrecognized segment %d\n", segment);
108  }
109 }
110 
111 void
112 X86StaticInst::divideStep(uint64_t dividend, uint64_t divisor,
113  uint64_t &quotient, uint64_t &remainder)
114 {
115  // Check for divide by zero.
116  assert(divisor != 0);
117  // If the divisor is bigger than the dividend, don't do anything.
118  if (divisor <= dividend) {
119  // Shift the divisor so it's msb lines up with the dividend.
120  int dividendMsb = findMsbSet(dividend);
121  int divisorMsb = findMsbSet(divisor);
122  int shift = dividendMsb - divisorMsb;
123  divisor <<= shift;
124  // Compute what we'll add to the quotient if the divisor isn't
125  // now larger than the dividend.
126  uint64_t quotientBit = 1;
127  quotientBit <<= shift;
128  // If we need to step back a bit (no pun intended) because the
129  // divisor got too to large, do that here. This is the "or two"
130  // part of one or two bit division.
131  if (divisor > dividend) {
132  quotientBit >>= 1;
133  divisor >>= 1;
134  }
135  // Decrement the remainder and increment the quotient.
136  quotient += quotientBit;
137  remainder -= divisor;
138  }
139 }
140 
141 void
142 X86StaticInst::printReg(std::ostream &os, RegId reg, int size)
143 {
144  assert(size == 1 || size == 2 || size == 4 || size == 8);
145  static const char * abcdFormats[9] =
146  {"", "%s", "%sx", "", "e%sx", "", "", "", "r%sx"};
147  static const char * piFormats[9] =
148  {"", "%s", "%s", "", "e%s", "", "", "", "r%s"};
149  static const char * longFormats[9] =
150  {"", "r%sb", "r%sw", "", "r%sd", "", "", "", "r%s"};
151  static const char * microFormats[9] =
152  {"", "t%db", "t%dw", "", "t%dd", "", "", "", "t%d"};
153 
154  RegIndex reg_idx = reg.index();
155 
156  switch (reg.classValue()) {
157  case IntRegClass:
158  {
159  const char * suffix = "";
160  bool fold = reg_idx & IntFoldBit;
161  reg_idx &= ~IntFoldBit;
162 
163  if (fold)
164  suffix = "h";
165  else if (reg_idx < 8 && size == 1)
166  suffix = "l";
167 
168  switch (reg_idx) {
169  case INTREG_RAX:
170  ccprintf(os, abcdFormats[size], "a");
171  break;
172  case INTREG_RBX:
173  ccprintf(os, abcdFormats[size], "b");
174  break;
175  case INTREG_RCX:
176  ccprintf(os, abcdFormats[size], "c");
177  break;
178  case INTREG_RDX:
179  ccprintf(os, abcdFormats[size], "d");
180  break;
181  case INTREG_RSP:
182  ccprintf(os, piFormats[size], "sp");
183  break;
184  case INTREG_RBP:
185  ccprintf(os, piFormats[size], "bp");
186  break;
187  case INTREG_RSI:
188  ccprintf(os, piFormats[size], "si");
189  break;
190  case INTREG_RDI:
191  ccprintf(os, piFormats[size], "di");
192  break;
193  case INTREG_R8W:
194  ccprintf(os, longFormats[size], "8");
195  break;
196  case INTREG_R9W:
197  ccprintf(os, longFormats[size], "9");
198  break;
199  case INTREG_R10W:
200  ccprintf(os, longFormats[size], "10");
201  break;
202  case INTREG_R11W:
203  ccprintf(os, longFormats[size], "11");
204  break;
205  case INTREG_R12W:
206  ccprintf(os, longFormats[size], "12");
207  break;
208  case INTREG_R13W:
209  ccprintf(os, longFormats[size], "13");
210  break;
211  case INTREG_R14W:
212  ccprintf(os, longFormats[size], "14");
213  break;
214  case INTREG_R15W:
215  ccprintf(os, longFormats[size], "15");
216  break;
217  default:
218  ccprintf(os, microFormats[size], reg_idx - INTREG_MICRO_BEGIN);
219  }
220  ccprintf(os, suffix);
221  }
222  break;
223  case FloatRegClass:
224  if (reg_idx < NumMMXRegs) {
225  ccprintf(os, "%%mmx%d", reg_idx);
226  return;
227  }
228  reg_idx -= NumMMXRegs;
229  if (reg_idx < NumXMMRegs * 2) {
230  ccprintf(os, "%%xmm%d_%s", reg_idx / 2,
231  (reg_idx % 2) ? "high": "low");
232  return;
233  }
234  reg_idx -= NumXMMRegs * 2;
235  if (reg_idx < NumMicroFpRegs) {
236  ccprintf(os, "%%ufp%d", reg_idx);
237  return;
238  }
239  reg_idx -= NumMicroFpRegs;
240  ccprintf(os, "%%st(%d)", reg_idx);
241  break;
242  case CCRegClass:
243  ccprintf(os, "%%cc%d", reg_idx);
244  break;
245  case MiscRegClass:
246  switch (reg_idx) {
247  default:
248  ccprintf(os, "%%ctrl%d", reg_idx);
249  }
250  break;
251  default:
252  panic("Unrecognized register class.");
253  }
254 }
255 
256 void
257 X86StaticInst::printMem(std::ostream &os, uint8_t segment,
258  uint8_t scale, RegIndex index, RegIndex base,
259  uint64_t disp, uint8_t addressSize, bool rip)
260 {
261  bool someAddr = false;
262  printSegment(os, segment);
263  os << ":[";
264  if (rip) {
265  os << "rip";
266  someAddr = true;
267  } else {
268  if (scale != 0 && index != NUM_INTREGS) {
269  if (scale != 1)
270  ccprintf(os, "%d*", scale);
271  printReg(os, RegId(IntRegClass, index), addressSize);
272  someAddr = true;
273  }
274  if (base != NUM_INTREGS) {
275  if (someAddr)
276  os << " + ";
277  printReg(os, RegId(IntRegClass, base), addressSize);
278  someAddr = true;
279  }
280  }
281  if (disp != 0) {
282  if (someAddr)
283  os << " + ";
284  ccprintf(os, "%#x", disp);
285  someAddr = true;
286  }
287  if (!someAddr)
288  os << "0";
289  os << "]";
290 }
291 
292 std::string
294  Addr pc, const loader::SymbolTable *symtab) const
295 {
296  std::stringstream ss;
297 
299 
300  return ss.str();
301 }
302 
303 } // namespace X86ISA
304 } // namespace gem5
gem5::X86ISA::pc
Bitfield< 19 > pc
Definition: misc.hh:811
gem5::X86ISA::SEGMENT_REG_ES
@ SEGMENT_REG_ES
Definition: segment.hh:48
gem5::CCRegClass
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:64
static_inst.hh
gem5::X86ISA::X86StaticInst::divideStep
static void divideStep(uint64_t divident, uint64_t divisor, uint64_t &quotient, uint64_t &remainder)
Definition: static_inst.cc:112
gem5::X86ISA::scale
scale
Definition: types.hh:97
gem5::FloatRegClass
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:58
gem5::X86ISA::SYS_SEGMENT_REG_TR
@ SYS_SEGMENT_REG_TR
Definition: segment.hh:62
gem5::MiscRegClass
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:65
gem5::X86ISA::X86StaticInst::printMem
static void printMem(std::ostream &os, uint8_t segment, uint8_t scale, RegIndex index, RegIndex base, uint64_t disp, uint8_t addressSize, bool rip)
Definition: static_inst.cc:257
gem5::loader::SymbolTable
Definition: symtab.hh:65
gem5::X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
sc_dt::remainder
return remainder
Definition: scfx_rep.cc:2201
gem5::X86ISA::SEGMENT_REG_MS
@ SEGMENT_REG_MS
Definition: segment.hh:58
gem5::X86ISA::SEGMENT_REG_CS
@ SEGMENT_REG_CS
Definition: segment.hh:49
gem5::ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
gem5::ArmISA::shift
Bitfield< 6, 5 > shift
Definition: types.hh:117
gem5::X86ISA::SEGMENT_REG_TSG
@ SEGMENT_REG_TSG
Definition: segment.hh:56
gem5::X86ISA::SEGMENT_REG_GS
@ SEGMENT_REG_GS
Definition: segment.hh:53
gem5::X86ISA::SEGMENT_REG_TSL
@ SEGMENT_REG_TSL
Definition: segment.hh:55
segment.hh
gem5::X86ISA::NumXMMRegs
const int NumXMMRegs
Definition: x86_traits.hh:53
gem5::X86ISA::NumMMXRegs
const int NumMMXRegs
Definition: x86_traits.hh:52
gem5::X86ISA::SEGMENT_REG_DS
@ SEGMENT_REG_DS
Definition: segment.hh:51
gem5::X86ISA::SEGMENT_REG_SS
@ SEGMENT_REG_SS
Definition: segment.hh:50
ss
std::stringstream ss
Definition: trace.test.cc:45
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::X86ISA::SYS_SEGMENT_REG_IDTR
@ SYS_SEGMENT_REG_IDTR
Definition: segment.hh:63
gem5::X86ISA::X86StaticInst::printReg
static void printReg(std::ostream &os, RegId reg, int size)
Definition: static_inst.cc:142
gem5::X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:92
gem5::X86ISA::SEGMENT_REG_FS
@ SEGMENT_REG_FS
Definition: segment.hh:52
gem5::X86ISA::X86StaticInst::printSegment
static void printSegment(std::ostream &os, int segment)
Definition: static_inst.cc:63
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:809
gem5::X86ISA::index
Bitfield< 5, 3 > index
Definition: types.hh:98
gem5::X86ISA::X86StaticInst::generateDisassembly
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: static_inst.cc:293
reg_class.hh
gem5::findMsbSet
constexpr int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition: bitfield.hh:263
gem5::RegIndex
uint16_t RegIndex
Definition: types.hh:176
gem5::StaticInst::mnemonic
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:281
gem5::IntRegClass
@ IntRegClass
Integer register.
Definition: reg_class.hh:57
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::X86ISA::SEGMENT_REG_HS
@ SEGMENT_REG_HS
Definition: segment.hh:54
gem5::X86ISA::IntFoldBit
static const IntRegIndex IntFoldBit
Definition: int.hh:172
gem5::RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:88
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::X86ISA::X86StaticInst::printMnemonic
static void printMnemonic(std::ostream &os, const char *mnemonic)
Definition: static_inst.cc:51
gem5::X86ISA::NumMicroFpRegs
const int NumMicroFpRegs
Definition: x86_traits.hh:54
gem5::X86ISA::SEGMENT_REG_LS
@ SEGMENT_REG_LS
Definition: segment.hh:57

Generated on Tue Sep 21 2021 12:24:35 for gem5 by doxygen 1.8.17