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

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13