Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 1 | /* |
Geoffrey Blake | af6aaf2 | 2012-01-31 07:46:03 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011 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 | 20eced3 | 2006-03-05 00:34:54 -0500 | [diff] [blame] | 14 | * Copyright (c) 2001-2006 The Regents of The University of Michigan |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 15 | * All rights reserved. |
| 16 | * |
| 17 | * Redistribution and use in source and binary forms, with or without |
| 18 | * modification, are permitted provided that the following conditions are |
| 19 | * met: redistributions of source code must retain the above copyright |
| 20 | * notice, this list of conditions and the following disclaimer; |
| 21 | * redistributions in binary form must reproduce the above copyright |
| 22 | * notice, this list of conditions and the following disclaimer in the |
| 23 | * documentation and/or other materials provided with the distribution; |
| 24 | * neither the name of the copyright holders nor the names of its |
| 25 | * contributors may be used to endorse or promote products derived from |
| 26 | * this software without specific prior written permission. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 29 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 30 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 31 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 32 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 33 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 34 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 35 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 36 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Ali Saidi | cb0cf2d | 2006-05-31 19:26:56 -0400 | [diff] [blame] | 39 | * |
| 40 | * Authors: Steve Reinhardt |
| 41 | * Nathan Binkert |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 42 | */ |
| 43 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 44 | #ifndef __CPU_SIMPLE_THREAD_HH__ |
| 45 | #define __CPU_SIMPLE_THREAD_HH__ |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 46 | |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 47 | #include "arch/isa.hh" |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 48 | #include "arch/isa_traits.hh" |
Gabe Black | b398b8f | 2009-07-08 23:02:21 -0700 | [diff] [blame] | 49 | #include "arch/registers.hh" |
Gabe Black | 537239b | 2007-08-26 20:24:18 -0700 | [diff] [blame] | 50 | #include "arch/tlb.hh" |
Gabe Black | a480ba0 | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 51 | #include "arch/types.hh" |
Nathan Binkert | 8d2e51c | 2009-05-17 14:34:52 -0700 | [diff] [blame] | 52 | #include "base/types.hh" |
Nathan Binkert | d9f39c8 | 2009-09-23 08:34:21 -0700 | [diff] [blame] | 53 | #include "config/the_isa.hh" |
Gabe Black | b7b545b | 2011-09-09 02:30:01 -0700 | [diff] [blame] | 54 | #include "cpu/decode.hh" |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 55 | #include "cpu/thread_context.hh" |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 56 | #include "cpu/thread_state.hh" |
Nathan Binkert | eddac53 | 2011-04-15 10:44:32 -0700 | [diff] [blame] | 57 | #include "debug/FloatRegs.hh" |
| 58 | #include "debug/IntRegs.hh" |
Gabe Black | 8ad2b8c | 2011-10-31 02:58:22 -0700 | [diff] [blame] | 59 | #include "mem/page_table.hh" |
Gabe Black | 872bbdf | 2006-03-09 18:35:28 -0500 | [diff] [blame] | 60 | #include "mem/request.hh" |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 61 | #include "sim/byteswap.hh" |
Kevin Lim | 20eced3 | 2006-03-05 00:34:54 -0500 | [diff] [blame] | 62 | #include "sim/eventq.hh" |
Gabe Black | 8ad2b8c | 2011-10-31 02:58:22 -0700 | [diff] [blame] | 63 | #include "sim/process.hh" |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 64 | #include "sim/serialize.hh" |
Gabe Black | 8ad2b8c | 2011-10-31 02:58:22 -0700 | [diff] [blame] | 65 | #include "sim/system.hh" |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 66 | |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 67 | class BaseCPU; |
Geoffrey Blake | 043709f | 2012-03-09 09:59:27 -0500 | [diff] [blame] | 68 | class CheckerCPU; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 69 | |
| 70 | class FunctionProfile; |
| 71 | class ProfileNode; |
Ali Saidi | bb80f71 | 2006-04-06 00:51:46 -0400 | [diff] [blame] | 72 | |
Gabe Black | 4bfb854 | 2006-11-07 05:36:54 -0500 | [diff] [blame] | 73 | namespace TheISA { |
| 74 | namespace Kernel { |
| 75 | class Statistics; |
Andreas Hansson | 7253829 | 2012-03-19 06:36:09 -0400 | [diff] [blame^] | 76 | } |
| 77 | } |
Kevin Lim | 4a5b51b | 2006-05-30 14:17:41 -0400 | [diff] [blame] | 78 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 79 | /** |
| 80 | * The SimpleThread object provides a combination of the ThreadState |
| 81 | * object and the ThreadContext interface. It implements the |
| 82 | * ThreadContext interface so that a ProxyThreadContext class can be |
| 83 | * made using SimpleThread as the template parameter (see |
| 84 | * thread_context.hh). It adds to the ThreadState object by adding all |
| 85 | * the objects needed for simple functional execution, including a |
| 86 | * simple architectural register file, and pointers to the ITB and DTB |
| 87 | * in full system mode. For CPU models that do not need more advanced |
| 88 | * ways to hold state (i.e. a separate physical register file, or |
| 89 | * separate fetch and commit PC's), this SimpleThread class provides |
| 90 | * all the necessary state for full architecture-level functional |
| 91 | * simulation. See the AtomicSimpleCPU or TimingSimpleCPU for |
| 92 | * examples. |
| 93 | */ |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 94 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 95 | class SimpleThread : public ThreadState |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 96 | { |
| 97 | protected: |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 98 | typedef TheISA::MachInst MachInst; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 99 | typedef TheISA::MiscReg MiscReg; |
Gabe Black | 8e4ec55 | 2006-03-14 15:55:00 -0500 | [diff] [blame] | 100 | typedef TheISA::FloatReg FloatReg; |
| 101 | typedef TheISA::FloatRegBits FloatRegBits; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 102 | public: |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 103 | typedef ThreadContext::Status Status; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 104 | |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 105 | protected: |
Gabe Black | 0cb180e | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 106 | union { |
| 107 | FloatReg f[TheISA::NumFloatRegs]; |
| 108 | FloatRegBits i[TheISA::NumFloatRegs]; |
| 109 | } floatRegs; |
Gabe Black | a480ba0 | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 110 | TheISA::IntReg intRegs[TheISA::NumIntRegs]; |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 111 | TheISA::ISA isa; // one "instance" of the current ISA. |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 112 | |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 113 | TheISA::PCState _pcState; |
Gabe Black | 43345bf | 2009-07-08 23:02:21 -0700 | [diff] [blame] | 114 | |
Min Kyu Jeong | 5f91ec3 | 2010-08-23 11:18:40 -0500 | [diff] [blame] | 115 | /** Did this instruction execute or is it predicated false */ |
| 116 | bool predicate; |
| 117 | |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 118 | public: |
Korey Sewell | b2e5152 | 2011-06-19 21:43:33 -0400 | [diff] [blame] | 119 | std::string name() const |
| 120 | { |
Andreas Hansson | 4fdecae | 2012-01-31 11:50:07 -0500 | [diff] [blame] | 121 | return csprintf("%s.[tid:%i]", baseCpu->name(), tc->threadId()); |
Korey Sewell | b2e5152 | 2011-06-19 21:43:33 -0400 | [diff] [blame] | 122 | } |
| 123 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 124 | ProxyThreadContext<SimpleThread> *tc; |
Kevin Lim | 20eced3 | 2006-03-05 00:34:54 -0500 | [diff] [blame] | 125 | |
Gabe Black | 872bbdf | 2006-03-09 18:35:28 -0500 | [diff] [blame] | 126 | System *system; |
| 127 | |
Gabe Black | 7b5a96f | 2009-04-08 22:21:27 -0700 | [diff] [blame] | 128 | TheISA::TLB *itb; |
| 129 | TheISA::TLB *dtb; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 130 | |
Gabe Black | b7b545b | 2011-09-09 02:30:01 -0700 | [diff] [blame] | 131 | Decoder decoder; |
| 132 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 133 | // constructor: initialize SimpleThread from given process structure |
Gabe Black | de21bb9 | 2011-11-18 01:33:28 -0800 | [diff] [blame] | 134 | // FS |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 135 | SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system, |
Gabe Black | 7b5a96f | 2009-04-08 22:21:27 -0700 | [diff] [blame] | 136 | TheISA::TLB *_itb, TheISA::TLB *_dtb, |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 137 | bool use_kernel_stats = true); |
Gabe Black | de21bb9 | 2011-11-18 01:33:28 -0800 | [diff] [blame] | 138 | // SE |
Gabe Black | e80ebc3 | 2012-02-10 02:05:31 -0800 | [diff] [blame] | 139 | SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system, |
| 140 | Process *_process, TheISA::TLB *_itb, TheISA::TLB *_dtb); |
Kevin Lim | e7ccc94 | 2006-07-06 17:53:26 -0400 | [diff] [blame] | 141 | |
Kevin Lim | fff7531 | 2006-07-06 23:13:38 -0400 | [diff] [blame] | 142 | SimpleThread(); |
Kevin Lim | e7ccc94 | 2006-07-06 17:53:26 -0400 | [diff] [blame] | 143 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 144 | virtual ~SimpleThread(); |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 145 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 146 | virtual void takeOverFrom(ThreadContext *oldContext); |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 147 | |
| 148 | void regStats(const std::string &name); |
| 149 | |
Kevin Lim | fff7531 | 2006-07-06 23:13:38 -0400 | [diff] [blame] | 150 | void copyTC(ThreadContext *context); |
| 151 | |
Kevin Lim | e7ccc94 | 2006-07-06 17:53:26 -0400 | [diff] [blame] | 152 | void copyState(ThreadContext *oldContext); |
| 153 | |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 154 | void serialize(std::ostream &os); |
| 155 | void unserialize(Checkpoint *cp, const std::string §ion); |
| 156 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 157 | /*************************************************************** |
| 158 | * SimpleThread functions to provide CPU with access to various |
Gabe Black | 5605079 | 2009-02-25 10:15:44 -0800 | [diff] [blame] | 159 | * state. |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 160 | **************************************************************/ |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 161 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 162 | /** Returns the pointer to this SimpleThread's ThreadContext. Used |
| 163 | * when a ThreadContext must be passed to objects outside of the |
| 164 | * CPU. |
| 165 | */ |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 166 | ThreadContext *getTC() { return tc; } |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 167 | |
Gabe Black | 8b4796a | 2008-02-26 23:38:51 -0500 | [diff] [blame] | 168 | void demapPage(Addr vaddr, uint64_t asn) |
| 169 | { |
| 170 | itb->demapPage(vaddr, asn); |
| 171 | dtb->demapPage(vaddr, asn); |
| 172 | } |
| 173 | |
| 174 | void demapInstPage(Addr vaddr, uint64_t asn) |
| 175 | { |
| 176 | itb->demapPage(vaddr, asn); |
| 177 | } |
| 178 | |
| 179 | void demapDataPage(Addr vaddr, uint64_t asn) |
| 180 | { |
| 181 | dtb->demapPage(vaddr, asn); |
| 182 | } |
| 183 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 184 | void dumpFuncProfile(); |
Ali Saidi | bb80f71 | 2006-04-06 00:51:46 -0400 | [diff] [blame] | 185 | |
Ali Saidi | b760b99 | 2008-10-20 16:22:59 -0400 | [diff] [blame] | 186 | Fault hwrei(); |
| 187 | |
| 188 | bool simPalCheck(int palFunc); |
| 189 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 190 | /******************************************* |
| 191 | * ThreadContext interface functions. |
| 192 | ******************************************/ |
| 193 | |
Andreas Hansson | 4fdecae | 2012-01-31 11:50:07 -0500 | [diff] [blame] | 194 | BaseCPU *getCpuPtr() { return baseCpu; } |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 195 | |
Gabe Black | 7b5a96f | 2009-04-08 22:21:27 -0700 | [diff] [blame] | 196 | TheISA::TLB *getITBPtr() { return itb; } |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 197 | |
Gabe Black | 7b5a96f | 2009-04-08 22:21:27 -0700 | [diff] [blame] | 198 | TheISA::TLB *getDTBPtr() { return dtb; } |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 199 | |
Geoffrey Blake | 043709f | 2012-03-09 09:59:27 -0500 | [diff] [blame] | 200 | CheckerCPU *getCheckerCpuPtr() { return NULL; } |
Geoffrey Blake | af6aaf2 | 2012-01-31 07:46:03 -0800 | [diff] [blame] | 201 | |
Gabe Black | b7b545b | 2011-09-09 02:30:01 -0700 | [diff] [blame] | 202 | Decoder *getDecoderPtr() { return &decoder; } |
| 203 | |
Gabe Black | 537239b | 2007-08-26 20:24:18 -0700 | [diff] [blame] | 204 | System *getSystemPtr() { return system; } |
| 205 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 206 | Status status() const { return _status; } |
| 207 | |
| 208 | void setStatus(Status newStatus) { _status = newStatus; } |
| 209 | |
| 210 | /// Set the status to Active. Optional delay indicates number of |
| 211 | /// cycles to wait before beginning execution. |
| 212 | void activate(int delay = 1); |
| 213 | |
| 214 | /// Set the status to Suspended. |
| 215 | void suspend(); |
| 216 | |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 217 | /// Set the status to Halted. |
| 218 | void halt(); |
| 219 | |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 220 | virtual bool misspeculating(); |
| 221 | |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 222 | void copyArchRegs(ThreadContext *tc); |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 223 | |
Gabe Black | 0cb180e | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 224 | void clearArchRegs() |
| 225 | { |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 226 | _pcState = 0; |
Gabe Black | a480ba0 | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 227 | memset(intRegs, 0, sizeof(intRegs)); |
Gabe Black | 0cb180e | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 228 | memset(floatRegs.i, 0, sizeof(floatRegs.i)); |
Ali Saidi | b8ec214 | 2010-06-02 12:58:16 -0500 | [diff] [blame] | 229 | isa.clear(); |
Gabe Black | 0cb180e | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 230 | } |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 231 | |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 232 | // |
| 233 | // New accessors for new decoder. |
| 234 | // |
| 235 | uint64_t readIntReg(int reg_idx) |
| 236 | { |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 237 | int flatIndex = isa.flattenIntIndex(reg_idx); |
Gabe Black | 1b29f16 | 2009-07-08 23:02:21 -0700 | [diff] [blame] | 238 | assert(flatIndex < TheISA::NumIntRegs); |
Gabe Black | 2871a13 | 2009-07-29 00:15:26 -0700 | [diff] [blame] | 239 | uint64_t regVal = intRegs[flatIndex]; |
Min Kyu Jeong | ad2c3b0 | 2010-08-23 11:18:41 -0500 | [diff] [blame] | 240 | DPRINTF(IntRegs, "Reading int reg %d (%d) as %#x.\n", |
| 241 | reg_idx, flatIndex, regVal); |
Gabe Black | 2871a13 | 2009-07-29 00:15:26 -0700 | [diff] [blame] | 242 | return regVal; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 243 | } |
| 244 | |
Gabe Black | 8e4ec55 | 2006-03-14 15:55:00 -0500 | [diff] [blame] | 245 | FloatReg readFloatReg(int reg_idx) |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 246 | { |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 247 | int flatIndex = isa.flattenFloatIndex(reg_idx); |
Gabe Black | 1b29f16 | 2009-07-08 23:02:21 -0700 | [diff] [blame] | 248 | assert(flatIndex < TheISA::NumFloatRegs); |
Gabe Black | d149e43 | 2010-06-02 12:58:12 -0500 | [diff] [blame] | 249 | FloatReg regVal = floatRegs.f[flatIndex]; |
Min Kyu Jeong | ad2c3b0 | 2010-08-23 11:18:41 -0500 | [diff] [blame] | 250 | DPRINTF(FloatRegs, "Reading float reg %d (%d) as %f, %#x.\n", |
| 251 | reg_idx, flatIndex, regVal, floatRegs.i[flatIndex]); |
Gabe Black | d149e43 | 2010-06-02 12:58:12 -0500 | [diff] [blame] | 252 | return regVal; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 253 | } |
| 254 | |
Gabe Black | 8e4ec55 | 2006-03-14 15:55:00 -0500 | [diff] [blame] | 255 | FloatRegBits readFloatRegBits(int reg_idx) |
| 256 | { |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 257 | int flatIndex = isa.flattenFloatIndex(reg_idx); |
Gabe Black | 1b29f16 | 2009-07-08 23:02:21 -0700 | [diff] [blame] | 258 | assert(flatIndex < TheISA::NumFloatRegs); |
Gabe Black | d149e43 | 2010-06-02 12:58:12 -0500 | [diff] [blame] | 259 | FloatRegBits regVal = floatRegs.i[flatIndex]; |
Min Kyu Jeong | ad2c3b0 | 2010-08-23 11:18:41 -0500 | [diff] [blame] | 260 | DPRINTF(FloatRegs, "Reading float reg %d (%d) bits as %#x, %f.\n", |
| 261 | reg_idx, flatIndex, regVal, floatRegs.f[flatIndex]); |
Gabe Black | d149e43 | 2010-06-02 12:58:12 -0500 | [diff] [blame] | 262 | return regVal; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | void setIntReg(int reg_idx, uint64_t val) |
| 266 | { |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 267 | int flatIndex = isa.flattenIntIndex(reg_idx); |
Gabe Black | 1b29f16 | 2009-07-08 23:02:21 -0700 | [diff] [blame] | 268 | assert(flatIndex < TheISA::NumIntRegs); |
Min Kyu Jeong | ad2c3b0 | 2010-08-23 11:18:41 -0500 | [diff] [blame] | 269 | DPRINTF(IntRegs, "Setting int reg %d (%d) to %#x.\n", |
| 270 | reg_idx, flatIndex, val); |
Gabe Black | a480ba0 | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 271 | intRegs[flatIndex] = val; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 272 | } |
| 273 | |
Gabe Black | 8e4ec55 | 2006-03-14 15:55:00 -0500 | [diff] [blame] | 274 | void setFloatReg(int reg_idx, FloatReg val) |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 275 | { |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 276 | int flatIndex = isa.flattenFloatIndex(reg_idx); |
Gabe Black | 1b29f16 | 2009-07-08 23:02:21 -0700 | [diff] [blame] | 277 | assert(flatIndex < TheISA::NumFloatRegs); |
Gabe Black | 0cb180e | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 278 | floatRegs.f[flatIndex] = val; |
Min Kyu Jeong | ad2c3b0 | 2010-08-23 11:18:41 -0500 | [diff] [blame] | 279 | DPRINTF(FloatRegs, "Setting float reg %d (%d) to %f, %#x.\n", |
| 280 | reg_idx, flatIndex, val, floatRegs.i[flatIndex]); |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 281 | } |
| 282 | |
Gabe Black | 8e4ec55 | 2006-03-14 15:55:00 -0500 | [diff] [blame] | 283 | void setFloatRegBits(int reg_idx, FloatRegBits val) |
| 284 | { |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 285 | int flatIndex = isa.flattenFloatIndex(reg_idx); |
Gabe Black | 1b29f16 | 2009-07-08 23:02:21 -0700 | [diff] [blame] | 286 | assert(flatIndex < TheISA::NumFloatRegs); |
Geoffrey Blake | af6aaf2 | 2012-01-31 07:46:03 -0800 | [diff] [blame] | 287 | // XXX: Fix array out of bounds compiler error for gem5.fast |
| 288 | // when checkercpu enabled |
| 289 | if (flatIndex < TheISA::NumFloatRegs) |
| 290 | floatRegs.i[flatIndex] = val; |
Min Kyu Jeong | ad2c3b0 | 2010-08-23 11:18:41 -0500 | [diff] [blame] | 291 | DPRINTF(FloatRegs, "Setting float reg %d (%d) bits to %#x, %#f.\n", |
| 292 | reg_idx, flatIndex, val, floatRegs.f[flatIndex]); |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 293 | } |
| 294 | |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 295 | TheISA::PCState |
| 296 | pcState() |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 297 | { |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 298 | return _pcState; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 299 | } |
| 300 | |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 301 | void |
| 302 | pcState(const TheISA::PCState &val) |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 303 | { |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 304 | _pcState = val; |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 305 | } |
| 306 | |
Geoffrey Blake | af6aaf2 | 2012-01-31 07:46:03 -0800 | [diff] [blame] | 307 | void |
| 308 | pcStateNoRecord(const TheISA::PCState &val) |
| 309 | { |
| 310 | _pcState = val; |
| 311 | } |
Geoffrey Blake | af6aaf2 | 2012-01-31 07:46:03 -0800 | [diff] [blame] | 312 | |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 313 | Addr |
| 314 | instAddr() |
Gabe Black | 333a7c4 | 2006-10-15 21:04:14 -0400 | [diff] [blame] | 315 | { |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 316 | return _pcState.instAddr(); |
Gabe Black | 333a7c4 | 2006-10-15 21:04:14 -0400 | [diff] [blame] | 317 | } |
| 318 | |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 319 | Addr |
| 320 | nextInstAddr() |
Gabe Black | 333a7c4 | 2006-10-15 21:04:14 -0400 | [diff] [blame] | 321 | { |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 322 | return _pcState.nextInstAddr(); |
Gabe Black | 333a7c4 | 2006-10-15 21:04:14 -0400 | [diff] [blame] | 323 | } |
| 324 | |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 325 | MicroPC |
| 326 | microPC() |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 327 | { |
Gabe Black | 6f4bd2c | 2010-10-31 00:07:20 -0700 | [diff] [blame] | 328 | return _pcState.microPC(); |
Gabe Black | 91545ac | 2006-03-09 15:15:55 -0500 | [diff] [blame] | 329 | } |
| 330 | |
Min Kyu Jeong | 5f91ec3 | 2010-08-23 11:18:40 -0500 | [diff] [blame] | 331 | bool readPredicate() |
| 332 | { |
| 333 | return predicate; |
| 334 | } |
| 335 | |
| 336 | void setPredicate(bool val) |
| 337 | { |
| 338 | predicate = val; |
| 339 | } |
| 340 | |
Nathan Binkert | 47877cf | 2009-05-26 09:23:13 -0700 | [diff] [blame] | 341 | MiscReg |
| 342 | readMiscRegNoEffect(int misc_reg, ThreadID tid = 0) |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 343 | { |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 344 | return isa.readMiscRegNoEffect(misc_reg); |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 345 | } |
| 346 | |
Nathan Binkert | 47877cf | 2009-05-26 09:23:13 -0700 | [diff] [blame] | 347 | MiscReg |
| 348 | readMiscReg(int misc_reg, ThreadID tid = 0) |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 349 | { |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 350 | return isa.readMiscReg(misc_reg, tc); |
Ali Saidi | 689cab3 | 2007-03-07 15:04:31 -0500 | [diff] [blame] | 351 | } |
| 352 | |
Nathan Binkert | 47877cf | 2009-05-26 09:23:13 -0700 | [diff] [blame] | 353 | void |
| 354 | setMiscRegNoEffect(int misc_reg, const MiscReg &val, ThreadID tid = 0) |
Ali Saidi | 689cab3 | 2007-03-07 15:04:31 -0500 | [diff] [blame] | 355 | { |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 356 | return isa.setMiscRegNoEffect(misc_reg, val); |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 357 | } |
| 358 | |
Nathan Binkert | 47877cf | 2009-05-26 09:23:13 -0700 | [diff] [blame] | 359 | void |
| 360 | setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid = 0) |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 361 | { |
Gabe Black | 32daf6f | 2009-07-08 23:02:20 -0700 | [diff] [blame] | 362 | return isa.setMiscReg(misc_reg, val, tc); |
| 363 | } |
| 364 | |
| 365 | int |
| 366 | flattenIntIndex(int reg) |
| 367 | { |
| 368 | return isa.flattenIntIndex(reg); |
| 369 | } |
| 370 | |
| 371 | int |
| 372 | flattenFloatIndex(int reg) |
| 373 | { |
| 374 | return isa.flattenFloatIndex(reg); |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | unsigned readStCondFailures() { return storeCondFailures; } |
| 378 | |
| 379 | void setStCondFailures(unsigned sc_failures) |
| 380 | { storeCondFailures = sc_failures; } |
| 381 | |
Gabe Black | 3d99b4a | 2006-04-18 09:27:22 -0400 | [diff] [blame] | 382 | void syscall(int64_t callnum) |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 383 | { |
Kevin Lim | eb0e416 | 2006-06-06 17:32:21 -0400 | [diff] [blame] | 384 | process->syscall(callnum, tc); |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 385 | } |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | |
| 389 | // for non-speculative execution context, spec_mode is always false |
| 390 | inline bool |
Kevin Lim | 54d4220 | 2006-06-07 15:29:53 -0400 | [diff] [blame] | 391 | SimpleThread::misspeculating() |
Kevin Lim | f15e492 | 2006-03-04 15:18:40 -0500 | [diff] [blame] | 392 | { |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | #endif // __CPU_CPU_EXEC_CONTEXT_HH__ |