1/*
2 * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
3 * All rights reserved.
4 *
5 * This software was developed by the University of Cambridge Computer
6 * Laboratory as part of the CTSRD Project, with support from the UK Higher
7 * Education Innovation Fund (HEIF).
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met: redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer;
13 * redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution;
16 * neither the name of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef __FREEBSD_HH__
34#define __FREEBSD_HH__
35
36#include <string>
37
38#include "base/types.hh"
39#include "kern/operatingsystem.hh"
40
41class ThreadContext;
42class Process;
43
44///
45/// This class encapsulates the types, structures, constants,
46/// functions, and syscall-number mappings specific to the Alpha FreeBSD
47/// syscall interface.
48///
49class FreeBSD : public OperatingSystem
50{
51
52  public:
53
54    //@{
55    /// Basic FreeBSD types.
56    typedef uint64_t size_t;
57    typedef uint64_t off_t;
58    typedef int64_t time_t;
59    typedef int64_t clock_t;
60    typedef uint32_t uid_t;
61    typedef uint32_t gid_t;
62    //@}
63
64    /// Clock ticks per second, for times().
65    static const int M5_SC_CLK_TCK = 100;
66
67    //@{
68    /// ioctl() command codes.
69    static const unsigned TGT_TIOCGETA   = 0x402c7413;
70    static const unsigned TGT_TIOCSETA   = 0x802c7414;
71    static const unsigned TGT_TIOCSETAW  = 0x802c7415;
72    static const unsigned TGT_FIONREAD   = 0x4004667f;
73    //@}
74
75    /// Return true for the ioctl codes for which we return ENOTTY
76    /// *without* printing a warning, since we know that ENOTTY is the
77    /// correct thing to return (and not just a sign that we don't
78    /// recognize the ioctl code.
79    static bool
80    isTtyReq(unsigned req)
81    {
82        switch (req) {
83          case TGT_TIOCGETA:
84          case TGT_TIOCSETA:
85          case TGT_TIOCSETAW:
86          case TGT_FIONREAD:
87            return true;
88          default:
89            return false;
90        }
91    }
92
93    /// Resource constants for getrlimit().
94    static const unsigned TGT_RLIMIT_CPU = 0;
95    static const unsigned TGT_RLIMIT_FSIZE = 1;
96    static const unsigned TGT_RLIMIT_DATA = 2;
97    static const unsigned TGT_RLIMIT_STACK = 3;
98    static const unsigned TGT_RLIMIT_CORE = 4;
99    static const unsigned TGT_RLIMIT_RSS = 5;
100    static const unsigned TGT_RLIMIT_MEMLOCK = 6;
101    static const unsigned TGT_RLIMIT_NPROC = 7;
102    static const unsigned TGT_RLIMIT_NOFILE = 8;
103    static const unsigned TGT_RLIMIT_SBSIZE = 9;
104    static const unsigned TGT_RLIMIT_VMEM = 10;
105    static const unsigned TGT_RLIMIT_AS = TGT_RLIMIT_VMEM;
106    static const unsigned TGT_RLIMIT_NPTS = 11;
107    static const unsigned TGT_RLIMIT_SWAP = 12;
108    static const unsigned TGT_RLIMIT_KQUEUES = 13;
109
110    /// For getrusage().
111    static const int TGT_RUSAGE_SELF     = 0;
112    static const int TGT_RUSAGE_CHILDREN = -1;
113    static const int TGT_RUSAGE_THREAD   = 1;
114
115    // for *at syscalls
116    static const int TGT_AT_FDCWD   = -100;
117
118};  // class FreeBSD
119
120#endif // __FREEBSD_HH__
121