/* * Copyright 2020 Google Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer; * redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution; * neither the name of the copyright holders nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "arch/sparc/linux/se_workload.hh" #include #include "arch/sparc/process.hh" #include "base/loader/object_file.hh" #include "base/trace.hh" #include "cpu/thread_context.hh" #include "sim/syscall_desc.hh" namespace { class LinuxLoader : public Process::Loader { public: Process * load(const ProcessParams ¶ms, ::Loader::ObjectFile *obj) override { auto arch = obj->getArch(); auto opsys = obj->getOpSys(); if (arch != ::Loader::SPARC64 && arch != ::Loader::SPARC32) return nullptr; if (opsys == ::Loader::UnknownOpSys) { warn("Unknown operating system; assuming Linux."); opsys = ::Loader::Linux; } if (opsys != ::Loader::Linux) return nullptr; if (arch == ::Loader::SPARC64) return new Sparc64Process(params, obj); else return new Sparc32Process(params, obj); } }; LinuxLoader loader; } // anonymous namespace namespace SparcISA { EmuLinux::EmuLinux(const Params &p) : SEWorkload(p), _params(p) {} void EmuLinux::handleTrap(ThreadContext *tc, int trapNum) { if (is64(tc)) { switch (trapNum) { // case 0x10: // Linux 32 bit syscall trap case 0x6d: // Linux 64 bit syscall trap syscall64(tc); return; case 0x6e: // Linux 64 bit getcontext trap warn("The getcontext trap is not implemented on SPARC"); return; case 0x6f: // Linux 64 bit setcontext trap panic("The setcontext trap is not implemented on SPARC"); default: break; } } else { switch (trapNum) { case 0x10: //Linux 32 bit syscall trap syscall32(tc); return; default: break; } } SEWorkload::handleTrap(tc, trapNum); } void EmuLinux::syscall32(ThreadContext *tc) { Process *process = tc->getProcessPtr(); // Call the syscall function in the base Process class to update stats. // This will move into the base SEWorkload function at some point. process->Process::syscall(tc); syscall32Descs.get(tc->readIntReg(1))->doSyscall(tc); } void EmuLinux::syscall64(ThreadContext *tc) { Process *process = tc->getProcessPtr(); // Call the syscall function in the base Process class to update stats. // This will move into the base SEWorkload function at some point. process->Process::syscall(tc); syscallDescs.get(tc->readIntReg(1))->doSyscall(tc); } void EmuLinux::syscall(ThreadContext *tc) { if (is64(tc)) syscall64(tc); else syscall32(tc); } } // namespace SparcISA SparcISA::EmuLinux * SparcEmuLinuxParams::create() const { return new SparcISA::EmuLinux(*this); }