faults.hh revision 7362:9ea92e0eb4a9
1/*
2 * Copyright (c) 2010 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder.  You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2003-2005 The Regents of The University of Michigan
15 * Copyright (c) 2007-2008 The Florida State University
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Ali Saidi
42 *          Gabe Black
43 */
44
45#ifndef __ARM_FAULTS_HH__
46#define __ARM_FAULTS_HH__
47
48#include "arch/arm/miscregs.hh"
49#include "arch/arm/types.hh"
50#include "config/full_system.hh"
51#include "sim/faults.hh"
52
53// The design of the "name" and "vect" functions is in sim/faults.hh
54
55namespace ArmISA
56{
57typedef const Addr FaultOffset;
58
59class ArmFault : public FaultBase
60{
61  protected:
62    Addr getVector(ThreadContext *tc);
63
64  public:
65    enum StatusEncoding
66    {
67        // Fault Status register encodings
68        // ARM ARM B3.9.4
69        AlignmentFault = 0x1,
70        DebugEvent = 0x2,
71        AccessFlag0 = 0x3,
72        InstructionCacheMaintenance = 0x4,
73        Translation0 = 0x5,
74        AccessFlag1 = 0x6,
75        Translation1 = 0x7,
76        SynchronousExternalAbort0 = 0x8,
77        Domain0 = 0x9,
78        Domain1 = 0xb,
79        TranslationTableWalk0 = 0xc,
80        Permission0 = 0xd,
81        SynchronousExternalAbort1 = 0xe,
82        Permission1 = 0xf,
83        AsynchronousExternalAbort = 0x16,
84        MemoryAccessAsynchronousParityError = 0x18,
85        MemoryAccessSynchronousParityError = 0x19,
86        TranslationTableWalk1 = 0x1c,
87        SynchronousParityError = 0x1e
88    };
89
90    struct FaultVals
91    {
92        const FaultName name;
93        const FaultOffset offset;
94        const OperatingMode nextMode;
95        const uint8_t armPcOffset;
96        const uint8_t thumbPcOffset;
97        const bool abortDisable;
98        const bool fiqDisable;
99        FaultStat count;
100    };
101
102#if FULL_SYSTEM
103    void invoke(ThreadContext *tc);
104#endif
105    virtual FaultStat& countStat() = 0;
106    virtual FaultOffset offset() = 0;
107    virtual OperatingMode nextMode() = 0;
108    virtual uint8_t armPcOffset() = 0;
109    virtual uint8_t thumbPcOffset() = 0;
110    virtual bool abortDisable() = 0;
111    virtual bool fiqDisable() = 0;
112};
113
114template<typename T>
115class ArmFaultVals : public ArmFault
116{
117  protected:
118    static FaultVals vals;
119
120  public:
121    FaultName name() const { return vals.name; }
122    FaultStat & countStat() {return vals.count;}
123    FaultOffset offset() { return vals.offset; }
124    OperatingMode nextMode() { return vals.nextMode; }
125    uint8_t armPcOffset() { return vals.armPcOffset; }
126    uint8_t thumbPcOffset() { return vals.thumbPcOffset; }
127    bool abortDisable() { return vals.abortDisable; }
128    bool fiqDisable() { return vals.fiqDisable; }
129};
130
131
132class Reset : public ArmFaultVals<Reset> {};
133
134class UndefinedInstruction : public ArmFaultVals<UndefinedInstruction>
135{
136#if !FULL_SYSTEM
137  protected:
138    ExtMachInst machInst;
139    bool unknown;
140    const char *mnemonic;
141
142  public:
143    UndefinedInstruction(ExtMachInst _machInst,
144                         bool _unknown,
145                         const char *_mnemonic = NULL) :
146        machInst(_machInst), unknown(_unknown), mnemonic(_mnemonic)
147    {
148    }
149
150    void invoke(ThreadContext *tc);
151#endif
152};
153
154class SupervisorCall : public ArmFaultVals<SupervisorCall>
155{
156#if !FULL_SYSTEM
157  protected:
158    ExtMachInst machInst;
159
160  public:
161    SupervisorCall(ExtMachInst _machInst) : machInst(_machInst)
162    {}
163
164    void invoke(ThreadContext *tc);
165#endif
166};
167
168template <class T>
169class AbortFault : public ArmFaultVals<T>
170{
171  protected:
172    Addr faultAddr;
173    bool write;
174    uint8_t domain;
175    uint8_t status;
176
177  public:
178    AbortFault(Addr _faultAddr, bool _write,
179            uint8_t _domain, uint8_t _status) :
180        faultAddr(_faultAddr), write(_write),
181        domain(_domain), status(_status)
182    {}
183
184    void invoke(ThreadContext *tc);
185};
186
187class PrefetchAbort : public AbortFault<PrefetchAbort>
188{
189  public:
190    static const MiscRegIndex FsrIndex = MISCREG_IFSR;
191    static const MiscRegIndex FarIndex = MISCREG_IFAR;
192
193    PrefetchAbort(Addr _addr, uint8_t _status) :
194        AbortFault<PrefetchAbort>(_addr, false, 0, _status)
195    {}
196};
197
198class DataAbort : public AbortFault<DataAbort>
199{
200  public:
201    static const MiscRegIndex FsrIndex = MISCREG_DFSR;
202    static const MiscRegIndex FarIndex = MISCREG_DFAR;
203
204    DataAbort(Addr _addr, bool _write, uint8_t _domain, uint8_t _status) :
205        AbortFault<DataAbort>(_addr, _write, _domain, _status)
206    {}
207};
208
209class Interrupt : public ArmFaultVals<Interrupt> {};
210class FastInterrupt : public ArmFaultVals<FastInterrupt> {};
211
212
213} // ArmISA namespace
214
215#endif // __ARM_FAULTS_HH__
216