gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
utility.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 ARM Limited
3  * Copyright (c) 2014-2015 Sven Karlsson
4  * Copyright (c) 2018 TU Dresden
5  * Copyright (c) 2020 Barkhausen Institut
6  * All rights reserved
7  *
8  * The license below extends only to copyright in the software and shall
9  * not be construed as granting a license to any other intellectual
10  * property including but not limited to intellectual property relating
11  * to a hardware implementation of the functionality of the software
12  * licensed hereunder. You may use the software subject to the license
13  * terms below provided that you ensure that this notice is replicated
14  * unmodified and in its entirety in all distributions of the software,
15  * modified or unmodified, in source code or in binary form.
16  *
17  * Copyright (c) 2016-2017 The University of Virginia
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions are
22  * met: redistributions of source code must retain the above copyright
23  * notice, this list of conditions and the following disclaimer;
24  * redistributions in binary form must reproduce the above copyright
25  * notice, this list of conditions and the following disclaimer in the
26  * documentation and/or other materials provided with the distribution;
27  * neither the name of the copyright holders nor the names of its
28  * contributors may be used to endorse or promote products derived from
29  * this software without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  */
43 
44 #ifndef __ARCH_RISCV_UTILITY_HH__
45 #define __ARCH_RISCV_UTILITY_HH__
46 
47 #include <cmath>
48 #include <cstdint>
49 #include <sstream>
50 #include <string>
51 
52 #include "arch/riscv/registers.hh"
53 #include "base/types.hh"
54 #include "cpu/reg_class.hh"
55 #include "cpu/static_inst.hh"
56 #include "cpu/thread_context.hh"
57 
58 namespace RiscvISA
59 {
60 
61 template<typename T> inline bool
63 {
64  return false;
65 }
66 
67 template<> inline bool
69 {
70  return std::isnan(val)
71  && (reinterpret_cast<uint32_t&>(val)&0x00400000);
72 }
73 
74 template<> inline bool
76 {
77  return std::isnan(val)
78  && (reinterpret_cast<uint64_t&>(val)&0x0008000000000000ULL);
79 }
80 
81 template<typename T> inline bool
83 {
84  return false;
85 }
86 
87 template<> inline bool
89 {
90  return std::isnan(val)
91  && (reinterpret_cast<uint32_t&>(val)&0x00200000);
92 }
93 
94 template<> inline bool
96 {
97  return std::isnan(val)
98  && (reinterpret_cast<uint64_t&>(val)&0x0004000000000000ULL);
99 }
100 
101 inline PCState
102 buildRetPC(const PCState &curPC, const PCState &callPC)
103 {
104  PCState retPC = callPC;
105  retPC.advance();
106  retPC.pc(curPC.npc());
107  return retPC;
108 }
109 
110 inline void
112 {
113  // First loop through the integer registers.
114  for (int i = 0; i < NumIntRegs; ++i)
115  dest->setIntReg(i, src->readIntReg(i));
116 
117  // Second loop through the float registers.
118  for (int i = 0; i < NumFloatRegs; ++i)
119  dest->setFloatReg(i, src->readFloatReg(i));
120 
121  // Lastly copy PC/NPC
122  dest->pcState(src->pcState());
123 }
124 
125 inline std::string
127 {
128  if (reg.isIntReg()) {
129  if (reg.index() >= NumIntArchRegs) {
130  /*
131  * This should only happen if a instruction is being speculatively
132  * executed along a not-taken branch, and if that instruction's
133  * width was incorrectly predecoded (i.e., it was predecoded as a
134  * full instruction rather than a compressed one or vice versa).
135  * It also should only happen if a debug flag is on that prints
136  * disassembly information, so rather than panic the incorrect
137  * value is printed for debugging help.
138  */
139  std::stringstream str;
140  str << "?? (x" << reg.index() << ')';
141  return str.str();
142  }
143  return IntRegNames[reg.index()];
144  } else {
145  if (reg.index() >= NumFloatRegs) {
146  std::stringstream str;
147  str << "?? (f" << reg.index() << ')';
148  return str.str();
149  }
150  return FloatRegNames[reg.index()];
151  }
152 }
153 
154 inline void
156 {
157  inst->advancePC(pc);
158 }
159 
160 } // namespace RiscvISA
161 
162 #endif // __ARCH_RISCV_UTILITY_HH__
RiscvISA::PCState
Definition: types.hh:53
GenericISA::SimplePCState::advance
void advance()
Definition: types.hh:188
StaticInst::advancePC
virtual void advancePC(TheISA::PCState &pcState) const =0
RiscvISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
RiscvISA::NumIntRegs
const int NumIntRegs
Definition: registers.hh:111
ThreadContext::setIntReg
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
RiscvISA::issignalingnan< float >
bool issignalingnan< float >(float val)
Definition: utility.hh:88
RiscvISA::isquietnan< float >
bool isquietnan< float >(float val)
Definition: utility.hh:68
RiscvISA::FloatRegNames
const std::vector< std::string > FloatRegNames
Definition: registers.hh:142
RiscvISA::copyRegs
void copyRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.hh:111
X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:88
RiscvISA
Definition: fs_workload.cc:36
RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
GenericISA::SimplePCState::npc
Addr npc() const
Definition: types.hh:161
ThreadContext::readFloatReg
virtual RegVal readFloatReg(RegIndex reg_idx) const =0
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
RiscvISA::IntRegNames
const std::vector< std::string > IntRegNames
Definition: registers.hh:132
static_inst.hh
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
RiscvISA::NumIntArchRegs
const int NumIntArchRegs
Definition: registers.hh:109
RiscvISA::issignalingnan
bool issignalingnan(T val)
Definition: utility.hh:82
RiscvISA::issignalingnan< double >
bool issignalingnan< double >(double val)
Definition: utility.hh:95
registers.hh
ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
RiscvISA::i
Bitfield< 2 > i
Definition: pra_constants.hh:276
RiscvISA::isquietnan
bool isquietnan(T val)
Definition: utility.hh:62
ThreadContext::setFloatReg
virtual void setFloatReg(RegIndex reg_idx, RegVal val)=0
MipsISA::PCState
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
types.hh
RiscvISA::isquietnan< double >
bool isquietnan< double >(double val)
Definition: utility.hh:75
reg_class.hh
GenericISA::SimplePCState::pc
Addr pc() const
Definition: types.hh:158
RiscvISA::registerName
std::string registerName(RegId reg)
Definition: utility.hh:126
RiscvISA::buildRetPC
PCState buildRetPC(const PCState &curPC, const PCState &callPC)
Definition: utility.hh:102
RiscvISA::NumFloatRegs
const int NumFloatRegs
Definition: registers.hh:112
RefCountingPtr< StaticInst >
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
RiscvISA::advancePC
void advancePC(PCState &pc, const StaticInstPtr &inst)
Definition: utility.hh:155
thread_context.hh

Generated on Tue Mar 23 2021 19:41:20 for gem5 by doxygen 1.8.17