12199SN/A/*
22199SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
32199SN/A * All rights reserved.
42199SN/A *
52199SN/A * Redistribution and use in source and binary forms, with or without
62199SN/A * modification, are permitted provided that the following conditions are
72199SN/A * met: redistributions of source code must retain the above copyright
82199SN/A * notice, this list of conditions and the following disclaimer;
92199SN/A * redistributions in binary form must reproduce the above copyright
102199SN/A * notice, this list of conditions and the following disclaimer in the
112199SN/A * documentation and/or other materials provided with the distribution;
122199SN/A * neither the name of the copyright holders nor the names of its
132199SN/A * contributors may be used to endorse or promote products derived from
142199SN/A * this software without specific prior written permission.
152199SN/A *
162199SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172199SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182199SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192199SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202199SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212199SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222199SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232199SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242199SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252199SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262199SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
292665Ssaidi@eecs.umich.edu *          Gabe Black
302665Ssaidi@eecs.umich.edu *          Ali Saidi
312199SN/A */
322199SN/A
338229Snate@binkert.org#include "arch/sparc/linux/process.hh"
3411793Sbrandon.potter@amd.com
352561SN/A#include "arch/sparc/isa_traits.hh"
366329Sgblack@eecs.umich.edu#include "arch/sparc/registers.hh"
3713988Sgabeblack@google.com#include "base/loader/object_file.hh"
382199SN/A#include "base/trace.hh"
392680Sktlim@umich.edu#include "cpu/thread_context.hh"
402199SN/A#include "kern/linux/linux.hh"
412199SN/A#include "sim/process.hh"
4211794Sbrandon.potter@amd.com#include "sim/syscall_desc.hh"
432199SN/A#include "sim/syscall_emul.hh"
442199SN/A
452199SN/Ausing namespace std;
462209SN/Ausing namespace SparcISA;
472199SN/A
4813988Sgabeblack@google.comnamespace
4913988Sgabeblack@google.com{
5013988Sgabeblack@google.com
5113988Sgabeblack@google.comclass SparcLinuxObjectFileLoader : public ObjectFile::Loader
5213988Sgabeblack@google.com{
5313988Sgabeblack@google.com  public:
5413988Sgabeblack@google.com    Process *
5513988Sgabeblack@google.com    load(ProcessParams *params, ObjectFile *obj_file) override
5613988Sgabeblack@google.com    {
5713988Sgabeblack@google.com        auto arch = obj_file->getArch();
5813988Sgabeblack@google.com        auto opsys = obj_file->getOpSys();
5913988Sgabeblack@google.com
6013988Sgabeblack@google.com        if (arch != ObjectFile::SPARC64 && arch != ObjectFile::SPARC32)
6113988Sgabeblack@google.com            return nullptr;
6213988Sgabeblack@google.com
6313988Sgabeblack@google.com        if (opsys == ObjectFile::UnknownOpSys) {
6413988Sgabeblack@google.com            warn("Unknown operating system; assuming Linux.");
6513988Sgabeblack@google.com            opsys = ObjectFile::Linux;
6613988Sgabeblack@google.com        }
6713988Sgabeblack@google.com
6813988Sgabeblack@google.com        if (opsys != ObjectFile::Linux)
6913988Sgabeblack@google.com            return nullptr;
7013988Sgabeblack@google.com
7113988Sgabeblack@google.com        if (arch == ObjectFile::SPARC64)
7213988Sgabeblack@google.com            return new Sparc64LinuxProcess(params, obj_file);
7313988Sgabeblack@google.com        else
7413988Sgabeblack@google.com            return new Sparc32LinuxProcess(params, obj_file);
7513988Sgabeblack@google.com    }
7613988Sgabeblack@google.com};
7713988Sgabeblack@google.com
7813988Sgabeblack@google.comSparcLinuxObjectFileLoader loader;
7913988Sgabeblack@google.com
8013988Sgabeblack@google.com} // anonymous namespace
8113988Sgabeblack@google.com
822199SN/ASyscallDesc*
832458SN/ASparcLinuxProcess::getDesc(int callnum)
842199SN/A{
855981Sstever@gmail.com    if (callnum < 0 || callnum >= Num_Syscall_Descs)
862199SN/A        return NULL;
872199SN/A    return &syscallDescs[callnum];
882199SN/A}
894111Sgblack@eecs.umich.edu
904188Sgblack@eecs.umich.eduSyscallDesc*
914188Sgblack@eecs.umich.eduSparcLinuxProcess::getDesc32(int callnum)
924188Sgblack@eecs.umich.edu{
935981Sstever@gmail.com    if (callnum < 0 || callnum >= Num_Syscall32_Descs)
944188Sgblack@eecs.umich.edu        return NULL;
954188Sgblack@eecs.umich.edu    return &syscall32Descs[callnum];
964188Sgblack@eecs.umich.edu}
974111Sgblack@eecs.umich.edu
9811851Sbrandon.potter@amd.comSparc32LinuxProcess::Sparc32LinuxProcess(ProcessParams * params,
995154Sgblack@eecs.umich.edu                                         ObjectFile *objFile)
10011851Sbrandon.potter@amd.com    : Sparc32Process(params, objFile)
1014111Sgblack@eecs.umich.edu{}
1024111Sgblack@eecs.umich.edu
10311877Sbrandon.potter@amd.comvoid Sparc32LinuxProcess::handleTrap(int trapNum, ThreadContext *tc,
10411877Sbrandon.potter@amd.com                                     Fault *fault)
1054111Sgblack@eecs.umich.edu{
1067741Sgblack@eecs.umich.edu    switch (trapNum) {
1074111Sgblack@eecs.umich.edu      case 0x10: //Linux 32 bit syscall trap
10811877Sbrandon.potter@amd.com        tc->syscall(tc->readIntReg(1), fault);
1094111Sgblack@eecs.umich.edu        break;
1104111Sgblack@eecs.umich.edu      default:
11111877Sbrandon.potter@amd.com        SparcProcess::handleTrap(trapNum, tc, fault);
1124111Sgblack@eecs.umich.edu    }
1134111Sgblack@eecs.umich.edu}
1144111Sgblack@eecs.umich.edu
11511851Sbrandon.potter@amd.comSparc64LinuxProcess::Sparc64LinuxProcess(ProcessParams * params,
1165154Sgblack@eecs.umich.edu                                         ObjectFile *objFile)
11711851Sbrandon.potter@amd.com    : Sparc64Process(params, objFile)
1184111Sgblack@eecs.umich.edu{}
1194111Sgblack@eecs.umich.edu
12011877Sbrandon.potter@amd.comvoid Sparc64LinuxProcess::handleTrap(int trapNum, ThreadContext *tc,
12111877Sbrandon.potter@amd.com                                     Fault *fault)
1224111Sgblack@eecs.umich.edu{
1237741Sgblack@eecs.umich.edu    switch (trapNum) {
1247741Sgblack@eecs.umich.edu      // case 0x10: // Linux 32 bit syscall trap
1257741Sgblack@eecs.umich.edu      case 0x6d: // Linux 64 bit syscall trap
12611877Sbrandon.potter@amd.com        tc->syscall(tc->readIntReg(1), fault);
1274111Sgblack@eecs.umich.edu        break;
1284111Sgblack@eecs.umich.edu      default:
12911877Sbrandon.potter@amd.com        SparcProcess::handleTrap(trapNum, tc, fault);
1304111Sgblack@eecs.umich.edu    }
1314111Sgblack@eecs.umich.edu}
132