gem5  v21.0.1.0
static_inst.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 The Hewlett-Packard Development Company
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __ARCH_X86_INSTS_STATICINST_HH__
39 #define __ARCH_X86_INSTS_STATICINST_HH__
40 
41 #include "base/trace.hh"
42 #include "cpu/static_inst.hh"
43 #include "debug/X86.hh"
44 
45 namespace X86ISA
46 {
47 
53 struct InstRegIndex : public RegId
54 {
55  explicit InstRegIndex(RegIndex _idx) :
56  RegId(computeRegClass(_idx), _idx) {}
57 
58  private:
59  // TODO: As X86 register index definition is highly built on the
60  // unified space concept, it is easier for the moment to rely on
61  // an helper function to compute the RegClass. It would be nice
62  // to fix those definition and get rid of this.
63  RegClass
65  {
66  if (_idx < FP_Reg_Base) {
67  return IntRegClass;
68  } else if (_idx < CC_Reg_Base) {
69  return FloatRegClass;
70  } else if (_idx < Misc_Reg_Base) {
71  return CCRegClass;
72  } else {
73  return MiscRegClass;
74  }
75  }
76 };
77 
82 class X86StaticInst : public StaticInst
83 {
84  protected:
86 
87  // Constructor.
88  X86StaticInst(const char *mnem,
89  ExtMachInst _machInst, OpClass __opClass)
90  : StaticInst(mnem, _machInst, __opClass)
91  {
92  }
93 
94  std::string generateDisassembly(
95  Addr pc, const Loader::SymbolTable *symtab) const override;
96 
97  void printMnemonic(std::ostream &os, const char * mnemonic) const;
98  void printMnemonic(std::ostream &os, const char * instMnemonic,
99  const char * mnemonic) const;
100 
101  void printSegment(std::ostream &os, int segment) const;
102 
103  void printReg(std::ostream &os, RegId reg, int size) const;
104  void printSrcReg(std::ostream &os, int reg, int size) const;
105  void printDestReg(std::ostream &os, int reg, int size) const;
106  void printMem(std::ostream &os, uint8_t segment,
107  uint8_t scale, RegIndex index, RegIndex base,
108  uint64_t disp, uint8_t addressSize, bool rip) const;
109 
110  inline uint64_t
111  merge(uint64_t into, uint64_t val, int size) const
112  {
113  X86IntReg reg = into;
114  if (destRegIdx(0).index() & IntFoldBit) {
115  reg.H = val;
116  return reg;
117  }
118  switch(size) {
119  case 1:
120  reg.L = val;
121  break;
122  case 2:
123  reg.X = val;
124  break;
125  case 4:
126  //XXX Check if this should be zeroed or sign extended
127  reg = 0;
128  reg.E = val;
129  break;
130  case 8:
131  reg.R = val;
132  break;
133  default:
134  panic("Tried to merge with unrecognized size %d.\n", size);
135  }
136  return reg;
137  }
138 
139  inline uint64_t
140  pick(uint64_t from, int idx, int size) const
141  {
142  X86IntReg reg = from;
143  DPRINTF(X86, "Picking with size %d\n", size);
144  if (srcRegIdx(idx).index() & IntFoldBit)
145  return reg.H;
146  switch(size) {
147  case 1:
148  return reg.L;
149  case 2:
150  return reg.X;
151  case 4:
152  return reg.E;
153  case 8:
154  return reg.R;
155  default:
156  panic("Tried to pick with unrecognized size %d.\n", size);
157  }
158  }
159 
160  inline int64_t
161  signedPick(uint64_t from, int idx, int size) const
162  {
163  X86IntReg reg = from;
164  DPRINTF(X86, "Picking with size %d\n", size);
165  if (srcRegIdx(idx).index() & IntFoldBit)
166  return reg.SH;
167  switch(size) {
168  case 1:
169  return reg.SL;
170  case 2:
171  return reg.SX;
172  case 4:
173  return reg.SE;
174  case 8:
175  return reg.SR;
176  default:
177  panic("Tried to pick with unrecognized size %d.\n", size);
178  }
179  }
180 
181  void
182  advancePC(PCState &pcState) const override
183  {
184  pcState.advance();
185  }
186 };
187 }
188 
189 #endif //__ARCH_X86_INSTS_STATICINST_HH__
X86ISA::IntFoldBit
static const IntRegIndex IntFoldBit
Definition: int.hh:151
X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:803
StaticInst::destRegIdx
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:234
StaticInst
Base, ISA-independent static instruction class.
Definition: static_inst.hh:85
X86ISA::X86StaticInst::merge
uint64_t merge(uint64_t into, uint64_t val, int size) const
Definition: static_inst.hh:111
Loader::SymbolTable
Definition: symtab.hh:58
X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:138
X86ISA::X86StaticInst::printDestReg
void printDestReg(std::ostream &os, int reg, int size) const
Definition: static_inst.cc:116
X86ISA::CC_Reg_Base
@ CC_Reg_Base
Definition: registers.hh:69
X86ISA::X86StaticInst::advancePC
void advancePC(PCState &pcState) const override
Definition: static_inst.hh:182
X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:88
X86ISA::scale
scale
Definition: types.hh:93
X86ISA::X86StaticInst::printReg
void printReg(std::ostream &os, RegId reg, int size) const
Definition: static_inst.cc:123
RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
X86ISA::FP_Reg_Base
@ FP_Reg_Base
Definition: registers.hh:68
X86ISA::InstRegIndex
Class for register indices passed to instruction constructors.
Definition: static_inst.hh:53
FloatRegClass
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:54
X86ISA::index
Bitfield< 5, 3 > index
Definition: types.hh:94
X86ISA::Misc_Reg_Base
@ Misc_Reg_Base
Definition: registers.hh:70
X86ISA::InstRegIndex::computeRegClass
RegClass computeRegClass(RegIndex _idx)
Definition: static_inst.hh:64
X86ISA::X86StaticInst::X86StaticInst
X86StaticInst(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
Definition: static_inst.hh:88
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
RegClass
RegClass
Enumerate the classes of registers.
Definition: reg_class.hh:52
X86ISA::X86StaticInst::printSegment
void printSegment(std::ostream &os, int segment) const
Definition: static_inst.cc:60
X86ISA::X86StaticInst::printMnemonic
void printMnemonic(std::ostream &os, const char *mnemonic) const
Definition: static_inst.cc:48
X86ISA::X86StaticInst::printMem
void printMem(std::ostream &os, uint8_t segment, uint8_t scale, RegIndex index, RegIndex base, uint64_t disp, uint8_t addressSize, bool rip) const
Definition: static_inst.cc:232
X86ISA::PCState
Definition: types.hh:286
StaticInst::mnemonic
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:284
X86ISA::ExtMachInst
Definition: types.hh:199
static_inst.hh
X86ISA::InstRegIndex::InstRegIndex
InstRegIndex(RegIndex _idx)
Definition: static_inst.hh:55
StaticInst::srcRegIdx
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:244
X86ISA::X86StaticInst::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: static_inst.cc:268
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
X86ISA
This is exposed globally, independent of the ISA.
Definition: acpi.hh:55
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
IntRegClass
@ IntRegClass
Integer register.
Definition: reg_class.hh:53
X86ISA::X86StaticInst
Base class for all X86 static instructions.
Definition: static_inst.hh:82
CCRegClass
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:60
X86ISA::PCState::advance
void advance()
Definition: types.hh:322
MiscRegClass
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:61
X86ISA::X86StaticInst::pick
uint64_t pick(uint64_t from, int idx, int size) const
Definition: static_inst.hh:140
RegIndex
uint16_t RegIndex
Definition: types.hh:52
X86ISA::X86StaticInst::printSrcReg
void printSrcReg(std::ostream &os, int reg, int size) const
Definition: static_inst.cc:109
trace.hh
X86ISA::pc
Bitfield< 19 > pc
Definition: misc.hh:805
X86ISA::X86StaticInst::signedPick
int64_t signedPick(uint64_t from, int idx, int size) const
Definition: static_inst.hh:161
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
MipsISA::ExtMachInst
uint64_t ExtMachInst
Definition: types.hh:39

Generated on Tue Jun 22 2021 15:28:20 for gem5 by doxygen 1.8.17