Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 1 | /* |
Rekai Gonzalez-Alberquilla | 00da089 | 2017-04-05 13:24:00 -0500 | [diff] [blame] | 2 | * Copyright (c) 2014, 2016 ARM Limited |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 3 | * 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 Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 14 | * Copyright (c) 2002-2005 The Regents of The University of Michigan |
Steve Reinhardt | 1b6355c | 2016-01-17 18:27:46 -0800 | [diff] [blame] | 15 | * Copyright (c) 2015 Advanced Micro Devices, Inc. |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 16 | * 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 Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 42 | * Andreas Sandberg |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 43 | */ |
| 44 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 45 | #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 Orr | bf80734 | 2014-11-06 05:42:22 -0600 | [diff] [blame] | 51 | #include "cpu/base.hh" |
Nathanael Premillieu | 5e8287d | 2017-04-05 12:46:06 -0500 | [diff] [blame] | 52 | #include "cpu/reg_class.hh" |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 53 | #include "cpu/static_inst_fwd.hh" |
| 54 | #include "cpu/translation.hh" |
Nikos Nikoleris | 698767e | 2016-08-15 12:00:35 +0100 | [diff] [blame] | 55 | #include "mem/request.hh" |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 56 | |
| 57 | /** |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 58 | * 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 Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 72 | */ |
| 73 | class ExecContext { |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 74 | 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-Alberquilla | 00da089 | 2017-04-05 13:24:00 -0500 | [diff] [blame] | 82 | using VecRegContainer = TheISA::VecRegContainer; |
| 83 | using VecElem = TheISA::VecElem; |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 84 | |
| 85 | public: |
| 86 | /** |
| 87 | * @{ |
| 88 | * @name Integer Register Interfaces |
| 89 | * |
| 90 | */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 91 | |
| 92 | /** Reads an integer register. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 93 | 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 Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 106 | |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 107 | /** Reads a floating point register of single register width. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 108 | virtual FloatReg readFloatRegOperand(const StaticInst *si, int idx) = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 109 | |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 110 | /** Reads a floating point register in its binary format, instead |
| 111 | * of by value. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 112 | virtual FloatRegBits readFloatRegOperandBits(const StaticInst *si, |
| 113 | int idx) = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 114 | |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 115 | /** Sets a floating point register of single width to a value. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 116 | virtual void setFloatRegOperand(const StaticInst *si, |
| 117 | int idx, FloatReg val) = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 118 | |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 119 | /** Sets the bits of a floating point register of single width |
| 120 | * to a binary value. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 121 | virtual void setFloatRegOperandBits(const StaticInst *si, |
| 122 | int idx, FloatRegBits val) = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 123 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 124 | /** @} */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 125 | |
Rekai Gonzalez-Alberquilla | 00da089 | 2017-04-05 13:24:00 -0500 | [diff] [blame] | 126 | /** 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 Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 183 | /** |
| 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 Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 190 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 191 | /** |
| 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 Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 198 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 199 | /** |
| 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 Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 204 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 205 | /** |
| 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 Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 210 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 211 | /** @} */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 212 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 213 | /** |
| 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 Reinhardt | 1b6355c | 2016-01-17 18:27:46 -0800 | [diff] [blame] | 226 | * 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 Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 232 | virtual Fault readMem(Addr addr, uint8_t *data, unsigned int size, |
Nikos Nikoleris | 698767e | 2016-08-15 12:00:35 +0100 | [diff] [blame] | 233 | Request::Flags flags) |
Steve Reinhardt | 1b6355c | 2016-01-17 18:27:46 -0800 | [diff] [blame] | 234 | { |
| 235 | panic("ExecContext::readMem() should be overridden\n"); |
| 236 | } |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 237 | |
Steve Reinhardt | 1b6355c | 2016-01-17 18:27:46 -0800 | [diff] [blame] | 238 | /** |
| 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 Nikoleris | 698767e | 2016-08-15 12:00:35 +0100 | [diff] [blame] | 246 | Request::Flags flags) |
Steve Reinhardt | 1b6355c | 2016-01-17 18:27:46 -0800 | [diff] [blame] | 247 | { |
| 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 Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 255 | virtual Fault writeMem(uint8_t *data, unsigned int size, Addr addr, |
Nikos Nikoleris | 698767e | 2016-08-15 12:00:35 +0100 | [diff] [blame] | 256 | Request::Flags flags, uint64_t *res) = 0; |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 257 | |
| 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 Potter | a5802c8 | 2015-07-20 09:15:21 -0500 | [diff] [blame] | 278 | virtual void syscall(int64_t callnum, Fault *fault) = 0; |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 279 | |
| 280 | /** @} */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 281 | |
| 282 | /** Returns a pointer to the ThreadContext. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 283 | virtual ThreadContext *tcBase() = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 284 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 285 | /** |
| 286 | * @{ |
| 287 | * @name Alpha-Specific Interfaces |
| 288 | */ |
Gabe Black | aa8c6e9 | 2010-08-13 06:16:02 -0700 | [diff] [blame] | 289 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 290 | /** |
| 291 | * Somewhat Alpha-specific function that handles returning from an |
| 292 | * error or interrupt. |
| 293 | */ |
| 294 | virtual Fault hwrei() = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 295 | |
| 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 Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 300 | virtual bool simPalCheck(int palFunc) = 0; |
Gabe Black | 1268e0d | 2011-11-01 04:01:13 -0700 | [diff] [blame] | 301 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 302 | /** @} */ |
Timothy M. Jones | 7fe9f92 | 2010-02-12 19:53:19 +0000 | [diff] [blame] | 303 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 304 | /** |
| 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 Orr | bf80734 | 2014-11-06 05:42:22 -0600 | [diff] [blame] | 323 | 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 Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 327 | |
| 328 | /** @} */ |
| 329 | |
| 330 | /** |
| 331 | * @{ |
| 332 | * @name MIPS-Specific Interfaces |
| 333 | */ |
| 334 | |
| 335 | #if THE_ISA == MIPS_ISA |
Rekai Gonzalez-Alberquilla | a473b5a | 2017-04-05 13:14:34 -0500 | [diff] [blame] | 336 | virtual MiscReg readRegOtherThread(const RegId& reg, |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 337 | ThreadID tid = InvalidThreadID) = 0; |
Rekai Gonzalez-Alberquilla | a473b5a | 2017-04-05 13:14:34 -0500 | [diff] [blame] | 338 | virtual void setRegOtherThread(const RegId& reg, MiscReg val, |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 339 | ThreadID tid = InvalidThreadID) = 0; |
| 340 | #endif |
| 341 | |
| 342 | /** @} */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 343 | }; |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 344 | |
| 345 | #endif // __CPU_EXEC_CONTEXT_HH__ |