2 * Copyright (c) 2011-2014 ARM Limited
3 * Copyright (c) 2013 Advanced Micro Devices, Inc.
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
15 * Copyright (c) 2002-2005 The Regents of The University of Michigan
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.
41 * Authors: Steve Reinhardt
50 * ExecContext bears the exec_context interface for Minor.
53 #ifndef __CPU_MINOR_EXEC_CONTEXT_HH__
54 #define __CPU_MINOR_EXEC_CONTEXT_HH__
56 #include "cpu/exec_context.hh"
57 #include "cpu/minor/execute.hh"
58 #include "cpu/minor/pipeline.hh"
59 #include "cpu/base.hh"
60 #include "cpu/simple_thread.hh"
61 #include "mem/request.hh"
62 #include "debug/MinorExecute.hh"
67 /* Forward declaration of Execute */
70 /** ExecContext bears the exec_context interface for Minor. This nicely
71 * separates that interface from other classes such as Pipeline, MinorCPU
72 * and DynMinorInst and makes it easier to see what state is accessed by it.
74 class ExecContext : public ::ExecContext
79 /** ThreadState object, provides all the architectural state. */
82 /** The execute stage so we can peek at its contents. */
85 /** Instruction for the benefit of memory operations and for PC */
90 SimpleThread &thread_, Execute &execute_,
91 MinorDynInstPtr inst_) :
97 DPRINTF(MinorExecute, "ExecContext setting PC: %s\n", inst->pc);
100 thread.setIntReg(TheISA::ZeroReg, 0);
101 #if THE_ISA == ALPHA_ISA
102 thread.setFloatReg(TheISA::ZeroReg, 0.0);
107 initiateMemRead(Addr addr, unsigned int size,
108 Request::Flags flags) override
110 execute.getLSQ().pushRequest(inst, true /* load */, nullptr,
111 size, addr, flags, NULL);
116 writeMem(uint8_t *data, unsigned int size, Addr addr,
117 Request::Flags flags, uint64_t *res) override
119 execute.getLSQ().pushRequest(inst, false /* store */, data,
120 size, addr, flags, res);
125 readIntRegOperand(const StaticInst *si, int idx) override
127 return thread.readIntReg(si->srcRegIdx(idx));
131 readFloatRegOperand(const StaticInst *si, int idx) override
133 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base;
134 return thread.readFloatReg(reg_idx);
138 readFloatRegOperandBits(const StaticInst *si, int idx) override
140 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base;
141 return thread.readFloatRegBits(reg_idx);
145 setIntRegOperand(const StaticInst *si, int idx, IntReg val) override
147 thread.setIntReg(si->destRegIdx(idx), val);
151 setFloatRegOperand(const StaticInst *si, int idx,
152 TheISA::FloatReg val) override
154 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base;
155 thread.setFloatReg(reg_idx, val);
159 setFloatRegOperandBits(const StaticInst *si, int idx,
160 TheISA::FloatRegBits val) override
162 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base;
163 thread.setFloatRegBits(reg_idx, val);
167 readPredicate() override
169 return thread.readPredicate();
173 setPredicate(bool val) override
175 thread.setPredicate(val);
179 pcState() const override
181 return thread.pcState();
185 pcState(const TheISA::PCState &val) override
191 readMiscRegNoEffect(int misc_reg) const
193 return thread.readMiscRegNoEffect(misc_reg);
197 readMiscReg(int misc_reg) override
199 return thread.readMiscReg(misc_reg);
203 setMiscReg(int misc_reg, const TheISA::MiscReg &val) override
205 thread.setMiscReg(misc_reg, val);
209 readMiscRegOperand(const StaticInst *si, int idx) override
211 int reg_idx = si->srcRegIdx(idx) - TheISA::Misc_Reg_Base;
212 return thread.readMiscReg(reg_idx);
216 setMiscRegOperand(const StaticInst *si, int idx,
217 const TheISA::MiscReg &val) override
219 int reg_idx = si->destRegIdx(idx) - TheISA::Misc_Reg_Base;
220 return thread.setMiscReg(reg_idx, val);
226 #if THE_ISA == ALPHA_ISA
227 return thread.hwrei();
234 simPalCheck(int palFunc) override
236 #if THE_ISA == ALPHA_ISA
237 return thread.simPalCheck(palFunc);
244 syscall(int64_t callnum) override
247 panic("Syscall emulation isn't available in FS mode.\n");
249 thread.syscall(callnum);
252 ThreadContext *tcBase() override { return thread.getTC(); }
254 /* @todo, should make stCondFailures persistent somewhere */
255 unsigned int readStCondFailures() const override { return 0; }
256 void setStCondFailures(unsigned int st_cond_failures) override {}
258 ContextID contextId() { return thread.contextId(); }
259 /* ISA-specific (or at least currently ISA singleton) functions */
261 /* X86: TLB twiddling */
263 demapPage(Addr vaddr, uint64_t asn) override
265 thread.getITBPtr()->demapPage(vaddr, asn);
266 thread.getDTBPtr()->demapPage(vaddr, asn);
270 readCCRegOperand(const StaticInst *si, int idx) override
272 int reg_idx = si->srcRegIdx(idx) - TheISA::CC_Reg_Base;
273 return thread.readCCReg(reg_idx);
277 setCCRegOperand(const StaticInst *si, int idx, TheISA::CCReg val) override
279 int reg_idx = si->destRegIdx(idx) - TheISA::CC_Reg_Base;
280 thread.setCCReg(reg_idx, val);
284 demapInstPage(Addr vaddr, uint64_t asn)
286 thread.getITBPtr()->demapPage(vaddr, asn);
290 demapDataPage(Addr vaddr, uint64_t asn)
292 thread.getDTBPtr()->demapPage(vaddr, asn);
295 /* ALPHA/POWER: Effective address storage */
296 void setEA(Addr ea) override
301 BaseCPU *getCpuPtr() { return &cpu; }
303 /* POWER: Effective address storage */
304 Addr getEA() const override
309 /* MIPS: other thread register reading/writing */
311 readRegOtherThread(int idx, ThreadID tid = InvalidThreadID)
313 SimpleThread *other_thread = (tid == InvalidThreadID
314 ? &thread : cpu.threads[tid]);
316 if (idx < TheISA::FP_Reg_Base) { /* Integer */
317 return other_thread->readIntReg(idx);
318 } else if (idx < TheISA::Misc_Reg_Base) { /* Float */
319 return other_thread->readFloatRegBits(idx
320 - TheISA::FP_Reg_Base);
322 return other_thread->readMiscReg(idx
323 - TheISA::Misc_Reg_Base);
328 setRegOtherThread(int idx, const TheISA::MiscReg &val,
329 ThreadID tid = InvalidThreadID)
331 SimpleThread *other_thread = (tid == InvalidThreadID
332 ? &thread : cpu.threads[tid]);
334 if (idx < TheISA::FP_Reg_Base) { /* Integer */
335 return other_thread->setIntReg(idx, val);
336 } else if (idx < TheISA::Misc_Reg_Base) { /* Float */
337 return other_thread->setFloatRegBits(idx
338 - TheISA::FP_Reg_Base, val);
340 return other_thread->setMiscReg(idx
341 - TheISA::Misc_Reg_Base, val);
346 // monitor/mwait funtions
347 void armMonitor(Addr address) override
348 { getCpuPtr()->armMonitor(inst->id.threadId, address); }
350 bool mwait(PacketPtr pkt) override
351 { return getCpuPtr()->mwait(inst->id.threadId, pkt); }
353 void mwaitAtomic(ThreadContext *tc) override
354 { return getCpuPtr()->mwaitAtomic(inst->id.threadId, tc, thread.dtb); }
356 AddressMonitor *getAddrMonitor() override
357 { return getCpuPtr()->getCpuAddrMonitor(inst->id.threadId); }
362 #endif /* __CPU_MINOR_EXEC_CONTEXT_HH__ */