linux.hh revision 13536:77e19417e723
1/* 2 * Copyright (c) 2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Korey Sewell 29 */ 30 31#ifndef __ARCH_RISCV_LINUX_LINUX_HH__ 32#define __ARCH_RISCV_LINUX_LINUX_HH__ 33 34#include "arch/riscv/utility.hh" 35#include "kern/linux/linux.hh" 36 37class RiscvLinux : public Linux 38{ 39 public: 40 static const int TGT_SIGHUP = 1; 41 static const int TGT_SIGINT = 2; 42 static const int TGT_SIGQUIT = 3; 43 static const int TGT_SIGILL = 4; 44 static const int TGT_SIGTRAP = 5; 45 static const int TGT_SIGABRT = 6; 46 static const int TGT_SIGIOT = 6; 47 static const int TGT_SIGEMT = 7; 48 static const int TGT_SIGFPE = 8; 49 static const int TGT_SIGKILL = 9; 50 static const int TGT_SIGBUS = 10; 51 static const int TGT_SIGSEGV = 11; 52 static const int TGT_SIGSYS = 12; 53 static const int TGT_SIGPIPE = 13; 54 static const int TGT_SIGALRM = 14; 55 static const int TGT_SIGTERM = 15; 56 static const int TGT_SIGURG = 16; 57 static const int TGT_SIGSTOP = 17; 58 static const int TGT_SIGTSTP = 18; 59 static const int TGT_SIGCONT = 19; 60 static const int TGT_SIGCHLD = 20; 61 static const int TGT_SIGCLD = 20; 62 static const int TGT_SIGTTIN = 21; 63 static const int TGT_SIGTTOU = 22; 64 static const int TGT_SIGPOLL = 23; 65 static const int TGT_SIGIO = 23; 66 static const int TGT_SIGXCPU = 24; 67 static const int TGT_SIGXFSZ = 25; 68 static const int TGT_SIGVTALRM = 26; 69 static const int TGT_SIGPROF = 27; 70 static const int TGT_SIGWINCH = 28; 71 static const int TGT_SIGLOST = 29; 72 static const int TGT_SIGPWR = 29; 73 static const int TGT_SIGUSR1 = 30; 74 static const int TGT_SIGUSR2 = 31; 75 76 /// This table maps the target open() flags to the corresponding 77 /// host open() flags. 78 static SyscallFlagTransTable openFlagTable[]; 79 80 /// Number of entries in openFlagTable[]. 81 static const int NUM_OPEN_FLAGS; 82 83 //@{ 84 /// open(2) flag values. 85 static const int TGT_O_RDONLY = 0x000000; //!< O_RDONLY 86 static const int TGT_O_WRONLY = 0x000001; //!< O_WRONLY 87 static const int TGT_O_RDWR = 0x000002; //!< O_RDWR 88 static const int TGT_O_CREAT = 0x000040; //!< O_CREAT 89 static const int TGT_O_EXCL = 0x000080; //!< O_EXCL 90 static const int TGT_O_NOCTTY = 0x000100; //!< O_NOCTTY 91 static const int TGT_O_TRUNC = 0x000200; //!< O_TRUNC 92 static const int TGT_O_APPEND = 0x000400; //!< O_APPEND 93 static const int TGT_O_NONBLOCK = 0x000800; //!< O_NONBLOCK 94 static const int TGT_O_SYNC = 0x001000; //!< O_SYNC 95 static const int TGT_FSYNC = 0x001000; //!< FSYNC 96 static const int TGT_FASYNC = 0x008000; //!< FASYNC 97 // The following are not present in riscv64-unknown-elf <fcntl.h> 98 static const int TGT_O_DSYNC = 0x010000; //!< O_DSYNC 99 static const int TGT_O_CLOEXEC = 0x040000; //!< O_CLOEXEC 100 static const int TGT_O_NOINHERIT = 0x040000; //!< O_NOINHERIT 101 static const int TGT_O_DIRECT = 0x080000; //!< O_DIRECT 102 static const int TGT_O_NOFOLLOW = 0x100000; //!< O_NOFOLLOW 103 static const int TGT_O_DIRECTORY = 0x200000; //!< O_DIRECTORY 104 // The following are not defined by riscv64-unknown-elf 105 static const int TGT_O_LARGEFILE = 0x020000; //!< O_LARGEFILE 106 static const int TGT_O_NOATIME = 0x800000; //!< O_NOATIME 107 static const int TGT_O_PATH = 0x400000; //!< O_PATH 108 //@} 109 110 // Only defined in riscv-unknown-elf for proxy kernel and not linux kernel 111 static const unsigned TGT_MAP_SHARED = 0x0001; 112 static const unsigned TGT_MAP_PRIVATE = 0x0002; 113 static const unsigned TGT_MAP_FIXED = 0x0010; 114 static const unsigned TGT_MAP_ANONYMOUS = 0x0020; 115 static const unsigned TGT_MAP_POPULATE = 0x1000; 116 static const unsigned TGT_MREMAP_FIXED = 0x0020; 117 118 static const unsigned NUM_MMAP_FLAGS; 119 120 typedef int64_t time_t; 121 typedef uint64_t dev_t; 122 typedef uint64_t ino_t; 123 typedef uint32_t mode_t; 124 typedef uint32_t nlink_t; 125 typedef uint32_t uid_t; 126 typedef uint32_t gid_t; 127 typedef int64_t off_t; 128 typedef uint64_t blksize_t; 129 typedef uint64_t blkcnt_t; 130 131 struct timespec { 132 time_t tv_sec; 133 int64_t tv_nsec; 134 }; 135 136 typedef struct { 137 dev_t st_dev; 138 ino_t st_ino; 139 mode_t st_mode; 140 nlink_t st_nlink; 141 uid_t st_uid; 142 gid_t st_gid; 143 dev_t st_rdev; 144 dev_t __pad1; 145 off_t st_size; 146 blksize_t st_blksize; 147 blkcnt_t st_blocks; 148 uint64_t st_atimeX; 149 uint64_t st_atime_nsec; 150 uint64_t st_mtimeX; 151 uint64_t st_mtime_nsec; 152 uint64_t st_ctimeX; 153 uint64_t st_ctime_nsec; 154 int32_t ___glibc_reserved[2]; 155 } tgt_stat64; 156 157 typedef struct { 158 int32_t val[2]; 159 } tgt_fsid_t; 160 161 typedef struct { 162 uint64_t f_type; 163 uint64_t f_bsize; 164 uint64_t f_blocks; 165 uint64_t f_bfree; 166 uint64_t f_bavail; 167 uint64_t f_files; 168 uint64_t f_ffree; 169 tgt_fsid_t f_fsid; 170 uint64_t f_namelen; 171 uint64_t f_frsize; 172 uint64_t f_flags; 173 uint64_t f_spare[4]; 174 } tgt_statfs; 175 176 typedef struct { 177 int64_t uptime; 178 uint64_t loads[3]; 179 uint64_t totalram; 180 uint64_t freeram; 181 uint64_t sharedram; 182 uint64_t bufferram; 183 uint64_t totalswap; 184 uint64_t freeswap; 185 uint16_t procs; 186 uint16_t pad; 187 uint64_t totalhigh; 188 uint64_t freehigh; 189 uint32_t mem_unit; 190 } tgt_sysinfo; 191 192 static void 193 archClone(uint64_t flags, 194 Process *pp, Process *cp, 195 ThreadContext *ptc, ThreadContext *ctc, 196 uint64_t stack, uint64_t tls) 197 { 198 RiscvISA::copyRegs(ptc, ctc); 199 if (stack) 200 ctc->setIntReg(RiscvISA::StackPointerReg, stack); 201 } 202}; 203 204#endif 205