exec_context.hh revision 10474:799c8ee4ecba
111723Sar4jc@virginia.edu/*
211723Sar4jc@virginia.edu * Copyright (c) 2014 ARM Limited
311723Sar4jc@virginia.edu * All rights reserved
411723Sar4jc@virginia.edu *
511723Sar4jc@virginia.edu * The license below extends only to copyright in the software and shall
611723Sar4jc@virginia.edu * not be construed as granting a license to any other intellectual
711723Sar4jc@virginia.edu * property including but not limited to intellectual property relating
811723Sar4jc@virginia.edu * to a hardware implementation of the functionality of the software
911723Sar4jc@virginia.edu * licensed hereunder.  You may use the software subject to the license
1011723Sar4jc@virginia.edu * terms below provided that you ensure that this notice is replicated
1111723Sar4jc@virginia.edu * unmodified and in its entirety in all distributions of the software,
1211723Sar4jc@virginia.edu * modified or unmodified, in source code or in binary form.
1311723Sar4jc@virginia.edu *
1411723Sar4jc@virginia.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan
1511723Sar4jc@virginia.edu * All rights reserved.
1611723Sar4jc@virginia.edu *
1711723Sar4jc@virginia.edu * Redistribution and use in source and binary forms, with or without
1811723Sar4jc@virginia.edu * modification, are permitted provided that the following conditions are
1911723Sar4jc@virginia.edu * met: redistributions of source code must retain the above copyright
2011723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer;
2111723Sar4jc@virginia.edu * redistributions in binary form must reproduce the above copyright
2211723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer in the
2311723Sar4jc@virginia.edu * documentation and/or other materials provided with the distribution;
2411723Sar4jc@virginia.edu * neither the name of the copyright holders nor the names of its
2511723Sar4jc@virginia.edu * contributors may be used to endorse or promote products derived from
2611723Sar4jc@virginia.edu * this software without specific prior written permission.
2711723Sar4jc@virginia.edu *
2811723Sar4jc@virginia.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2911723Sar4jc@virginia.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3011723Sar4jc@virginia.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3111723Sar4jc@virginia.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3211723Sar4jc@virginia.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3311723Sar4jc@virginia.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3411723Sar4jc@virginia.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3511723Sar4jc@virginia.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3611723Sar4jc@virginia.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3711723Sar4jc@virginia.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3811723Sar4jc@virginia.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3911723Sar4jc@virginia.edu *
4011723Sar4jc@virginia.edu * Authors: Kevin Lim
4111723Sar4jc@virginia.edu *          Andreas Sandberg
4211723Sar4jc@virginia.edu */
4311725Sar4jc@virginia.edu
4411725Sar4jc@virginia.edu#ifndef __CPU_EXEC_CONTEXT_HH__
4511725Sar4jc@virginia.edu#define __CPU_EXEC_CONTEXT_HH__
4611725Sar4jc@virginia.edu
4711725Sar4jc@virginia.edu#include "arch/registers.hh"
4811725Sar4jc@virginia.edu#include "base/types.hh"
4911723Sar4jc@virginia.edu#include "config/the_isa.hh"
5011723Sar4jc@virginia.edu#include "cpu/static_inst_fwd.hh"
5111723Sar4jc@virginia.edu#include "cpu/translation.hh"
5211723Sar4jc@virginia.edu
5311723Sar4jc@virginia.edu/**
5411723Sar4jc@virginia.edu * The ExecContext is an abstract base class the provides the
5511723Sar4jc@virginia.edu * interface used by the ISA to manipulate the state of the CPU model.
5611723Sar4jc@virginia.edu *
5711723Sar4jc@virginia.edu * Register accessor methods in this class typically provide the index
5811723Sar4jc@virginia.edu * of the instruction's operand (e.g., 0 or 1), not the architectural
5911723Sar4jc@virginia.edu * register index, to simplify the implementation of register
6011723Sar4jc@virginia.edu * renaming.  The architectural register index can be found by
6111723Sar4jc@virginia.edu * indexing into the instruction's own operand index table.
6211723Sar4jc@virginia.edu *
6311723Sar4jc@virginia.edu * @note The methods in this class typically take a raw pointer to the
6411723Sar4jc@virginia.edu * StaticInst is provided instead of a ref-counted StaticInstPtr to
6511723Sar4jc@virginia.edu * reduce overhead as an argument. This is fine as long as the
6611723Sar4jc@virginia.edu * implementation doesn't copy the pointer into any long-term storage
6711723Sar4jc@virginia.edu * (which is pretty hard to imagine they would have reason to do).
6811723Sar4jc@virginia.edu */
6911723Sar4jc@virginia.educlass ExecContext {
7011723Sar4jc@virginia.edu  public:
7111723Sar4jc@virginia.edu    typedef TheISA::IntReg IntReg;
7211723Sar4jc@virginia.edu    typedef TheISA::PCState PCState;
7311723Sar4jc@virginia.edu    typedef TheISA::FloatReg FloatReg;
7411723Sar4jc@virginia.edu    typedef TheISA::FloatRegBits FloatRegBits;
7511723Sar4jc@virginia.edu    typedef TheISA::MiscReg MiscReg;
7611723Sar4jc@virginia.edu
7711723Sar4jc@virginia.edu    typedef TheISA::CCReg CCReg;
7811723Sar4jc@virginia.edu
7911723Sar4jc@virginia.edu  public:
8011723Sar4jc@virginia.edu    /**
8111723Sar4jc@virginia.edu     * @{
8211723Sar4jc@virginia.edu     * @name Integer Register Interfaces
8311723Sar4jc@virginia.edu     *
8411723Sar4jc@virginia.edu     */
8511723Sar4jc@virginia.edu
8611723Sar4jc@virginia.edu    /** Reads an integer register. */
8711723Sar4jc@virginia.edu    virtual IntReg readIntRegOperand(const StaticInst *si, int idx) = 0;
8811723Sar4jc@virginia.edu
8911723Sar4jc@virginia.edu    /** Sets an integer register to a value. */
9011723Sar4jc@virginia.edu    virtual void setIntRegOperand(const StaticInst *si,
9111723Sar4jc@virginia.edu                                  int idx, IntReg val) = 0;
9211723Sar4jc@virginia.edu
9311723Sar4jc@virginia.edu    /** @} */
9411723Sar4jc@virginia.edu
9511723Sar4jc@virginia.edu
9611723Sar4jc@virginia.edu    /**
9711723Sar4jc@virginia.edu     * @{
9811723Sar4jc@virginia.edu     * @name Floating Point Register Interfaces
9911723Sar4jc@virginia.edu     */
10011723Sar4jc@virginia.edu
10111723Sar4jc@virginia.edu    /** Reads a floating point register of single register width. */
10211723Sar4jc@virginia.edu    virtual FloatReg readFloatRegOperand(const StaticInst *si, int idx) = 0;
10311723Sar4jc@virginia.edu
10411723Sar4jc@virginia.edu    /** Reads a floating point register in its binary format, instead
10511723Sar4jc@virginia.edu     * of by value. */
10611723Sar4jc@virginia.edu    virtual FloatRegBits readFloatRegOperandBits(const StaticInst *si,
10711723Sar4jc@virginia.edu                                                 int idx) = 0;
10811723Sar4jc@virginia.edu
10911723Sar4jc@virginia.edu    /** Sets a floating point register of single width to a value. */
11011723Sar4jc@virginia.edu    virtual void setFloatRegOperand(const StaticInst *si,
11111723Sar4jc@virginia.edu                                    int idx, FloatReg val) = 0;
11211723Sar4jc@virginia.edu
11311723Sar4jc@virginia.edu    /** Sets the bits of a floating point register of single width
11411723Sar4jc@virginia.edu     * to a binary value. */
11511723Sar4jc@virginia.edu    virtual void setFloatRegOperandBits(const StaticInst *si,
11611723Sar4jc@virginia.edu                                        int idx, FloatRegBits val) = 0;
11711723Sar4jc@virginia.edu
11811723Sar4jc@virginia.edu    /** @} */
11912136Sar4jc@virginia.edu
12012136Sar4jc@virginia.edu    /**
12112136Sar4jc@virginia.edu     * @{
12212136Sar4jc@virginia.edu     * @name Condition Code Registers
12312136Sar4jc@virginia.edu     */
12412136Sar4jc@virginia.edu    virtual CCReg readCCRegOperand(const StaticInst *si, int idx) = 0;
12512136Sar4jc@virginia.edu    virtual void setCCRegOperand(const StaticInst *si, int idx, CCReg val) = 0;
12612136Sar4jc@virginia.edu    /** @} */
12712136Sar4jc@virginia.edu
12812136Sar4jc@virginia.edu    /**
12912136Sar4jc@virginia.edu     * @{
13012136Sar4jc@virginia.edu     * @name Misc Register Interfaces
13112136Sar4jc@virginia.edu     */
13211723Sar4jc@virginia.edu    virtual MiscReg readMiscRegOperand(const StaticInst *si, int idx) = 0;
13311723Sar4jc@virginia.edu    virtual void setMiscRegOperand(const StaticInst *si,
13411723Sar4jc@virginia.edu                                   int idx, const MiscReg &val) = 0;
13511723Sar4jc@virginia.edu
13611723Sar4jc@virginia.edu    /**
13711723Sar4jc@virginia.edu     * Reads a miscellaneous register, handling any architectural
13811723Sar4jc@virginia.edu     * side effects due to reading that register.
13911723Sar4jc@virginia.edu     */
14011723Sar4jc@virginia.edu    virtual MiscReg readMiscReg(int misc_reg) = 0;
14111723Sar4jc@virginia.edu
14211723Sar4jc@virginia.edu    /**
14311723Sar4jc@virginia.edu     * Sets a miscellaneous register, handling any architectural
14411723Sar4jc@virginia.edu     * side effects due to writing that register.
14511723Sar4jc@virginia.edu     */
14611725Sar4jc@virginia.edu    virtual void setMiscReg(int misc_reg, const MiscReg &val) = 0;
14711725Sar4jc@virginia.edu
14811725Sar4jc@virginia.edu    /** @} */
14911725Sar4jc@virginia.edu
15011725Sar4jc@virginia.edu    /**
15111725Sar4jc@virginia.edu     * @{
15211725Sar4jc@virginia.edu     * @name PC Control
15311725Sar4jc@virginia.edu     */
15411725Sar4jc@virginia.edu    virtual PCState pcState() const = 0;
15511725Sar4jc@virginia.edu    virtual void pcState(const PCState &val) = 0;
15611725Sar4jc@virginia.edu    /** @} */
15711725Sar4jc@virginia.edu
15811725Sar4jc@virginia.edu    /**
15911725Sar4jc@virginia.edu     * @{
16011723Sar4jc@virginia.edu     * @name Memory Interface
16111723Sar4jc@virginia.edu     */
16211723Sar4jc@virginia.edu    /**
16311723Sar4jc@virginia.edu     * Record the effective address of the instruction.
16411723Sar4jc@virginia.edu     *
16511723Sar4jc@virginia.edu     * @note Only valid for memory ops.
16611723Sar4jc@virginia.edu     */
16711723Sar4jc@virginia.edu    virtual void setEA(Addr EA) = 0;
16811723Sar4jc@virginia.edu    /**
16911723Sar4jc@virginia.edu     * Get the effective address of the instruction.
17011723Sar4jc@virginia.edu     *
17111723Sar4jc@virginia.edu     * @note Only valid for memory ops.
17211723Sar4jc@virginia.edu     */
17311723Sar4jc@virginia.edu    virtual Addr getEA() const = 0;
17411723Sar4jc@virginia.edu
17511723Sar4jc@virginia.edu    virtual Fault readMem(Addr addr, uint8_t *data, unsigned int size,
17611723Sar4jc@virginia.edu                          unsigned int flags) = 0;
17711723Sar4jc@virginia.edu
17811723Sar4jc@virginia.edu    virtual Fault writeMem(uint8_t *data, unsigned int size, Addr addr,
17911723Sar4jc@virginia.edu                           unsigned int flags, uint64_t *res) = 0;
18011723Sar4jc@virginia.edu
18111723Sar4jc@virginia.edu    /**
18211723Sar4jc@virginia.edu     * Sets the number of consecutive store conditional failures.
18311723Sar4jc@virginia.edu     */
18411723Sar4jc@virginia.edu    virtual void setStCondFailures(unsigned int sc_failures) = 0;
185
186    /**
187     * Returns the number of consecutive store conditional failures.
188     */
189    virtual unsigned int readStCondFailures() const = 0;
190
191    /** @} */
192
193    /**
194     * @{
195     * @name SysCall Emulation Interfaces
196     */
197
198    /**
199     * Executes a syscall specified by the callnum.
200     */
201    virtual void syscall(int64_t callnum) = 0;
202
203    /** @} */
204
205    /** Returns a pointer to the ThreadContext. */
206    virtual ThreadContext *tcBase() = 0;
207
208    /**
209     * @{
210     * @name Alpha-Specific Interfaces
211     */
212
213    /**
214     * Somewhat Alpha-specific function that handles returning from an
215     * error or interrupt.
216     */
217    virtual Fault hwrei() = 0;
218
219    /**
220     * Check for special simulator handling of specific PAL calls.  If
221     * return value is false, actual PAL call will be suppressed.
222     */
223    virtual bool simPalCheck(int palFunc) = 0;
224
225    /** @} */
226
227    /**
228     * @{
229     * @name ARM-Specific Interfaces
230     */
231
232    virtual bool readPredicate() = 0;
233    virtual void setPredicate(bool val) = 0;
234
235    /** @} */
236
237    /**
238     * @{
239     * @name X86-Specific Interfaces
240     */
241
242    /**
243     * Invalidate a page in the DTLB <i>and</i> ITLB.
244     */
245    virtual void demapPage(Addr vaddr, uint64_t asn) = 0;
246
247    /** @} */
248
249    /**
250     * @{
251     * @name MIPS-Specific Interfaces
252     */
253
254#if THE_ISA == MIPS_ISA
255    virtual MiscReg readRegOtherThread(int regIdx,
256                                       ThreadID tid = InvalidThreadID) = 0;
257    virtual void setRegOtherThread(int regIdx, MiscReg val,
258                                   ThreadID tid = InvalidThreadID) = 0;
259#endif
260
261    /** @} */
262};
263
264#endif // __CPU_EXEC_CONTEXT_HH__
265