2 * Copyright (c) 2010, 2011-2012, 2015 ARM Limited
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.
14 * Copyright (c) 2003-2005 The Regents of The University of Michigan
15 * Copyright (c) 2007-2008 The Florida State University
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 #ifndef __ARCH_ARM_LINUX_LINUX_HH__
46 #define __ARCH_ARM_LINUX_LINUX_HH__
48 #include "arch/arm/utility.hh"
49 #include "kern/linux/linux.hh"
51 class ArmLinux : public Linux
54 static const ByteOrder byteOrder = LittleEndianByteOrder;
57 archClone(uint64_t flags,
58 Process *pp, Process *cp,
59 ThreadContext *ptc, ThreadContext *ctc,
60 uint64_t stack, uint64_t tls)
62 ArmISA::copyRegs(ptc, ctc);
64 if (flags & TGT_CLONE_SETTLS) {
65 /* TPIDR_EL0 is architecturally mapped to TPIDRURW, so
66 * this works for both aarch32 and aarch64. */
67 ctc->setMiscReg(ArmISA::MISCREG_TPIDR_EL0, tls);
72 class ArmLinux32 : public ArmLinux
76 static const int TGT_SIGHUP = 0x000001;
77 static const int TGT_SIGINT = 0x000002;
78 static const int TGT_SIGQUIT = 0x000003;
79 static const int TGT_SIGILL = 0x000004;
80 static const int TGT_SIGTRAP = 0x000005;
81 static const int TGT_SIGABRT = 0x000006;
82 static const int TGT_SIGIOT = 0x000006;
83 static const int TGT_SIGBUS = 0x000007;
84 static const int TGT_SIGFPE = 0x000008;
85 static const int TGT_SIGKILL = 0x000009;
86 static const int TGT_SIGUSR1 = 0x00000a;
87 static const int TGT_SIGSEGV = 0x00000b;
88 static const int TGT_SIGUSR2 = 0x00000c;
89 static const int TGT_SIGPIPE = 0x00000d;
90 static const int TGT_SIGALRM = 0x00000e;
91 static const int TGT_SIGTERM = 0x00000f;
92 static const int TGT_SIGSTKFLT = 0x000010;
93 static const int TGT_SIGCHLD = 0x000011;
94 static const int TGT_SIGCONT = 0x000012;
95 static const int TGT_SIGSTOP = 0x000013;
96 static const int TGT_SIGTSTP = 0x000014;
97 static const int TGT_SIGTTIN = 0x000015;
98 static const int TGT_SIGTTOU = 0x000016;
99 static const int TGT_SIGURG = 0x000017;
100 static const int TGT_SIGXCPU = 0x000018;
101 static const int TGT_SIGXFSZ = 0x000019;
102 static const int TGT_SIGVTALRM = 0x00001a;
103 static const int TGT_SIGPROF = 0x00001b;
104 static const int TGT_SIGWINCH = 0x00001c;
105 static const int TGT_SIGIO = 0x00001d;
106 static const int TGT_SIGPOLL = 0x00001d;
107 static const int TGT_SIGPWR = 0x00001e;
108 static const int TGT_SIGSYS = 0x00001f;
109 static const int TGT_SIGUNUSED = 0x00001f;
111 /// This table maps the target open() flags to the corresponding
112 /// host open() flags.
113 static SyscallFlagTransTable openFlagTable[];
115 /// Number of entries in openFlagTable[].
116 static const int NUM_OPEN_FLAGS;
119 /// Basic ARM Linux types
120 typedef uint32_t size_t;
121 typedef uint32_t off_t;
122 typedef int32_t time_t;
123 typedef int32_t clock_t;
127 /// open(2) flag values.
128 static const int TGT_O_RDONLY = 000000000; //!< O_RDONLY
129 static const int TGT_O_WRONLY = 000000001; //!< O_WRONLY
130 static const int TGT_O_RDWR = 000000002; //!< O_RDWR
131 static const int TGT_O_CREAT = 000000100; //!< O_CREAT
132 static const int TGT_O_EXCL = 000000200; //!< O_EXCL
133 static const int TGT_O_NOCTTY = 000000400; //!< O_NOCTTY
134 static const int TGT_O_TRUNC = 000001000; //!< O_TRUNC
135 static const int TGT_O_APPEND = 000002000; //!< O_APPEND
136 static const int TGT_O_NONBLOCK = 000004000; //!< O_NONBLOCK
137 static const int TGT_O_DSYNC = 000010000; //!< O_DSYNC
138 static const int TGT_FASYNC = 000020000; //!< FASYNC
139 static const int TGT_O_DIRECT = 000200000; //!< O_DIRECT
140 static const int TGT_O_LARGEFILE = 000400000; //!< O_LARGEFILE
141 static const int TGT_O_DIRECTORY = 000040000; //!< O_DIRECTORY
142 static const int TGT_O_NOFOLLOW = 000100000; //!< O_NOFOLLOW
143 static const int TGT_O_NOATIME = 001000000; //!< O_NOATIME
144 static const int TGT_O_CLOEXEC = 002000000; //!< O_NOATIME
145 static const int TGT_O_SYNC = 004010000; //!< O_SYNC
146 static const int TGT_O_PATH = 010000000; //!< O_PATH
149 static const unsigned TGT_MAP_SHARED = 0x00001;
150 static const unsigned TGT_MAP_PRIVATE = 0x00002;
151 static const unsigned TGT_MAP_ANON = 0x00020;
152 static const unsigned TGT_MAP_DENYWRITE = 0x00800;
153 static const unsigned TGT_MAP_EXECUTABLE = 0x01000;
154 static const unsigned TGT_MAP_FILE = 0x00000;
155 static const unsigned TGT_MAP_GROWSDOWN = 0x00100;
156 static const unsigned TGT_MAP_HUGETLB = 0x40000;
157 static const unsigned TGT_MAP_LOCKED = 0x02000;
158 static const unsigned TGT_MAP_NONBLOCK = 0x10000;
159 static const unsigned TGT_MAP_NORESERVE = 0x04000;
160 static const unsigned TGT_MAP_POPULATE = 0x08000;
161 static const unsigned TGT_MAP_STACK = 0x20000;
162 static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
163 static const unsigned TGT_MAP_FIXED = 0x00010;
165 static const unsigned NUM_MMAP_FLAGS;
168 static const int TBL_SYSINFO = 12;
170 /// Limit struct for getrlimit/setrlimit.
172 uint32_t rlim_cur; //!< soft limit
173 uint32_t rlim_max; //!< hard limit
176 /// For gettimeofday().
178 int32_t tv_sec; //!< seconds
179 int32_t tv_usec; //!< microseconds
183 int32_t tv_sec; //!< seconds
184 int32_t tv_nsec; //!< nanoseconds
189 uint32_t iov_base; // void *
208 uint32_t st_atime_nsec;
210 uint32_t st_mtime_nsec;
212 uint32_t st_ctime_nsec;
225 int64_t __attribute__ ((aligned (8))) st_size;
227 uint64_t __attribute__ ((aligned (8))) st_blocks;
229 uint32_t st_atime_nsec;
231 uint32_t st_mtime_nsec;
233 uint32_t st_ctime_nsec;
238 int32_t uptime; /* Seconds since boot */
239 uint32_t loads[3]; /* 1, 5, and 15 minute load averages */
240 uint32_t totalram; /* Total usable main memory size */
241 uint32_t freeram; /* Available memory size */
242 uint32_t sharedram; /* Amount of shared memory */
243 uint32_t bufferram; /* Memory used by buffers */
244 uint32_t totalswap; /* Total swap space size */
245 uint32_t freeswap; /* swap space still available */
246 uint16_t procs; /* Number of current processes */
247 uint32_t totalhigh; /* Total high memory size */
248 uint32_t freehigh; /* Available high memory size */
249 uint32_t mem_unit; /* Memory unit size in bytes */
254 struct timeval ru_utime; //!< user time used
255 struct timeval ru_stime; //!< system time used
256 int32_t ru_maxrss; //!< max rss
257 int32_t ru_ixrss; //!< integral shared memory size
258 int32_t ru_idrss; //!< integral unshared data "
259 int32_t ru_isrss; //!< integral unshared stack "
260 int32_t ru_minflt; //!< page reclaims - total vmfaults
261 int32_t ru_majflt; //!< page faults
262 int32_t ru_nswap; //!< swaps
263 int32_t ru_inblock; //!< block input operations
264 int32_t ru_oublock; //!< block output operations
265 int32_t ru_msgsnd; //!< messages sent
266 int32_t ru_msgrcv; //!< messages received
267 int32_t ru_nsignals; //!< signals received
268 int32_t ru_nvcsw; //!< voluntary context switches
269 int32_t ru_nivcsw; //!< involuntary "
274 int32_t tms_utime; //!< user time
275 int32_t tms_stime; //!< system time
276 int32_t tms_cutime; //!< user time of children
277 int32_t tms_cstime; //!< system time of children
281 archClone(uint64_t flags,
282 Process *pp, Process *cp,
283 ThreadContext *ptc, ThreadContext *ctc,
284 uint64_t stack, uint64_t tls)
286 ArmLinux::archClone(flags, pp, cp, ptc, ctc, stack, tls);
289 ctc->setIntReg(ArmISA::INTREG_SP, stack);
293 class ArmLinux64 : public ArmLinux
297 static const int TGT_SIGHUP = 0x000001;
298 static const int TGT_SIGINT = 0x000002;
299 static const int TGT_SIGQUIT = 0x000003;
300 static const int TGT_SIGILL = 0x000004;
301 static const int TGT_SIGTRAP = 0x000005;
302 static const int TGT_SIGABRT = 0x000006;
303 static const int TGT_SIGIOT = 0x000006;
304 static const int TGT_SIGBUS = 0x000007;
305 static const int TGT_SIGFPE = 0x000008;
306 static const int TGT_SIGKILL = 0x000009;
307 static const int TGT_SIGUSR1 = 0x00000a;
308 static const int TGT_SIGSEGV = 0x00000b;
309 static const int TGT_SIGUSR2 = 0x00000c;
310 static const int TGT_SIGPIPE = 0x00000d;
311 static const int TGT_SIGALRM = 0x00000e;
312 static const int TGT_SIGTERM = 0x00000f;
313 static const int TGT_SIGSTKFLT = 0x000010;
314 static const int TGT_SIGCHLD = 0x000011;
315 static const int TGT_SIGCONT = 0x000012;
316 static const int TGT_SIGSTOP = 0x000013;
317 static const int TGT_SIGTSTP = 0x000014;
318 static const int TGT_SIGTTIN = 0x000015;
319 static const int TGT_SIGTTOU = 0x000016;
320 static const int TGT_SIGURG = 0x000017;
321 static const int TGT_SIGXCPU = 0x000018;
322 static const int TGT_SIGXFSZ = 0x000019;
323 static const int TGT_SIGVTALRM = 0x00001a;
324 static const int TGT_SIGPROF = 0x00001b;
325 static const int TGT_SIGWINCH = 0x00001c;
326 static const int TGT_SIGIO = 0x00001d;
327 static const int TGT_SIGPOLL = 0x00001d;
328 static const int TGT_SIGPWR = 0x00001e;
329 static const int TGT_SIGSYS = 0x00001f;
330 static const int TGT_SIGUNUSED = 0x00001f;
332 /// This table maps the target open() flags to the corresponding
333 /// host open() flags.
334 static SyscallFlagTransTable openFlagTable[];
336 /// Number of entries in openFlagTable[].
337 static const int NUM_OPEN_FLAGS;
340 /// Basic ARM Linux types
341 typedef uint64_t size_t;
342 typedef uint64_t off_t;
343 typedef int64_t time_t;
344 typedef int64_t clock_t;
348 /// open(2) flag values.
349 static const int TGT_O_RDONLY = 000000000; //!< O_RDONLY
350 static const int TGT_O_WRONLY = 000000001; //!< O_WRONLY
351 static const int TGT_O_RDWR = 000000002; //!< O_RDWR
352 static const int TGT_O_CREAT = 000000100; //!< O_CREAT
353 static const int TGT_O_EXCL = 000000200; //!< O_EXCL
354 static const int TGT_O_NOCTTY = 000000400; //!< O_NOCTTY
355 static const int TGT_O_TRUNC = 000001000; //!< O_TRUNC
356 static const int TGT_O_APPEND = 000002000; //!< O_APPEND
357 static const int TGT_O_NONBLOCK = 000004000; //!< O_NONBLOCK
358 static const int TGT_O_DSYNC = 000010000; //!< O_DSYNC
359 static const int TGT_FASYNC = 000020000; //!< FASYNC
360 static const int TGT_O_DIRECT = 000200000; //!< O_DIRECT
361 static const int TGT_O_LARGEFILE = 000400000; //!< O_LARGEFILE
362 static const int TGT_O_DIRECTORY = 000040000; //!< O_DIRECTORY
363 static const int TGT_O_NOFOLLOW = 000100000; //!< O_NOFOLLOW
364 static const int TGT_O_NOATIME = 001000000; //!< O_NOATIME
365 static const int TGT_O_CLOEXEC = 002000000; //!< O_NOATIME
366 static const int TGT_O_SYNC = 004010000; //!< O_SYNC
367 static const int TGT_O_PATH = 010000000; //!< O_PATH
371 static SyscallFlagTransTable mmapFlagTable[];
373 static const unsigned TGT_MAP_SHARED = 0x00001;
374 static const unsigned TGT_MAP_PRIVATE = 0x00002;
375 static const unsigned TGT_MAP_ANON = 0x00020;
376 static const unsigned TGT_MAP_DENYWRITE = 0x00800;
377 static const unsigned TGT_MAP_EXECUTABLE = 0x01000;
378 static const unsigned TGT_MAP_FILE = 0x00000;
379 static const unsigned TGT_MAP_GROWSDOWN = 0x00100;
380 static const unsigned TGT_MAP_HUGETLB = 0x40000;
381 static const unsigned TGT_MAP_LOCKED = 0x02000;
382 static const unsigned TGT_MAP_NONBLOCK = 0x10000;
383 static const unsigned TGT_MAP_NORESERVE = 0x04000;
384 static const unsigned TGT_MAP_POPULATE = 0x08000;
385 static const unsigned TGT_MAP_STACK = 0x20000;
386 static const unsigned TGT_MAP_ANONYMOUS = 0x00020;
387 static const unsigned TGT_MAP_FIXED = 0x00010;
389 static const unsigned NUM_MMAP_FLAGS;
393 static const int TGT_RUSAGE_SELF = 0;
394 static const int TGT_RUSAGE_CHILDREN = -1;
395 static const int TGT_RUSAGE_BOTH = -2;
399 /// ioctl() command codes.
400 static const unsigned TIOCGETP_ = 0x5401;
401 static const unsigned TIOCSETP_ = 0x80067409;
402 static const unsigned TIOCSETN_ = 0x8006740a;
403 static const unsigned TIOCSETC_ = 0x80067411;
404 static const unsigned TIOCGETC_ = 0x40067412;
405 static const unsigned FIONREAD_ = 0x4004667f;
406 static const unsigned TIOCISATTY_ = 0x2000745e;
407 static const unsigned TIOCGETS_ = 0x402c7413;
408 static const unsigned TIOCGETA_ = 0x5405;
409 static const unsigned TCSETAW_ = 0x5407; // 2.6.15 kernel
413 static const int TBL_SYSINFO = 12;
415 /// Resource enumeration for getrlimit().
416 enum rlimit_resources {
418 TGT_RLIMIT_FSIZE = 1,
420 TGT_RLIMIT_STACK = 3,
423 TGT_RLIMIT_NPROC = 6,
424 TGT_RLIMIT_NOFILE = 7,
425 TGT_RLIMIT_MEMLOCK = 8,
427 TGT_RLIMIT_LOCKS = 10
430 /// Limit struct for getrlimit/setrlimit.
432 uint64_t rlim_cur; //!< soft limit
433 uint64_t rlim_max; //!< hard limit
436 /// For gettimeofday().
438 int64_t tv_sec; //!< seconds
439 int64_t tv_usec; //!< microseconds
443 int64_t tv_sec; //!< seconds
444 int64_t tv_nsec; //!< nanoseconds
449 uint64_t iov_base; // void *
466 uint64_t st_atime_nsec;
468 uint64_t st_mtime_nsec;
470 uint64_t st_ctime_nsec;
486 uint64_t st_atime_nsec;
488 uint64_t st_mtime_nsec;
490 uint64_t st_ctime_nsec;
494 int64_t uptime; /* Seconds since boot */
495 uint64_t loads[3]; /* 1, 5, and 15 minute load averages */
496 uint64_t totalram; /* Total usable main memory size */
497 uint64_t freeram; /* Available memory size */
498 uint64_t sharedram; /* Amount of shared memory */
499 uint64_t bufferram; /* Memory used by buffers */
500 uint64_t totalswap; /* Total swap space size */
501 uint64_t freeswap; /* swap space still available */
502 uint16_t procs; /* Number of current processes */
504 uint64_t totalhigh; /* Total high memory size */
505 uint64_t freehigh; /* Available high memory size */
506 uint32_t mem_unit; /* Memory unit size in bytes */
511 struct timeval ru_utime; //!< user time used
512 struct timeval ru_stime; //!< system time used
513 int64_t ru_maxrss; //!< max rss
514 int64_t ru_ixrss; //!< integral shared memory size
515 int64_t ru_idrss; //!< integral unshared data "
516 int64_t ru_isrss; //!< integral unshared stack "
517 int64_t ru_minflt; //!< page reclaims - total vmfaults
518 int64_t ru_majflt; //!< page faults
519 int64_t ru_nswap; //!< swaps
520 int64_t ru_inblock; //!< block input operations
521 int64_t ru_oublock; //!< block output operations
522 int64_t ru_msgsnd; //!< messages sent
523 int64_t ru_msgrcv; //!< messages received
524 int64_t ru_nsignals; //!< signals received
525 int64_t ru_nvcsw; //!< voluntary context switches
526 int64_t ru_nivcsw; //!< involuntary "
531 int64_t tms_utime; //!< user time
532 int64_t tms_stime; //!< system time
533 int64_t tms_cutime; //!< user time of children
534 int64_t tms_cstime; //!< system time of children
537 static void archClone(uint64_t flags,
538 Process *pp, Process *cp,
539 ThreadContext *ptc, ThreadContext *ctc,
540 uint64_t stack, uint64_t tls)
542 ArmLinux::archClone(flags, pp, cp, ptc, ctc, stack, tls);
545 ctc->setIntReg(ArmISA::INTREG_SP0, stack);