blob: 59d74146b5a1ec4314deb57c0ad1e13a29b13d33 [file] [log] [blame]
Kevin Limdef9ea32006-06-16 17:19:36 -04001/*
Rekai Gonzalez-Alberquilla00da0892017-04-05 13:24:00 -05002 * Copyright (c) 2014, 2016 ARM Limited
Andreas Sandberg326662b2014-09-03 07:42:22 -04003 * 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 *
Kevin Limdef9ea32006-06-16 17:19:36 -040014 * Copyright (c) 2002-2005 The Regents of The University of Michigan
Steve Reinhardt1b6355c2016-01-17 18:27:46 -080015 * Copyright (c) 2015 Advanced Micro Devices, Inc.
Kevin Limdef9ea32006-06-16 17:19:36 -040016 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Kevin Lim
Andreas Sandberg326662b2014-09-03 07:42:22 -040042 * Andreas Sandberg
Kevin Limdef9ea32006-06-16 17:19:36 -040043 */
44
Andreas Sandberg326662b2014-09-03 07:42:22 -040045#ifndef __CPU_EXEC_CONTEXT_HH__
46#define __CPU_EXEC_CONTEXT_HH__
47
48#include "arch/registers.hh"
49#include "base/types.hh"
50#include "config/the_isa.hh"
Marc Orrbf807342014-11-06 05:42:22 -060051#include "cpu/base.hh"
Nathanael Premillieu5e8287d2017-04-05 12:46:06 -050052#include "cpu/reg_class.hh"
Andreas Sandberg326662b2014-09-03 07:42:22 -040053#include "cpu/static_inst_fwd.hh"
54#include "cpu/translation.hh"
Nikos Nikoleris698767e2016-08-15 12:00:35 +010055#include "mem/request.hh"
Kevin Limdef9ea32006-06-16 17:19:36 -040056
57/**
Andreas Sandberg326662b2014-09-03 07:42:22 -040058 * The ExecContext is an abstract base class the provides the
59 * interface used by the ISA to manipulate the state of the CPU model.
60 *
61 * Register accessor methods in this class typically provide the index
62 * of the instruction's operand (e.g., 0 or 1), not the architectural
63 * register index, to simplify the implementation of register
64 * renaming. The architectural register index can be found by
65 * indexing into the instruction's own operand index table.
66 *
67 * @note The methods in this class typically take a raw pointer to the
68 * StaticInst is provided instead of a ref-counted StaticInstPtr to
69 * reduce overhead as an argument. This is fine as long as the
70 * implementation doesn't copy the pointer into any long-term storage
71 * (which is pretty hard to imagine they would have reason to do).
Kevin Limdef9ea32006-06-16 17:19:36 -040072 */
73class ExecContext {
Andreas Sandberg326662b2014-09-03 07:42:22 -040074 public:
75 typedef TheISA::IntReg IntReg;
76 typedef TheISA::PCState PCState;
77 typedef TheISA::FloatReg FloatReg;
78 typedef TheISA::FloatRegBits FloatRegBits;
79 typedef TheISA::MiscReg MiscReg;
80
81 typedef TheISA::CCReg CCReg;
Rekai Gonzalez-Alberquilla00da0892017-04-05 13:24:00 -050082 using VecRegContainer = TheISA::VecRegContainer;
83 using VecElem = TheISA::VecElem;
Andreas Sandberg326662b2014-09-03 07:42:22 -040084
85 public:
86 /**
87 * @{
88 * @name Integer Register Interfaces
89 *
90 */
Kevin Limdef9ea32006-06-16 17:19:36 -040091
92 /** Reads an integer register. */
Andreas Sandberg326662b2014-09-03 07:42:22 -040093 virtual IntReg readIntRegOperand(const StaticInst *si, int idx) = 0;
94
95 /** Sets an integer register to a value. */
96 virtual void setIntRegOperand(const StaticInst *si,
97 int idx, IntReg val) = 0;
98
99 /** @} */
100
101
102 /**
103 * @{
104 * @name Floating Point Register Interfaces
105 */
Kevin Limdef9ea32006-06-16 17:19:36 -0400106
Kevin Limdef9ea32006-06-16 17:19:36 -0400107 /** Reads a floating point register of single register width. */
Andreas Sandberg326662b2014-09-03 07:42:22 -0400108 virtual FloatReg readFloatRegOperand(const StaticInst *si, int idx) = 0;
Kevin Limdef9ea32006-06-16 17:19:36 -0400109
Kevin Limdef9ea32006-06-16 17:19:36 -0400110 /** Reads a floating point register in its binary format, instead
111 * of by value. */
Andreas Sandberg326662b2014-09-03 07:42:22 -0400112 virtual FloatRegBits readFloatRegOperandBits(const StaticInst *si,
113 int idx) = 0;
Kevin Limdef9ea32006-06-16 17:19:36 -0400114
Kevin Limdef9ea32006-06-16 17:19:36 -0400115 /** Sets a floating point register of single width to a value. */
Andreas Sandberg326662b2014-09-03 07:42:22 -0400116 virtual void setFloatRegOperand(const StaticInst *si,
117 int idx, FloatReg val) = 0;
Kevin Limdef9ea32006-06-16 17:19:36 -0400118
Kevin Limdef9ea32006-06-16 17:19:36 -0400119 /** Sets the bits of a floating point register of single width
120 * to a binary value. */
Andreas Sandberg326662b2014-09-03 07:42:22 -0400121 virtual void setFloatRegOperandBits(const StaticInst *si,
122 int idx, FloatRegBits val) = 0;
Kevin Limdef9ea32006-06-16 17:19:36 -0400123
Andreas Sandberg326662b2014-09-03 07:42:22 -0400124 /** @} */
Kevin Limdef9ea32006-06-16 17:19:36 -0400125
Rekai Gonzalez-Alberquilla00da0892017-04-05 13:24:00 -0500126 /** Vector Register Interfaces. */
127 /** @{ */
128 /** Reads source vector register operand. */
129 virtual const VecRegContainer&
130 readVecRegOperand(const StaticInst *si, int idx) const = 0;
131
132 /** Gets destination vector register operand for modification. */
133 virtual VecRegContainer&
134 getWritableVecRegOperand(const StaticInst *si, int idx) = 0;
135
136 /** Sets a destination vector register operand to a value. */
137 virtual void
138 setVecRegOperand(const StaticInst *si, int idx,
139 const VecRegContainer& val) = 0;
140 /** @} */
141
142 /** Vector Register Lane Interfaces. */
143 /** @{ */
144 /** Reads source vector 8bit operand. */
145 virtual ConstVecLane8
146 readVec8BitLaneOperand(const StaticInst *si, int idx) const = 0;
147
148 /** Reads source vector 16bit operand. */
149 virtual ConstVecLane16
150 readVec16BitLaneOperand(const StaticInst *si, int idx) const = 0;
151
152 /** Reads source vector 32bit operand. */
153 virtual ConstVecLane32
154 readVec32BitLaneOperand(const StaticInst *si, int idx) const = 0;
155
156 /** Reads source vector 64bit operand. */
157 virtual ConstVecLane64
158 readVec64BitLaneOperand(const StaticInst *si, int idx) const = 0;
159
160 /** Write a lane of the destination vector operand. */
161 /** @{ */
162 virtual void setVecLaneOperand(const StaticInst *si, int idx,
163 const LaneData<LaneSize::Byte>& val) = 0;
164 virtual void setVecLaneOperand(const StaticInst *si, int idx,
165 const LaneData<LaneSize::TwoByte>& val) = 0;
166 virtual void setVecLaneOperand(const StaticInst *si, int idx,
167 const LaneData<LaneSize::FourByte>& val) = 0;
168 virtual void setVecLaneOperand(const StaticInst *si, int idx,
169 const LaneData<LaneSize::EightByte>& val) = 0;
170 /** @} */
171
172 /** Vector Elem Interfaces. */
173 /** @{ */
174 /** Reads an element of a vector register. */
175 virtual VecElem readVecElemOperand(const StaticInst *si,
176 int idx) const = 0;
177
178 /** Sets a vector register to a value. */
179 virtual void setVecElemOperand(const StaticInst *si, int idx,
180 const VecElem val) = 0;
181 /** @} */
182
Andreas Sandberg326662b2014-09-03 07:42:22 -0400183 /**
184 * @{
185 * @name Condition Code Registers
186 */
187 virtual CCReg readCCRegOperand(const StaticInst *si, int idx) = 0;
188 virtual void setCCRegOperand(const StaticInst *si, int idx, CCReg val) = 0;
189 /** @} */
Kevin Limdef9ea32006-06-16 17:19:36 -0400190
Andreas Sandberg326662b2014-09-03 07:42:22 -0400191 /**
192 * @{
193 * @name Misc Register Interfaces
194 */
195 virtual MiscReg readMiscRegOperand(const StaticInst *si, int idx) = 0;
196 virtual void setMiscRegOperand(const StaticInst *si,
197 int idx, const MiscReg &val) = 0;
Kevin Limdef9ea32006-06-16 17:19:36 -0400198
Andreas Sandberg326662b2014-09-03 07:42:22 -0400199 /**
200 * Reads a miscellaneous register, handling any architectural
201 * side effects due to reading that register.
202 */
203 virtual MiscReg readMiscReg(int misc_reg) = 0;
Kevin Limdef9ea32006-06-16 17:19:36 -0400204
Andreas Sandberg326662b2014-09-03 07:42:22 -0400205 /**
206 * Sets a miscellaneous register, handling any architectural
207 * side effects due to writing that register.
208 */
209 virtual void setMiscReg(int misc_reg, const MiscReg &val) = 0;
Kevin Limdef9ea32006-06-16 17:19:36 -0400210
Andreas Sandberg326662b2014-09-03 07:42:22 -0400211 /** @} */
Kevin Limdef9ea32006-06-16 17:19:36 -0400212
Andreas Sandberg326662b2014-09-03 07:42:22 -0400213 /**
214 * @{
215 * @name PC Control
216 */
217 virtual PCState pcState() const = 0;
218 virtual void pcState(const PCState &val) = 0;
219 /** @} */
220
221 /**
222 * @{
223 * @name Memory Interface
224 */
225 /**
Steve Reinhardt1b6355c2016-01-17 18:27:46 -0800226 * Perform an atomic memory read operation. Must be overridden
227 * for exec contexts that support atomic memory mode. Not pure
228 * virtual since exec contexts that only support timing memory
229 * mode need not override (though in that case this function
230 * should never be called).
231 */
Andreas Sandberg326662b2014-09-03 07:42:22 -0400232 virtual Fault readMem(Addr addr, uint8_t *data, unsigned int size,
Nikos Nikoleris698767e2016-08-15 12:00:35 +0100233 Request::Flags flags)
Steve Reinhardt1b6355c2016-01-17 18:27:46 -0800234 {
235 panic("ExecContext::readMem() should be overridden\n");
236 }
Andreas Sandberg326662b2014-09-03 07:42:22 -0400237
Steve Reinhardt1b6355c2016-01-17 18:27:46 -0800238 /**
239 * Initiate a timing memory read operation. Must be overridden
240 * for exec contexts that support timing memory mode. Not pure
241 * virtual since exec contexts that only support atomic memory
242 * mode need not override (though in that case this function
243 * should never be called).
244 */
245 virtual Fault initiateMemRead(Addr addr, unsigned int size,
Nikos Nikoleris698767e2016-08-15 12:00:35 +0100246 Request::Flags flags)
Steve Reinhardt1b6355c2016-01-17 18:27:46 -0800247 {
248 panic("ExecContext::initiateMemRead() should be overridden\n");
249 }
250
251 /**
252 * For atomic-mode contexts, perform an atomic memory write operation.
253 * For timing-mode contexts, initiate a timing memory write operation.
254 */
Andreas Sandberg326662b2014-09-03 07:42:22 -0400255 virtual Fault writeMem(uint8_t *data, unsigned int size, Addr addr,
Nikos Nikoleris698767e2016-08-15 12:00:35 +0100256 Request::Flags flags, uint64_t *res) = 0;
Andreas Sandberg326662b2014-09-03 07:42:22 -0400257
258 /**
259 * Sets the number of consecutive store conditional failures.
260 */
261 virtual void setStCondFailures(unsigned int sc_failures) = 0;
262
263 /**
264 * Returns the number of consecutive store conditional failures.
265 */
266 virtual unsigned int readStCondFailures() const = 0;
267
268 /** @} */
269
270 /**
271 * @{
272 * @name SysCall Emulation Interfaces
273 */
274
275 /**
276 * Executes a syscall specified by the callnum.
277 */
Brandon Pottera5802c82015-07-20 09:15:21 -0500278 virtual void syscall(int64_t callnum, Fault *fault) = 0;
Andreas Sandberg326662b2014-09-03 07:42:22 -0400279
280 /** @} */
Kevin Limdef9ea32006-06-16 17:19:36 -0400281
282 /** Returns a pointer to the ThreadContext. */
Andreas Sandberg326662b2014-09-03 07:42:22 -0400283 virtual ThreadContext *tcBase() = 0;
Kevin Limdef9ea32006-06-16 17:19:36 -0400284
Andreas Sandberg326662b2014-09-03 07:42:22 -0400285 /**
286 * @{
287 * @name Alpha-Specific Interfaces
288 */
Gabe Blackaa8c6e92010-08-13 06:16:02 -0700289
Andreas Sandberg326662b2014-09-03 07:42:22 -0400290 /**
291 * Somewhat Alpha-specific function that handles returning from an
292 * error or interrupt.
293 */
294 virtual Fault hwrei() = 0;
Kevin Limdef9ea32006-06-16 17:19:36 -0400295
296 /**
297 * Check for special simulator handling of specific PAL calls. If
298 * return value is false, actual PAL call will be suppressed.
299 */
Andreas Sandberg326662b2014-09-03 07:42:22 -0400300 virtual bool simPalCheck(int palFunc) = 0;
Gabe Black1268e0d2011-11-01 04:01:13 -0700301
Andreas Sandberg326662b2014-09-03 07:42:22 -0400302 /** @} */
Timothy M. Jones7fe9f922010-02-12 19:53:19 +0000303
Andreas Sandberg326662b2014-09-03 07:42:22 -0400304 /**
305 * @{
306 * @name ARM-Specific Interfaces
307 */
308
309 virtual bool readPredicate() = 0;
310 virtual void setPredicate(bool val) = 0;
311
312 /** @} */
313
314 /**
315 * @{
316 * @name X86-Specific Interfaces
317 */
318
319 /**
320 * Invalidate a page in the DTLB <i>and</i> ITLB.
321 */
322 virtual void demapPage(Addr vaddr, uint64_t asn) = 0;
Marc Orrbf807342014-11-06 05:42:22 -0600323 virtual void armMonitor(Addr address) = 0;
324 virtual bool mwait(PacketPtr pkt) = 0;
325 virtual void mwaitAtomic(ThreadContext *tc) = 0;
326 virtual AddressMonitor *getAddrMonitor() = 0;
Andreas Sandberg326662b2014-09-03 07:42:22 -0400327
328 /** @} */
329
330 /**
331 * @{
332 * @name MIPS-Specific Interfaces
333 */
334
335#if THE_ISA == MIPS_ISA
Rekai Gonzalez-Alberquillaa473b5a2017-04-05 13:14:34 -0500336 virtual MiscReg readRegOtherThread(const RegId& reg,
Andreas Sandberg326662b2014-09-03 07:42:22 -0400337 ThreadID tid = InvalidThreadID) = 0;
Rekai Gonzalez-Alberquillaa473b5a2017-04-05 13:14:34 -0500338 virtual void setRegOtherThread(const RegId& reg, MiscReg val,
Andreas Sandberg326662b2014-09-03 07:42:22 -0400339 ThreadID tid = InvalidThreadID) = 0;
340#endif
341
342 /** @} */
Kevin Limdef9ea32006-06-16 17:19:36 -0400343};
Andreas Sandberg326662b2014-09-03 07:42:22 -0400344
345#endif // __CPU_EXEC_CONTEXT_HH__