linux.hh revision 11759:deaf82fd2e7c
1/*
2 * Copyright (c) 2007 The Hewlett-Packard Development Company
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder.  You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: Gabe Black
38 */
39
40#ifndef __ARCH_X86_LINUX_LINUX_HH__
41#define __ARCH_X86_LINUX_LINUX_HH__
42
43#include "kern/linux/linux.hh"
44
45class X86Linux64 : public Linux
46{
47  public:
48
49    typedef struct {
50        uint64_t st_dev;
51        uint64_t st_ino;
52        uint64_t st_nlink;
53        uint32_t st_mode;
54        uint32_t st_uid;
55        uint32_t st_gid;
56        uint32_t __pad0;
57        uint64_t st_rdev;
58        int64_t st_size;
59        int64_t st_blksize;
60        int64_t st_blocks;
61        uint64_t st_atimeX;
62        uint64_t st_atime_nsec;
63        uint64_t st_mtimeX;
64        uint64_t st_mtime_nsec;
65        uint64_t st_ctimeX;
66        uint64_t st_ctime_nsec;
67        int64_t unused0[3];
68    } tgt_stat64;
69
70    typedef struct {
71        long val[2];
72    } tgt_fsid;
73
74    typedef struct {
75        long f_type;
76        long f_bsize;
77        long f_blocks;
78        long f_bfree;
79        long f_bavail;
80        long f_files;
81        long f_ffree;
82        tgt_fsid f_fsid;
83        long f_namelen;
84        long f_frsize;
85        long f_spare[5];
86    } tgt_statfs;
87
88    static const int TGT_SIGHUP         = 0x000001;
89    static const int TGT_SIGINT         = 0x000002;
90    static const int TGT_SIGQUIT        = 0x000003;
91    static const int TGT_SIGILL         = 0x000004;
92    static const int TGT_SIGTRAP        = 0x000005;
93    static const int TGT_SIGABRT        = 0x000006;
94    static const int TGT_SIGIOT         = 0x000006;
95    static const int TGT_SIGBUS         = 0x000007;
96    static const int TGT_SIGFPE         = 0x000008;
97    static const int TGT_SIGKILL        = 0x000009;
98    static const int TGT_SIGUSR1        = 0x00000a;
99    static const int TGT_SIGSEGV        = 0x00000b;
100    static const int TGT_SIGUSR2        = 0x00000c;
101    static const int TGT_SIGPIPE        = 0x00000d;
102    static const int TGT_SIGALRM        = 0x00000e;
103    static const int TGT_SIGTERM        = 0x00000f;
104    static const int TGT_SIGSTKFLT      = 0x000010;
105    static const int TGT_SIGCHLD        = 0x000011;
106    static const int TGT_SIGCONT        = 0x000012;
107    static const int TGT_SIGSTOP        = 0x000013;
108    static const int TGT_SIGTSTP        = 0x000014;
109    static const int TGT_SIGTTIN        = 0x000015;
110    static const int TGT_SIGTTOU        = 0x000016;
111    static const int TGT_SIGURG         = 0x000017;
112    static const int TGT_SIGXCPU        = 0x000018;
113    static const int TGT_SIGXFSZ        = 0x000019;
114    static const int TGT_SIGVTALRM      = 0x00001a;
115    static const int TGT_SIGPROF        = 0x00001b;
116    static const int TGT_SIGWINCH       = 0x00001c;
117    static const int TGT_SIGIO          = 0x00001d;
118    static const int TGT_SIGPOLL        = 0x00001d;
119    static const int TGT_SIGPWR         = 0x00001e;
120    static const int TGT_SIGSYS         = 0x00001f;
121    static const int TGT_SIGUNUSED      = 0x00001f;
122
123    static SyscallFlagTransTable openFlagTable[];
124
125    static const int TGT_O_RDONLY       = 000000000;     //!< O_RDONLY
126    static const int TGT_O_WRONLY       = 000000001;     //!< O_WRONLY
127    static const int TGT_O_RDWR         = 000000002;     //!< O_RDWR
128    static const int TGT_O_CREAT        = 000000100;     //!< O_CREAT
129    static const int TGT_O_EXCL         = 000000200;     //!< O_EXCL
130    static const int TGT_O_NOCTTY       = 000000400;     //!< O_NOCTTY
131    static const int TGT_O_TRUNC        = 000001000;     //!< O_TRUNC
132    static const int TGT_O_APPEND       = 000002000;     //!< O_APPEND
133    static const int TGT_O_NONBLOCK     = 000004000;     //!< O_NONBLOCK
134    static const int TGT_O_DSYNC        = 000010000;
135    static const int TGT_FASYNC         = 000020000;
136    static const int TGT_O_DIRECT       = 000040000;     //!< O_DIRECTIO
137    static const int TGT_O_LARGEFILE    = 000100000;
138    static const int TGT_O_DIRECTORY    = 000200000;
139    static const int TGT_O_NOFOLLOW     = 000400000;
140    static const int TGT_O_NOATIME      = 001000000;
141    static const int TGT_O_CLOEXEC      = 002000000;
142    static const int TGT_O_SYNC         = 004010000;     //!< O_SYNC
143    static const int TGT_O_PATH         = 010000000;
144
145    static const int NUM_OPEN_FLAGS;
146
147    static const unsigned TGT_MAP_SHARED        = 0x00001;
148    static const unsigned TGT_MAP_PRIVATE       = 0x00002;
149    static const unsigned TGT_MAP_32BIT         = 0x00040;
150    static const unsigned TGT_MAP_ANON          = 0x00020;
151    static const unsigned TGT_MAP_DENYWRITE     = 0x00800;
152    static const unsigned TGT_MAP_EXECUTABLE    = 0x01000;
153    static const unsigned TGT_MAP_FILE          = 0x00000;
154    static const unsigned TGT_MAP_GROWSDOWN     = 0x00100;
155    static const unsigned TGT_MAP_HUGETLB       = 0x40000;
156    static const unsigned TGT_MAP_LOCKED        = 0x02000;
157    static const unsigned TGT_MAP_NONBLOCK      = 0x10000;
158    static const unsigned TGT_MAP_NORESERVE     = 0x04000;
159    static const unsigned TGT_MAP_POPULATE      = 0x08000;
160    static const unsigned TGT_MAP_STACK         = 0x20000;
161    static const unsigned TGT_MAP_ANONYMOUS     = 0x00020;
162    static const unsigned TGT_MAP_FIXED         = 0x00010;
163
164    static const unsigned NUM_MMAP_FLAGS;
165
166    typedef struct {
167        uint64_t iov_base; // void *
168        uint64_t iov_len;  // size_t
169    } tgt_iovec;
170
171    typedef struct {
172        int64_t  uptime;    /* Seconds since boot */
173        uint64_t loads[3];  /* 1, 5, and 15 minute load averages */
174        uint64_t totalram;  /* Total usable main memory size */
175        uint64_t freeram;   /* Available memory size */
176        uint64_t sharedram; /* Amount of shared memory */
177        uint64_t bufferram; /* Memory used by buffers */
178        uint64_t totalswap; /* Total swap space size */
179        uint64_t freeswap;  /* swap space still available */
180        uint16_t procs;     /* Number of current processes */
181        uint64_t totalhigh; /* Total high memory size */
182        uint64_t freehigh;  /* Available high memory size */
183        uint64_t mem_unit;  /* Memory unit size in bytes */
184    } tgt_sysinfo;
185
186};
187
188class X86Linux32 : public Linux
189{
190  public:
191
192    typedef struct {
193        uint64_t st_dev;
194        uint8_t __pad0[4];
195        uint32_t __st_ino;
196        uint32_t st_mode;
197        uint32_t st_nlink;
198        uint32_t st_uid;
199        uint32_t st_gid;
200        uint64_t st_rdev;
201        uint8_t __pad3[4];
202        int64_t st_size;
203        uint32_t st_blksize;
204        uint64_t st_blocks;
205        uint32_t st_atimeX;
206        uint32_t st_atime_nsec;
207        uint32_t st_mtimeX;
208        uint32_t st_mtime_nsec;
209        uint32_t st_ctimeX;
210        uint32_t st_ctime_nsec;
211        uint64_t st_ino;
212    } __attribute__((__packed__)) tgt_stat64;
213
214    static const int TGT_SIGHUP         = 0x000001;
215    static const int TGT_SIGINT         = 0x000002;
216    static const int TGT_SIGQUIT        = 0x000003;
217    static const int TGT_SIGILL         = 0x000004;
218    static const int TGT_SIGTRAP        = 0x000005;
219    static const int TGT_SIGABRT        = 0x000006;
220    static const int TGT_SIGIOT         = 0x000006;
221    static const int TGT_SIGBUS         = 0x000007;
222    static const int TGT_SIGFPE         = 0x000008;
223    static const int TGT_SIGKILL        = 0x000009;
224    static const int TGT_SIGUSR1        = 0x00000a;
225    static const int TGT_SIGSEGV        = 0x00000b;
226    static const int TGT_SIGUSR2        = 0x00000c;
227    static const int TGT_SIGPIPE        = 0x00000d;
228    static const int TGT_SIGALRM        = 0x00000e;
229    static const int TGT_SIGTERM        = 0x00000f;
230    static const int TGT_SIGSTKFLT      = 0x000010;
231    static const int TGT_SIGCHLD        = 0x000011;
232    static const int TGT_SIGCONT        = 0x000012;
233    static const int TGT_SIGSTOP        = 0x000013;
234    static const int TGT_SIGTSTP        = 0x000014;
235    static const int TGT_SIGTTIN        = 0x000015;
236    static const int TGT_SIGTTOU        = 0x000016;
237    static const int TGT_SIGURG         = 0x000017;
238    static const int TGT_SIGXCPU        = 0x000018;
239    static const int TGT_SIGXFSZ        = 0x000019;
240    static const int TGT_SIGVTALRM      = 0x00001a;
241    static const int TGT_SIGPROF        = 0x00001b;
242    static const int TGT_SIGWINCH       = 0x00001c;
243    static const int TGT_SIGIO          = 0x00001d;
244    static const int TGT_SIGPOLL        = 0x00001d;
245    static const int TGT_SIGPWR         = 0x00001e;
246    static const int TGT_SIGSYS         = 0x00001f;
247    static const int TGT_SIGUNUSED      = 0x00001f;
248
249    static SyscallFlagTransTable openFlagTable[];
250
251    static const int TGT_O_RDONLY       = 000000000;     //!< O_RDONLY
252    static const int TGT_O_WRONLY       = 000000001;     //!< O_WRONLY
253    static const int TGT_O_RDWR         = 000000002;     //!< O_RDWR
254    static const int TGT_O_CREAT        = 000000100;     //!< O_CREAT
255    static const int TGT_O_EXCL         = 000000200;     //!< O_EXCL
256    static const int TGT_O_NOCTTY       = 000000400;     //!< O_NOCTTY
257    static const int TGT_O_TRUNC        = 000001000;     //!< O_TRUNC
258    static const int TGT_O_APPEND       = 000002000;     //!< O_APPEND
259    static const int TGT_O_NONBLOCK     = 000004000;     //!< O_NONBLOCK
260    static const int TGT_O_DSYNC        = 000010000;     //!< O_DSYNC
261    static const int TGT_FASYNC         = 000020000;
262    static const int TGT_O_DIRECT       = 000040000;     //!< O_DIRECTIO
263    static const int TGT_O_LARGEFILE    = 000100000;
264    static const int TGT_O_DIRECTORY    = 000200000;
265    static const int TGT_O_NOFOLLOW     = 000400000;
266    static const int TGT_O_NOATIME      = 001000000;
267    static const int TGT_O_CLOEXEC      = 002000000;
268    static const int TGT_O_SYNC         = 004010000;     //!< O_SYNC
269    static const int TGT_O_PATH         = 010000000;
270
271    static const int NUM_OPEN_FLAGS;
272
273    static SyscallFlagTransTable mmapFlagTable[];
274
275    static const unsigned TGT_MAP_SHARED        = 0x00001;
276    static const unsigned TGT_MAP_PRIVATE       = 0x00002;
277    static const unsigned TGT_MAP_32BIT         = 0x00040;
278    static const unsigned TGT_MAP_ANON          = 0x00020;
279    static const unsigned TGT_MAP_DENYWRITE     = 0x00800;
280    static const unsigned TGT_MAP_EXECUTABLE    = 0x01000;
281    static const unsigned TGT_MAP_FILE          = 0x00000;
282    static const unsigned TGT_MAP_GROWSDOWN     = 0x00100;
283    static const unsigned TGT_MAP_HUGETLB       = 0x40000;
284    static const unsigned TGT_MAP_LOCKED        = 0x02000;
285    static const unsigned TGT_MAP_NONBLOCK      = 0x10000;
286    static const unsigned TGT_MAP_NORESERVE     = 0x04000;
287    static const unsigned TGT_MAP_POPULATE      = 0x08000;
288    static const unsigned TGT_MAP_STACK         = 0x20000;
289    static const unsigned TGT_MAP_ANONYMOUS     = 0x00020;
290    static const unsigned TGT_MAP_FIXED         = 0x00010;
291
292    static const unsigned NUM_MMAP_FLAGS;
293
294    typedef struct {
295       int32_t  uptime;    /* Seconds since boot */
296       uint32_t loads[3];  /* 1, 5, and 15 minute load averages */
297       uint32_t totalram;  /* Total usable main memory size */
298       uint32_t freeram;   /* Available memory size */
299       uint32_t sharedram; /* Amount of shared memory */
300       uint32_t bufferram; /* Memory used by buffers */
301       uint32_t totalswap; /* Total swap space size */
302       uint32_t freeswap;  /* swap space still available */
303       uint16_t procs;     /* Number of current processes */
304       uint32_t totalhigh; /* Total high memory size */
305       uint32_t freehigh;  /* Available high memory size */
306       uint32_t mem_unit;  /* Memory unit size in bytes */
307    } tgt_sysinfo;
308};
309
310#endif
311