arch: Use a fault to trigger system calls in SE mode.
[gem5.git] / src / sim / faults.hh
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 __FAULTS_HH__
30 #define __FAULTS_HH__
31
32 #include "base/types.hh"
33 #include "cpu/static_inst.hh"
34 #include "sim/stats.hh"
35
36 class ThreadContext;
37
38 typedef const char *FaultName;
39 typedef Stats::Scalar FaultStat;
40
41 class FaultBase
42 {
43 public:
44 virtual FaultName name() const = 0;
45 virtual void invoke(ThreadContext * tc, const StaticInstPtr &inst=
46 StaticInst::nullStaticInstPtr);
47
48 virtual ~FaultBase() {};
49 };
50
51 class UnimpFault : public FaultBase
52 {
53 private:
54 std::string panicStr;
55 public:
56 UnimpFault(std::string _str) : panicStr(_str) {}
57
58 FaultName
59 name() const override
60 {
61 return "Unimplemented simulator feature";
62 }
63 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
64 StaticInst::nullStaticInstPtr) override;
65 };
66
67 // A fault to trigger a system call in SE mode.
68 class SESyscallFault : public FaultBase
69 {
70 const char *name() const override { return "syscall_fault"; }
71
72 void invoke(ThreadContext *tc, const StaticInstPtr &inst=
73 StaticInst::nullStaticInstPtr) override;
74 };
75
76 class ReExec : public FaultBase
77 {
78 public:
79 virtual FaultName name() const override { return "Re-execution fault"; }
80 void invoke(ThreadContext *tc, const StaticInstPtr &inst=
81 StaticInst::nullStaticInstPtr) override;
82 };
83
84 /*
85 * This class is needed to allow system call retries to occur for blocking
86 * system calls in SE mode. A retry fault will be generated by the system call
87 * emulation code if blocking conditions arise; the fault is passed up the
88 * function call chain into the CPU model where it is handled by retrying the
89 * syscall instruction on a later tick.
90 */
91 class SyscallRetryFault : public FaultBase
92 {
93 public:
94 FaultName name() const override { return "System call retry fault"; }
95 SyscallRetryFault() {}
96 void invoke(ThreadContext *tc, const StaticInstPtr &inst=
97 StaticInst::nullStaticInstPtr) override;
98 };
99
100 class GenericPageTableFault : public FaultBase
101 {
102 private:
103 Addr vaddr;
104 public:
105 FaultName name() const override { return "Generic page table fault"; }
106 GenericPageTableFault(Addr va) : vaddr(va) {}
107 void invoke(ThreadContext *tc, const StaticInstPtr &inst=
108 StaticInst::nullStaticInstPtr) override;
109 Addr getFaultVAddr() const { return vaddr; }
110 };
111
112 class GenericAlignmentFault : public FaultBase
113 {
114 private:
115 Addr vaddr;
116 public:
117 FaultName name() const override { return "Generic alignment fault"; }
118 GenericAlignmentFault(Addr va) : vaddr(va) {}
119 void invoke(ThreadContext *tc, const StaticInstPtr &inst=
120 StaticInst::nullStaticInstPtr) override;
121 Addr getFaultVAddr() const { return vaddr; }
122 };
123
124 #endif // __FAULTS_HH__