isa_traits.hh revision 2474
1/*
2 * Copyright (c) 2003-2005 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 __ARCH_SPARC_ISA_TRAITS_HH__
30#define __ARCH_SPARC_ISA_TRAITS_HH__
31
32#include "base/misc.hh"
33#include "config/full_system.hh"
34#include "sim/host.hh"
35
36class ExecContext;
37class FastCPU;
38//class FullCPU;
39class Checkpoint;
40
41class StaticInst;
42class StaticInstPtr;
43
44namespace BigEndianGuest {}
45
46#if !FULL_SYSTEM
47class SyscallReturn
48{
49  public:
50    template <class T>
51    SyscallReturn(T v, bool s)
52    {
53        retval = (uint64_t)v;
54        success = s;
55    }
56
57    template <class T>
58    SyscallReturn(T v)
59    {
60        success = (v >= 0);
61        retval = (uint64_t)v;
62    }
63
64    ~SyscallReturn() {}
65
66    SyscallReturn& operator=(const SyscallReturn& s)
67    {
68        retval = s.retval;
69        success = s.success;
70        return *this;
71    }
72
73    bool successful() { return success; }
74    uint64_t value() { return retval; }
75
76    private:
77    uint64_t retval;
78    bool success;
79};
80
81#endif
82
83
84namespace SparcISA
85{
86    //This makes sure the big endian versions of certain functions are used.
87    using namespace BigEndianGuest;
88
89    typedef uint32_t MachInst;
90    typedef uint64_t ExtMachInst;
91
92    const int NumIntRegs = 32;
93    const int NumFloatRegs = 64;
94    const int NumMiscRegs = 32;
95
96    // semantically meaningful register indices
97    const int ZeroReg = 0;	// architecturally meaningful
98    // the rest of these depend on the ABI
99    const int StackPointerReg = 14;
100    const int ReturnAddressReg = 31; // post call, precall is 15
101    const int ReturnValueReg = 8; // Post return, 24 is pre-return.
102    const int FramePointerReg = 30;
103    const int ArgumentReg0 = 8;
104    const int ArgumentReg1 = 9;
105    const int ArgumentReg2 = 10;
106    const int ArgumentReg3 = 11;
107    const int ArgumentReg4 = 12;
108    const int ArgumentReg5 = 13;
109    // Some OS syscall sue a second register (o1) to return a second value
110    const int SyscallPseudoReturnReg = ArgumentReg1;
111
112    //XXX These numbers are bogus
113    const int MaxInstSrcRegs = 3;
114    const int MaxInstDestRegs = 2;
115
116    typedef uint64_t IntReg;
117
118    // control register file contents
119    typedef uint64_t MiscReg;
120
121    typedef double FloatReg;
122    typedef uint64_t FloatRegBits;
123
124    //8K. This value is implmentation specific; and should probably
125    //be somewhere else.
126    const int LogVMPageSize = 13;
127    const int VMPageSize = (1 << LogVMPageSize);
128
129    //Why does both the previous set of constants and this one exist?
130    const int PageShift = 13;
131    const int PageBytes = ULL(1) << PageShift;
132
133    const int BranchPredAddrShiftAmt = 2;
134
135    const int MachineBytes = 8;
136    const int WordBytes = 4;
137    const int HalfwordBytes = 2;
138    const int ByteBytes = 1;
139
140    void serialize(std::ostream & os);
141
142    void unserialize(Checkpoint *cp, const std::string &section);
143
144    StaticInstPtr decodeInst(MachInst);
145
146    // return a no-op instruction... used for instruction fetch faults
147    extern const MachInst NoopMachInst;
148
149    // Instruction address compression hooks
150    inline Addr realPCToFetchPC(const Addr &addr)
151    {
152        return addr;
153    }
154
155    inline Addr fetchPCToRealPC(const Addr &addr)
156    {
157        return addr;
158    }
159
160    // the size of "fetched" instructions (not necessarily the size
161    // of real instructions for PISA)
162    inline size_t fetchInstSize()
163    {
164        return sizeof(MachInst);
165    }
166
167    /**
168     * Function to insure ISA semantics about 0 registers.
169     * @param xc The execution context.
170     */
171    template <class XC>
172    void zeroRegisters(XC *xc);
173}
174
175#include "arch/sparc/regfile.hh"
176
177namespace SparcISA
178{
179
180#if !FULL_SYSTEM
181    static inline void setSyscallReturn(SyscallReturn return_value,
182            RegFile *regs)
183    {
184        // check for error condition.  SPARC syscall convention is to
185        // indicate success/failure in reg the carry bit of the ccr
186        // and put the return value itself in the standard return value reg ().
187        if (return_value.successful()) {
188            // no error
189            regs->miscRegs.setReg(MISCREG_CCR_ICC_C, 0);
190            regs->intRegFile[ReturnValueReg] = return_value.value();
191        } else {
192            // got an error, return details
193            regs->miscRegs.setReg(MISCREG_CCR_ICC_C, 1);
194            regs->intRegFile[ReturnValueReg] = -return_value.value();
195        }
196    }
197#endif
198};
199
200#endif // __ARCH_SPARC_ISA_TRAITS_HH__
201