<commit_before>/*
 * Copyright (c) 2003-2005 The Regents of The University of Michigan
 * Copyright (c) 2007-2008 The Florida State University
 * Copyright (c) 2009 The University of Edinburgh
 * All rights reserved.
 *
 * 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/power/linux/process.hh"

#include "arch/power/isa_traits.hh"
#include "arch/power/linux/linux.hh"
#include "base/loader/object_file.hh"
#include "base/trace.hh"
#include "cpu/thread_context.hh"
#include "kern/linux/linux.hh"
#include "sim/process.hh"
#include "sim/syscall_desc.hh"
#include "sim/syscall_emul.hh"
#include "sim/system.hh"

using namespace std;
using namespace PowerISA;

namespace
{

class PowerLinuxObjectFileLoader : public Process::Loader
{
  public:
    Process *
    load(ProcessParams *params, ObjectFile *obj_file) override
    {
        if (obj_file->getArch() != ObjectFile::Power)
            return nullptr;

        auto opsys = obj_file->getOpSys();

        if (opsys == ObjectFile::UnknownOpSys) {
            warn("Unknown operating system; assuming Linux.");
            opsys = ObjectFile::Linux;
        }

        if (opsys != ObjectFile::Linux)
            return nullptr;

        return new PowerLinuxProcess(params, obj_file);
    }
};

PowerLinuxObjectFileLoader loader;

} // anonymous namespace

/// Target uname() handler.
static SyscallReturn
unameFunc(SyscallDesc *desc, ThreadContext *tc, Addr utsname)
{
    auto process = tc->getProcessPtr();
    TypedBufferArg<Linux::utsname> name(utsname);

    strcpy(name->sysname, "Linux");
    strcpy(name->nodename, "sim.gem5.org");
    strcpy(name->release, process->release.c_str());
    strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
    strcpy(name->machine, "power");

    name.copyOut(tc->getVirtProxy());
    return 0;
}

SyscallDescTable<PowerProcess::SyscallABI> PowerLinuxProcess::syscallDescs = {
    {  0, "syscall" },
    {  1, "exit", exitFunc },
    {  2, "fork" },
    {  3, "read", readFunc<PowerLinux> },
    {  4, "write", writeFunc<PowerLinux> },
    {  5, "open", openFunc<PowerLinux> },
    {  6, "close", closeFunc },
    {  7, "waitpid" }, //???
    {  8, "creat" },
    {  9, "link" },
    { 10, "unlink", unlinkFunc },
    { 11, "execve" },
    { 12, "chdir" },
    { 13, "time", timeFunc<PowerLinux> },
    { 14, "mknod" },
    { 15, "chmod", chmodFunc<PowerLinux> },
    { 16, "lchown", chownFunc },
    { 17, "break", brkFunc }, //???
    { 18, "unused#18" }, //???
    { 19, "lseek", lseekFunc },
    { 20, "getpid", getpidFunc },
    { 21, "mount" },
    { 22, "umount" },
    { 23, "setuid", ignoreFunc },
    { 24, "getuid", getuidFunc },
    { 25, "stime" },
    { 26, "ptrace" },
    { 27, "alarm" },
    { 28, "unused#28" },
    { 29, "pause" },
    { 30, "utime" },
    { 31, "stty" },
    { 32, "gtty" },
    { 33, "access" },
    { 34, "nice" },
    { 35, "ftime" },
    { 36, "sync" },
    { 37, "kill", ignoreFunc },
    { 38, "rename", renameFunc },
    { 39, "mkdir" },
    { 40, "rmdir" },
    { 41, "dup", dupFunc },
    { 42, "pipe" },
    { 43, "times", timesFunc<PowerLinux> },
    { 44, "prof" },
    { 45, "brk", brkFunc },
    { 46, "setgid" },
    { 47, "getgid", getgidFunc },
    { 48, "signal", ignoreFunc },
    { 49, "geteuid", geteuidFunc },
    { 50, "getegid", getegidFunc },
    { 51, "acct" },
    { 52, "umount2" },
    { 53, "lock" },
    { 54, "ioctl", ioctlFunc<PowerLinux> },
    { 55, "fcntl", fcntlFunc },
    { 56, "mpx" },
    { 57, "setpgid" },
    { 58, "ulimit" },
    { 59, "unused#59" },
    { 60, "umask", umaskFunc },
    { 61, "chroot" },
    { 62, "ustat" },
    { 63, "dup2" },
    { 64, "getppid", getpagesizeFunc },
    { 65, "getpgrp" },
    { 66, "setsid" },
    { 67, "sigaction" },
    { 68, "sgetmask" },
    { 69, "ssetmask" },
    { 70, "setreuid" },
    { 71, "setregid" },
    { 72, "sigsuspend" },
    { 73, "sigpending" },
    { 74, "sethostname", ignoreFunc },
    { 75, "setrlimit", ignoreFunc },
    { 76, "getrlimit" },
    { 77, "getrusage", ignoreFunc },
    { 78, "gettimeofday" },
    { 79, "settimeofday" },
    { 80, "getgroups" },
    { 81, "setgroups" },
    { 82, "reserved#82" },
    { 83, "symlink" },
    { 84, "unused#84" },
    { 85, "readlink" },
    { 86, "uselib" },
    { 87, "swapon", gethostnameFunc },
    { 88, "reboot" },
    { 89, "readdir" },
    { 90, "mmap", mmapFunc<PowerLinux> },
    { 91, "munmap",munmapFunc },
    { 92, "truncate", truncateFunc },
    { 93, "ftruncate", ftruncateFunc },
    { 94, "fchmod" },
    { 95, "fchown" },
    { 96, "getpriority" },
    { 97, "setpriority" },
    { 98, "profil" },
    { 99, "statfs" },
    { 100, "fstatfs" },
    { 101, "ioperm" },<commit_msg>power: Hook up the readlink system call.<commit_after>/*
 * Copyright (c) 2003-2005 The Regents of The University of Michigan
 * Copyright (c) 2007-2008 The Florida State University
 * Copyright (c) 2009 The University of Edinburgh
 * All rights reserved.
 *
 * 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/power/linux/process.hh"

#include "arch/power/isa_traits.hh"
#include "arch/power/linux/linux.hh"
#include "base/loader/object_file.hh"
#include "base/trace.hh"
#include "cpu/thread_context.hh"
#include "kern/linux/linux.hh"
#include "sim/process.hh"
#include "sim/syscall_desc.hh"
#include "sim/syscall_emul.hh"
#include "sim/system.hh"

using namespace std;
using namespace PowerISA;

namespace
{

class PowerLinuxObjectFileLoader : public Process::Loader
{
  public:
    Process *
    load(ProcessParams *params, ObjectFile *obj_file) override
    {
        if (obj_file->getArch() != ObjectFile::Power)
            return nullptr;

        auto opsys = obj_file->getOpSys();

        if (opsys == ObjectFile::UnknownOpSys) {
            warn("Unknown operating system; assuming Linux.");
            opsys = ObjectFile::Linux;
        }

        if (opsys != ObjectFile::Linux)
            return nullptr;

        return new PowerLinuxProcess(params, obj_file);
    }
};

PowerLinuxObjectFileLoader loader;

} // anonymous namespace

/// Target uname() handler.
static SyscallReturn
unameFunc(SyscallDesc *desc, ThreadContext *tc, Addr utsname)
{
    auto process = tc->getProcessPtr();
    TypedBufferArg<Linux::utsname> name(utsname);

    strcpy(name->sysname, "Linux");
    strcpy(name->nodename, "sim.gem5.org");
    strcpy(name->release, process->release.c_str());
    strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
    strcpy(name->machine, "power");

    name.copyOut(tc->getVirtProxy());
    return 0;
}

SyscallDescTable<PowerProcess::SyscallABI> PowerLinuxProcess::syscallDescs = {
    {  0, "syscall" },
    {  1, "exit", exitFunc },
    {  2, "fork" },
    {  3, "read", readFunc<PowerLinux> },
    {  4, "write", writeFunc<PowerLinux> },
    {  5, "open", openFunc<PowerLinux> },
    {  6, "close", closeFunc },
    {  7, "waitpid" }, //???
    {  8, "creat" },
    {  9, "link" },
    { 10, "unlink", unlinkFunc },
    { 11, "execve" },
    { 12, "chdir" },
    { 13, "time", timeFunc<PowerLinux> },
    { 14, "mknod" },
    { 15, "chmod", chmodFunc<PowerLinux> },
    { 16, "lchown", chownFunc },
    { 17, "break", brkFunc }, //???
    { 18, "unused#18" }, //???
    { 19, "lseek", lseekFunc },
    { 20, "getpid", getpidFunc },
    { 21, "mount" },
    { 22, "umount" },
    { 23, "setuid", ignoreFunc },
    { 24, "getuid", getuidFunc },
    { 25, "stime" },
    { 26, "ptrace" },
    { 27, "alarm" },
    { 28, "unused#28" },
    { 29, "pause" },
    { 30, "utime" },
    { 31, "stty" },
    { 32, "gtty" },
    { 33, "access" },
    { 34, "nice" },
    { 35, "ftime" },
    { 36, "sync" },
    { 37, "kill", ignoreFunc },
    { 38, "rename", renameFunc },
    { 39, "mkdir" },
    { 40, "rmdir" },
    { 41, "dup", dupFunc },
    { 42, "pipe" },
    { 43, "times", timesFunc<PowerLinux> },
    { 44, "prof" },
    { 45, "brk", brkFunc },
    { 46, "setgid" },
    { 47, "getgid", getgidFunc },
    { 48, "signal", ignoreFunc },
    { 49, "geteuid", geteuidFunc },
    { 50, "getegid", getegidFunc },
    { 51, "acct" },
    { 52, "umount2" },
    { 53, "lock" },
    { 54, "ioctl", ioctlFunc<PowerLinux> },
    { 55, "fcntl", fcntlFunc },
    { 56, "mpx" },
    { 57, "setpgid" },
    { 58, "ulimit" },
    { 59, "unused#59" },
    { 60, "umask", umaskFunc },
    { 61, "chroot" },
    { 62, "ustat" },
    { 63, "dup2" },
    { 64, "getppid", getpagesizeFunc },
    { 65, "getpgrp" },
    { 66, "setsid" },
    { 67, "sigaction" },
    { 68, "sgetmask" },
    { 69, "ssetmask" },
    { 70, "setreuid" },
    { 71, "setregid" },
    { 72, "sigsuspend" },
    { 73, "sigpending" },
    { 74, "sethostname", ignoreFunc },
    { 75, "setrlimit", ignoreFunc },
    { 76, "getrlimit" },
    { 77, "getrusage", ignoreFunc },
    { 78, "gettimeofday" },
    { 79, "settimeofday" },
    { 80, "getgroups" },
    { 81, "setgroups" },
    { 82, "reserved#82" },
    { 83, "symlink" },
    { 84, "unused#84" },
    { 85, "readlink", readlinkFunc },
    { 86, "uselib" },
    { 87, "swapon", gethostnameFunc },
    { 88, "reboot" },
    { 89, "readdir" },
    { 90, "mmap", mmapFunc<PowerLinux> },
    { 91, "munmap",munmapFunc },
    { 92, "truncate", truncateFunc },
    { 93, "ftruncate", ftruncateFunc },
    { 94, "fchmod" },
    { 95, "fchown" },
    { 96, "getpriority" },
    { 97, "setpriority" },
    { 98, "profil" },
    { 99, "statfs" },
    { 100, "fstatfs" },
    { 101, "ioperm" },
{'fraction_non_alphanumeric': 0.15994481863182666, 'fraction_numerical': 0.03943844842976548, 'mean_word_length': 3.0446340662947162, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1761387', 'n_tokens_mistral': 4754, 'n_tokens_neox': 4137, 'n_words': 1181}