exec_context.hh revision 10698
12SN/A/*
210905Sandreas.sandberg@arm.com * Copyright (c) 2011-2014 ARM Limited
310905Sandreas.sandberg@arm.com * Copyright (c) 2013 Advanced Micro Devices, Inc.
410905Sandreas.sandberg@arm.com * All rights reserved
510905Sandreas.sandberg@arm.com *
610905Sandreas.sandberg@arm.com * The license below extends only to copyright in the software and shall
710905Sandreas.sandberg@arm.com * not be construed as granting a license to any other intellectual
810905Sandreas.sandberg@arm.com * property including but not limited to intellectual property relating
910905Sandreas.sandberg@arm.com * to a hardware implementation of the functionality of the software
1010905Sandreas.sandberg@arm.com * licensed hereunder.  You may use the software subject to the license
1110905Sandreas.sandberg@arm.com * terms below provided that you ensure that this notice is replicated
1210905Sandreas.sandberg@arm.com * unmodified and in its entirety in all distributions of the software,
1310905Sandreas.sandberg@arm.com * modified or unmodified, in source code or in binary form.
141762SN/A *
159983Sstever@gmail.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
169983Sstever@gmail.com * All rights reserved.
172SN/A *
182SN/A * Redistribution and use in source and binary forms, with or without
192SN/A * modification, are permitted provided that the following conditions are
202SN/A * met: redistributions of source code must retain the above copyright
212SN/A * notice, this list of conditions and the following disclaimer;
222SN/A * redistributions in binary form must reproduce the above copyright
232SN/A * notice, this list of conditions and the following disclaimer in the
242SN/A * documentation and/or other materials provided with the distribution;
252SN/A * neither the name of the copyright holders nor the names of its
262SN/A * contributors may be used to endorse or promote products derived from
272SN/A * this software without specific prior written permission.
282SN/A *
292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402SN/A *
412665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
422760Sbinkertn@umich.edu *          Dave Greene
432760Sbinkertn@umich.edu *          Nathan Binkert
442665Ssaidi@eecs.umich.edu *          Andrew Bardsley
4510905Sandreas.sandberg@arm.com */
462SN/A
472SN/A/**
488229Snate@binkert.org * @file
492SN/A *
50363SN/A *  ExecContext bears the exec_context interface for Minor.
512SN/A */
528229Snate@binkert.org
532SN/A#ifndef __CPU_MINOR_EXEC_CONTEXT_HH__
542SN/A#define __CPU_MINOR_EXEC_CONTEXT_HH__
552SN/A
562SN/A#include "cpu/exec_context.hh"
572SN/A#include "cpu/minor/execute.hh"
5810907Sandreas.sandberg@arm.com#include "cpu/minor/pipeline.hh"
59363SN/A#include "cpu/base.hh"
6056SN/A#include "cpu/simple_thread.hh"
611388SN/A#include "debug/MinorExecute.hh"
62217SN/A
63363SN/Anamespace Minor
6410905Sandreas.sandberg@arm.com{
6556SN/A
6656SN/A/* Forward declaration of Execute */
6756SN/Aclass Execute;
681638SN/A
6956SN/A/** ExecContext bears the exec_context interface for Minor.  This nicely
702SN/A *  separates that interface from other classes such as Pipeline, MinorCPU
712356SN/A *  and DynMinorInst and makes it easier to see what state is accessed by it.
722356SN/A */
732356SN/Aclass ExecContext : public ::ExecContext
742SN/A{
752SN/A  public:
764762Snate@binkert.org    MinorCPU &cpu;
774762Snate@binkert.org
784762Snate@binkert.org    /** ThreadState object, provides all the architectural state. */
794762Snate@binkert.org    SimpleThread &thread;
804762Snate@binkert.org
814762Snate@binkert.org    /** The execute stage so we can peek at its contents. */
824762Snate@binkert.org    Execute &execute;
834762Snate@binkert.org
844762Snate@binkert.org    /** Instruction for the benefit of memory operations and for PC */
854762Snate@binkert.org    MinorDynInstPtr inst;
864762Snate@binkert.org
874762Snate@binkert.org    ExecContext (
884762Snate@binkert.org        MinorCPU &cpu_,
8910905Sandreas.sandberg@arm.com        SimpleThread &thread_, Execute &execute_,
904762Snate@binkert.org        MinorDynInstPtr inst_) :
914762Snate@binkert.org        cpu(cpu_),
924762Snate@binkert.org        thread(thread_),
934762Snate@binkert.org        execute(execute_),
944762Snate@binkert.org        inst(inst_)
954762Snate@binkert.org    {
964762Snate@binkert.org        DPRINTF(MinorExecute, "ExecContext setting PC: %s\n", inst->pc);
974762Snate@binkert.org        pcState(inst->pc);
984762Snate@binkert.org        setPredicate(true);
994762Snate@binkert.org        thread.setIntReg(TheISA::ZeroReg, 0);
1004762Snate@binkert.org#if THE_ISA == ALPHA_ISA
1014762Snate@binkert.org        thread.setFloatReg(TheISA::ZeroReg, 0.0);
1024762Snate@binkert.org#endif
1034762Snate@binkert.org    }
1044762Snate@binkert.org
10510905Sandreas.sandberg@arm.com    Fault
1067494Ssteve.reinhardt@amd.com    readMem(Addr addr, uint8_t *data, unsigned int size,
1077494Ssteve.reinhardt@amd.com        unsigned int flags)
1087494Ssteve.reinhardt@amd.com    {
1097494Ssteve.reinhardt@amd.com        execute.getLSQ().pushRequest(inst, true /* load */, data,
1107494Ssteve.reinhardt@amd.com            size, addr, flags, NULL);
1117494Ssteve.reinhardt@amd.com        return NoFault;
1127494Ssteve.reinhardt@amd.com    }
11310905Sandreas.sandberg@arm.com
1144762Snate@binkert.org    Fault
1154762Snate@binkert.org    writeMem(uint8_t *data, unsigned int size, Addr addr,
1164762Snate@binkert.org        unsigned int flags, uint64_t *res)
1174762Snate@binkert.org    {
1184762Snate@binkert.org        execute.getLSQ().pushRequest(inst, false /* store */, data,
1194762Snate@binkert.org            size, addr, flags, res);
1204762Snate@binkert.org        return NoFault;
12110905Sandreas.sandberg@arm.com    }
1224762Snate@binkert.org
1234762Snate@binkert.org    IntReg
1244762Snate@binkert.org    readIntRegOperand(const StaticInst *si, int idx)
1254762Snate@binkert.org    {
1264762Snate@binkert.org        return thread.readIntReg(si->srcRegIdx(idx));
1274762Snate@binkert.org    }
1284762Snate@binkert.org
1294762Snate@binkert.org    TheISA::FloatReg
1304762Snate@binkert.org    readFloatRegOperand(const StaticInst *si, int idx)
13110386Sandreas.hansson@arm.com    {
1324762Snate@binkert.org        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base;
1334762Snate@binkert.org        return thread.readFloatReg(reg_idx);
1344762Snate@binkert.org    }
1354762Snate@binkert.org
1364762Snate@binkert.org    TheISA::FloatRegBits
1374762Snate@binkert.org    readFloatRegOperandBits(const StaticInst *si, int idx)
13810386Sandreas.hansson@arm.com    {
1394762Snate@binkert.org        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base;
1404762Snate@binkert.org        return thread.readFloatRegBits(reg_idx);
1414762Snate@binkert.org    }
1424762Snate@binkert.org
1434762Snate@binkert.org    void
1444762Snate@binkert.org    setIntRegOperand(const StaticInst *si, int idx, IntReg val)
14510386Sandreas.hansson@arm.com    {
1464762Snate@binkert.org        thread.setIntReg(si->destRegIdx(idx), val);
1474762Snate@binkert.org    }
1484762Snate@binkert.org
1494762Snate@binkert.org    void
1504762Snate@binkert.org    setFloatRegOperand(const StaticInst *si, int idx,
15110905Sandreas.sandberg@arm.com        TheISA::FloatReg val)
1524762Snate@binkert.org    {
1534762Snate@binkert.org        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base;
1544762Snate@binkert.org        thread.setFloatReg(reg_idx, val);
1554762Snate@binkert.org    }
1564762Snate@binkert.org
1574762Snate@binkert.org    void
1584762Snate@binkert.org    setFloatRegOperandBits(const StaticInst *si, int idx,
1594762Snate@binkert.org        TheISA::FloatRegBits val)
1604762Snate@binkert.org    {
1614762Snate@binkert.org        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base;
1624762Snate@binkert.org        thread.setFloatRegBits(reg_idx, val);
1634762Snate@binkert.org    }
1644762Snate@binkert.org
1654762Snate@binkert.org    bool
1662287SN/A    readPredicate()
1672287SN/A    {
1682287SN/A        return thread.readPredicate();
16910905Sandreas.sandberg@arm.com    }
1702SN/A
171217SN/A    void
1722SN/A    setPredicate(bool val)
17310905Sandreas.sandberg@arm.com    {
1742SN/A        thread.setPredicate(val);
175217SN/A    }
176217SN/A
177217SN/A    TheISA::PCState
1782SN/A    pcState() const
1792SN/A    {
1804841Ssaidi@eecs.umich.edu        return thread.pcState();
1814841Ssaidi@eecs.umich.edu    }
18210905Sandreas.sandberg@arm.com
1834841Ssaidi@eecs.umich.edu    void
1846227Snate@binkert.org    pcState(const TheISA::PCState &val)
1854841Ssaidi@eecs.umich.edu    {
1864841Ssaidi@eecs.umich.edu        thread.pcState(val);
1874841Ssaidi@eecs.umich.edu    }
1886227Snate@binkert.org
1894841Ssaidi@eecs.umich.edu    TheISA::MiscReg
1904841Ssaidi@eecs.umich.edu    readMiscRegNoEffect(int misc_reg) const
1914841Ssaidi@eecs.umich.edu    {
1924841Ssaidi@eecs.umich.edu        return thread.readMiscRegNoEffect(misc_reg);
1934841Ssaidi@eecs.umich.edu    }
1944841Ssaidi@eecs.umich.edu
1957948SAli.Saidi@ARM.com    TheISA::MiscReg
1967948SAli.Saidi@ARM.com    readMiscReg(int misc_reg)
19710905Sandreas.sandberg@arm.com    {
1987948SAli.Saidi@ARM.com        return thread.readMiscReg(misc_reg);
1997948SAli.Saidi@ARM.com    }
2007948SAli.Saidi@ARM.com
2017948SAli.Saidi@ARM.com    void
2027948SAli.Saidi@ARM.com    setMiscReg(int misc_reg, const TheISA::MiscReg &val)
2037948SAli.Saidi@ARM.com    {
2047948SAli.Saidi@ARM.com        thread.setMiscReg(misc_reg, val);
2057948SAli.Saidi@ARM.com    }
2067948SAli.Saidi@ARM.com
2077948SAli.Saidi@ARM.com    TheISA::MiscReg
2087948SAli.Saidi@ARM.com    readMiscRegOperand(const StaticInst *si, int idx)
2097948SAli.Saidi@ARM.com    {
2107948SAli.Saidi@ARM.com        int reg_idx = si->srcRegIdx(idx) - TheISA::Misc_Reg_Base;
2117948SAli.Saidi@ARM.com        return thread.readMiscReg(reg_idx);
212217SN/A    }
213217SN/A
214217SN/A    void
21510905Sandreas.sandberg@arm.com    setMiscRegOperand(const StaticInst *si, int idx,
2162SN/A        const TheISA::MiscReg &val)
21710905Sandreas.sandberg@arm.com    {
2186225Snate@binkert.org        int reg_idx = si->destRegIdx(idx) - TheISA::Misc_Reg_Base;
21910905Sandreas.sandberg@arm.com        return thread.setMiscReg(reg_idx, val);
220217SN/A    }
221217SN/A
2222SN/A    Fault
2232SN/A    hwrei()
2246820SLisa.Hsu@amd.com    {
2256820SLisa.Hsu@amd.com#if THE_ISA == ALPHA_ISA
22610905Sandreas.sandberg@arm.com        return thread.hwrei();
2276820SLisa.Hsu@amd.com#else
22810905Sandreas.sandberg@arm.com        return NoFault;
2296820SLisa.Hsu@amd.com#endif
23010905Sandreas.sandberg@arm.com    }
2316820SLisa.Hsu@amd.com
2326820SLisa.Hsu@amd.com    bool
2336820SLisa.Hsu@amd.com    simPalCheck(int palFunc)
2346820SLisa.Hsu@amd.com    {
2356820SLisa.Hsu@amd.com#if THE_ISA == ALPHA_ISA
2366820SLisa.Hsu@amd.com        return thread.simPalCheck(palFunc);
237217SN/A#else
238217SN/A        return false;
239217SN/A#endif
24010905Sandreas.sandberg@arm.com    }
24110905Sandreas.sandberg@arm.com
242217SN/A    void
243217SN/A    syscall(int64_t callnum)
244217SN/A    {
245217SN/A        if (FullSystem)
2466227Snate@binkert.org            panic("Syscall emulation isn't available in FS mode.\n");
247217SN/A
248217SN/A        thread.syscall(callnum);
249217SN/A    }
250217SN/A
251217SN/A    ThreadContext *tcBase() { return thread.getTC(); }
252217SN/A
253217SN/A    /* @todo, should make stCondFailures persistent somewhere */
254217SN/A    unsigned int readStCondFailures() const { return 0; }
255217SN/A    void setStCondFailures(unsigned int st_cond_failures) {}
25610905Sandreas.sandberg@arm.com
257217SN/A    int contextId() { return thread.contextId(); }
25810905Sandreas.sandberg@arm.com    /* ISA-specific (or at least currently ISA singleton) functions */
2596225Snate@binkert.org
26010905Sandreas.sandberg@arm.com    /* X86: TLB twiddling */
261217SN/A    void
262217SN/A    demapPage(Addr vaddr, uint64_t asn)
263217SN/A    {
264217SN/A        thread.getITBPtr()->demapPage(vaddr, asn);
265217SN/A        thread.getDTBPtr()->demapPage(vaddr, asn);
266217SN/A    }
267217SN/A
268217SN/A    TheISA::CCReg
269217SN/A    readCCRegOperand(const StaticInst *si, int idx)
270217SN/A    {
271217SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::CC_Reg_Base;
272217SN/A        return thread.readCCReg(reg_idx);
273217SN/A    }
274217SN/A
275217SN/A    void
276217SN/A    setCCRegOperand(const StaticInst *si, int idx, TheISA::CCReg val)
277217SN/A    {
2786227Snate@binkert.org        int reg_idx = si->destRegIdx(idx) - TheISA::CC_Reg_Base;
279217SN/A        thread.setCCReg(reg_idx, val);
280217SN/A    }
281217SN/A
282217SN/A    void
28310905Sandreas.sandberg@arm.com    demapInstPage(Addr vaddr, uint64_t asn)
284217SN/A    {
285217SN/A        thread.getITBPtr()->demapPage(vaddr, asn);
286217SN/A    }
287217SN/A
288217SN/A    void
289217SN/A    demapDataPage(Addr vaddr, uint64_t asn)
290217SN/A    {
291217SN/A        thread.getDTBPtr()->demapPage(vaddr, asn);
292217SN/A    }
293217SN/A
294217SN/A    /* ALPHA/POWER: Effective address storage */
295217SN/A    void setEA(Addr ea)
296217SN/A    {
297217SN/A        inst->ea = ea;
2984841Ssaidi@eecs.umich.edu    }
2994841Ssaidi@eecs.umich.edu
30010905Sandreas.sandberg@arm.com    BaseCPU *getCpuPtr() { return &cpu; }
3014841Ssaidi@eecs.umich.edu
30210905Sandreas.sandberg@arm.com    /* POWER: Effective address storage */
3036225Snate@binkert.org    Addr getEA() const
30410905Sandreas.sandberg@arm.com    {
3054841Ssaidi@eecs.umich.edu        return inst->ea;
3064841Ssaidi@eecs.umich.edu    }
3074841Ssaidi@eecs.umich.edu
3084841Ssaidi@eecs.umich.edu    /* MIPS: other thread register reading/writing */
3094841Ssaidi@eecs.umich.edu    uint64_t
3104841Ssaidi@eecs.umich.edu    readRegOtherThread(int idx, ThreadID tid = InvalidThreadID)
3114841Ssaidi@eecs.umich.edu    {
3124841Ssaidi@eecs.umich.edu        SimpleThread *other_thread = (tid == InvalidThreadID
3134841Ssaidi@eecs.umich.edu            ? &thread : cpu.threads[tid]);
3144841Ssaidi@eecs.umich.edu
3154841Ssaidi@eecs.umich.edu        if (idx < TheISA::FP_Reg_Base) { /* Integer */
3164841Ssaidi@eecs.umich.edu            return other_thread->readIntReg(idx);
3174841Ssaidi@eecs.umich.edu        } else if (idx < TheISA::Misc_Reg_Base) { /* Float */
3184841Ssaidi@eecs.umich.edu            return other_thread->readFloatRegBits(idx
3194841Ssaidi@eecs.umich.edu                - TheISA::FP_Reg_Base);
3206227Snate@binkert.org        } else { /* Misc */
3214841Ssaidi@eecs.umich.edu            return other_thread->readMiscReg(idx
3224841Ssaidi@eecs.umich.edu                - TheISA::Misc_Reg_Base);
3234841Ssaidi@eecs.umich.edu        }
3244841Ssaidi@eecs.umich.edu    }
32510905Sandreas.sandberg@arm.com
3264841Ssaidi@eecs.umich.edu    void
3274841Ssaidi@eecs.umich.edu    setRegOtherThread(int idx, const TheISA::MiscReg &val,
3284841Ssaidi@eecs.umich.edu        ThreadID tid = InvalidThreadID)
3294841Ssaidi@eecs.umich.edu    {
3304841Ssaidi@eecs.umich.edu        SimpleThread *other_thread = (tid == InvalidThreadID
3314841Ssaidi@eecs.umich.edu            ? &thread : cpu.threads[tid]);
3324841Ssaidi@eecs.umich.edu
3334841Ssaidi@eecs.umich.edu        if (idx < TheISA::FP_Reg_Base) { /* Integer */
3344841Ssaidi@eecs.umich.edu            return other_thread->setIntReg(idx, val);
3354841Ssaidi@eecs.umich.edu        } else if (idx < TheISA::Misc_Reg_Base) { /* Float */
3364841Ssaidi@eecs.umich.edu            return other_thread->setFloatRegBits(idx
3374841Ssaidi@eecs.umich.edu                - TheISA::FP_Reg_Base, val);
3384841Ssaidi@eecs.umich.edu        } else { /* Misc */
3394841Ssaidi@eecs.umich.edu            return other_thread->setMiscReg(idx
3407948SAli.Saidi@ARM.com                - TheISA::Misc_Reg_Base, val);
3417948SAli.Saidi@ARM.com        }
34210905Sandreas.sandberg@arm.com    }
3437948SAli.Saidi@ARM.com
34410905Sandreas.sandberg@arm.com  public:
3457948SAli.Saidi@ARM.com    // monitor/mwait funtions
34610905Sandreas.sandberg@arm.com    void armMonitor(Addr address) { getCpuPtr()->armMonitor(address); }
3477948SAli.Saidi@ARM.com    bool mwait(PacketPtr pkt) { return getCpuPtr()->mwait(pkt); }
3487948SAli.Saidi@ARM.com    void mwaitAtomic(ThreadContext *tc)
3497948SAli.Saidi@ARM.com    { return getCpuPtr()->mwaitAtomic(tc, thread.dtb); }
3507948SAli.Saidi@ARM.com    AddressMonitor *getAddrMonitor()
3517948SAli.Saidi@ARM.com    { return getCpuPtr()->getCpuAddrMonitor(); }
3527948SAli.Saidi@ARM.com};
3537948SAli.Saidi@ARM.com
3547948SAli.Saidi@ARM.com}
35510905Sandreas.sandberg@arm.com
3567948SAli.Saidi@ARM.com#endif /* __CPU_MINOR_EXEC_CONTEXT_HH__ */
3577948SAli.Saidi@ARM.com