misc: Delete the now unnecessary create methods.
[gem5.git] / src / arch / sparc / linux / se_workload.cc
1 /*
2 * Copyright 2003-2005 The Regents of The University of Michigan
3 * Copyright 2020 Google Inc.
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 #include "arch/sparc/linux/se_workload.hh"
30
31 #include <sys/syscall.h>
32
33 #include "arch/sparc/process.hh"
34 #include "base/loader/object_file.hh"
35 #include "base/trace.hh"
36 #include "cpu/thread_context.hh"
37 #include "sim/syscall_desc.hh"
38
39 namespace
40 {
41
42 class LinuxLoader : public Process::Loader
43 {
44 public:
45 Process *
46 load(const ProcessParams &params, ::Loader::ObjectFile *obj) override
47 {
48 auto arch = obj->getArch();
49 auto opsys = obj->getOpSys();
50
51 if (arch != ::Loader::SPARC64 && arch != ::Loader::SPARC32)
52 return nullptr;
53
54 if (opsys == ::Loader::UnknownOpSys) {
55 warn("Unknown operating system; assuming Linux.");
56 opsys = ::Loader::Linux;
57 }
58
59 if (opsys != ::Loader::Linux)
60 return nullptr;
61
62 if (arch == ::Loader::SPARC64)
63 return new Sparc64Process(params, obj);
64 else
65 return new Sparc32Process(params, obj);
66 }
67 };
68
69 LinuxLoader loader;
70
71 } // anonymous namespace
72
73 namespace SparcISA
74 {
75
76 EmuLinux::EmuLinux(const Params &p) : SEWorkload(p), _params(p)
77 {}
78
79 void
80 EmuLinux::handleTrap(ThreadContext *tc, int trapNum)
81 {
82 if (is64(tc)) {
83 switch (trapNum) {
84 // case 0x10: // Linux 32 bit syscall trap
85 case 0x6d: // Linux 64 bit syscall trap
86 syscall64(tc);
87 return;
88 case 0x6e: // Linux 64 bit getcontext trap
89 warn("The getcontext trap is not implemented on SPARC");
90 return;
91 case 0x6f: // Linux 64 bit setcontext trap
92 panic("The setcontext trap is not implemented on SPARC");
93 default:
94 break;
95 }
96 } else {
97 switch (trapNum) {
98 case 0x10: //Linux 32 bit syscall trap
99 syscall32(tc);
100 return;
101 default:
102 break;
103 }
104 }
105 SEWorkload::handleTrap(tc, trapNum);
106 }
107
108 void
109 EmuLinux::syscall32(ThreadContext *tc)
110 {
111 Process *process = tc->getProcessPtr();
112 // Call the syscall function in the base Process class to update stats.
113 // This will move into the base SEWorkload function at some point.
114 process->Process::syscall(tc);
115
116 syscall32Descs.get(tc->readIntReg(1))->doSyscall(tc);
117 }
118
119 void
120 EmuLinux::syscall64(ThreadContext *tc)
121 {
122 Process *process = tc->getProcessPtr();
123 // Call the syscall function in the base Process class to update stats.
124 // This will move into the base SEWorkload function at some point.
125 process->Process::syscall(tc);
126
127 syscallDescs.get(tc->readIntReg(1))->doSyscall(tc);
128 }
129
130 void
131 EmuLinux::syscall(ThreadContext *tc)
132 {
133 if (is64(tc))
134 syscall64(tc);
135 else
136 syscall32(tc);
137 }
138
139 } // namespace SparcISA