gem5  v20.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 uint64_t
111 getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp)
112 {
113  panic_if(fp, "getArgument(): Floating point arguments not implemented");
114  panic_if(size != 8, "getArgument(): Can only handle 64-bit arguments.");
115  panic_if(number >= ArgumentRegs.size(),
116  "getArgument(): Don't know how to handle stack arguments");
117 
118  // The first 8 integer arguments are passed in registers, the rest
119  // are passed on the stack.
120  return tc->readIntReg(ArgumentRegs[number]);
121 }
122 
123 inline void
125 {
126  // First loop through the integer registers.
127  for (int i = 0; i < NumIntRegs; ++i)
128  dest->setIntReg(i, src->readIntReg(i));
129 
130  // Lastly copy PC/NPC
131  dest->pcState(src->pcState());
132 }
133 
134 inline std::string
136 {
137  if (reg.isIntReg()) {
138  if (reg.index() >= NumIntArchRegs) {
139  /*
140  * This should only happen if a instruction is being speculatively
141  * executed along a not-taken branch, and if that instruction's
142  * width was incorrectly predecoded (i.e., it was predecoded as a
143  * full instruction rather than a compressed one or vice versa).
144  * It also should only happen if a debug flag is on that prints
145  * disassembly information, so rather than panic the incorrect
146  * value is printed for debugging help.
147  */
148  std::stringstream str;
149  str << "?? (x" << reg.index() << ')';
150  return str.str();
151  }
152  return IntRegNames[reg.index()];
153  } else {
154  if (reg.index() >= NumFloatRegs) {
155  std::stringstream str;
156  str << "?? (f" << reg.index() << ')';
157  return str.str();
158  }
159  return FloatRegNames[reg.index()];
160  }
161 }
162 
163 inline void
165 {
166  inst->advancePC(pc);
167 }
168 
169 static inline bool
171 {
172  return true;
173 }
174 
175 inline uint64_t
177 {
178  return 0;
179 }
180 
181 } // namespace RiscvISA
182 
183 #endif // __ARCH_RISCV_UTILITY_HH__
const std::vector< std::string > IntRegNames
Definition: registers.hh:108
const std::vector< int > ArgumentRegs
Definition: registers.hh:101
const int NumFloatRegs
Definition: registers.hh:83
Bitfield< 5, 3 > reg
Definition: types.hh:87
const int NumIntArchRegs
Definition: registers.hh:80
bool issignalingnan< double >(double val)
Definition: utility.hh:95
virtual TheISA::PCState pcState() const =0
virtual RegVal readIntReg(RegIndex reg_idx) const =0
bool isquietnan< double >(double val)
Definition: utility.hh:75
uint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp)
Definition: utility.hh:111
ThreadContext is the external interface to all thread state for anything outside of the CPU...
static bool inUserMode(ThreadContext *tc)
Definition: utility.hh:170
Bitfield< 63 > val
Definition: misc.hh:769
const std::vector< std::string > FloatRegNames
Definition: registers.hh:118
const int NumIntRegs
Definition: registers.hh:82
std::string registerName(RegId reg)
Definition: utility.hh:135
Bitfield< 4 > pc
bool isquietnan< float >(float val)
Definition: utility.hh:68
bool issignalingnan(T val)
Definition: utility.hh:82
Bitfield< 0 > fp
Bitfield< 2 > i
uint64_t getExecutingAsid(ThreadContext *tc)
Definition: utility.hh:176
bool isIntReg() const
Definition: reg_class.hh:143
PCState buildRetPC(const PCState &curPC, const PCState &callPC)
Definition: utility.hh:102
bool isquietnan(T val)
Definition: utility.hh:62
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:149
bool issignalingnan< float >(float val)
Definition: utility.hh:88
virtual void advancePC(TheISA::PCState &pcState) const =0
const RegIndex & index() const
Index accessors.
Definition: reg_class.hh:173
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:181
void copyRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.hh:124
void advancePC(PCState &pc, const StaticInstPtr &inst)
Definition: utility.hh:164

Generated on Thu May 28 2020 16:11:03 for gem5 by doxygen 1.8.13