2 * Copyright (c) 2014, 2016-2018, 2020 ARM Limited
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.
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * Copyright (c) 2015 Advanced Micro Devices, Inc.
16 * All rights reserved.
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.
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.
42 #ifndef __CPU_EXEC_CONTEXT_HH__
43 #define __CPU_EXEC_CONTEXT_HH__
45 #include "arch/registers.hh"
46 #include "base/types.hh"
47 #include "config/the_isa.hh"
48 #include "cpu/base.hh"
49 #include "cpu/reg_class.hh"
50 #include "cpu/static_inst_fwd.hh"
51 #include "cpu/translation.hh"
52 #include "mem/request.hh"
55 * The ExecContext is an abstract base class the provides the
56 * interface used by the ISA to manipulate the state of the CPU model.
58 * Register accessor methods in this class typically provide the index
59 * of the instruction's operand (e.g., 0 or 1), not the architectural
60 * register index, to simplify the implementation of register
61 * renaming. The architectural register index can be found by
62 * indexing into the instruction's own operand index table.
64 * @note The methods in this class typically take a raw pointer to the
65 * StaticInst is provided instead of a ref-counted StaticInstPtr to
66 * reduce overhead as an argument. This is fine as long as the
67 * implementation doesn't copy the pointer into any long-term storage
68 * (which is pretty hard to imagine they would have reason to do).
72 typedef TheISA::PCState PCState;
74 using VecRegContainer = TheISA::VecRegContainer;
75 using VecElem = TheISA::VecElem;
76 using VecPredRegContainer = TheISA::VecPredRegContainer;
81 * @name Integer Register Interfaces
85 /** Reads an integer register. */
86 virtual RegVal readIntRegOperand(const StaticInst *si, int idx) = 0;
88 /** Sets an integer register to a value. */
89 virtual void setIntRegOperand(const StaticInst *si,
90 int idx, RegVal val) = 0;
97 * @name Floating Point Register Interfaces
100 /** Reads a floating point register in its binary format, instead
102 virtual RegVal readFloatRegOperandBits(const StaticInst *si, int idx) = 0;
104 /** Sets the bits of a floating point register of single width
105 * to a binary value. */
106 virtual void setFloatRegOperandBits(const StaticInst *si,
107 int idx, RegVal val) = 0;
111 /** Vector Register Interfaces. */
113 /** Reads source vector register operand. */
114 virtual const VecRegContainer&
115 readVecRegOperand(const StaticInst *si, int idx) const = 0;
117 /** Gets destination vector register operand for modification. */
118 virtual VecRegContainer&
119 getWritableVecRegOperand(const StaticInst *si, int idx) = 0;
121 /** Sets a destination vector register operand to a value. */
123 setVecRegOperand(const StaticInst *si, int idx,
124 const VecRegContainer& val) = 0;
127 /** Vector Register Lane Interfaces. */
129 /** Reads source vector 8bit operand. */
130 virtual ConstVecLane8
131 readVec8BitLaneOperand(const StaticInst *si, int idx) const = 0;
133 /** Reads source vector 16bit operand. */
134 virtual ConstVecLane16
135 readVec16BitLaneOperand(const StaticInst *si, int idx) const = 0;
137 /** Reads source vector 32bit operand. */
138 virtual ConstVecLane32
139 readVec32BitLaneOperand(const StaticInst *si, int idx) const = 0;
141 /** Reads source vector 64bit operand. */
142 virtual ConstVecLane64
143 readVec64BitLaneOperand(const StaticInst *si, int idx) const = 0;
145 /** Write a lane of the destination vector operand. */
147 virtual void setVecLaneOperand(const StaticInst *si, int idx,
148 const LaneData<LaneSize::Byte>& val) = 0;
149 virtual void setVecLaneOperand(const StaticInst *si, int idx,
150 const LaneData<LaneSize::TwoByte>& val) = 0;
151 virtual void setVecLaneOperand(const StaticInst *si, int idx,
152 const LaneData<LaneSize::FourByte>& val) = 0;
153 virtual void setVecLaneOperand(const StaticInst *si, int idx,
154 const LaneData<LaneSize::EightByte>& val) = 0;
157 /** Vector Elem Interfaces. */
159 /** Reads an element of a vector register. */
160 virtual VecElem readVecElemOperand(const StaticInst *si,
163 /** Sets a vector register to a value. */
164 virtual void setVecElemOperand(const StaticInst *si, int idx,
165 const VecElem val) = 0;
168 /** Predicate registers interface. */
170 /** Reads source predicate register operand. */
171 virtual const VecPredRegContainer&
172 readVecPredRegOperand(const StaticInst *si, int idx) const = 0;
174 /** Gets destination predicate register operand for modification. */
175 virtual VecPredRegContainer&
176 getWritableVecPredRegOperand(const StaticInst *si, int idx) = 0;
178 /** Sets a destination predicate register operand to a value. */
180 setVecPredRegOperand(const StaticInst *si, int idx,
181 const VecPredRegContainer& val) = 0;
186 * @name Condition Code Registers
188 virtual RegVal readCCRegOperand(const StaticInst *si, int idx) = 0;
189 virtual void setCCRegOperand(
190 const StaticInst *si, int idx, RegVal val) = 0;
195 * @name Misc Register Interfaces
197 virtual RegVal readMiscRegOperand(const StaticInst *si, int idx) = 0;
198 virtual void setMiscRegOperand(const StaticInst *si,
199 int idx, RegVal val) = 0;
202 * Reads a miscellaneous register, handling any architectural
203 * side effects due to reading that register.
205 virtual RegVal readMiscReg(int misc_reg) = 0;
208 * Sets a miscellaneous register, handling any architectural
209 * side effects due to writing that register.
211 virtual void setMiscReg(int misc_reg, RegVal val) = 0;
219 virtual PCState pcState() const = 0;
220 virtual void pcState(const PCState &val) = 0;
225 * @name Memory Interface
228 * Perform an atomic memory read operation. Must be overridden
229 * for exec contexts that support atomic memory mode. Not pure
230 * virtual since exec contexts that only support timing memory
231 * mode need not override (though in that case this function
232 * should never be called).
234 virtual Fault readMem(Addr addr, uint8_t *data, unsigned int size,
235 Request::Flags flags,
236 const std::vector<bool>& byte_enable = std::vector<bool>())
238 panic("ExecContext::readMem() should be overridden\n");
242 * Initiate a timing memory read operation. Must be overridden
243 * for exec contexts that support timing memory mode. Not pure
244 * virtual since exec contexts that only support atomic memory
245 * mode need not override (though in that case this function
246 * should never be called).
248 virtual Fault initiateMemRead(Addr addr, unsigned int size,
249 Request::Flags flags,
250 const std::vector<bool>& byte_enable = std::vector<bool>())
252 panic("ExecContext::initiateMemRead() should be overridden\n");
256 * Initiate an HTM command,
257 * e.g. tell Ruby we're starting/stopping a transaction
259 virtual Fault initiateHtmCmd(Request::Flags flags) = 0;
261 * For atomic-mode contexts, perform an atomic memory write operation.
262 * For timing-mode contexts, initiate a timing memory write operation.
264 virtual Fault writeMem(uint8_t *data, unsigned int size, Addr addr,
265 Request::Flags flags, uint64_t *res,
266 const std::vector<bool>& byte_enable =
267 std::vector<bool>()) = 0;
270 * For atomic-mode contexts, perform an atomic AMO (a.k.a., Atomic
271 * Read-Modify-Write Memory Operation)
273 virtual Fault amoMem(Addr addr, uint8_t *data, unsigned int size,
274 Request::Flags flags,
275 AtomicOpFunctorPtr amo_op)
277 panic("ExecContext::amoMem() should be overridden\n");
281 * For timing-mode contexts, initiate an atomic AMO (atomic
282 * read-modify-write memory operation)
284 virtual Fault initiateMemAMO(Addr addr, unsigned int size,
285 Request::Flags flags,
286 AtomicOpFunctorPtr amo_op)
288 panic("ExecContext::initiateMemAMO() should be overridden\n");
292 * Sets the number of consecutive store conditional failures.
294 virtual void setStCondFailures(unsigned int sc_failures) = 0;
297 * Returns the number of consecutive store conditional failures.
299 virtual unsigned int readStCondFailures() const = 0;
303 /** Returns a pointer to the ThreadContext. */
304 virtual ThreadContext *tcBase() const = 0;
308 * @name ARM-Specific Interfaces
311 virtual bool readPredicate() const = 0;
312 virtual void setPredicate(bool val) = 0;
313 virtual bool readMemAccPredicate() const = 0;
314 virtual void setMemAccPredicate(bool val) = 0;
316 // hardware transactional memory
317 virtual uint64_t newHtmTransactionUid() const = 0;
318 virtual uint64_t getHtmTransactionUid() const = 0;
319 virtual bool inHtmTransactionalState() const = 0;
320 virtual uint64_t getHtmTransactionalDepth() const = 0;
326 * @name X86-Specific Interfaces
330 * Invalidate a page in the DTLB <i>and</i> ITLB.
332 virtual void demapPage(Addr vaddr, uint64_t asn) = 0;
333 virtual void armMonitor(Addr address) = 0;
334 virtual bool mwait(PacketPtr pkt) = 0;
335 virtual void mwaitAtomic(ThreadContext *tc) = 0;
336 virtual AddressMonitor *getAddrMonitor() = 0;
341 #endif // __CPU_EXEC_CONTEXT_HH__