exec_context.hh revision 13557
112771Sqtt2@cornell.edu/*
212771Sqtt2@cornell.edu * Copyright (c) 2011-2014, 2016 ARM Limited
312771Sqtt2@cornell.edu * Copyright (c) 2013 Advanced Micro Devices, Inc.
412771Sqtt2@cornell.edu * All rights reserved
512771Sqtt2@cornell.edu *
612771Sqtt2@cornell.edu * The license below extends only to copyright in the software and shall
712771Sqtt2@cornell.edu * not be construed as granting a license to any other intellectual
812771Sqtt2@cornell.edu * property including but not limited to intellectual property relating
912771Sqtt2@cornell.edu * to a hardware implementation of the functionality of the software
1012771Sqtt2@cornell.edu * licensed hereunder.  You may use the software subject to the license
1112771Sqtt2@cornell.edu * terms below provided that you ensure that this notice is replicated
1212771Sqtt2@cornell.edu * unmodified and in its entirety in all distributions of the software,
1312771Sqtt2@cornell.edu * modified or unmodified, in source code or in binary form.
1412771Sqtt2@cornell.edu *
1512771Sqtt2@cornell.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan
1612771Sqtt2@cornell.edu * All rights reserved.
1712771Sqtt2@cornell.edu *
1812771Sqtt2@cornell.edu * Redistribution and use in source and binary forms, with or without
1912771Sqtt2@cornell.edu * modification, are permitted provided that the following conditions are
2012771Sqtt2@cornell.edu * met: redistributions of source code must retain the above copyright
2112771Sqtt2@cornell.edu * notice, this list of conditions and the following disclaimer;
2212771Sqtt2@cornell.edu * redistributions in binary form must reproduce the above copyright
2312771Sqtt2@cornell.edu * notice, this list of conditions and the following disclaimer in the
2412771Sqtt2@cornell.edu * documentation and/or other materials provided with the distribution;
2512771Sqtt2@cornell.edu * neither the name of the copyright holders nor the names of its
2612771Sqtt2@cornell.edu * contributors may be used to endorse or promote products derived from
2712771Sqtt2@cornell.edu * this software without specific prior written permission.
2812771Sqtt2@cornell.edu *
2912771Sqtt2@cornell.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3012771Sqtt2@cornell.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3112771Sqtt2@cornell.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3212771Sqtt2@cornell.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3312771Sqtt2@cornell.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3412771Sqtt2@cornell.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3512771Sqtt2@cornell.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3612771Sqtt2@cornell.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3712771Sqtt2@cornell.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3812771Sqtt2@cornell.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3912771Sqtt2@cornell.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4012771Sqtt2@cornell.edu *
4112771Sqtt2@cornell.edu * Authors: Steve Reinhardt
4212771Sqtt2@cornell.edu *          Dave Greene
4312771Sqtt2@cornell.edu *          Nathan Binkert
4412771Sqtt2@cornell.edu *          Andrew Bardsley
4512771Sqtt2@cornell.edu */
4612771Sqtt2@cornell.edu
4712771Sqtt2@cornell.edu/**
4812771Sqtt2@cornell.edu * @file
4912771Sqtt2@cornell.edu *
5012771Sqtt2@cornell.edu *  ExecContext bears the exec_context interface for Minor.
5112771Sqtt2@cornell.edu */
5212771Sqtt2@cornell.edu
5312771Sqtt2@cornell.edu#ifndef __CPU_MINOR_EXEC_CONTEXT_HH__
5412771Sqtt2@cornell.edu#define __CPU_MINOR_EXEC_CONTEXT_HH__
5512771Sqtt2@cornell.edu
5612771Sqtt2@cornell.edu#include "cpu/exec_context.hh"
5712771Sqtt2@cornell.edu#include "cpu/minor/execute.hh"
5812771Sqtt2@cornell.edu#include "cpu/minor/pipeline.hh"
5912771Sqtt2@cornell.edu#include "cpu/base.hh"
6012771Sqtt2@cornell.edu#include "cpu/simple_thread.hh"
6112771Sqtt2@cornell.edu#include "mem/request.hh"
6212771Sqtt2@cornell.edu#include "debug/MinorExecute.hh"
6312771Sqtt2@cornell.edu
6412771Sqtt2@cornell.edunamespace Minor
6512771Sqtt2@cornell.edu{
6612771Sqtt2@cornell.edu
6712771Sqtt2@cornell.edu/* Forward declaration of Execute */
6812771Sqtt2@cornell.educlass Execute;
6912771Sqtt2@cornell.edu
7012771Sqtt2@cornell.edu/** ExecContext bears the exec_context interface for Minor.  This nicely
7112771Sqtt2@cornell.edu *  separates that interface from other classes such as Pipeline, MinorCPU
7212771Sqtt2@cornell.edu *  and DynMinorInst and makes it easier to see what state is accessed by it.
73 */
74class ExecContext : public ::ExecContext
75{
76  public:
77    MinorCPU &cpu;
78
79    /** ThreadState object, provides all the architectural state. */
80    SimpleThread &thread;
81
82    /** The execute stage so we can peek at its contents. */
83    Execute &execute;
84
85    /** Instruction for the benefit of memory operations and for PC */
86    MinorDynInstPtr inst;
87
88    ExecContext (
89        MinorCPU &cpu_,
90        SimpleThread &thread_, Execute &execute_,
91        MinorDynInstPtr inst_) :
92        cpu(cpu_),
93        thread(thread_),
94        execute(execute_),
95        inst(inst_)
96    {
97        DPRINTF(MinorExecute, "ExecContext setting PC: %s\n", inst->pc);
98        pcState(inst->pc);
99        setPredicate(true);
100        thread.setIntReg(TheISA::ZeroReg, 0);
101#if THE_ISA == ALPHA_ISA
102        thread.setFloatRegBits(TheISA::ZeroReg, 0);
103#endif
104    }
105
106    Fault
107    initiateMemRead(Addr addr, unsigned int size,
108                    Request::Flags flags) override
109    {
110        execute.getLSQ().pushRequest(inst, true /* load */, nullptr,
111            size, addr, flags, NULL);
112        return NoFault;
113    }
114
115    Fault
116    writeMem(uint8_t *data, unsigned int size, Addr addr,
117             Request::Flags flags, uint64_t *res) override
118    {
119        execute.getLSQ().pushRequest(inst, false /* store */, data,
120            size, addr, flags, res);
121        return NoFault;
122    }
123
124    RegVal
125    readIntRegOperand(const StaticInst *si, int idx) override
126    {
127        const RegId& reg = si->srcRegIdx(idx);
128        assert(reg.isIntReg());
129        return thread.readIntReg(reg.index());
130    }
131
132    RegVal
133    readFloatRegOperandBits(const StaticInst *si, int idx) override
134    {
135        const RegId& reg = si->srcRegIdx(idx);
136        assert(reg.isFloatReg());
137        return thread.readFloatRegBits(reg.index());
138    }
139
140    const TheISA::VecRegContainer &
141    readVecRegOperand(const StaticInst *si, int idx) const override
142    {
143        const RegId& reg = si->srcRegIdx(idx);
144        assert(reg.isVecReg());
145        return thread.readVecReg(reg);
146    }
147
148    TheISA::VecRegContainer &
149    getWritableVecRegOperand(const StaticInst *si, int idx) override
150    {
151        const RegId& reg = si->destRegIdx(idx);
152        assert(reg.isVecReg());
153        return thread.getWritableVecReg(reg);
154    }
155
156    TheISA::VecElem
157    readVecElemOperand(const StaticInst *si, int idx) const override
158    {
159        const RegId& reg = si->srcRegIdx(idx);
160        assert(reg.isVecReg());
161        return thread.readVecElem(reg);
162    }
163
164    void
165    setIntRegOperand(const StaticInst *si, int idx, RegVal val) override
166    {
167        const RegId& reg = si->destRegIdx(idx);
168        assert(reg.isIntReg());
169        thread.setIntReg(reg.index(), val);
170    }
171
172    void
173    setFloatRegOperandBits(const StaticInst *si, int idx, RegVal val) override
174    {
175        const RegId& reg = si->destRegIdx(idx);
176        assert(reg.isFloatReg());
177        thread.setFloatRegBits(reg.index(), val);
178    }
179
180    void
181    setVecRegOperand(const StaticInst *si, int idx,
182                     const TheISA::VecRegContainer& val) override
183    {
184        const RegId& reg = si->destRegIdx(idx);
185        assert(reg.isVecReg());
186        thread.setVecReg(reg, val);
187    }
188
189    /** Vector Register Lane Interfaces. */
190    /** @{ */
191    /** Reads source vector 8bit operand. */
192    ConstVecLane8
193    readVec8BitLaneOperand(const StaticInst *si, int idx) const
194                            override
195    {
196        const RegId& reg = si->srcRegIdx(idx);
197        assert(reg.isVecReg());
198        return thread.readVec8BitLaneReg(reg);
199    }
200
201    /** Reads source vector 16bit operand. */
202    ConstVecLane16
203    readVec16BitLaneOperand(const StaticInst *si, int idx) const
204                            override
205    {
206        const RegId& reg = si->srcRegIdx(idx);
207        assert(reg.isVecReg());
208        return thread.readVec16BitLaneReg(reg);
209    }
210
211    /** Reads source vector 32bit operand. */
212    ConstVecLane32
213    readVec32BitLaneOperand(const StaticInst *si, int idx) const
214                            override
215    {
216        const RegId& reg = si->srcRegIdx(idx);
217        assert(reg.isVecReg());
218        return thread.readVec32BitLaneReg(reg);
219    }
220
221    /** Reads source vector 64bit operand. */
222    ConstVecLane64
223    readVec64BitLaneOperand(const StaticInst *si, int idx) const
224                            override
225    {
226        const RegId& reg = si->srcRegIdx(idx);
227        assert(reg.isVecReg());
228        return thread.readVec64BitLaneReg(reg);
229    }
230
231    /** Write a lane of the destination vector operand. */
232    template <typename LD>
233    void
234    setVecLaneOperandT(const StaticInst *si, int idx, const LD& val)
235    {
236        const RegId& reg = si->destRegIdx(idx);
237        assert(reg.isVecReg());
238        return thread.setVecLane(reg, val);
239    }
240    virtual void
241    setVecLaneOperand(const StaticInst *si, int idx,
242            const LaneData<LaneSize::Byte>& val) override
243    {
244        setVecLaneOperandT(si, idx, val);
245    }
246    virtual void
247    setVecLaneOperand(const StaticInst *si, int idx,
248            const LaneData<LaneSize::TwoByte>& val) override
249    {
250        setVecLaneOperandT(si, idx, val);
251    }
252    virtual void
253    setVecLaneOperand(const StaticInst *si, int idx,
254            const LaneData<LaneSize::FourByte>& val) override
255    {
256        setVecLaneOperandT(si, idx, val);
257    }
258    virtual void
259    setVecLaneOperand(const StaticInst *si, int idx,
260            const LaneData<LaneSize::EightByte>& val) override
261    {
262        setVecLaneOperandT(si, idx, val);
263    }
264    /** @} */
265
266    void
267    setVecElemOperand(const StaticInst *si, int idx,
268                      const TheISA::VecElem val) override
269    {
270        const RegId& reg = si->destRegIdx(idx);
271        assert(reg.isVecReg());
272        thread.setVecElem(reg, val);
273    }
274
275    bool
276    readPredicate() const override
277    {
278        return thread.readPredicate();
279    }
280
281    void
282    setPredicate(bool val) override
283    {
284        thread.setPredicate(val);
285    }
286
287    TheISA::PCState
288    pcState() const override
289    {
290        return thread.pcState();
291    }
292
293    void
294    pcState(const TheISA::PCState &val) override
295    {
296        thread.pcState(val);
297    }
298
299    RegVal
300    readMiscRegNoEffect(int misc_reg) const
301    {
302        return thread.readMiscRegNoEffect(misc_reg);
303    }
304
305    RegVal
306    readMiscReg(int misc_reg) override
307    {
308        return thread.readMiscReg(misc_reg);
309    }
310
311    void
312    setMiscReg(int misc_reg, const RegVal &val) override
313    {
314        thread.setMiscReg(misc_reg, val);
315    }
316
317    RegVal
318    readMiscRegOperand(const StaticInst *si, int idx) override
319    {
320        const RegId& reg = si->srcRegIdx(idx);
321        assert(reg.isMiscReg());
322        return thread.readMiscReg(reg.index());
323    }
324
325    void
326    setMiscRegOperand(const StaticInst *si, int idx,
327                      const RegVal &val) override
328    {
329        const RegId& reg = si->destRegIdx(idx);
330        assert(reg.isMiscReg());
331        return thread.setMiscReg(reg.index(), val);
332    }
333
334    Fault
335    hwrei() override
336    {
337#if THE_ISA == ALPHA_ISA
338        return thread.hwrei();
339#else
340        return NoFault;
341#endif
342    }
343
344    bool
345    simPalCheck(int palFunc) override
346    {
347#if THE_ISA == ALPHA_ISA
348        return thread.simPalCheck(palFunc);
349#else
350        return false;
351#endif
352    }
353
354    void
355    syscall(int64_t callnum, Fault *fault) override
356    {
357        if (FullSystem)
358            panic("Syscall emulation isn't available in FS mode.\n");
359
360        thread.syscall(callnum, fault);
361    }
362
363    ThreadContext *tcBase() override { return thread.getTC(); }
364
365    /* @todo, should make stCondFailures persistent somewhere */
366    unsigned int readStCondFailures() const override { return 0; }
367    void setStCondFailures(unsigned int st_cond_failures) override {}
368
369    ContextID contextId() { return thread.contextId(); }
370    /* ISA-specific (or at least currently ISA singleton) functions */
371
372    /* X86: TLB twiddling */
373    void
374    demapPage(Addr vaddr, uint64_t asn) override
375    {
376        thread.getITBPtr()->demapPage(vaddr, asn);
377        thread.getDTBPtr()->demapPage(vaddr, asn);
378    }
379
380    TheISA::CCReg
381    readCCRegOperand(const StaticInst *si, int idx) override
382    {
383        const RegId& reg = si->srcRegIdx(idx);
384        assert(reg.isCCReg());
385        return thread.readCCReg(reg.index());
386    }
387
388    void
389    setCCRegOperand(const StaticInst *si, int idx, TheISA::CCReg val) override
390    {
391        const RegId& reg = si->destRegIdx(idx);
392        assert(reg.isCCReg());
393        thread.setCCReg(reg.index(), val);
394    }
395
396    void
397    demapInstPage(Addr vaddr, uint64_t asn)
398    {
399        thread.getITBPtr()->demapPage(vaddr, asn);
400    }
401
402    void
403    demapDataPage(Addr vaddr, uint64_t asn)
404    {
405        thread.getDTBPtr()->demapPage(vaddr, asn);
406    }
407
408    BaseCPU *getCpuPtr() { return &cpu; }
409
410    /* MIPS: other thread register reading/writing */
411    RegVal
412    readRegOtherThread(const RegId &reg, ThreadID tid=InvalidThreadID)
413    {
414        SimpleThread *other_thread = (tid == InvalidThreadID
415            ? &thread : cpu.threads[tid]);
416
417        switch (reg.classValue()) {
418            case IntRegClass:
419                return other_thread->readIntReg(reg.index());
420                break;
421            case FloatRegClass:
422                return other_thread->readFloatRegBits(reg.index());
423                break;
424            case MiscRegClass:
425                return other_thread->readMiscReg(reg.index());
426            default:
427                panic("Unexpected reg class! (%s)",
428                      reg.className());
429                return 0;
430        }
431    }
432
433    void
434    setRegOtherThread(const RegId &reg, const RegVal &val,
435                      ThreadID tid=InvalidThreadID)
436    {
437        SimpleThread *other_thread = (tid == InvalidThreadID
438            ? &thread : cpu.threads[tid]);
439
440        switch (reg.classValue()) {
441            case IntRegClass:
442                return other_thread->setIntReg(reg.index(), val);
443                break;
444            case FloatRegClass:
445                return other_thread->setFloatRegBits(reg.index(), val);
446                break;
447            case MiscRegClass:
448                return other_thread->setMiscReg(reg.index(), val);
449            default:
450                panic("Unexpected reg class! (%s)",
451                      reg.className());
452        }
453    }
454
455  public:
456    // monitor/mwait funtions
457    void armMonitor(Addr address) override
458    { getCpuPtr()->armMonitor(inst->id.threadId, address); }
459
460    bool mwait(PacketPtr pkt) override
461    { return getCpuPtr()->mwait(inst->id.threadId, pkt); }
462
463    void mwaitAtomic(ThreadContext *tc) override
464    { return getCpuPtr()->mwaitAtomic(inst->id.threadId, tc, thread.dtb); }
465
466    AddressMonitor *getAddrMonitor() override
467    { return getCpuPtr()->getCpuAddrMonitor(inst->id.threadId); }
468};
469
470}
471
472#endif /* __CPU_MINOR_EXEC_CONTEXT_HH__ */
473