Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 1 | /* |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 2 | * Copyright (c) 2014 ARM Limited |
| 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" |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 52 | #include "cpu/static_inst_fwd.hh" |
| 53 | #include "cpu/translation.hh" |
Nikos Nikoleris | 698767e | 2016-08-15 12:00:35 +0100 | [diff] [blame^] | 54 | #include "mem/request.hh" |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 55 | |
| 56 | /** |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 57 | * The ExecContext is an abstract base class the provides the |
| 58 | * interface used by the ISA to manipulate the state of the CPU model. |
| 59 | * |
| 60 | * Register accessor methods in this class typically provide the index |
| 61 | * of the instruction's operand (e.g., 0 or 1), not the architectural |
| 62 | * register index, to simplify the implementation of register |
| 63 | * renaming. The architectural register index can be found by |
| 64 | * indexing into the instruction's own operand index table. |
| 65 | * |
| 66 | * @note The methods in this class typically take a raw pointer to the |
| 67 | * StaticInst is provided instead of a ref-counted StaticInstPtr to |
| 68 | * reduce overhead as an argument. This is fine as long as the |
| 69 | * implementation doesn't copy the pointer into any long-term storage |
| 70 | * (which is pretty hard to imagine they would have reason to do). |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 71 | */ |
| 72 | class ExecContext { |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 73 | public: |
| 74 | typedef TheISA::IntReg IntReg; |
| 75 | typedef TheISA::PCState PCState; |
| 76 | typedef TheISA::FloatReg FloatReg; |
| 77 | typedef TheISA::FloatRegBits FloatRegBits; |
| 78 | typedef TheISA::MiscReg MiscReg; |
| 79 | |
| 80 | typedef TheISA::CCReg CCReg; |
| 81 | |
| 82 | public: |
| 83 | /** |
| 84 | * @{ |
| 85 | * @name Integer Register Interfaces |
| 86 | * |
| 87 | */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 88 | |
| 89 | /** Reads an integer register. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 90 | virtual IntReg readIntRegOperand(const StaticInst *si, int idx) = 0; |
| 91 | |
| 92 | /** Sets an integer register to a value. */ |
| 93 | virtual void setIntRegOperand(const StaticInst *si, |
| 94 | int idx, IntReg val) = 0; |
| 95 | |
| 96 | /** @} */ |
| 97 | |
| 98 | |
| 99 | /** |
| 100 | * @{ |
| 101 | * @name Floating Point Register Interfaces |
| 102 | */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 103 | |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 104 | /** Reads a floating point register of single register width. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 105 | virtual FloatReg readFloatRegOperand(const StaticInst *si, int idx) = 0; |
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 in its binary format, instead |
| 108 | * of by value. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 109 | virtual FloatRegBits readFloatRegOperandBits(const StaticInst *si, |
| 110 | int idx) = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 111 | |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 112 | /** Sets a floating point register of single width to a value. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 113 | virtual void setFloatRegOperand(const StaticInst *si, |
| 114 | int idx, FloatReg val) = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 115 | |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 116 | /** Sets the bits of a floating point register of single width |
| 117 | * to a binary value. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 118 | virtual void setFloatRegOperandBits(const StaticInst *si, |
| 119 | int idx, FloatRegBits val) = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 120 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 121 | /** @} */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 122 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 123 | /** |
| 124 | * @{ |
| 125 | * @name Condition Code Registers |
| 126 | */ |
| 127 | virtual CCReg readCCRegOperand(const StaticInst *si, int idx) = 0; |
| 128 | virtual void setCCRegOperand(const StaticInst *si, int idx, CCReg val) = 0; |
| 129 | /** @} */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 130 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 131 | /** |
| 132 | * @{ |
| 133 | * @name Misc Register Interfaces |
| 134 | */ |
| 135 | virtual MiscReg readMiscRegOperand(const StaticInst *si, int idx) = 0; |
| 136 | virtual void setMiscRegOperand(const StaticInst *si, |
| 137 | int idx, const MiscReg &val) = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 138 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 139 | /** |
| 140 | * Reads a miscellaneous register, handling any architectural |
| 141 | * side effects due to reading that register. |
| 142 | */ |
| 143 | virtual MiscReg readMiscReg(int misc_reg) = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 144 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 145 | /** |
| 146 | * Sets a miscellaneous register, handling any architectural |
| 147 | * side effects due to writing that register. |
| 148 | */ |
| 149 | virtual void setMiscReg(int misc_reg, const MiscReg &val) = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 150 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 151 | /** @} */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 152 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 153 | /** |
| 154 | * @{ |
| 155 | * @name PC Control |
| 156 | */ |
| 157 | virtual PCState pcState() const = 0; |
| 158 | virtual void pcState(const PCState &val) = 0; |
| 159 | /** @} */ |
| 160 | |
| 161 | /** |
| 162 | * @{ |
| 163 | * @name Memory Interface |
| 164 | */ |
| 165 | /** |
| 166 | * Record the effective address of the instruction. |
| 167 | * |
| 168 | * @note Only valid for memory ops. |
| 169 | */ |
| 170 | virtual void setEA(Addr EA) = 0; |
| 171 | /** |
| 172 | * Get the effective address of the instruction. |
| 173 | * |
| 174 | * @note Only valid for memory ops. |
| 175 | */ |
| 176 | virtual Addr getEA() const = 0; |
| 177 | |
Steve Reinhardt | 1b6355c | 2016-01-17 18:27:46 -0800 | [diff] [blame] | 178 | /** |
| 179 | * Perform an atomic memory read operation. Must be overridden |
| 180 | * for exec contexts that support atomic memory mode. Not pure |
| 181 | * virtual since exec contexts that only support timing memory |
| 182 | * mode need not override (though in that case this function |
| 183 | * should never be called). |
| 184 | */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 185 | virtual Fault readMem(Addr addr, uint8_t *data, unsigned int size, |
Nikos Nikoleris | 698767e | 2016-08-15 12:00:35 +0100 | [diff] [blame^] | 186 | Request::Flags flags) |
Steve Reinhardt | 1b6355c | 2016-01-17 18:27:46 -0800 | [diff] [blame] | 187 | { |
| 188 | panic("ExecContext::readMem() should be overridden\n"); |
| 189 | } |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 190 | |
Steve Reinhardt | 1b6355c | 2016-01-17 18:27:46 -0800 | [diff] [blame] | 191 | /** |
| 192 | * Initiate a timing memory read operation. Must be overridden |
| 193 | * for exec contexts that support timing memory mode. Not pure |
| 194 | * virtual since exec contexts that only support atomic memory |
| 195 | * mode need not override (though in that case this function |
| 196 | * should never be called). |
| 197 | */ |
| 198 | virtual Fault initiateMemRead(Addr addr, unsigned int size, |
Nikos Nikoleris | 698767e | 2016-08-15 12:00:35 +0100 | [diff] [blame^] | 199 | Request::Flags flags) |
Steve Reinhardt | 1b6355c | 2016-01-17 18:27:46 -0800 | [diff] [blame] | 200 | { |
| 201 | panic("ExecContext::initiateMemRead() should be overridden\n"); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * For atomic-mode contexts, perform an atomic memory write operation. |
| 206 | * For timing-mode contexts, initiate a timing memory write operation. |
| 207 | */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 208 | virtual Fault writeMem(uint8_t *data, unsigned int size, Addr addr, |
Nikos Nikoleris | 698767e | 2016-08-15 12:00:35 +0100 | [diff] [blame^] | 209 | Request::Flags flags, uint64_t *res) = 0; |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * Sets the number of consecutive store conditional failures. |
| 213 | */ |
| 214 | virtual void setStCondFailures(unsigned int sc_failures) = 0; |
| 215 | |
| 216 | /** |
| 217 | * Returns the number of consecutive store conditional failures. |
| 218 | */ |
| 219 | virtual unsigned int readStCondFailures() const = 0; |
| 220 | |
| 221 | /** @} */ |
| 222 | |
| 223 | /** |
| 224 | * @{ |
| 225 | * @name SysCall Emulation Interfaces |
| 226 | */ |
| 227 | |
| 228 | /** |
| 229 | * Executes a syscall specified by the callnum. |
| 230 | */ |
| 231 | virtual void syscall(int64_t callnum) = 0; |
| 232 | |
| 233 | /** @} */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 234 | |
| 235 | /** Returns a pointer to the ThreadContext. */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 236 | virtual ThreadContext *tcBase() = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 237 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 238 | /** |
| 239 | * @{ |
| 240 | * @name Alpha-Specific Interfaces |
| 241 | */ |
Gabe Black | aa8c6e9 | 2010-08-13 06:16:02 -0700 | [diff] [blame] | 242 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 243 | /** |
| 244 | * Somewhat Alpha-specific function that handles returning from an |
| 245 | * error or interrupt. |
| 246 | */ |
| 247 | virtual Fault hwrei() = 0; |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 248 | |
| 249 | /** |
| 250 | * Check for special simulator handling of specific PAL calls. If |
| 251 | * return value is false, actual PAL call will be suppressed. |
| 252 | */ |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 253 | virtual bool simPalCheck(int palFunc) = 0; |
Gabe Black | 1268e0d | 2011-11-01 04:01:13 -0700 | [diff] [blame] | 254 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 255 | /** @} */ |
Timothy M. Jones | 7fe9f92 | 2010-02-12 19:53:19 +0000 | [diff] [blame] | 256 | |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 257 | /** |
| 258 | * @{ |
| 259 | * @name ARM-Specific Interfaces |
| 260 | */ |
| 261 | |
| 262 | virtual bool readPredicate() = 0; |
| 263 | virtual void setPredicate(bool val) = 0; |
| 264 | |
| 265 | /** @} */ |
| 266 | |
| 267 | /** |
| 268 | * @{ |
| 269 | * @name X86-Specific Interfaces |
| 270 | */ |
| 271 | |
| 272 | /** |
| 273 | * Invalidate a page in the DTLB <i>and</i> ITLB. |
| 274 | */ |
| 275 | virtual void demapPage(Addr vaddr, uint64_t asn) = 0; |
Marc Orr | bf80734 | 2014-11-06 05:42:22 -0600 | [diff] [blame] | 276 | virtual void armMonitor(Addr address) = 0; |
| 277 | virtual bool mwait(PacketPtr pkt) = 0; |
| 278 | virtual void mwaitAtomic(ThreadContext *tc) = 0; |
| 279 | virtual AddressMonitor *getAddrMonitor() = 0; |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 280 | |
| 281 | /** @} */ |
| 282 | |
| 283 | /** |
| 284 | * @{ |
| 285 | * @name MIPS-Specific Interfaces |
| 286 | */ |
| 287 | |
| 288 | #if THE_ISA == MIPS_ISA |
| 289 | virtual MiscReg readRegOtherThread(int regIdx, |
| 290 | ThreadID tid = InvalidThreadID) = 0; |
| 291 | virtual void setRegOtherThread(int regIdx, MiscReg val, |
| 292 | ThreadID tid = InvalidThreadID) = 0; |
| 293 | #endif |
| 294 | |
| 295 | /** @} */ |
Kevin Lim | def9ea3 | 2006-06-16 17:19:36 -0400 | [diff] [blame] | 296 | }; |
Andreas Sandberg | 326662b | 2014-09-03 07:42:22 -0400 | [diff] [blame] | 297 | |
| 298 | #endif // __CPU_EXEC_CONTEXT_HH__ |