12579SN/A/*
22579SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
32579SN/A * All rights reserved.
42579SN/A *
52579SN/A * Redistribution and use in source and binary forms, with or without
62579SN/A * modification, are permitted provided that the following conditions are
72579SN/A * met: redistributions of source code must retain the above copyright
82579SN/A * notice, this list of conditions and the following disclaimer;
92579SN/A * redistributions in binary form must reproduce the above copyright
102579SN/A * notice, this list of conditions and the following disclaimer in the
112579SN/A * documentation and/or other materials provided with the distribution;
122579SN/A * neither the name of the copyright holders nor the names of its
132579SN/A * contributors may be used to endorse or promote products derived from
142579SN/A * this software without specific prior written permission.
152579SN/A *
162579SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172579SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182579SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192579SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202579SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212579SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222579SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232579SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242579SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252579SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262579SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Gabe Black
292579SN/A */
302579SN/A
312599SN/A#ifndef __ARCH_SPARC_LINUX_LINUX_HH__
322599SN/A#define __ARCH_SPARC_LINUX_LINUX_HH__
332579SN/A
3413536Sandreas.sandberg@arm.com#include "arch/sparc/utility.hh"
352579SN/A#include "kern/linux/linux.hh"
362579SN/A
372579SN/Aclass SparcLinux : public Linux
382579SN/A{
392579SN/A  public:
402579SN/A
413113Sgblack@eecs.umich.edu    typedef struct {
423113Sgblack@eecs.umich.edu        uint32_t st_dev;
433113Sgblack@eecs.umich.edu        char __pad1[4];
443113Sgblack@eecs.umich.edu        uint64_t st_ino;
453113Sgblack@eecs.umich.edu        uint32_t st_mode;
463113Sgblack@eecs.umich.edu        uint16_t st_nlink;
473113Sgblack@eecs.umich.edu        uint32_t st_uid;
483113Sgblack@eecs.umich.edu        uint32_t st_gid;
493113Sgblack@eecs.umich.edu        uint32_t st_rdev;
503113Sgblack@eecs.umich.edu        char __pad2[4];
513113Sgblack@eecs.umich.edu        int64_t st_size;
523113Sgblack@eecs.umich.edu        int64_t st_atimeX;
533113Sgblack@eecs.umich.edu        int64_t st_mtimeX;
543113Sgblack@eecs.umich.edu        int64_t st_ctimeX;
553113Sgblack@eecs.umich.edu        int64_t st_blksize;
563113Sgblack@eecs.umich.edu        int64_t st_blocks;
573113Sgblack@eecs.umich.edu        uint64_t __unused4[2];
583113Sgblack@eecs.umich.edu    } tgt_stat;
593113Sgblack@eecs.umich.edu
6011382Sbrandon.potter@amd.com    // SPARC receives weird subsignals for several of its signals. If you
6111382Sbrandon.potter@amd.com    // find yourself needing to implement these in detail, look at the
6211382Sbrandon.potter@amd.com    // Linux source.
6311382Sbrandon.potter@amd.com    static const int TGT_SIGHUP         = 0x000001;
6411382Sbrandon.potter@amd.com    static const int TGT_SIGINT         = 0x000002;
6511382Sbrandon.potter@amd.com    static const int TGT_SIGQUIT        = 0x000003;
6611382Sbrandon.potter@amd.com    static const int TGT_SIGILL         = 0x000004;
6711382Sbrandon.potter@amd.com    static const int TGT_SIGTRAP        = 0x000005;
6811382Sbrandon.potter@amd.com    static const int TGT_SIGABRT        = 0x000006;
6911382Sbrandon.potter@amd.com    static const int TGT_SIGIOT         = 0x000006;
7011382Sbrandon.potter@amd.com    static const int TGT_SIGEMT         = 0x000007;
7111382Sbrandon.potter@amd.com    static const int TGT_SIGFPE         = 0x000008;
7211382Sbrandon.potter@amd.com    static const int TGT_SIGKILL        = 0x000009;
7311382Sbrandon.potter@amd.com    static const int TGT_SIGBUS         = 0x00000a;
7411382Sbrandon.potter@amd.com    static const int TGT_SIGSEGV        = 0x00000b;
7511382Sbrandon.potter@amd.com    static const int TGT_SIGSYS         = 0x00000c;
7611382Sbrandon.potter@amd.com    static const int TGT_SIGPIPE        = 0x00000d;
7711382Sbrandon.potter@amd.com    static const int TGT_SIGALRM        = 0x00000e;
7811382Sbrandon.potter@amd.com    static const int TGT_SIGTERM        = 0x00000f;
7911382Sbrandon.potter@amd.com    static const int TGT_SIGURG         = 0x000010;
8011382Sbrandon.potter@amd.com    static const int TGT_SIGSTOP        = 0x000011;
8111382Sbrandon.potter@amd.com    static const int TGT_SIGTSTP        = 0x000012;
8211382Sbrandon.potter@amd.com    static const int TGT_SIGCONT        = 0x000013;
8311382Sbrandon.potter@amd.com    static const int TGT_SIGCHLD        = 0x000014;
8411382Sbrandon.potter@amd.com    static const int TGT_SIGTTIN        = 0x000015;
8511382Sbrandon.potter@amd.com    static const int TGT_SIGTTOU        = 0x000016;
8611382Sbrandon.potter@amd.com    static const int TGT_SIGIO          = 0x000017;
8711382Sbrandon.potter@amd.com    static const int TGT_SIGPOLL        = 0x000017;
8811382Sbrandon.potter@amd.com    static const int TGT_SIGXCPU        = 0x000018;
8911382Sbrandon.potter@amd.com    static const int TGT_SIGXFSZ        = 0x000019;
9011382Sbrandon.potter@amd.com    static const int TGT_SIGVTALRM      = 0x00001a;
9111382Sbrandon.potter@amd.com    static const int TGT_SIGPROF        = 0x00001b;
9211382Sbrandon.potter@amd.com    static const int TGT_SIGWINCH       = 0x00001c;
9311382Sbrandon.potter@amd.com    static const int TGT_SIGLOST        = 0x00001d;
9411382Sbrandon.potter@amd.com    static const int TGT_SIGPWR         = 0x00001d;
9511382Sbrandon.potter@amd.com    static const int TGT_SIGUSR1        = 0x00001e;
9611382Sbrandon.potter@amd.com    static const int TGT_SIGUSR2        = 0x00001f;
9711382Sbrandon.potter@amd.com
9811381Sbrandon.potter@amd.com    static SyscallFlagTransTable openFlagTable[];
992579SN/A
1005543Ssaidi@eecs.umich.edu    static const int TGT_O_RDONLY       = 0x00000000;   //!< O_RDONLY
1015543Ssaidi@eecs.umich.edu    static const int TGT_O_WRONLY       = 0x00000001;   //!< O_WRONLY
1025543Ssaidi@eecs.umich.edu    static const int TGT_O_RDWR         = 0x00000002;   //!< O_RDWR
1035543Ssaidi@eecs.umich.edu    static const int TGT_O_NONBLOCK     = 0x00004000;   //!< O_NONBLOCK
1045543Ssaidi@eecs.umich.edu    static const int TGT_O_APPEND       = 0x00000008;   //!< O_APPEND
10511382Sbrandon.potter@amd.com    static const int TGT_FASYNC         = 0x00000040;   //!< FASYNC
1065543Ssaidi@eecs.umich.edu    static const int TGT_O_CREAT        = 0x00000200;   //!< O_CREAT
1075543Ssaidi@eecs.umich.edu    static const int TGT_O_TRUNC        = 0x00000400;   //!< O_TRUNC
1085543Ssaidi@eecs.umich.edu    static const int TGT_O_EXCL         = 0x00000800;   //!< O_EXCL
1095543Ssaidi@eecs.umich.edu    static const int TGT_O_NOCTTY       = 0x00008000;   //!< O_NOCTTY
11011413Ssteve.reinhardt@amd.com    static const int TGT_O_DSYNC        = 0x00002000;   //!< O_DSYNC
11111382Sbrandon.potter@amd.com    static const int TGT_O_LARGEFILE    = 0x00040000;   //!< O_LARGEFILE
11211382Sbrandon.potter@amd.com    static const int TGT_O_DIRECT       = 0x00100000;   //!< O_DIRECT
11311382Sbrandon.potter@amd.com    static const int TGT_O_NOATIME      = 0x00200000;   //!< O_NOATIME
11411382Sbrandon.potter@amd.com    static const int TGT_O_CLOEXEC      = 0x00400000;   //!< O_CLOEXEC
11511413Ssteve.reinhardt@amd.com    static const int TGT_O_SYNC         = 0x00802000;   //!< O_SYNC
11611382Sbrandon.potter@amd.com    static const int TGT_O_PATH         = 0x01000000;   //!< O_PATH
11711382Sbrandon.potter@amd.com
11811382Sbrandon.potter@amd.com    static const int TGT_O_DIRECTORY    = 000200000;   //!< O_DIRECTORY
11911382Sbrandon.potter@amd.com    static const int TGT_O_NOFOLLOW     = 000400000;   //!< O_NOFOLLOW
1202579SN/A
1212579SN/A    static const int NUM_OPEN_FLAGS;
1222579SN/A
12311383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_SHARED        = 0x00001;
12411383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_PRIVATE       = 0x00002;
12511383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_ANON          = 0x00020;
12611383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_DENYWRITE     = 0x00800;
12711383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_EXECUTABLE    = 0x01000;
12811383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_FILE          = 0x00000;
12911383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_GROWSDOWN     = 0x00200;
13011383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_HUGETLB       = 0x40000;
13111383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_LOCKED        = 0x00100;
13211383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_NONBLOCK      = 0x10000;
13311383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_NORESERVE     = 0x00040;
13411383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_POPULATE      = 0x08000;
13511383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_STACK         = 0x20000;
13611383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_ANONYMOUS     = 0x00020;
13711383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_FIXED         = 0x00010;
13811383Sbrandon.potter@amd.com    static const unsigned TGT_MAP_INHERIT       = 0x00080;
13911383Sbrandon.potter@amd.com
14011383Sbrandon.potter@amd.com    static const unsigned NUM_MMAP_FLAGS;
14111320Ssteve.reinhardt@amd.com
14211320Ssteve.reinhardt@amd.com    typedef struct {
1436640Svince@csl.cornell.edu        int64_t  uptime;    /* Seconds since boot */
1446640Svince@csl.cornell.edu        uint64_t loads[3];  /* 1, 5, and 15 minute load averages */
1456640Svince@csl.cornell.edu        uint64_t totalram;  /* Total usable main memory size */
1466640Svince@csl.cornell.edu        uint64_t freeram;   /* Available memory size */
1476640Svince@csl.cornell.edu        uint64_t sharedram; /* Amount of shared memory */
1486640Svince@csl.cornell.edu        uint64_t bufferram; /* Memory used by buffers */
1496640Svince@csl.cornell.edu        uint64_t totalswap; /* Total swap space size */
1506640Svince@csl.cornell.edu        uint64_t freeswap;  /* swap space still available */
1516640Svince@csl.cornell.edu        uint16_t procs;     /* Number of current processes */
1526640Svince@csl.cornell.edu        uint64_t totalhigh; /* Total high memory size */
1536640Svince@csl.cornell.edu        uint64_t freehigh;  /* Available high memory size */
1546640Svince@csl.cornell.edu        uint64_t mem_unit;  /* Memory unit size in bytes */
1556640Svince@csl.cornell.edu    } tgt_sysinfo;
1566640Svince@csl.cornell.edu
1579141Smarc.orr@gmail.com    //@{
1589141Smarc.orr@gmail.com    /// ioctl() command codes.
1599141Smarc.orr@gmail.com    /// These were calculated using the SPARC Linux headers on an x86
1609141Smarc.orr@gmail.com    /// machine and thus may not be correct.  It would be good to
1619141Smarc.orr@gmail.com    /// verify/update these values on an actual SPARC Linux machine.
1629141Smarc.orr@gmail.com    static const unsigned TGT_TCGETA    = 0x40125401;
1639141Smarc.orr@gmail.com    static const unsigned TGT_TCSETAW   = 0x80125403;
1649141Smarc.orr@gmail.com    static const unsigned TGT_TCGETS    = 0x40385408;
1659141Smarc.orr@gmail.com    static const unsigned TGT_FIONREAD  = 0x4004667f;
1669141Smarc.orr@gmail.com    static const unsigned TGT_TIOCGETP  = 0x40067408;
1679141Smarc.orr@gmail.com    static const unsigned TGT_TIOCSETP  = 0x80067409;
1689141Smarc.orr@gmail.com    static const unsigned TGT_TIOCSETN  = 0x8006740a;
1699141Smarc.orr@gmail.com    //@}
1709141Smarc.orr@gmail.com
1719141Smarc.orr@gmail.com    static bool
1729141Smarc.orr@gmail.com    isTtyReq(unsigned req)
1739141Smarc.orr@gmail.com    {
1749141Smarc.orr@gmail.com        switch (req) {
1759141Smarc.orr@gmail.com          case TGT_TIOCGETP:
1769141Smarc.orr@gmail.com          case TGT_TIOCSETP:
1779141Smarc.orr@gmail.com          case TGT_TIOCSETN:
1789141Smarc.orr@gmail.com          case TGT_TCGETS:
1799141Smarc.orr@gmail.com          case TGT_TCGETA:
1809141Smarc.orr@gmail.com          case TGT_TCSETAW:
1819141Smarc.orr@gmail.com            return true;
1829141Smarc.orr@gmail.com          default:
1839141Smarc.orr@gmail.com            return false;
1849141Smarc.orr@gmail.com        }
1859141Smarc.orr@gmail.com    }
18613536Sandreas.sandberg@arm.com
18713536Sandreas.sandberg@arm.com    static void
18813536Sandreas.sandberg@arm.com    archClone(uint64_t flags,
18913536Sandreas.sandberg@arm.com              Process *pp, Process *cp,
19013536Sandreas.sandberg@arm.com              ThreadContext *ptc, ThreadContext *ctc,
19113536Sandreas.sandberg@arm.com              uint64_t stack, uint64_t tls)
19213536Sandreas.sandberg@arm.com    {
19313536Sandreas.sandberg@arm.com        SparcISA::copyRegs(ptc, ctc);
19413536Sandreas.sandberg@arm.com        ctc->setIntReg(SparcISA::NumIntArchRegs + 6, 0);
19513536Sandreas.sandberg@arm.com        ctc->setIntReg(SparcISA::NumIntArchRegs + 4, 0);
19613536Sandreas.sandberg@arm.com        ctc->setIntReg(SparcISA::NumIntArchRegs + 3, SparcISA::NWindows - 2);
19713536Sandreas.sandberg@arm.com        ctc->setIntReg(SparcISA::NumIntArchRegs + 5, SparcISA::NWindows);
19813536Sandreas.sandberg@arm.com        ctc->setMiscReg(SparcISA::MISCREG_CWP, 0);
19913536Sandreas.sandberg@arm.com        ctc->setIntReg(SparcISA::NumIntArchRegs + 7, 0);
20013536Sandreas.sandberg@arm.com        ctc->setMiscRegNoEffect(SparcISA::MISCREG_TL, 0);
20113536Sandreas.sandberg@arm.com        ctc->setMiscReg(SparcISA::MISCREG_ASI, SparcISA::ASI_PRIMARY);
20213536Sandreas.sandberg@arm.com        for (int y = 8; y < 32; y++)
20313536Sandreas.sandberg@arm.com            ctc->setIntReg(y, ptc->readIntReg(y));
20413536Sandreas.sandberg@arm.com
20513536Sandreas.sandberg@arm.com        if (stack)
20613536Sandreas.sandberg@arm.com            ctc->setIntReg(SparcISA::StackPointerReg, stack);
20713536Sandreas.sandberg@arm.com    }
2082579SN/A};
2092579SN/A
2104188Sgblack@eecs.umich.educlass Sparc32Linux : public SparcLinux
2114188Sgblack@eecs.umich.edu{
2124188Sgblack@eecs.umich.edu  public:
2134188Sgblack@eecs.umich.edu
2144188Sgblack@eecs.umich.edu    typedef struct {
2154188Sgblack@eecs.umich.edu        uint64_t st_dev;
2164188Sgblack@eecs.umich.edu        uint64_t st_ino;
2174188Sgblack@eecs.umich.edu        uint32_t st_mode;
2184188Sgblack@eecs.umich.edu        uint32_t st_nlink;
2194188Sgblack@eecs.umich.edu        uint32_t st_uid;
2204188Sgblack@eecs.umich.edu        uint32_t st_gid;
2214188Sgblack@eecs.umich.edu        uint64_t st_rdev;
2224188Sgblack@eecs.umich.edu        uint8_t __pad3[8];
2234188Sgblack@eecs.umich.edu        int64_t st_size;
2244188Sgblack@eecs.umich.edu        int32_t st_blksize;
2254188Sgblack@eecs.umich.edu        uint8_t __pad4[8];
2264188Sgblack@eecs.umich.edu        int64_t st_blocks;
2274188Sgblack@eecs.umich.edu        uint64_t st_atimeX;
2284188Sgblack@eecs.umich.edu        uint64_t st_atime_nsec;
2294188Sgblack@eecs.umich.edu        uint64_t st_mtimeX;
2304188Sgblack@eecs.umich.edu        uint64_t st_mtime_nsec;
2314188Sgblack@eecs.umich.edu        uint64_t st_ctimeX;
2324188Sgblack@eecs.umich.edu        uint64_t st_ctime_nsec;
2334188Sgblack@eecs.umich.edu        uint32_t __unused4;
2344188Sgblack@eecs.umich.edu        uint32_t __unused5;
2354188Sgblack@eecs.umich.edu    } tgt_stat64;
23611320Ssteve.reinhardt@amd.com
2376640Svince@csl.cornell.edu    typedef struct {
2386640Svince@csl.cornell.edu        int32_t  uptime;    /* Seconds since boot */
2396640Svince@csl.cornell.edu        uint32_t loads[3];  /* 1, 5, and 15 minute load averages */
2406640Svince@csl.cornell.edu        uint32_t totalram;  /* Total usable main memory size */
2416640Svince@csl.cornell.edu        uint32_t freeram;   /* Available memory size */
2426640Svince@csl.cornell.edu        uint32_t sharedram; /* Amount of shared memory */
2436640Svince@csl.cornell.edu        uint32_t bufferram; /* Memory used by buffers */
2446640Svince@csl.cornell.edu        uint32_t totalswap; /* Total swap space size */
2456640Svince@csl.cornell.edu        uint32_t freeswap;  /* swap space still available */
2466640Svince@csl.cornell.edu        uint16_t procs;     /* Number of current processes */
2476640Svince@csl.cornell.edu        uint32_t totalhigh; /* Total high memory size */
2486640Svince@csl.cornell.edu        uint32_t freehigh;  /* Available high memory size */
2496640Svince@csl.cornell.edu        uint32_t mem_unit;  /* Memory unit size in bytes */
25011320Ssteve.reinhardt@amd.com    } tgt_sysinfo;
2516640Svince@csl.cornell.edu
2529146Smarc.orr@gmail.com    /// Resource constants for getrlimit() (overide some generics).
2539146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_NPROC = 7;
2549146Smarc.orr@gmail.com    static const unsigned TGT_RLIMIT_NOFILE = 6;
2554188Sgblack@eecs.umich.edu};
2564188Sgblack@eecs.umich.edu
2572579SN/A#endif
258