linux.hh revision 13634:748418e0ca3f
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 RiscvLinux64 : 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
204class RiscvLinux32 : public Linux
205{
206  public:
207    static const int TGT_SIGHUP         =  1;
208    static const int TGT_SIGINT         =  2;
209    static const int TGT_SIGQUIT        =  3;
210    static const int TGT_SIGILL         =  4;
211    static const int TGT_SIGTRAP        =  5;
212    static const int TGT_SIGABRT        =  6;
213    static const int TGT_SIGIOT         =  6;
214    static const int TGT_SIGEMT         =  7;
215    static const int TGT_SIGFPE         =  8;
216    static const int TGT_SIGKILL        =  9;
217    static const int TGT_SIGBUS         = 10;
218    static const int TGT_SIGSEGV        = 11;
219    static const int TGT_SIGSYS         = 12;
220    static const int TGT_SIGPIPE        = 13;
221    static const int TGT_SIGALRM        = 14;
222    static const int TGT_SIGTERM        = 15;
223    static const int TGT_SIGURG         = 16;
224    static const int TGT_SIGSTOP        = 17;
225    static const int TGT_SIGTSTP        = 18;
226    static const int TGT_SIGCONT        = 19;
227    static const int TGT_SIGCHLD        = 20;
228    static const int TGT_SIGCLD         = 20;
229    static const int TGT_SIGTTIN        = 21;
230    static const int TGT_SIGTTOU        = 22;
231    static const int TGT_SIGPOLL        = 23;
232    static const int TGT_SIGIO          = 23;
233    static const int TGT_SIGXCPU        = 24;
234    static const int TGT_SIGXFSZ        = 25;
235    static const int TGT_SIGVTALRM      = 26;
236    static const int TGT_SIGPROF        = 27;
237    static const int TGT_SIGWINCH       = 28;
238    static const int TGT_SIGLOST        = 29;
239    static const int TGT_SIGPWR         = 29;
240    static const int TGT_SIGUSR1        = 30;
241    static const int TGT_SIGUSR2        = 31;
242
243    /// This table maps the target open() flags to the corresponding
244    /// host open() flags.
245    static SyscallFlagTransTable openFlagTable[];
246
247    /// Number of entries in openFlagTable[].
248    static const int NUM_OPEN_FLAGS;
249
250    //@{
251    /// open(2) flag values.
252    // The following values match newlib 3.0.0.
253    // Note that glibc has different values.
254    static const int TGT_O_RDONLY       = 0x000000; //!< O_RDONLY
255    static const int TGT_O_WRONLY       = 0x000001; //!< O_WRONLY
256    static const int TGT_O_RDWR         = 0x000002; //!< O_RDWR
257    static const int TGT_O_CREAT        = 0x000200; //!< O_CREAT
258    static const int TGT_O_EXCL         = 0x000800; //!< O_EXCL
259    static const int TGT_O_NOCTTY       = 0x008000; //!< O_NOCTTY
260    static const int TGT_O_TRUNC        = 0x000400; //!< O_TRUNC
261    static const int TGT_O_APPEND       = 0x000008; //!< O_APPEND
262    static const int TGT_O_NONBLOCK     = 0x004000; //!< O_NONBLOCK
263    static const int TGT_O_SYNC         = 0x002000; //!< O_SYNC
264    static const int TGT_FSYNC          = 0x002000; //!< FSYNC
265    static const int TGT_FASYNC         = 0x000040; //!< FASYNC
266    // The following are not present in riscv32-unknown-elf <fcntl.h>
267    static const int TGT_O_DSYNC        = 0x010000; //!< O_DSYNC
268    static const int TGT_O_CLOEXEC      = 0x040000; //!< O_CLOEXEC
269    static const int TGT_O_NOINHERIT    = 0x040000; //!< O_NOINHERIT
270    static const int TGT_O_DIRECT       = 0x080000; //!< O_DIRECT
271    static const int TGT_O_NOFOLLOW     = 0x100000; //!< O_NOFOLLOW
272    static const int TGT_O_DIRECTORY    = 0x200000; //!< O_DIRECTORY
273    // The following are not defined by riscv32-unknown-elf
274    static const int TGT_O_LARGEFILE    = 0x020000; //!< O_LARGEFILE
275    static const int TGT_O_NOATIME      = 0x800000; //!< O_NOATIME
276    static const int TGT_O_PATH         = 0x400000; //!< O_PATH
277    //@}
278
279    // Only defined in riscv-unknown-elf for proxy kernel and not linux kernel
280    static const unsigned TGT_MAP_SHARED        = 0x0001;
281    static const unsigned TGT_MAP_PRIVATE       = 0x0002;
282    static const unsigned TGT_MAP_FIXED         = 0x0010;
283    static const unsigned TGT_MAP_ANONYMOUS     = 0x0020;
284    static const unsigned TGT_MAP_POPULATE      = 0x1000;
285    static const unsigned TGT_MREMAP_FIXED      = 0x0020;
286
287    static const unsigned NUM_MMAP_FLAGS;
288
289    // Newlib 3.0.0 defaults to 64-bits for time_t.
290    // Currently time_t in glibc for riscv32 is 32-bits, but will be changed.
291    typedef int64_t time_t;
292
293    /// Limit struct for getrlimit/setrlimit.
294    struct rlimit {
295        uint32_t  rlim_cur;     //!< soft limit
296        uint32_t  rlim_max;     //!< hard limit
297    };
298
299    struct timespec {
300        time_t tv_sec;
301        int32_t tv_nsec;
302    };
303
304    typedef struct {
305        int32_t val[2];
306    } tgt_fsid_t;
307
308    typedef struct {
309        uint64_t st_dev;
310        uint64_t st_ino;
311        uint32_t st_mode;
312        uint32_t st_nlink;
313        uint32_t st_uid;
314        uint32_t st_gid;
315        uint64_t st_rdev;
316        uint64_t __pad1;
317        int64_t st_size;
318        int32_t st_blksize;
319        int32_t __pad2;
320        int64_t st_blocks;
321        time_t st_atimeX;
322        int32_t st_atime_nsec;
323        time_t st_mtimeX;
324        int32_t st_mtime_nsec;
325        time_t st_ctimeX;
326        int32_t st_ctime_nsec;
327        int32_t __unused4;
328        int32_t __unused5;
329    } tgt_stat;
330
331    typedef struct {
332        uint32_t f_type;
333        uint32_t f_bsize;
334        uint32_t f_blocks;
335        uint32_t f_bfree;
336        uint32_t f_bavail;
337        uint32_t f_files;
338        uint32_t f_ffree;
339        tgt_fsid_t f_fsid;
340        uint32_t f_namelen;
341        uint32_t f_frsize;
342        uint32_t f_flags;
343        uint32_t f_spare[4];
344    } tgt_statfs;
345
346    typedef struct {
347        int32_t uptime;
348        uint32_t loads[3];
349        uint32_t totalram;
350        uint32_t freeram;
351        uint32_t sharedram;
352        uint32_t bufferram;
353        uint32_t totalswap;
354        uint32_t freeswap;
355        uint16_t procs;
356        uint16_t pad;
357        uint32_t totalhigh;
358        uint32_t freehigh;
359        uint32_t mem_unit;
360    } tgt_sysinfo;
361
362    static void
363    archClone(uint64_t flags,
364              Process *pp, Process *cp,
365              ThreadContext *ptc, ThreadContext *ctc,
366              uint64_t stack, uint64_t tls)
367    {
368        RiscvISA::copyRegs(ptc, ctc);
369        if (stack)
370            ctc->setIntReg(RiscvISA::StackPointerReg, stack);
371    }
372};
373
374#endif
375