process.cc revision 6395:05f1d2cd7e9e
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * Copyright (c) 2007-2008 The Florida State University
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Authors: Korey Sewell
30 *          Stephen Hines
31 */
32
33#include "arch/arm/linux/linux.hh"
34#include "arch/arm/linux/process.hh"
35#include "arch/arm/isa_traits.hh"
36
37#include "base/trace.hh"
38#include "cpu/thread_context.hh"
39#include "kern/linux/linux.hh"
40
41#include "sim/process.hh"
42#include "sim/syscall_emul.hh"
43#include "sim/system.hh"
44
45using namespace std;
46using namespace ArmISA;
47
48/// Target uname() handler.
49static SyscallReturn
50unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
51          ThreadContext *tc)
52{
53    TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, 0));
54
55    strcpy(name->sysname, "Linux");
56    strcpy(name->nodename, "m5.eecs.umich.edu");
57    strcpy(name->release, "2.6.16.19");
58    strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
59    strcpy(name->machine, "arm");
60
61    name.copyOut(tc->getMemPort());
62    return 0;
63}
64
65SyscallDesc ArmLinuxProcess::syscallDescs[] = {
66    /*  0 */ SyscallDesc("syscall", unimplementedFunc),
67    /*  1 */ SyscallDesc("exit", exitFunc),
68    /*  2 */ SyscallDesc("fork", unimplementedFunc),
69    /*  3 */ SyscallDesc("read", readFunc),
70    /*  4 */ SyscallDesc("write", writeFunc),
71    /*  5 */ SyscallDesc("open", openFunc<ArmLinux>),
72    /*  6 */ SyscallDesc("close", closeFunc),
73    /*  7 */ SyscallDesc("waitpid", unimplementedFunc), //???
74    /*  8 */ SyscallDesc("creat", unimplementedFunc),
75    /*  9 */ SyscallDesc("link", unimplementedFunc),
76    /* 10 */ SyscallDesc("unlink", unlinkFunc),
77    /* 11 */ SyscallDesc("execve", unimplementedFunc),
78    /* 12 */ SyscallDesc("chdir", unimplementedFunc),
79    /* 13 */ SyscallDesc("time", unimplementedFunc),
80    /* 14 */ SyscallDesc("mknod", unimplementedFunc),
81    /* 15 */ SyscallDesc("chmod", chmodFunc<ArmLinux>),
82    /* 16 */ SyscallDesc("lchown", chownFunc),
83    /* 17 */ SyscallDesc("break", brkFunc), //???
84    /* 18 */ SyscallDesc("unused#18", unimplementedFunc), //???
85    /* 19 */ SyscallDesc("lseek", lseekFunc),
86    /* 20 */ SyscallDesc("getpid", getpidFunc),
87    /* 21 */ SyscallDesc("mount", unimplementedFunc),
88    /* 22 */ SyscallDesc("umount", unimplementedFunc),
89    /* 23 */ SyscallDesc("setuid", setuidFunc),
90    /* 24 */ SyscallDesc("getuid", getuidFunc),
91    /* 25 */ SyscallDesc("stime", unimplementedFunc),
92    /* 26 */ SyscallDesc("ptrace", unimplementedFunc),
93    /* 27 */ SyscallDesc("alarm", unimplementedFunc),
94    /* 28 */ SyscallDesc("unused#28", unimplementedFunc),
95    /* 29 */ SyscallDesc("pause", unimplementedFunc),
96    /* 30 */ SyscallDesc("utime", unimplementedFunc),
97    /* 31 */ SyscallDesc("stty", unimplementedFunc),
98    /* 32 */ SyscallDesc("gtty", unimplementedFunc),
99    /* 33 */ SyscallDesc("access", unimplementedFunc),
100    /* 34 */ SyscallDesc("nice", unimplementedFunc),
101    /* 35 */ SyscallDesc("ftime", unimplementedFunc),
102    /* 36 */ SyscallDesc("sync", unimplementedFunc),
103    /* 37 */ SyscallDesc("kill", ignoreFunc),
104    /* 38 */ SyscallDesc("rename", unimplementedFunc),
105    /* 39 */ SyscallDesc("mkdir", unimplementedFunc),
106    /* 40 */ SyscallDesc("rmdir", unimplementedFunc),
107    /* 41 */ SyscallDesc("dup", unimplementedFunc),
108    /* 42 */ SyscallDesc("pipe", unimplementedFunc),
109    /* 43 */ SyscallDesc("times", unimplementedFunc),
110    /* 44 */ SyscallDesc("prof", unimplementedFunc),
111    /* 45 */ SyscallDesc("brk", brkFunc),
112    /* 46 */ SyscallDesc("setgid", unimplementedFunc),
113    /* 47 */ SyscallDesc("getgid", getgidFunc),
114    /* 48 */ SyscallDesc("signal", ignoreFunc),
115    /* 49 */ SyscallDesc("geteuid", geteuidFunc),
116    /* 50 */ SyscallDesc("getegid", getegidFunc),
117    /* 51 */ SyscallDesc("acct", unimplementedFunc),
118    /* 52 */ SyscallDesc("umount2", unimplementedFunc),
119    /* 53 */ SyscallDesc("lock", unimplementedFunc),
120    /* 54 */ SyscallDesc("ioctl", ioctlFunc<ArmLinux>),
121    /* 55 */ SyscallDesc("fcntl", fcntlFunc),
122    /* 56 */ SyscallDesc("mpx", unimplementedFunc),
123    /* 57 */ SyscallDesc("setpgid", unimplementedFunc),
124    /* 58 */ SyscallDesc("ulimit", unimplementedFunc),
125    /* 59 */ SyscallDesc("unused#59", unimplementedFunc),
126    /* 60 */ SyscallDesc("umask", unimplementedFunc),
127    /* 61 */ SyscallDesc("chroot", unimplementedFunc),
128    /* 62 */ SyscallDesc("ustat", unimplementedFunc),
129    /* 63 */ SyscallDesc("dup2", unimplementedFunc),
130    /* 64 */ SyscallDesc("getppid", getpagesizeFunc),
131    /* 65 */ SyscallDesc("getpgrp", unimplementedFunc),
132    /* 66 */ SyscallDesc("setsid", unimplementedFunc),
133    /* 67 */ SyscallDesc("sigaction",unimplementedFunc),
134    /* 68 */ SyscallDesc("sgetmask", unimplementedFunc),
135    /* 69 */ SyscallDesc("ssetmask", unimplementedFunc),
136    /* 70 */ SyscallDesc("setreuid", unimplementedFunc),
137    /* 71 */ SyscallDesc("setregid", unimplementedFunc),
138    /* 72 */ SyscallDesc("sigsuspend", unimplementedFunc),
139    /* 73 */ SyscallDesc("sigpending", unimplementedFunc),
140    /* 74 */ SyscallDesc("sethostname", ignoreFunc),
141    /* 75 */ SyscallDesc("setrlimit", unimplementedFunc),
142    /* 76 */ SyscallDesc("getrlimit", unimplementedFunc),
143    /* 77 */ SyscallDesc("getrusage", unimplementedFunc),
144    /* 78 */ SyscallDesc("gettimeofday", unimplementedFunc),
145    /* 79 */ SyscallDesc("settimeofday", unimplementedFunc),
146    /* 80 */ SyscallDesc("getgroups", unimplementedFunc),
147    /* 81 */ SyscallDesc("setgroups", unimplementedFunc),
148    /* 82 */ SyscallDesc("reserved#82", unimplementedFunc),
149    /* 83 */ SyscallDesc("symlink", unimplementedFunc),
150    /* 84 */ SyscallDesc("unused#84", unimplementedFunc),
151    /* 85 */ SyscallDesc("readlink", unimplementedFunc),
152    /* 86 */ SyscallDesc("uselib", unimplementedFunc),
153    /* 87 */ SyscallDesc("swapon", gethostnameFunc),
154    /* 88 */ SyscallDesc("reboot", unimplementedFunc),
155    /* 89 */ SyscallDesc("readdir", unimplementedFunc),
156    /* 90 */ SyscallDesc("mmap", mmapFunc<ArmLinux>),
157    /* 91 */ SyscallDesc("munmap",munmapFunc),
158    /* 92 */ SyscallDesc("truncate", truncateFunc),
159    /* 93 */ SyscallDesc("ftruncate", ftruncateFunc),
160    /* 94 */ SyscallDesc("fchmod", unimplementedFunc),
161    /* 95 */ SyscallDesc("fchown", unimplementedFunc),
162    /* 96 */ SyscallDesc("getpriority", unimplementedFunc),
163    /* 97 */ SyscallDesc("setpriority", unimplementedFunc),
164    /* 98 */ SyscallDesc("profil", unimplementedFunc),
165    /* 99 */ SyscallDesc("statfs", unimplementedFunc),
166    /* 100 */ SyscallDesc("fstatfs", unimplementedFunc),
167    /* 101 */ SyscallDesc("ioperm", unimplementedFunc),
168    /* 102 */ SyscallDesc("socketcall", unimplementedFunc),
169    /* 103 */ SyscallDesc("syslog", unimplementedFunc),
170    /* 104 */ SyscallDesc("setitimer", unimplementedFunc),
171    /* 105 */ SyscallDesc("getitimer", unimplementedFunc),
172    /* 106 */ SyscallDesc("stat",  statFunc<ArmLinux>),
173    /* 107 */ SyscallDesc("lstat", unimplementedFunc),
174    /* 108 */ SyscallDesc("fstat", fstatFunc<ArmLinux>),
175    /* 109 */ SyscallDesc("unused#109", unimplementedFunc),
176    /* 110 */ SyscallDesc("iopl", unimplementedFunc),
177    /* 111 */ SyscallDesc("vhangup", unimplementedFunc),
178    /* 112 */ SyscallDesc("idle", ignoreFunc),
179    /* 113 */ SyscallDesc("vm86", unimplementedFunc),
180    /* 114 */ SyscallDesc("wait4", unimplementedFunc),
181    /* 115 */ SyscallDesc("swapoff", unimplementedFunc),
182    /* 116 */ SyscallDesc("sysinfo", unimplementedFunc),
183    /* 117 */ SyscallDesc("ipc", unimplementedFunc),
184    /* 118 */ SyscallDesc("fsync", unimplementedFunc),
185    /* 119 */ SyscallDesc("sigreturn", unimplementedFunc),
186    /* 120 */ SyscallDesc("clone", unimplementedFunc),
187    /* 121 */ SyscallDesc("setdomainname", unimplementedFunc),
188    /* 122 */ SyscallDesc("uname", unameFunc),
189    /* 123 */ SyscallDesc("modify_ldt", unimplementedFunc),
190    /* 124 */ SyscallDesc("adjtimex", unimplementedFunc),
191    /* 125 */ SyscallDesc("mprotect", ignoreFunc),
192    /* 126 */ SyscallDesc("sigprocmask", unimplementedFunc),
193    /* 127 */ SyscallDesc("create_module", unimplementedFunc),
194    /* 128 */ SyscallDesc("init_module", unimplementedFunc),
195    /* 129 */ SyscallDesc("delete_module", unimplementedFunc),
196    /* 130 */ SyscallDesc("get_kernel_syms", unimplementedFunc),
197    /* 131 */ SyscallDesc("quotactl", unimplementedFunc),
198    /* 132 */ SyscallDesc("getpgid", unimplementedFunc),
199    /* 133 */ SyscallDesc("fchdir", unimplementedFunc),
200    /* 134 */ SyscallDesc("bdflush", unimplementedFunc),
201    /* 135 */ SyscallDesc("sysfs", unimplementedFunc),
202    /* 136 */ SyscallDesc("personality", unimplementedFunc),
203    /* 137 */ SyscallDesc("afs_syscall", unimplementedFunc),
204    /* 138 */ SyscallDesc("setfsuid", unimplementedFunc),
205    /* 139 */ SyscallDesc("setfsgid", unimplementedFunc),
206    /* 140 */ SyscallDesc("llseek", unimplementedFunc),
207    /* 141 */ SyscallDesc("getdents", unimplementedFunc),
208    /* 142 */ SyscallDesc("newselect", unimplementedFunc),
209    /* 143 */ SyscallDesc("flock", unimplementedFunc),
210    /* 144 */ SyscallDesc("msync", unimplementedFunc),
211    /* 145 */ SyscallDesc("readv", unimplementedFunc),
212    /* 146 */ SyscallDesc("writev", writevFunc<ArmLinux>),
213    /* 147 */ SyscallDesc("getsid", unimplementedFunc),
214    /* 148 */ SyscallDesc("fdatasync", unimplementedFunc),
215    /* 149 */ SyscallDesc("sysctl", unimplementedFunc),
216    /* 150 */ SyscallDesc("mlock", unimplementedFunc),
217    /* 151 */ SyscallDesc("munlock", unimplementedFunc),
218    /* 152 */ SyscallDesc("mlockall", unimplementedFunc),
219    /* 153 */ SyscallDesc("munlockall", unimplementedFunc),
220    /* 154 */ SyscallDesc("sched_setparam", unimplementedFunc),
221    /* 155 */ SyscallDesc("sched_getparam", unimplementedFunc),
222    /* 156 */ SyscallDesc("sched_setscheduler", unimplementedFunc),
223    /* 157 */ SyscallDesc("sched_getscheduler", unimplementedFunc),
224    /* 158 */ SyscallDesc("sched_yield", unimplementedFunc),
225    /* 159 */ SyscallDesc("sched_get_priority_max", unimplementedFunc),
226    /* 160 */ SyscallDesc("sched_get_priority_min", unimplementedFunc),
227    /* 161 */ SyscallDesc("sched_rr_get_interval", unimplementedFunc),
228    /* 162 */ SyscallDesc("nanosleep", unimplementedFunc),
229    /* 163 */ SyscallDesc("mremap", unimplementedFunc), // ARM-specific
230    /* 164 */ SyscallDesc("setresuid", unimplementedFunc),
231    /* 165 */ SyscallDesc("getresuid", unimplementedFunc),
232    /* 166 */ SyscallDesc("vm862", unimplementedFunc),
233    /* 167 */ SyscallDesc("query_module", unimplementedFunc),
234    /* 168 */ SyscallDesc("poll", unimplementedFunc),
235    /* 169 */ SyscallDesc("nfsservctl", unimplementedFunc),
236    /* 170 */ SyscallDesc("setresgid", unimplementedFunc),
237    /* 171 */ SyscallDesc("getresgid", unimplementedFunc),
238    /* 172 */ SyscallDesc("prctl", unimplementedFunc),
239    /* 173 */ SyscallDesc("rt_sigreturn", unimplementedFunc),
240    /* 174 */ SyscallDesc("rt_sigaction", unimplementedFunc),
241    /* 175 */ SyscallDesc("rt_sigprocmask", unimplementedFunc),
242    /* 176 */ SyscallDesc("rt_sigpending", unimplementedFunc),
243    /* 177 */ SyscallDesc("rt_sigtimedwait", unimplementedFunc),
244    /* 178 */ SyscallDesc("rt_sigqueueinfo", ignoreFunc),
245    /* 179 */ SyscallDesc("rt_sigsuspend", unimplementedFunc),
246    /* 180 */ SyscallDesc("pread64", unimplementedFunc),
247    /* 181 */ SyscallDesc("pwrite64", unimplementedFunc),
248    /* 182 */ SyscallDesc("chown", unimplementedFunc),
249    /* 183 */ SyscallDesc("getcwd", unimplementedFunc),
250    /* 184 */ SyscallDesc("capget", unimplementedFunc),
251    /* 185 */ SyscallDesc("capset", unimplementedFunc),
252    /* 186 */ SyscallDesc("sigaltstack", unimplementedFunc),
253    /* 187 */ SyscallDesc("sendfile", unimplementedFunc),
254    /* 188 */ SyscallDesc("getpmsg", unimplementedFunc),
255    /* 189 */ SyscallDesc("putpmsg", unimplementedFunc),
256    /* 190 */ SyscallDesc("vfork", unimplementedFunc),
257    /* 191 */ SyscallDesc("getrlimit", unimplementedFunc),
258    /* 192 */ SyscallDesc("mmap2", mmapFunc<ArmLinux>),
259    /* 193 */ SyscallDesc("truncate64", unimplementedFunc),
260    /* 194 */ SyscallDesc("ftruncate64", unimplementedFunc),
261    /* 195 */ SyscallDesc("stat64", unimplementedFunc),
262    /* 196 */ SyscallDesc("lstat64", lstat64Func<ArmLinux>),
263    /* 197 */ SyscallDesc("fstat64", fstat64Func<ArmLinux>),
264    /* 198 */ SyscallDesc("lchown", unimplementedFunc),
265    /* 199 */ SyscallDesc("getuid", getuidFunc),
266    /* 200 */ SyscallDesc("getgid", getgidFunc),
267    /* 201 */ SyscallDesc("geteuid", geteuidFunc),
268    /* 202 */ SyscallDesc("getegid", getegidFunc),
269    /* 203 */ SyscallDesc("setreuid", unimplementedFunc),
270    /* 204 */ SyscallDesc("setregid", unimplementedFunc),
271    /* 205 */ SyscallDesc("getgroups", unimplementedFunc),
272    /* 206 */ SyscallDesc("setgroups", unimplementedFunc),
273    /* 207 */ SyscallDesc("fchown", unimplementedFunc),
274    /* 208 */ SyscallDesc("setresuid", unimplementedFunc),
275    /* 209 */ SyscallDesc("getresuid", unimplementedFunc),
276    /* 210 */ SyscallDesc("setresgid", unimplementedFunc),
277    /* 211 */ SyscallDesc("getresgid", unimplementedFunc),
278    /* 212 */ SyscallDesc("chown", unimplementedFunc),
279    /* 213 */ SyscallDesc("setuid", unimplementedFunc),
280    /* 214 */ SyscallDesc("setgid", unimplementedFunc),
281    /* 215 */ SyscallDesc("setfsuid", unimplementedFunc),
282    /* 216 */ SyscallDesc("setfsgid", unimplementedFunc),
283    /* 217 */ SyscallDesc("getdents64", unimplementedFunc),
284    /* 218 */ SyscallDesc("pivot_root", unimplementedFunc),
285    /* 219 */ SyscallDesc("mincore", unimplementedFunc),
286    /* 220 */ SyscallDesc("madvise", unimplementedFunc),
287    /* 221 */ SyscallDesc("fcntl64", fcntl64Func),
288    /* 222 */ SyscallDesc("tux", unimplementedFunc),
289    /* 223 */ SyscallDesc("unknown#223", unimplementedFunc),
290    /* 224 */ SyscallDesc("gettid", unimplementedFunc),
291    /* 225 */ SyscallDesc("readahead", unimplementedFunc),
292    /* 226 */ SyscallDesc("setxattr", unimplementedFunc),
293    /* 227 */ SyscallDesc("lsetxattr", unimplementedFunc),
294    /* 228 */ SyscallDesc("fsetxattr", unimplementedFunc),
295    /* 229 */ SyscallDesc("getxattr", unimplementedFunc),
296    /* 230 */ SyscallDesc("lgetxattr", unimplementedFunc),
297    /* 231 */ SyscallDesc("fgetxattr", unimplementedFunc),
298    /* 232 */ SyscallDesc("listxattr", unimplementedFunc),
299    /* 233 */ SyscallDesc("llistxattr", unimplementedFunc),
300    /* 234 */ SyscallDesc("flistxattr", unimplementedFunc),
301    /* 235 */ SyscallDesc("removexattr", unimplementedFunc),
302    /* 236 */ SyscallDesc("lremovexattr", unimplementedFunc),
303    /* 237 */ SyscallDesc("fremovexattr", unimplementedFunc),
304    /* 238 */ SyscallDesc("tkill", unimplementedFunc),
305    /* 239 */ SyscallDesc("sendfile64", unimplementedFunc),
306    /* 240 */ SyscallDesc("futex", unimplementedFunc),
307    /* 241 */ SyscallDesc("sched_setaffinity", unimplementedFunc),
308    /* 242 */ SyscallDesc("sched_getaffinity", unimplementedFunc),
309    /* 243 */ SyscallDesc("io_setup", unimplementedFunc),
310    /* 244 */ SyscallDesc("io_destory", unimplementedFunc),
311    /* 245 */ SyscallDesc("io_getevents", unimplementedFunc),
312    /* 246 */ SyscallDesc("io_submit", unimplementedFunc),
313    /* 247 */ SyscallDesc("io_cancel", unimplementedFunc),
314    /* 248 */ SyscallDesc("exit_group", exitFunc),
315    /* 249 */ SyscallDesc("lookup_dcookie", unimplementedFunc),
316    /* 250 */ SyscallDesc("epoll_create", unimplementedFunc),
317    /* 251 */ SyscallDesc("epoll_ctl", unimplementedFunc),
318    /* 252 */ SyscallDesc("epoll_wait", unimplementedFunc),
319    /* 253 */ SyscallDesc("remap_file_pages", unimplementedFunc),
320    /* 254 */ SyscallDesc("set_thread_area", unimplementedFunc),
321    /* 255 */ SyscallDesc("get_thread_area", unimplementedFunc),
322    /* 256 */ SyscallDesc("set_tid_address", unimplementedFunc),
323    /* 257 */ SyscallDesc("timer_create", unimplementedFunc),
324    /* 258 */ SyscallDesc("timer_settime", unimplementedFunc),
325    /* 259 */ SyscallDesc("timer_gettime", unimplementedFunc),
326    /* 260 */ SyscallDesc("timer_getoverrun", unimplementedFunc),
327    /* 261 */ SyscallDesc("timer_delete", unimplementedFunc),
328    /* 262 */ SyscallDesc("clock_settime", unimplementedFunc),
329    /* 263 */ SyscallDesc("clock_gettime", unimplementedFunc),
330    /* 264 */ SyscallDesc("clock_getres", unimplementedFunc),
331    /* 265 */ SyscallDesc("clock_nanosleep", unimplementedFunc),
332    /* 266 */ SyscallDesc("statfs64", unimplementedFunc),
333    /* 267 */ SyscallDesc("fstatfs64", unimplementedFunc),
334    /* 268 */ SyscallDesc("tgkill", unimplementedFunc),
335    /* 269 */ SyscallDesc("utimes", unimplementedFunc),
336    /* 270 */ SyscallDesc("arm_fadvise64_64", unimplementedFunc),
337    /* 271 */ SyscallDesc("pciconfig_iobase", unimplementedFunc),
338    /* 272 */ SyscallDesc("pciconfig_read", unimplementedFunc),
339    /* 273 */ SyscallDesc("pciconfig_write", unimplementedFunc),
340    /* 274 */ SyscallDesc("mq_open", unimplementedFunc),
341    /* 275 */ SyscallDesc("mq_unlink", unimplementedFunc),
342    /* 276 */ SyscallDesc("mq_timedsend", unimplementedFunc),
343    /* 277 */ SyscallDesc("mq_timedreceive", unimplementedFunc),
344    /* 278 */ SyscallDesc("mq_notify", unimplementedFunc),
345    /* 279 */ SyscallDesc("mq_getsetattr", unimplementedFunc),
346    /* 280 */ SyscallDesc("waitid", unimplementedFunc),
347    /* 281 */ SyscallDesc("socket", unimplementedFunc),
348    /* 282 */ SyscallDesc("bind", unimplementedFunc),
349    /* 283 */ SyscallDesc("connect", unimplementedFunc),
350    /* 284 */ SyscallDesc("listen", unimplementedFunc),
351    /* 285 */ SyscallDesc("accept", unimplementedFunc),
352    /* 286 */ SyscallDesc("getsockname", unimplementedFunc),
353    /* 287 */ SyscallDesc("getpeername", unimplementedFunc),
354    /* 288 */ SyscallDesc("socketpair", unimplementedFunc),
355    /* 289 */ SyscallDesc("send", unimplementedFunc),
356    /* 290 */ SyscallDesc("sendto", unimplementedFunc),
357    /* 291 */ SyscallDesc("recv", unimplementedFunc),
358    /* 292 */ SyscallDesc("recvfrom", unimplementedFunc),
359    /* 293 */ SyscallDesc("shutdown", unimplementedFunc),
360    /* 294 */ SyscallDesc("setsockopt", unimplementedFunc),
361    /* 295 */ SyscallDesc("getsockopt", unimplementedFunc),
362    /* 296 */ SyscallDesc("sendmsg", unimplementedFunc),
363    /* 297 */ SyscallDesc("rcvmsg", unimplementedFunc),
364    /* 298 */ SyscallDesc("semop", unimplementedFunc),
365    /* 299 */ SyscallDesc("semget", unimplementedFunc),
366    /* 300 */ SyscallDesc("semctl", unimplementedFunc),
367    /* 301 */ SyscallDesc("msgsend", unimplementedFunc),
368    /* 302 */ SyscallDesc("msgrcv", unimplementedFunc),
369    /* 303 */ SyscallDesc("msgget", unimplementedFunc),
370    /* 304 */ SyscallDesc("msgctl", unimplementedFunc),
371    /* 305 */ SyscallDesc("shmat", unimplementedFunc),
372    /* 306 */ SyscallDesc("shmdt", unimplementedFunc),
373    /* 307 */ SyscallDesc("shmget", unimplementedFunc),
374    /* 308 */ SyscallDesc("shmctl", unimplementedFunc),
375    /* 309 */ SyscallDesc("add_key", unimplementedFunc),
376    /* 310 */ SyscallDesc("request_key", unimplementedFunc),
377    /* 311 */ SyscallDesc("keyctl", unimplementedFunc),
378    /* 312 */ SyscallDesc("semtimedop", unimplementedFunc),
379    /* 313 */ SyscallDesc("vserver", unimplementedFunc),
380    /* 314 */ SyscallDesc("ioprio_set", unimplementedFunc),
381    /* 315 */ SyscallDesc("ioprio_get", unimplementedFunc),
382    /* 316 */ SyscallDesc("inotify_init", unimplementedFunc),
383    /* 317 */ SyscallDesc("inotify_add_watch", unimplementedFunc),
384    /* 318 */ SyscallDesc("inotify_rm_watch", unimplementedFunc),
385    /* 319 */ SyscallDesc("mbind", unimplementedFunc),
386    /* 320 */ SyscallDesc("get_mempolicy", unimplementedFunc),
387    /* 321 */ SyscallDesc("set_mempolicy", unimplementedFunc),
388    /* 322 */ SyscallDesc("openat", unimplementedFunc),
389    /* 323 */ SyscallDesc("mkdirat", unimplementedFunc),
390    /* 324 */ SyscallDesc("mknodat", unimplementedFunc),
391    /* 325 */ SyscallDesc("fchownat", unimplementedFunc),
392    /* 326 */ SyscallDesc("futimesat", unimplementedFunc),
393    /* 327 */ SyscallDesc("fstatat64", unimplementedFunc),
394    /* 328 */ SyscallDesc("unlinkat", unimplementedFunc),
395    /* 329 */ SyscallDesc("renameat", unimplementedFunc),
396    /* 330 */ SyscallDesc("linkat", unimplementedFunc),
397    /* 331 */ SyscallDesc("symlinkat", unimplementedFunc),
398    /* 332 */ SyscallDesc("readlinkat", unimplementedFunc),
399    /* 333 */ SyscallDesc("fchmodat", unimplementedFunc),
400    /* 334 */ SyscallDesc("faccessat", unimplementedFunc),
401    /* 335 */ SyscallDesc("pselect6", unimplementedFunc),
402    /* 336 */ SyscallDesc("ppoll", unimplementedFunc),
403    /* 337 */ SyscallDesc("unshare", unimplementedFunc),
404    /* 338 */ SyscallDesc("set_robust_list", unimplementedFunc),
405    /* 339 */ SyscallDesc("get_robust_list", unimplementedFunc),
406    /* 340 */ SyscallDesc("splice", unimplementedFunc),
407    /* 341 */ SyscallDesc("arm_sync_file_range", unimplementedFunc),
408    /* 342 */ SyscallDesc("tee", unimplementedFunc),
409    /* 343 */ SyscallDesc("vmsplice", unimplementedFunc),
410    /* 344 */ SyscallDesc("move_pages", unimplementedFunc),
411    /* 345 */ SyscallDesc("getcpu", unimplementedFunc),
412    /* 346 */ SyscallDesc("epoll_pwait", unimplementedFunc),
413};
414
415/// Target set_tls() handler.
416static SyscallReturn
417setTLSFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
418          ThreadContext *tc)
419{
420    uint32_t tlsPtr = process->getSyscallArg(tc, 0);
421    TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, 0));
422
423    tc->getMemPort()->writeBlob(ArmLinuxProcess::commPage + 0x0ff0,
424                                (uint8_t *)&tlsPtr, sizeof(tlsPtr));
425    return 0;
426}
427
428SyscallDesc ArmLinuxProcess::privSyscallDescs[] = {
429    /*  1 */ SyscallDesc("breakpoint", unimplementedFunc),
430    /*  2 */ SyscallDesc("cacheflush", unimplementedFunc),
431    /*  3 */ SyscallDesc("usr26", unimplementedFunc),
432    /*  4 */ SyscallDesc("usr32", unimplementedFunc),
433    /*  5 */ SyscallDesc("set_tls", setTLSFunc)
434};
435
436ArmLinuxProcess::ArmLinuxProcess(LiveProcessParams * params,
437        ObjectFile *objFile)
438    : ArmLiveProcess(params, objFile),
439     Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc)),
440     Num_Priv_Syscall_Descs(sizeof(privSyscallDescs) / sizeof(SyscallDesc))
441{ }
442
443const Addr ArmLinuxProcess::commPage = 0xffff0000;
444
445SyscallDesc*
446ArmLinuxProcess::getDesc(int callnum)
447{
448    // Angel SWI syscalls are unsupported in this release
449    if (callnum == 0x123456) {
450        panic("Attempt to execute an ANGEL_SWI system call (newlib-related)");
451    } else if ((callnum & 0x00f00000) == 0x00900000 ||
452            (callnum & 0xf0000) == 0xf0000) {
453        callnum &= 0x000fffff;
454        if ((callnum & 0x0f0000) == 0xf0000) {
455            callnum -= 0x0f0001;
456            if (callnum < 0 || callnum > Num_Priv_Syscall_Descs)
457                return NULL;
458            return &privSyscallDescs[callnum];
459        }
460    }
461    // Linux syscalls have to strip off the 0x00900000
462
463    if (callnum < 0 || callnum > Num_Syscall_Descs)
464        return NULL;
465
466    return &syscallDescs[callnum];
467}
468
469void
470ArmLinuxProcess::startup()
471{
472    ArmLiveProcess::startup();
473    pTable->allocate(commPage, PageBytes);
474    ThreadContext *tc = system->getThreadContext(contextIds[0]);
475
476    uint8_t swiNeg1[] = {
477        0xff, 0xff, 0xff, 0xef  //swi -1
478    };
479
480    // Fill this page with swi -1 so we'll no if we land in it somewhere.
481    for (Addr addr = 0; addr < PageBytes; addr += sizeof(swiNeg1)) {
482        tc->getMemPort()->writeBlob(commPage + addr,
483                                    swiNeg1, sizeof(swiNeg1));
484    }
485
486    // We don't have barriers, so just return.
487    uint8_t memory_barrier[] =
488    {
489        0x0e, 0xf0, 0xa0, 0xe1  //usr_ret lr
490    };
491    tc->getMemPort()->writeBlob(commPage + 0x0fa0, memory_barrier,
492                                sizeof(memory_barrier));
493
494    // This -should- be atomic, but I don't think all the support that we'd
495    // need is implemented. There should also be memory barriers around it.
496    uint8_t cmpxchg[] =
497    {
498        0x00, 0x30, 0x92, 0xe5, //ldr r3, [r2]
499        0x00, 0x30, 0x53, 0xe0, //subs r3, r3, r0
500        0x00, 0x10, 0x92, 0x05, //streq r1, [r2]
501        0x03, 0x00, 0xa0, 0xe1, //mov r0, r3
502        0x0e, 0xf0, 0xa0, 0xe1  //usr_ret lr
503    };
504    tc->getMemPort()->writeBlob(commPage + 0x0fc0, cmpxchg, sizeof(cmpxchg));
505
506    uint8_t get_tls[] =
507    {
508        0x08, 0x00, 0x9f, 0xe5, //ldr r0, [pc, #(16 - 8)]
509        0x0e, 0xf0, 0xa0, 0xe1  //usr_ret lr
510    };
511    tc->getMemPort()->writeBlob(commPage + 0x0fe0, get_tls, sizeof(get_tls));
512}
513
514ArmISA::IntReg
515ArmLinuxProcess::getSyscallArg(ThreadContext *tc, int i)
516{
517    // Linux apparently allows more parameter than the ABI says it should.
518    // This limit may need to be increased even further.
519    assert(i < 6);
520    return tc->readIntReg(ArgumentReg0 + i);
521}
522
523void
524ArmLinuxProcess::setSyscallArg(ThreadContext *tc, int i, ArmISA::IntReg val)
525{
526    // Linux apparently allows more parameter than the ABI says it should.
527    // This limit may need to be increased even further.
528    assert(i < 6);
529    tc->setIntReg(ArgumentReg0 + i, val);
530}
531