thread_context.hh revision 2350
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __CPU_CHECKER_EXEC_CONTEXT_HH__
30#define __CPU_CHECKER_EXEC_CONTEXT_HH__
31
32#include "cpu/checker/cpu.hh"
33#include "cpu/cpu_exec_context.hh"
34#include "cpu/exec_context.hh"
35
36class EndQuiesceEvent;
37namespace Kernel {
38    class Statistics;
39};
40
41/**
42 * Derived ExecContext class for use with the Checker.  The template
43 * parameter is the ExecContext class used by the specific CPU being
44 * verified.  This CheckerExecContext is then used by the main CPU in
45 * place of its usual ExecContext class.  It handles updating the
46 * checker's state any time state is updated through the ExecContext.
47 */
48template <class XC>
49class CheckerExecContext : public ExecContext
50{
51  public:
52    CheckerExecContext(XC *actual_xc,
53                       CheckerCPU *checker_cpu)
54        : actualXC(actual_xc), checkerXC(checker_cpu->cpuXC),
55          checkerCPU(checker_cpu)
56    { }
57
58  private:
59    XC *actualXC;
60    CPUExecContext *checkerXC;
61    CheckerCPU *checkerCPU;
62
63  public:
64
65    BaseCPU *getCpuPtr() { return actualXC->getCpuPtr(); }
66
67    void setCpuId(int id)
68    {
69        actualXC->setCpuId(id);
70        checkerXC->setCpuId(id);
71    }
72
73    int readCpuId() { return actualXC->readCpuId(); }
74
75    FunctionalMemory *getMemPtr() { return actualXC->getMemPtr(); }
76
77#if FULL_SYSTEM
78    System *getSystemPtr() { return actualXC->getSystemPtr(); }
79
80    PhysicalMemory *getPhysMemPtr() { return actualXC->getPhysMemPtr(); }
81
82    AlphaITB *getITBPtr() { return actualXC->getITBPtr(); }
83
84    AlphaDTB *getDTBPtr() { return actualXC->getDTBPtr(); }
85
86    Kernel::Statistics *getKernelStats() { return actualXC->getKernelStats(); }
87#else
88    Process *getProcessPtr() { return actualXC->getProcessPtr(); }
89#endif
90
91    Status status() const { return actualXC->status(); }
92
93    void setStatus(Status new_status)
94    {
95        actualXC->setStatus(new_status);
96        checkerXC->setStatus(new_status);
97    }
98
99    /// Set the status to Active.  Optional delay indicates number of
100    /// cycles to wait before beginning execution.
101    void activate(int delay = 1) { actualXC->activate(delay); }
102
103    /// Set the status to Suspended.
104    void suspend() { actualXC->suspend(); }
105
106    /// Set the status to Unallocated.
107    void deallocate() { actualXC->deallocate(); }
108
109    /// Set the status to Halted.
110    void halt() { actualXC->halt(); }
111
112#if FULL_SYSTEM
113    void dumpFuncProfile() { actualXC->dumpFuncProfile(); }
114#endif
115
116    void takeOverFrom(ExecContext *oldContext)
117    {
118        actualXC->takeOverFrom(oldContext);
119        checkerXC->takeOverFrom(oldContext);
120    }
121
122    void regStats(const std::string &name) { actualXC->regStats(name); }
123
124    void serialize(std::ostream &os) { actualXC->serialize(os); }
125    void unserialize(Checkpoint *cp, const std::string &section)
126    { actualXC->unserialize(cp, section); }
127
128#if FULL_SYSTEM
129    EndQuiesceEvent *getQuiesceEvent() { return actualXC->getQuiesceEvent(); }
130
131    Tick readLastActivate() { return actualXC->readLastActivate(); }
132    Tick readLastSuspend() { return actualXC->readLastSuspend(); }
133
134    void profileClear() { return actualXC->profileClear(); }
135    void profileSample() { return actualXC->profileSample(); }
136#endif
137
138    int getThreadNum() { return actualXC->getThreadNum(); }
139
140    // @todo: Do I need this?
141    MachInst getInst() { return actualXC->getInst(); }
142
143    // @todo: Do I need this?
144    void copyArchRegs(ExecContext *xc)
145    {
146        actualXC->copyArchRegs(xc);
147        checkerXC->copyArchRegs(xc);
148    }
149
150    void clearArchRegs()
151    {
152        actualXC->clearArchRegs();
153        checkerXC->clearArchRegs();
154    }
155
156    //
157    // New accessors for new decoder.
158    //
159    uint64_t readIntReg(int reg_idx)
160    { return actualXC->readIntReg(reg_idx); }
161
162    float readFloatRegSingle(int reg_idx)
163    { return actualXC->readFloatRegSingle(reg_idx); }
164
165    double readFloatRegDouble(int reg_idx)
166    { return actualXC->readFloatRegDouble(reg_idx); }
167
168    uint64_t readFloatRegInt(int reg_idx)
169    { return actualXC->readFloatRegInt(reg_idx); }
170
171    void setIntReg(int reg_idx, uint64_t val)
172    {
173        actualXC->setIntReg(reg_idx, val);
174        checkerXC->setIntReg(reg_idx, val);
175    }
176
177    void setFloatRegSingle(int reg_idx, float val)
178    {
179        actualXC->setFloatRegSingle(reg_idx, val);
180        checkerXC->setFloatRegSingle(reg_idx, val);
181    }
182
183    void setFloatRegDouble(int reg_idx, double val)
184    {
185        actualXC->setFloatRegDouble(reg_idx, val);
186        checkerXC->setFloatRegSingle(reg_idx, val);
187    }
188
189    void setFloatRegInt(int reg_idx, uint64_t val)
190    {
191        actualXC->setFloatRegInt(reg_idx, val);
192        checkerXC->setFloatRegInt(reg_idx, val);
193    }
194
195    uint64_t readPC() { return actualXC->readPC(); }
196
197    void setPC(uint64_t val)
198    {
199        actualXC->setPC(val);
200        checkerXC->setPC(val);
201        checkerCPU->recordPCChange(val);
202    }
203
204    uint64_t readNextPC() { return actualXC->readNextPC(); }
205
206    void setNextPC(uint64_t val)
207    {
208        actualXC->setNextPC(val);
209        checkerXC->setNextPC(val);
210        checkerCPU->recordNextPCChange(val);
211    }
212
213    MiscReg readMiscReg(int misc_reg)
214    { return actualXC->readMiscReg(misc_reg); }
215
216    MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault)
217    { return actualXC->readMiscRegWithEffect(misc_reg, fault); }
218
219    Fault setMiscReg(int misc_reg, const MiscReg &val)
220    {
221        checkerXC->setMiscReg(misc_reg, val);
222        return actualXC->setMiscReg(misc_reg, val);
223    }
224
225    Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val)
226    {
227        checkerXC->setMiscRegWithEffect(misc_reg, val);
228        return actualXC->setMiscRegWithEffect(misc_reg, val);
229    }
230
231    unsigned readStCondFailures()
232    { return actualXC->readStCondFailures(); }
233
234    void setStCondFailures(unsigned sc_failures)
235    {
236        checkerXC->setStCondFailures(sc_failures);
237        actualXC->setStCondFailures(sc_failures);
238    }
239#if FULL_SYSTEM
240    bool inPalMode() { return actualXC->inPalMode(); }
241#endif
242
243    // @todo: Fix this!
244    bool misspeculating() { return actualXC->misspeculating(); }
245
246#if !FULL_SYSTEM
247    IntReg getSyscallArg(int i) { return actualXC->getSyscallArg(i); }
248
249    // used to shift args for indirect syscall
250    void setSyscallArg(int i, IntReg val)
251    {
252        checkerXC->setSyscallArg(i, val);
253        actualXC->setSyscallArg(i, val);
254    }
255
256    void setSyscallReturn(SyscallReturn return_value)
257    {
258        checkerXC->setSyscallReturn(return_value);
259        actualXC->setSyscallReturn(return_value);
260    }
261
262    Counter readFuncExeInst() { return actualXC->readFuncExeInst(); }
263#endif
264};
265
266#endif // __CPU_CHECKER_EXEC_CONTEXT_HH__
267