110810Sbr@bsdpad.com/*
210810Sbr@bsdpad.com * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
310810Sbr@bsdpad.com * All rights reserved.
410810Sbr@bsdpad.com *
510810Sbr@bsdpad.com * This software was developed by the University of Cambridge Computer
610810Sbr@bsdpad.com * Laboratory as part of the CTSRD Project, with support from the UK Higher
710810Sbr@bsdpad.com * Education Innovation Fund (HEIF).
810810Sbr@bsdpad.com *
910810Sbr@bsdpad.com * Redistribution and use in source and binary forms, with or without
1010810Sbr@bsdpad.com * modification, are permitted provided that the following conditions are
1110810Sbr@bsdpad.com * met: redistributions of source code must retain the above copyright
1210810Sbr@bsdpad.com * notice, this list of conditions and the following disclaimer;
1310810Sbr@bsdpad.com * redistributions in binary form must reproduce the above copyright
1410810Sbr@bsdpad.com * notice, this list of conditions and the following disclaimer in the
1510810Sbr@bsdpad.com * documentation and/or other materials provided with the distribution;
1610810Sbr@bsdpad.com * neither the name of the copyright holders nor the names of its
1710810Sbr@bsdpad.com * contributors may be used to endorse or promote products derived from
1810810Sbr@bsdpad.com * this software without specific prior written permission.
1910810Sbr@bsdpad.com *
2010810Sbr@bsdpad.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2110810Sbr@bsdpad.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2210810Sbr@bsdpad.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2310810Sbr@bsdpad.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2410810Sbr@bsdpad.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2510810Sbr@bsdpad.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2610810Sbr@bsdpad.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2710810Sbr@bsdpad.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2810810Sbr@bsdpad.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2910810Sbr@bsdpad.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3010810Sbr@bsdpad.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3110810Sbr@bsdpad.com */
3210810Sbr@bsdpad.com
3310810Sbr@bsdpad.com#ifndef __FREEBSD_HH__
3410810Sbr@bsdpad.com#define __FREEBSD_HH__
3510810Sbr@bsdpad.com
3610810Sbr@bsdpad.com#include <string>
3710810Sbr@bsdpad.com
3810810Sbr@bsdpad.com#include "base/types.hh"
3910810Sbr@bsdpad.com#include "kern/operatingsystem.hh"
4010810Sbr@bsdpad.com
4110810Sbr@bsdpad.comclass ThreadContext;
4211851Sbrandon.potter@amd.comclass Process;
4310810Sbr@bsdpad.com
4410810Sbr@bsdpad.com///
4510810Sbr@bsdpad.com/// This class encapsulates the types, structures, constants,
4610810Sbr@bsdpad.com/// functions, and syscall-number mappings specific to the Alpha FreeBSD
4710810Sbr@bsdpad.com/// syscall interface.
4810810Sbr@bsdpad.com///
4910810Sbr@bsdpad.comclass FreeBSD : public OperatingSystem
5010810Sbr@bsdpad.com{
5110810Sbr@bsdpad.com
5210810Sbr@bsdpad.com  public:
5310810Sbr@bsdpad.com
5410810Sbr@bsdpad.com    //@{
5510810Sbr@bsdpad.com    /// Basic FreeBSD types.
5610810Sbr@bsdpad.com    typedef uint64_t size_t;
5710810Sbr@bsdpad.com    typedef uint64_t off_t;
5810810Sbr@bsdpad.com    typedef int64_t time_t;
5910810Sbr@bsdpad.com    typedef int64_t clock_t;
6010810Sbr@bsdpad.com    typedef uint32_t uid_t;
6110810Sbr@bsdpad.com    typedef uint32_t gid_t;
6210810Sbr@bsdpad.com    //@}
6310810Sbr@bsdpad.com
6410810Sbr@bsdpad.com    /// Clock ticks per second, for times().
6510810Sbr@bsdpad.com    static const int M5_SC_CLK_TCK = 100;
6610810Sbr@bsdpad.com
6710810Sbr@bsdpad.com    //@{
6810810Sbr@bsdpad.com    /// ioctl() command codes.
6910810Sbr@bsdpad.com    static const unsigned TGT_TIOCGETA   = 0x402c7413;
7010810Sbr@bsdpad.com    static const unsigned TGT_TIOCSETA   = 0x802c7414;
7110810Sbr@bsdpad.com    static const unsigned TGT_TIOCSETAW  = 0x802c7415;
7210810Sbr@bsdpad.com    static const unsigned TGT_FIONREAD   = 0x4004667f;
7310810Sbr@bsdpad.com    //@}
7410810Sbr@bsdpad.com
7510810Sbr@bsdpad.com    /// Return true for the ioctl codes for which we return ENOTTY
7610810Sbr@bsdpad.com    /// *without* printing a warning, since we know that ENOTTY is the
7710810Sbr@bsdpad.com    /// correct thing to return (and not just a sign that we don't
7810810Sbr@bsdpad.com    /// recognize the ioctl code.
7910810Sbr@bsdpad.com    static bool
8010810Sbr@bsdpad.com    isTtyReq(unsigned req)
8110810Sbr@bsdpad.com    {
8210810Sbr@bsdpad.com        switch (req) {
8310810Sbr@bsdpad.com          case TGT_TIOCGETA:
8410810Sbr@bsdpad.com          case TGT_TIOCSETA:
8510810Sbr@bsdpad.com          case TGT_TIOCSETAW:
8610810Sbr@bsdpad.com          case TGT_FIONREAD:
8710810Sbr@bsdpad.com            return true;
8810810Sbr@bsdpad.com          default:
8910810Sbr@bsdpad.com            return false;
9010810Sbr@bsdpad.com        }
9110810Sbr@bsdpad.com    }
9210810Sbr@bsdpad.com
9310810Sbr@bsdpad.com    /// Resource constants for getrlimit().
9410810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_CPU = 0;
9510810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_FSIZE = 1;
9610810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_DATA = 2;
9710810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_STACK = 3;
9810810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_CORE = 4;
9910810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_RSS = 5;
10010810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_MEMLOCK = 6;
10110810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_NPROC = 7;
10210810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_NOFILE = 8;
10310810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_SBSIZE = 9;
10410810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_VMEM = 10;
10510810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_AS = TGT_RLIMIT_VMEM;
10610810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_NPTS = 11;
10710810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_SWAP = 12;
10810810Sbr@bsdpad.com    static const unsigned TGT_RLIMIT_KQUEUES = 13;
10910810Sbr@bsdpad.com
11010810Sbr@bsdpad.com    /// For getrusage().
11110810Sbr@bsdpad.com    static const int TGT_RUSAGE_SELF     = 0;
11210810Sbr@bsdpad.com    static const int TGT_RUSAGE_CHILDREN = -1;
11310810Sbr@bsdpad.com    static const int TGT_RUSAGE_THREAD   = 1;
11410810Sbr@bsdpad.com
11510810Sbr@bsdpad.com    // for *at syscalls
11610810Sbr@bsdpad.com    static const int TGT_AT_FDCWD   = -100;
11710810Sbr@bsdpad.com
11810810Sbr@bsdpad.com};  // class FreeBSD
11910810Sbr@bsdpad.com
12010810Sbr@bsdpad.com#endif // __FREEBSD_HH__
121