Merge ktlim@zizzer.eecs.umich.edu:/bk/m5
[gem5.git] / arch / alpha / alpha_tru64_process.cc
1 /*
2 * Copyright (c) 2001-2005 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
29 #include <errno.h>
30 #include <unistd.h>
31 #include <fcntl.h> // for host open() flags
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <string.h> // for memset()
35 #include <dirent.h>
36
37 #include "sim/host.hh"
38 #include "cpu/base_cpu.hh"
39 #include "mem/functional_mem/functional_memory.hh"
40 #include "sim/process.hh"
41 #include "cpu/exec_context.hh"
42 #include "sim/fake_syscall.hh"
43
44 #include "arch/alpha/alpha_common_syscall_emul.hh"
45 #include "arch/alpha/alpha_tru64_process.hh"
46
47 #include "sim/syscall_emul.hh"
48 #include "sim/universe.hh" // for curTick & ticksPerSecond
49
50 #include "base/trace.hh"
51
52 using namespace std;
53
54 ///
55 /// This class encapsulates the types, structures, constants,
56 /// functions, and syscall-number mappings specific to the Alpha Tru64
57 /// syscall interface.
58 ///
59 class Tru64 {
60
61 public:
62
63 //@{
64 /// Basic Tru64 types.
65 typedef uint64_t size_t;
66 typedef uint64_t off_t;
67 typedef uint16_t nlink_t;
68 typedef int32_t dev_t;
69 typedef uint32_t uid_t;
70 typedef uint32_t gid_t;
71 typedef uint32_t time_t;
72 typedef uint32_t mode_t;
73 typedef uint32_t ino_t;
74 //@}
75
76 //@{
77 /// open(2) flag values.
78 static const int TGT_O_RDONLY = 00000000;
79 static const int TGT_O_WRONLY = 00000001;
80 static const int TGT_O_RDWR = 00000002;
81 static const int TGT_O_NONBLOCK = 00000004;
82 static const int TGT_O_APPEND = 00000010;
83 static const int TGT_O_CREAT = 00001000;
84 static const int TGT_O_TRUNC = 00002000;
85 static const int TGT_O_EXCL = 00004000;
86 static const int TGT_O_NOCTTY = 00010000;
87 static const int TGT_O_SYNC = 00040000;
88 static const int TGT_O_DRD = 00100000;
89 static const int TGT_O_DIRECTIO = 00200000;
90 static const int TGT_O_CACHE = 00400000;
91 static const int TGT_O_DSYNC = 02000000;
92 static const int TGT_O_RSYNC = 04000000;
93 //@}
94
95 /// This table maps the target open() flags to the corresponding
96 /// host open() flags.
97 static OpenFlagTransTable openFlagTable[];
98
99 /// Number of entries in openFlagTable[].
100 static const int NUM_OPEN_FLAGS;
101
102 /// Stat buffer. Note that Tru64 v5.0+ use a new "F64" stat structure,
103 /// and a new set of syscall numbers for stat calls. Backwards
104 /// compatibility with v4.x should be feasible by implementing
105 /// another set of stat functions using the old structure
106 /// definition and binding them to the old syscall numbers, but we
107 /// haven't done that yet.
108 struct F64_stat {
109 dev_t st_dev; //!< st_dev
110 int32_t st_retired1; //!< st_retired1
111 mode_t st_mode; //!< st_mode
112 nlink_t st_nlink; //!< st_nlink
113 uint16_t st_nlink_reserved; //!< st_nlink_reserved
114 uid_t st_uid; //!< st_uid
115 gid_t st_gid; //!< st_gid
116 dev_t st_rdev; //!< st_rdev
117 dev_t st_ldev; //!< st_ldev
118 off_t st_size; //!< st_size
119 time_t st_retired2; //!< st_retired2
120 int32_t st_uatime; //!< st_uatime
121 time_t st_retired3; //!< st_retired3
122 int32_t st_umtime; //!< st_umtime
123 time_t st_retired4; //!< st_retired4
124 int32_t st_uctime; //!< st_uctime
125 int32_t st_retired5; //!< st_retired5
126 int32_t st_retired6; //!< st_retired6
127 uint32_t st_flags; //!< st_flags
128 uint32_t st_gen; //!< st_gen
129 uint64_t st_spare[4]; //!< st_spare[4]
130 ino_t st_ino; //!< st_ino
131 int32_t st_ino_reserved; //!< st_ino_reserved
132 time_t st_atimeX; //!< st_atime
133 int32_t st_atime_reserved; //!< st_atime_reserved
134 time_t st_mtimeX; //!< st_mtime
135 int32_t st_mtime_reserved; //!< st_mtime_reserved
136 time_t st_ctimeX; //!< st_ctime
137 int32_t st_ctime_reserved; //!< st_ctime_reserved
138 uint64_t st_blksize; //!< st_blksize
139 uint64_t st_blocks; //!< st_blocks
140 };
141
142
143 /// For getdirentries().
144 struct dirent
145 {
146 ino_t d_ino; //!< file number of entry
147 uint16_t d_reclen; //!< length of this record
148 uint16_t d_namlen; //!< length of string in d_name
149 char d_name[256]; //!< dummy name length
150 };
151
152
153 /// Length of strings in struct utsname (plus 1 for null char).
154 static const int _SYS_NMLN = 32;
155
156 /// Interface struct for uname().
157 struct utsname {
158 char sysname[_SYS_NMLN]; //!< System name.
159 char nodename[_SYS_NMLN]; //!< Node name.
160 char release[_SYS_NMLN]; //!< OS release.
161 char version[_SYS_NMLN]; //!< OS version.
162 char machine[_SYS_NMLN]; //!< Machine type.
163 };
164
165 //@{
166 /// ioctl() command codes.
167 static const unsigned TIOCGETP = 0x40067408;
168 static const unsigned TIOCSETP = 0x80067409;
169 static const unsigned TIOCSETN = 0x8006740a;
170 static const unsigned TIOCSETC = 0x80067411;
171 static const unsigned TIOCGETC = 0x40067412;
172 static const unsigned FIONREAD = 0x4004667f;
173 static const unsigned TIOCISATTY = 0x2000745e;
174 // TIOCGETS not defined in tru64, so I made up a number
175 static const unsigned TIOCGETS = 0x40000000;
176 static const unsigned TIOCGETA = 0x402c7413;
177 //@}
178
179 /// Resource enumeration for getrlimit().
180 enum rlimit_resources {
181 RLIMIT_CPU = 0,
182 RLIMIT_FSIZE = 1,
183 RLIMIT_DATA = 2,
184 RLIMIT_STACK = 3,
185 RLIMIT_CORE = 4,
186 RLIMIT_RSS = 5,
187 RLIMIT_NOFILE = 6,
188 RLIMIT_AS = 7,
189 RLIMIT_VMEM = 7
190 };
191
192 /// Limit struct for getrlimit/setrlimit.
193 struct rlimit {
194 uint64_t rlim_cur; //!< soft limit
195 uint64_t rlim_max; //!< hard limit
196 };
197
198
199 /// For mmap().
200 static const unsigned TGT_MAP_ANONYMOUS = 0x10;
201
202
203 //@{
204 /// For getsysinfo().
205 static const unsigned GSI_PLATFORM_NAME = 103; //!< platform name as string
206 static const unsigned GSI_CPU_INFO = 59; //!< CPU information
207 static const unsigned GSI_PROC_TYPE = 60; //!< get proc_type
208 static const unsigned GSI_MAX_CPU = 30; //!< max # cpu's on this machine
209 static const unsigned GSI_CPUS_IN_BOX = 55; //!< number of CPUs in system
210 static const unsigned GSI_PHYSMEM = 19; //!< Physical memory in KB
211 static const unsigned GSI_CLK_TCK = 42; //!< clock freq in Hz
212 //@}
213
214 /// For getsysinfo() GSI_CPU_INFO option.
215 struct cpu_info {
216 uint32_t current_cpu; //!< current_cpu
217 uint32_t cpus_in_box; //!< cpus_in_box
218 uint32_t cpu_type; //!< cpu_type
219 uint32_t ncpus; //!< ncpus
220 uint64_t cpus_present; //!< cpus_present
221 uint64_t cpus_running; //!< cpus_running
222 uint64_t cpu_binding; //!< cpu_binding
223 uint64_t cpu_ex_binding; //!< cpu_ex_binding
224 uint32_t mhz; //!< mhz
225 uint32_t unused[3]; //!< future expansion
226 };
227
228 /// For gettimeofday.
229 struct timeval {
230 uint32_t tv_sec; //!< seconds
231 uint32_t tv_usec; //!< microseconds
232 };
233
234 //@{
235 /// For getrusage().
236 static const int RUSAGE_THREAD = 1;
237 static const int RUSAGE_SELF = 0;
238 static const int RUSAGE_CHILDREN = -1;
239 //@}
240
241 /// For getrusage().
242 struct rusage {
243 struct timeval ru_utime; //!< user time used
244 struct timeval ru_stime; //!< system time used
245 uint64_t ru_maxrss; //!< ru_maxrss
246 uint64_t ru_ixrss; //!< integral shared memory size
247 uint64_t ru_idrss; //!< integral unshared data "
248 uint64_t ru_isrss; //!< integral unshared stack "
249 uint64_t ru_minflt; //!< page reclaims - total vmfaults
250 uint64_t ru_majflt; //!< page faults
251 uint64_t ru_nswap; //!< swaps
252 uint64_t ru_inblock; //!< block input operations
253 uint64_t ru_oublock; //!< block output operations
254 uint64_t ru_msgsnd; //!< messages sent
255 uint64_t ru_msgrcv; //!< messages received
256 uint64_t ru_nsignals; //!< signals received
257 uint64_t ru_nvcsw; //!< voluntary context switches
258 uint64_t ru_nivcsw; //!< involuntary "
259 };
260
261 /// For sigreturn().
262 struct sigcontext {
263 int64_t sc_onstack; //!< sigstack state to restore
264 int64_t sc_mask; //!< signal mask to restore
265 int64_t sc_pc; //!< pc at time of signal
266 int64_t sc_ps; //!< psl to retore
267 int64_t sc_regs[32]; //!< processor regs 0 to 31
268 int64_t sc_ownedfp; //!< fp has been used
269 int64_t sc_fpregs[32]; //!< fp regs 0 to 31
270 uint64_t sc_fpcr; //!< floating point control reg
271 uint64_t sc_fp_control; //!< software fpcr
272 int64_t sc_reserved1; //!< reserved for kernel
273 uint32_t sc_kreserved1; //!< reserved for kernel
274 uint32_t sc_kreserved2; //!< reserved for kernel
275 size_t sc_ssize; //!< stack size
276 caddr_t sc_sbase; //!< stack start
277 uint64_t sc_traparg_a0; //!< a0 argument to trap on exc
278 uint64_t sc_traparg_a1; //!< a1 argument to trap on exc
279 uint64_t sc_traparg_a2; //!< a2 argument to trap on exc
280 uint64_t sc_fp_trap_pc; //!< imprecise pc
281 uint64_t sc_fp_trigger_sum; //!< Exception summary at trigg
282 uint64_t sc_fp_trigger_inst; //!< Instruction at trigger pc
283 };
284
285
286 /// For table().
287 static const int TBL_SYSINFO = 12;
288
289 /// For table().
290 struct tbl_sysinfo {
291 uint64_t si_user; //!< User time
292 uint64_t si_nice; //!< Nice time
293 uint64_t si_sys; //!< System time
294 uint64_t si_idle; //!< Idle time
295 uint64_t si_hz; //!< hz
296 uint64_t si_phz; //!< phz
297 uint64_t si_boottime; //!< Boot time in seconds
298 uint64_t wait; //!< Wait time
299 uint32_t si_max_procs; //!< rpb->rpb_numprocs
300 uint32_t pad; //!< padding
301 };
302
303
304 /// For stack_create.
305 struct vm_stack {
306 // was void *
307 Addr address; //!< address hint
308 size_t rsize; //!< red zone size
309 size_t ysize; //!< yellow zone size
310 size_t gsize; //!< green zone size
311 size_t swap; //!< amount of swap to reserve
312 size_t incr; //!< growth increment
313 uint64_t align; //!< address alignment
314 uint64_t flags; //!< MAP_FIXED etc.
315 // was struct memalloc_attr *
316 Addr attr; //!< allocation policy
317 uint64_t reserved; //!< reserved
318 };
319
320 /// Return values for nxm calls.
321 enum {
322 KERN_NOT_RECEIVER = 7,
323 KERN_NOT_IN_SET = 12
324 };
325
326 /// For nxm_task_init.
327 static const int NXM_TASK_INIT_VP = 2; //!< initial thread is VP
328
329 /// Task attribute structure.
330 struct nxm_task_attr {
331 int64_t nxm_callback; //!< nxm_callback
332 unsigned int nxm_version; //!< nxm_version
333 unsigned short nxm_uniq_offset; //!< nxm_uniq_offset
334 unsigned short flags; //!< flags
335 int nxm_quantum; //!< nxm_quantum
336 int pad1; //!< pad1
337 int64_t pad2; //!< pad2
338 };
339
340 /// Signal set.
341 typedef uint64_t sigset_t;
342
343 /// Thread state shared between user & kernel.
344 struct ushared_state {
345 sigset_t sigmask; //!< thread signal mask
346 sigset_t sig; //!< thread pending mask
347 // struct nxm_pth_state *
348 Addr pth_id; //!< out-of-line state
349 int flags; //!< shared flags
350 #define US_SIGSTACK 0x1 // thread called sigaltstack
351 #define US_ONSTACK 0x2 // thread is running on altstack
352 #define US_PROFILE 0x4 // thread called profil
353 #define US_SYSCALL 0x8 // thread in syscall
354 #define US_TRAP 0x10 // thread has trapped
355 #define US_YELLOW 0x20 // thread has mellowed yellow
356 #define US_YZONE 0x40 // thread has zoned out
357 #define US_FP_OWNED 0x80 // thread used floating point
358
359 int cancel_state; //!< thread's cancelation state
360 #define US_CANCEL 0x1 // cancel pending
361 #define US_NOCANCEL 0X2 // synch cancel disabled
362 #define US_SYS_NOCANCEL 0x4 // syscall cancel disabled
363 #define US_ASYNC_NOCANCEL 0x8 // asynch cancel disabled
364 #define US_CANCEL_BITS (US_NOCANCEL|US_SYS_NOCANCEL|US_ASYNC_NOCANCEL)
365 #define US_CANCEL_MASK (US_CANCEL|US_NOCANCEL|US_SYS_NOCANCEL| \
366 US_ASYNC_NOCANCEL)
367
368 // These are semi-shared. They are always visible to
369 // the kernel but are never context-switched by the library.
370
371 int nxm_ssig; //!< scheduler's synchronous signals
372 int reserved1; //!< reserved1
373 int64_t nxm_active; //!< scheduler active
374 int64_t reserved2; //!< reserved2
375 };
376
377 struct nxm_sched_state {
378 struct ushared_state nxm_u; //!< state own by user thread
379 unsigned int nxm_bits; //!< scheduler state / slot
380 int nxm_quantum; //!< quantum count-down value
381 int nxm_set_quantum; //!< quantum reset value
382 int nxm_sysevent; //!< syscall state
383 // struct nxm_upcall *
384 Addr nxm_uc_ret; //!< stack ptr of null thread
385 // void *
386 Addr nxm_tid; //!< scheduler's thread id
387 int64_t nxm_va; //!< page fault address
388 // struct nxm_pth_state *
389 Addr nxm_pthid; //!< id of null thread
390 uint64_t nxm_bound_pcs_count; //!< bound PCS thread count
391 int64_t pad[2]; //!< pad
392 };
393
394 /// nxm_shared.
395 struct nxm_shared {
396 int64_t nxm_callback; //!< address of upcall routine
397 unsigned int nxm_version; //!< version number
398 unsigned short nxm_uniq_offset; //!< correction factor for TEB
399 unsigned short pad1; //!< pad1
400 int64_t space[2]; //!< future growth
401 struct nxm_sched_state nxm_ss[1]; //!< array of shared areas
402 };
403
404 /// nxm_slot_state_t.
405 enum nxm_slot_state_t {
406 NXM_SLOT_AVAIL,
407 NXM_SLOT_BOUND,
408 NXM_SLOT_UNBOUND,
409 NXM_SLOT_EMPTY
410 };
411
412 /// nxm_config_info
413 struct nxm_config_info {
414 int nxm_nslots_per_rad; //!< max number of VP slots per RAD
415 int nxm_nrads; //!< max number of RADs
416 // nxm_slot_state_t *
417 Addr nxm_slot_state; //!< per-VP slot state
418 // struct nxm_shared *
419 Addr nxm_rad[1]; //!< per-RAD shared areas
420 };
421
422 /// For nxm_thread_create.
423 enum nxm_thread_type {
424 NXM_TYPE_SCS = 0,
425 NXM_TYPE_VP = 1,
426 NXM_TYPE_MANAGER = 2
427 };
428
429 /// Thread attributes.
430 struct nxm_thread_attr {
431 int version; //!< version
432 int type; //!< type
433 int cancel_flags; //!< cancel_flags
434 int priority; //!< priority
435 int policy; //!< policy
436 int signal_type; //!< signal_type
437 // void *
438 Addr pthid; //!< pthid
439 sigset_t sigmask; //!< sigmask
440 /// Initial register values.
441 struct {
442 uint64_t pc; //!< pc
443 uint64_t sp; //!< sp
444 uint64_t a0; //!< a0
445 } registers;
446 uint64_t pad2[2]; //!< pad2
447 };
448
449 /// Helper function to convert a host stat buffer to a target stat
450 /// buffer. Also copies the target buffer out to the simulated
451 /// memorty space. Used by stat(), fstat(), and lstat().
452 static void
453 copyOutStatBuf(FunctionalMemory *mem, Addr addr, struct stat *host)
454 {
455 TypedBufferArg<Tru64::F64_stat> tgt(addr);
456
457 tgt->st_dev = host->st_dev;
458 tgt->st_ino = host->st_ino;
459 tgt->st_mode = host->st_mode;
460 tgt->st_nlink = host->st_nlink;
461 tgt->st_uid = host->st_uid;
462 tgt->st_gid = host->st_gid;
463 tgt->st_rdev = host->st_rdev;
464 tgt->st_size = host->st_size;
465 tgt->st_atimeX = host->st_atime;
466 tgt->st_mtimeX = host->st_mtime;
467 tgt->st_ctimeX = host->st_ctime;
468 tgt->st_blksize = host->st_blksize;
469 tgt->st_blocks = host->st_blocks;
470
471 tgt.copyOut(mem);
472 }
473
474
475 /// The target system's hostname.
476 static const char *hostname;
477
478 /// Target uname() handler.
479 static SyscallReturn
480 unameFunc(SyscallDesc *desc, int callnum, Process *process,
481 ExecContext *xc)
482 {
483 TypedBufferArg<Tru64::utsname> name(xc->getSyscallArg(0));
484
485 strcpy(name->sysname, "OSF1");
486 strcpy(name->nodename, hostname);
487 strcpy(name->release, "V5.1");
488 strcpy(name->version, "732");
489 strcpy(name->machine, "alpha");
490
491 name.copyOut(xc->mem);
492 return 0;
493 }
494
495
496 /// Target getsysyinfo() handler.
497 static SyscallReturn
498 getsysinfoFunc(SyscallDesc *desc, int callnum, Process *process,
499 ExecContext *xc)
500 {
501 unsigned op = xc->getSyscallArg(0);
502 unsigned nbytes = xc->getSyscallArg(2);
503
504 switch (op) {
505
506 case Tru64::GSI_MAX_CPU: {
507 TypedBufferArg<uint32_t> max_cpu(xc->getSyscallArg(1));
508 *max_cpu = process->numCpus();
509 max_cpu.copyOut(xc->mem);
510 return 1;
511 }
512
513 case Tru64::GSI_CPUS_IN_BOX: {
514 TypedBufferArg<uint32_t> cpus_in_box(xc->getSyscallArg(1));
515 *cpus_in_box = process->numCpus();
516 cpus_in_box.copyOut(xc->mem);
517 return 1;
518 }
519
520 case Tru64::GSI_PHYSMEM: {
521 TypedBufferArg<uint64_t> physmem(xc->getSyscallArg(1));
522 *physmem = 1024 * 1024; // physical memory in KB
523 physmem.copyOut(xc->mem);
524 return 1;
525 }
526
527 case Tru64::GSI_CPU_INFO: {
528 TypedBufferArg<Tru64::cpu_info> infop(xc->getSyscallArg(1));
529
530 infop->current_cpu = 0;
531 infop->cpus_in_box = process->numCpus();
532 infop->cpu_type = 57;
533 infop->ncpus = process->numCpus();
534 int cpumask = (1 << process->numCpus()) - 1;
535 infop->cpus_present = infop->cpus_running = cpumask;
536 infop->cpu_binding = 0;
537 infop->cpu_ex_binding = 0;
538 infop->mhz = 667;
539
540 infop.copyOut(xc->mem);
541 return 1;
542 }
543
544 case Tru64::GSI_PROC_TYPE: {
545 TypedBufferArg<uint64_t> proc_type(xc->getSyscallArg(1));
546 *proc_type = 11;
547 proc_type.copyOut(xc->mem);
548 return 1;
549 }
550
551 case Tru64::GSI_PLATFORM_NAME: {
552 BufferArg bufArg(xc->getSyscallArg(1), nbytes);
553 strncpy((char *)bufArg.bufferPtr(),
554 "COMPAQ Professional Workstation XP1000",
555 nbytes);
556 bufArg.copyOut(xc->mem);
557 return 1;
558 }
559
560 case Tru64::GSI_CLK_TCK: {
561 TypedBufferArg<uint64_t> clk_hz(xc->getSyscallArg(1));
562 *clk_hz = 1024;
563 clk_hz.copyOut(xc->mem);
564 return 1;
565 }
566
567 default:
568 cerr << "getsysinfo: unknown op " << op << endl;
569 abort();
570 break;
571 }
572
573 return 0;
574 }
575
576 /// Target fnctl() handler.
577 static SyscallReturn
578 fcntlFunc(SyscallDesc *desc, int callnum, Process *process,
579 ExecContext *xc)
580 {
581 int fd = xc->getSyscallArg(0);
582
583 if (fd < 0 || process->sim_fd(fd) < 0)
584 return -EBADF;
585
586 int cmd = xc->getSyscallArg(1);
587 switch (cmd) {
588 case 0: // F_DUPFD
589 // if we really wanted to support this, we'd need to do it
590 // in the target fd space.
591 warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd);
592 return -EMFILE;
593
594 case 1: // F_GETFD (get close-on-exec flag)
595 case 2: // F_SETFD (set close-on-exec flag)
596 return 0;
597
598 case 3: // F_GETFL (get file flags)
599 case 4: // F_SETFL (set file flags)
600 // not sure if this is totally valid, but we'll pass it through
601 // to the underlying OS
602 warn("fcntl(%d, %d) passed through to host\n", fd, cmd);
603 return fcntl(process->sim_fd(fd), cmd);
604 // return 0;
605
606 case 7: // F_GETLK (get lock)
607 case 8: // F_SETLK (set lock)
608 case 9: // F_SETLKW (set lock and wait)
609 // don't mess with file locking... just act like it's OK
610 warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd);
611 return 0;
612
613 default:
614 warn("Unknown fcntl command %d\n", cmd);
615 return 0;
616 }
617 }
618
619
620 /// Target getdirentries() handler.
621 static SyscallReturn
622 getdirentriesFunc(SyscallDesc *desc, int callnum, Process *process,
623 ExecContext *xc)
624 {
625 #ifdef __CYGWIN__
626 panic("getdirent not implemented on cygwin!");
627 #else
628 int fd = process->sim_fd(xc->getSyscallArg(0));
629 Addr tgt_buf = xc->getSyscallArg(1);
630 int tgt_nbytes = xc->getSyscallArg(2);
631 Addr tgt_basep = xc->getSyscallArg(3);
632
633 char * const host_buf = new char[tgt_nbytes];
634
635 // just pass basep through uninterpreted.
636 TypedBufferArg<int64_t> basep(tgt_basep);
637 basep.copyIn(xc->mem);
638 long host_basep = (off_t)*basep;
639 int host_result = getdirentries(fd, host_buf, tgt_nbytes, &host_basep);
640
641 // check for error
642 if (host_result < 0) {
643 delete [] host_buf;
644 return -errno;
645 }
646
647 // no error: copy results back to target space
648 Addr tgt_buf_ptr = tgt_buf;
649 char *host_buf_ptr = host_buf;
650 char *host_buf_end = host_buf + host_result;
651 while (host_buf_ptr < host_buf_end) {
652 struct dirent *host_dp = (struct dirent *)host_buf_ptr;
653 int namelen = strlen(host_dp->d_name);
654
655 // Actual size includes padded string rounded up for alignment.
656 // Subtract 256 for dummy char array in Tru64::dirent definition.
657 // Add 1 to namelen for terminating null char.
658 int tgt_bufsize = sizeof(Tru64::dirent) - 256 + RoundUp(namelen+1, 8);
659 TypedBufferArg<Tru64::dirent> tgt_dp(tgt_buf_ptr, tgt_bufsize);
660 tgt_dp->d_ino = host_dp->d_ino;
661 tgt_dp->d_reclen = tgt_bufsize;
662 tgt_dp->d_namlen = namelen;
663 strcpy(tgt_dp->d_name, host_dp->d_name);
664 tgt_dp.copyOut(xc->mem);
665
666 tgt_buf_ptr += tgt_bufsize;
667 host_buf_ptr += host_dp->d_reclen;
668 }
669
670 delete [] host_buf;
671
672 *basep = host_basep;
673 basep.copyOut(xc->mem);
674
675 return tgt_buf_ptr - tgt_buf;
676 #endif
677 }
678
679 /// Target sigreturn() handler.
680 static SyscallReturn
681 sigreturnFunc(SyscallDesc *desc, int callnum, Process *process,
682 ExecContext *xc)
683 {
684 RegFile *regs = &xc->regs;
685 TypedBufferArg<Tru64::sigcontext> sc(xc->getSyscallArg(0));
686
687 sc.copyIn(xc->mem);
688
689 // Restore state from sigcontext structure.
690 // Note that we'll advance PC <- NPC before the end of the cycle,
691 // so we need to restore the desired PC into NPC.
692 // The current regs->pc will get clobbered.
693 regs->npc = sc->sc_pc;
694
695 for (int i = 0; i < 31; ++i) {
696 regs->intRegFile[i] = sc->sc_regs[i];
697 regs->floatRegFile.q[i] = sc->sc_fpregs[i];
698 }
699
700 regs->miscRegs.fpcr = sc->sc_fpcr;
701
702 return 0;
703 }
704
705 /// Target table() handler.
706 static SyscallReturn
707 tableFunc(SyscallDesc *desc, int callnum, Process *process,
708 ExecContext *xc)
709 {
710 int id = xc->getSyscallArg(0); // table ID
711 int index = xc->getSyscallArg(1); // index into table
712 // arg 2 is buffer pointer; type depends on table ID
713 int nel = xc->getSyscallArg(3); // number of elements
714 int lel = xc->getSyscallArg(4); // expected element size
715
716 switch (id) {
717 case Tru64::TBL_SYSINFO: {
718 if (index != 0 || nel != 1 || lel != sizeof(Tru64::tbl_sysinfo))
719 return -EINVAL;
720 TypedBufferArg<Tru64::tbl_sysinfo> elp(xc->getSyscallArg(2));
721
722 const int clk_hz = one_million;
723 elp->si_user = curTick / (Clock::Frequency / clk_hz);
724 elp->si_nice = 0;
725 elp->si_sys = 0;
726 elp->si_idle = 0;
727 elp->wait = 0;
728 elp->si_hz = clk_hz;
729 elp->si_phz = clk_hz;
730 elp->si_boottime = seconds_since_epoch; // seconds since epoch?
731 elp->si_max_procs = process->numCpus();
732 elp.copyOut(xc->mem);
733 return 0;
734 }
735
736 default:
737 cerr << "table(): id " << id << " unknown." << endl;
738 return -EINVAL;
739 }
740 }
741
742 /// Array of syscall descriptors, indexed by call number.
743 static SyscallDesc syscallDescs[];
744
745 /// Number of syscalls in syscallDescs[].
746 static const int Num_Syscall_Descs;
747
748 /// Max supported syscall number.
749 static const int Max_Syscall_Desc;
750
751 //
752 // Mach syscalls -- identified by negated syscall numbers
753 //
754
755 /// Create a stack region for a thread.
756 static SyscallReturn
757 stack_createFunc(SyscallDesc *desc, int callnum, Process *process,
758 ExecContext *xc)
759 {
760 TypedBufferArg<Tru64::vm_stack> argp(xc->getSyscallArg(0));
761
762 argp.copyIn(xc->mem);
763
764 // if the user chose an address, just let them have it. Otherwise
765 // pick one for them.
766 if (argp->address == 0) {
767 argp->address = process->next_thread_stack_base;
768 int stack_size = (argp->rsize + argp->ysize + argp->gsize);
769 process->next_thread_stack_base -= stack_size;
770 argp.copyOut(xc->mem);
771 }
772
773 return 0;
774 }
775
776 /// NXM library version stamp.
777 static
778 const int NXM_LIB_VERSION = 301003;
779
780 /// This call sets up the interface between the user and kernel
781 /// schedulers by creating a shared-memory region. The shared memory
782 /// region has several structs, some global, some per-RAD, some per-VP.
783 static SyscallReturn
784 nxm_task_initFunc(SyscallDesc *desc, int callnum, Process *process,
785 ExecContext *xc)
786 {
787 TypedBufferArg<Tru64::nxm_task_attr> attrp(xc->getSyscallArg(0));
788 TypedBufferArg<Addr> configptr_ptr(xc->getSyscallArg(1));
789
790 attrp.copyIn(xc->mem);
791
792 if (attrp->nxm_version != NXM_LIB_VERSION) {
793 cerr << "nxm_task_init: thread library version mismatch! "
794 << "got " << attrp->nxm_version
795 << ", expected " << NXM_LIB_VERSION << endl;
796 abort();
797 }
798
799 if (attrp->flags != Tru64::NXM_TASK_INIT_VP) {
800 cerr << "nxm_task_init: bad flag value " << attrp->flags
801 << " (expected " << Tru64::NXM_TASK_INIT_VP << ")" << endl;
802 abort();
803 }
804
805 const Addr base_addr = 0x12000; // was 0x3f0000000LL;
806 Addr cur_addr = base_addr; // next addresses to use
807 // first comes the config_info struct
808 Addr config_addr = cur_addr;
809 cur_addr += sizeof(Tru64::nxm_config_info);
810 // next comes the per-cpu state vector
811 Addr slot_state_addr = cur_addr;
812 int slot_state_size =
813 process->numCpus() * sizeof(Tru64::nxm_slot_state_t);
814 cur_addr += slot_state_size;
815 // now the per-RAD state struct (we only support one RAD)
816 cur_addr = 0x14000; // bump up addr for alignment
817 Addr rad_state_addr = cur_addr;
818 int rad_state_size =
819 (sizeof(Tru64::nxm_shared)
820 + (process->numCpus()-1) * sizeof(Tru64::nxm_sched_state));
821 cur_addr += rad_state_size;
822
823 // now initialize a config_info struct and copy it out to user space
824 TypedBufferArg<Tru64::nxm_config_info> config(config_addr);
825
826 config->nxm_nslots_per_rad = process->numCpus();
827 config->nxm_nrads = 1; // only one RAD in our system!
828 config->nxm_slot_state = slot_state_addr;
829 config->nxm_rad[0] = rad_state_addr;
830
831 config.copyOut(xc->mem);
832
833 // initialize the slot_state array and copy it out
834 TypedBufferArg<Tru64::nxm_slot_state_t> slot_state(slot_state_addr,
835 slot_state_size);
836 for (int i = 0; i < process->numCpus(); ++i) {
837 // CPU 0 is bound to the calling process; all others are available
838 slot_state[i] =
839 (i == 0) ? Tru64::NXM_SLOT_BOUND : Tru64::NXM_SLOT_AVAIL;
840 }
841
842 slot_state.copyOut(xc->mem);
843
844 // same for the per-RAD "shared" struct. Note that we need to
845 // allocate extra bytes for the per-VP array which is embedded at
846 // the end.
847 TypedBufferArg<Tru64::nxm_shared> rad_state(rad_state_addr,
848 rad_state_size);
849
850 rad_state->nxm_callback = attrp->nxm_callback;
851 rad_state->nxm_version = attrp->nxm_version;
852 rad_state->nxm_uniq_offset = attrp->nxm_uniq_offset;
853 for (int i = 0; i < process->numCpus(); ++i) {
854 Tru64::nxm_sched_state *ssp = &rad_state->nxm_ss[i];
855 ssp->nxm_u.sigmask = 0;
856 ssp->nxm_u.sig = 0;
857 ssp->nxm_u.flags = 0;
858 ssp->nxm_u.cancel_state = 0;
859 ssp->nxm_u.nxm_ssig = 0;
860 ssp->nxm_bits = 0;
861 ssp->nxm_quantum = attrp->nxm_quantum;
862 ssp->nxm_set_quantum = attrp->nxm_quantum;
863 ssp->nxm_sysevent = 0;
864
865 if (i == 0) {
866 uint64_t uniq = xc->regs.miscRegs.uniq;
867 ssp->nxm_u.pth_id = uniq + attrp->nxm_uniq_offset;
868 ssp->nxm_u.nxm_active = uniq | 1;
869 }
870 else {
871 ssp->nxm_u.pth_id = 0;
872 ssp->nxm_u.nxm_active = 0;
873 }
874 }
875
876 rad_state.copyOut(xc->mem);
877
878 //
879 // copy pointer to shared config area out to user
880 //
881 *configptr_ptr = config_addr;
882 configptr_ptr.copyOut(xc->mem);
883
884 // Register this as a valid address range with the process
885 process->nxm_start = base_addr;
886 process->nxm_end = cur_addr;
887
888 return 0;
889 }
890
891 /// Initialize execution context.
892 static void
893 init_exec_context(ExecContext *ec,
894 Tru64::nxm_thread_attr *attrp, uint64_t uniq_val)
895 {
896 memset(&ec->regs, 0, sizeof(ec->regs));
897
898 ec->regs.intRegFile[ArgumentReg0] = attrp->registers.a0;
899 ec->regs.intRegFile[27/*t12*/] = attrp->registers.pc;
900 ec->regs.intRegFile[StackPointerReg] = attrp->registers.sp;
901 ec->regs.miscRegs.uniq = uniq_val;
902
903 ec->regs.pc = attrp->registers.pc;
904 ec->regs.npc = attrp->registers.pc + sizeof(MachInst);
905
906 ec->activate();
907 }
908
909 /// Create thread.
910 static SyscallReturn
911 nxm_thread_createFunc(SyscallDesc *desc, int callnum, Process *process,
912 ExecContext *xc)
913 {
914 TypedBufferArg<Tru64::nxm_thread_attr> attrp(xc->getSyscallArg(0));
915 TypedBufferArg<uint64_t> kidp(xc->getSyscallArg(1));
916 int thread_index = xc->getSyscallArg(2);
917
918 // get attribute args
919 attrp.copyIn(xc->mem);
920
921 if (attrp->version != NXM_LIB_VERSION) {
922 cerr << "nxm_thread_create: thread library version mismatch! "
923 << "got " << attrp->version
924 << ", expected " << NXM_LIB_VERSION << endl;
925 abort();
926 }
927
928 if (thread_index < 0 | thread_index > process->numCpus()) {
929 cerr << "nxm_thread_create: bad thread index " << thread_index
930 << endl;
931 abort();
932 }
933
934 // On a real machine, the per-RAD shared structure is in
935 // shared memory, so both the user and kernel can get at it.
936 // We don't have that luxury, so we just copy it in and then
937 // back out again.
938 int rad_state_size =
939 (sizeof(Tru64::nxm_shared) +
940 (process->numCpus()-1) * sizeof(Tru64::nxm_sched_state));
941
942 TypedBufferArg<Tru64::nxm_shared> rad_state(0x14000,
943 rad_state_size);
944 rad_state.copyIn(xc->mem);
945
946 uint64_t uniq_val = attrp->pthid - rad_state->nxm_uniq_offset;
947
948 if (attrp->type == Tru64::NXM_TYPE_MANAGER) {
949 // DEC pthreads seems to always create one of these (in
950 // addition to N application threads), but we don't use it,
951 // so don't bother creating it.
952
953 // This is supposed to be a port number. Make something up.
954 *kidp = 99;
955 kidp.copyOut(xc->mem);
956
957 return 0;
958 } else if (attrp->type == Tru64::NXM_TYPE_VP) {
959 // A real "virtual processor" kernel thread. Need to fork
960 // this thread on another CPU.
961 Tru64::nxm_sched_state *ssp = &rad_state->nxm_ss[thread_index];
962
963 if (ssp->nxm_u.nxm_active != 0)
964 return (int) Tru64::KERN_NOT_RECEIVER;
965
966 ssp->nxm_u.pth_id = attrp->pthid;
967 ssp->nxm_u.nxm_active = uniq_val | 1;
968
969 rad_state.copyOut(xc->mem);
970
971 Addr slot_state_addr = 0x12000 + sizeof(Tru64::nxm_config_info);
972 int slot_state_size =
973 process->numCpus() * sizeof(Tru64::nxm_slot_state_t);
974
975 TypedBufferArg<Tru64::nxm_slot_state_t>
976 slot_state(slot_state_addr,
977 slot_state_size);
978
979 slot_state.copyIn(xc->mem);
980
981 if (slot_state[thread_index] != Tru64::NXM_SLOT_AVAIL) {
982 cerr << "nxm_thread_createFunc: requested VP slot "
983 << thread_index << " not available!" << endl;
984 fatal("");
985 }
986
987 slot_state[thread_index] = Tru64::NXM_SLOT_BOUND;
988
989 slot_state.copyOut(xc->mem);
990
991 // Find a free simulator execution context.
992 for (int i = 0; i < process->numCpus(); ++i) {
993 ExecContext *xc = process->execContexts[i];
994
995 if (xc->status() == ExecContext::Unallocated) {
996 // inactive context... grab it
997 init_exec_context(xc, attrp, uniq_val);
998
999 // This is supposed to be a port number, but we'll try
1000 // and get away with just sticking the thread index
1001 // here.
1002 *kidp = thread_index;
1003 kidp.copyOut(xc->mem);
1004
1005 return 0;
1006 }
1007 }
1008
1009 // fell out of loop... no available inactive context
1010 cerr << "nxm_thread_create: no idle contexts available." << endl;
1011 abort();
1012 } else {
1013 cerr << "nxm_thread_create: can't handle thread type "
1014 << attrp->type << endl;
1015 abort();
1016 }
1017
1018 return 0;
1019 }
1020
1021 /// Thread idle call (like yield()).
1022 static SyscallReturn
1023 nxm_idleFunc(SyscallDesc *desc, int callnum, Process *process,
1024 ExecContext *xc)
1025 {
1026 return 0;
1027 }
1028
1029 /// Block thread.
1030 static SyscallReturn
1031 nxm_thread_blockFunc(SyscallDesc *desc, int callnum, Process *process,
1032 ExecContext *xc)
1033 {
1034 uint64_t tid = xc->getSyscallArg(0);
1035 uint64_t secs = xc->getSyscallArg(1);
1036 uint64_t flags = xc->getSyscallArg(2);
1037 uint64_t action = xc->getSyscallArg(3);
1038 uint64_t usecs = xc->getSyscallArg(4);
1039
1040 cout << xc->cpu->name() << ": nxm_thread_block " << tid << " " << secs
1041 << " " << flags << " " << action << " " << usecs << endl;
1042
1043 return 0;
1044 }
1045
1046 /// block.
1047 static SyscallReturn
1048 nxm_blockFunc(SyscallDesc *desc, int callnum, Process *process,
1049 ExecContext *xc)
1050 {
1051 Addr uaddr = xc->getSyscallArg(0);
1052 uint64_t val = xc->getSyscallArg(1);
1053 uint64_t secs = xc->getSyscallArg(2);
1054 uint64_t usecs = xc->getSyscallArg(3);
1055 uint64_t flags = xc->getSyscallArg(4);
1056
1057 BaseCPU *cpu = xc->cpu;
1058
1059 cout << cpu->name() << ": nxm_block "
1060 << hex << uaddr << dec << " " << val
1061 << " " << secs << " " << usecs
1062 << " " << flags << endl;
1063
1064 return 0;
1065 }
1066
1067 /// Unblock thread.
1068 static SyscallReturn
1069 nxm_unblockFunc(SyscallDesc *desc, int callnum, Process *process,
1070 ExecContext *xc)
1071 {
1072 Addr uaddr = xc->getSyscallArg(0);
1073
1074 cout << xc->cpu->name() << ": nxm_unblock "
1075 << hex << uaddr << dec << endl;
1076
1077 return 0;
1078 }
1079
1080 /// Switch thread priority.
1081 static SyscallReturn
1082 swtch_priFunc(SyscallDesc *desc, int callnum, Process *process,
1083 ExecContext *xc)
1084 {
1085 // Attempts to switch to another runnable thread (if there is
1086 // one). Returns false if there are no other threads to run
1087 // (i.e., the thread can reasonably spin-wait) or true if there
1088 // are other threads.
1089 //
1090 // Since we assume at most one "kernel" thread per CPU, it's
1091 // always safe to return false here.
1092 return 0; //false;
1093 }
1094
1095
1096 /// Activate exec context waiting on a channel. Just activate one
1097 /// by default.
1098 static int
1099 activate_waiting_context(Addr uaddr, Process *process,
1100 bool activate_all = false)
1101 {
1102 int num_activated = 0;
1103
1104 list<Process::WaitRec>::iterator i = process->waitList.begin();
1105 list<Process::WaitRec>::iterator end = process->waitList.end();
1106
1107 while (i != end && (num_activated == 0 || activate_all)) {
1108 if (i->waitChan == uaddr) {
1109 // found waiting process: make it active
1110 ExecContext *newCtx = i->waitingContext;
1111 assert(newCtx->status() == ExecContext::Suspended);
1112 newCtx->activate();
1113
1114 // get rid of this record
1115 i = process->waitList.erase(i);
1116
1117 ++num_activated;
1118 } else {
1119 ++i;
1120 }
1121 }
1122
1123 return num_activated;
1124 }
1125
1126 /// M5 hacked-up lock acquire.
1127 static void
1128 m5_lock_mutex(Addr uaddr, Process *process, ExecContext *xc)
1129 {
1130 TypedBufferArg<uint64_t> lockp(uaddr);
1131
1132 lockp.copyIn(xc->mem);
1133
1134 if (*lockp == 0) {
1135 // lock is free: grab it
1136 *lockp = 1;
1137 lockp.copyOut(xc->mem);
1138 } else {
1139 // lock is busy: disable until free
1140 process->waitList.push_back(Process::WaitRec(uaddr, xc));
1141 xc->suspend();
1142 }
1143 }
1144
1145 /// M5 unlock call.
1146 static void
1147 m5_unlock_mutex(Addr uaddr, Process *process, ExecContext *xc)
1148 {
1149 TypedBufferArg<uint64_t> lockp(uaddr);
1150
1151 lockp.copyIn(xc->mem);
1152 assert(*lockp != 0);
1153
1154 // Check for a process waiting on the lock.
1155 int num_waiting = activate_waiting_context(uaddr, process);
1156
1157 // clear lock field if no waiting context is taking over the lock
1158 if (num_waiting == 0) {
1159 *lockp = 0;
1160 lockp.copyOut(xc->mem);
1161 }
1162 }
1163
1164 /// Lock acquire syscall handler.
1165 static SyscallReturn
1166 m5_mutex_lockFunc(SyscallDesc *desc, int callnum, Process *process,
1167 ExecContext *xc)
1168 {
1169 Addr uaddr = xc->getSyscallArg(0);
1170
1171 m5_lock_mutex(uaddr, process, xc);
1172
1173 // Return 0 since we will always return to the user with the lock
1174 // acquired. We will just keep the context inactive until that is
1175 // true.
1176 return 0;
1177 }
1178
1179 /// Try lock (non-blocking).
1180 static SyscallReturn
1181 m5_mutex_trylockFunc(SyscallDesc *desc, int callnum, Process *process,
1182 ExecContext *xc)
1183 {
1184 Addr uaddr = xc->getSyscallArg(0);
1185 TypedBufferArg<uint64_t> lockp(uaddr);
1186
1187 lockp.copyIn(xc->mem);
1188
1189 if (*lockp == 0) {
1190 // lock is free: grab it
1191 *lockp = 1;
1192 lockp.copyOut(xc->mem);
1193 return 0;
1194 } else {
1195 return 1;
1196 }
1197 }
1198
1199 /// Unlock syscall handler.
1200 static SyscallReturn
1201 m5_mutex_unlockFunc(SyscallDesc *desc, int callnum, Process *process,
1202 ExecContext *xc)
1203 {
1204 Addr uaddr = xc->getSyscallArg(0);
1205
1206 m5_unlock_mutex(uaddr, process, xc);
1207
1208 return 0;
1209 }
1210
1211 /// Signal ocndition.
1212 static SyscallReturn
1213 m5_cond_signalFunc(SyscallDesc *desc, int callnum, Process *process,
1214 ExecContext *xc)
1215 {
1216 Addr cond_addr = xc->getSyscallArg(0);
1217
1218 // Wake up one process waiting on the condition variable.
1219 activate_waiting_context(cond_addr, process);
1220
1221 return 0;
1222 }
1223
1224 /// Wake up all processes waiting on the condition variable.
1225 static SyscallReturn
1226 m5_cond_broadcastFunc(SyscallDesc *desc, int callnum, Process *process,
1227 ExecContext *xc)
1228 {
1229 Addr cond_addr = xc->getSyscallArg(0);
1230
1231 activate_waiting_context(cond_addr, process, true);
1232
1233 return 0;
1234 }
1235
1236 /// Wait on a condition.
1237 static SyscallReturn
1238 m5_cond_waitFunc(SyscallDesc *desc, int callnum, Process *process,
1239 ExecContext *xc)
1240 {
1241 Addr cond_addr = xc->getSyscallArg(0);
1242 Addr lock_addr = xc->getSyscallArg(1);
1243 TypedBufferArg<uint64_t> condp(cond_addr);
1244 TypedBufferArg<uint64_t> lockp(lock_addr);
1245
1246 // user is supposed to acquire lock before entering
1247 lockp.copyIn(xc->mem);
1248 assert(*lockp != 0);
1249
1250 m5_unlock_mutex(lock_addr, process, xc);
1251
1252 process->waitList.push_back(Process::WaitRec(cond_addr, xc));
1253 xc->suspend();
1254
1255 return 0;
1256 }
1257
1258 /// Thread exit.
1259 static SyscallReturn
1260 m5_thread_exitFunc(SyscallDesc *desc, int callnum, Process *process,
1261 ExecContext *xc)
1262 {
1263 assert(xc->status() == ExecContext::Active);
1264 xc->deallocate();
1265
1266 return 0;
1267 }
1268
1269 /// Array of syscall descriptors for Mach syscalls, indexed by
1270 /// (negated) call number.
1271 static SyscallDesc machSyscallDescs[];
1272
1273 /// Number of syscalls in machSyscallDescs[].
1274 static const int Num_Mach_Syscall_Descs;
1275
1276 /// Max supported Mach syscall number.
1277 static const int Max_Mach_Syscall_Desc;
1278
1279 /// Since negated values are used to identify Mach syscalls, the
1280 /// minimum (signed) valid syscall number is the negated max Mach
1281 /// syscall number.
1282 static const int Min_Syscall_Desc;
1283
1284 /// Do the specified syscall. Just looks the call number up in
1285 /// the table and invokes the appropriate handler.
1286 static void
1287 doSyscall(int callnum, Process *process, ExecContext *xc)
1288 {
1289 if (callnum < Min_Syscall_Desc || callnum > Max_Syscall_Desc) {
1290 cerr << "Syscall " << callnum << " out of range" << endl;
1291 abort();
1292 }
1293
1294 SyscallDesc *desc =
1295 (callnum < 0) ?
1296 &machSyscallDescs[-callnum] : &syscallDescs[callnum];
1297
1298 desc->doSyscall(callnum, process, xc);
1299 }
1300
1301 /// Indirect syscall invocation (call #0).
1302 static SyscallReturn
1303 indirectSyscallFunc(SyscallDesc *desc, int callnum, Process *process,
1304 ExecContext *xc)
1305 {
1306 int new_callnum = xc->getSyscallArg(0);
1307
1308 for (int i = 0; i < 5; ++i)
1309 xc->setSyscallArg(i, xc->getSyscallArg(i+1));
1310
1311 doSyscall(new_callnum, process, xc);
1312
1313 return 0;
1314 }
1315
1316 }; // class Tru64
1317
1318
1319 // open(2) flags translation table
1320 OpenFlagTransTable Tru64::openFlagTable[] = {
1321 #ifdef _MSC_VER
1322 { Tru64::TGT_O_RDONLY, _O_RDONLY },
1323 { Tru64::TGT_O_WRONLY, _O_WRONLY },
1324 { Tru64::TGT_O_RDWR, _O_RDWR },
1325 { Tru64::TGT_O_APPEND, _O_APPEND },
1326 { Tru64::TGT_O_CREAT, _O_CREAT },
1327 { Tru64::TGT_O_TRUNC, _O_TRUNC },
1328 { Tru64::TGT_O_EXCL, _O_EXCL },
1329 #ifdef _O_NONBLOCK
1330 { Tru64::TGT_O_NONBLOCK, _O_NONBLOCK },
1331 #endif
1332 #ifdef _O_NOCTTY
1333 { Tru64::TGT_O_NOCTTY, _O_NOCTTY },
1334 #endif
1335 #ifdef _O_SYNC
1336 { Tru64::TGT_O_SYNC, _O_SYNC },
1337 #endif
1338 #else /* !_MSC_VER */
1339 { Tru64::TGT_O_RDONLY, O_RDONLY },
1340 { Tru64::TGT_O_WRONLY, O_WRONLY },
1341 { Tru64::TGT_O_RDWR, O_RDWR },
1342 { Tru64::TGT_O_APPEND, O_APPEND },
1343 { Tru64::TGT_O_CREAT, O_CREAT },
1344 { Tru64::TGT_O_TRUNC, O_TRUNC },
1345 { Tru64::TGT_O_EXCL, O_EXCL },
1346 { Tru64::TGT_O_NONBLOCK, O_NONBLOCK },
1347 { Tru64::TGT_O_NOCTTY, O_NOCTTY },
1348 #ifdef O_SYNC
1349 { Tru64::TGT_O_SYNC, O_SYNC },
1350 #endif
1351 #endif /* _MSC_VER */
1352 };
1353
1354 const int Tru64::NUM_OPEN_FLAGS = (sizeof(Tru64::openFlagTable)/sizeof(Tru64::openFlagTable[0]));
1355
1356 const char *Tru64::hostname = "m5.eecs.umich.edu";
1357
1358 SyscallDesc Tru64::syscallDescs[] = {
1359 /* 0 */ SyscallDesc("syscall (#0)", indirectSyscallFunc,
1360 SyscallDesc::SuppressReturnValue),
1361 /* 1 */ SyscallDesc("exit", exitFunc),
1362 /* 2 */ SyscallDesc("fork", unimplementedFunc),
1363 /* 3 */ SyscallDesc("read", readFunc),
1364 /* 4 */ SyscallDesc("write", writeFunc),
1365 /* 5 */ SyscallDesc("old_open", unimplementedFunc),
1366 /* 6 */ SyscallDesc("close", closeFunc),
1367 /* 7 */ SyscallDesc("wait4", unimplementedFunc),
1368 /* 8 */ SyscallDesc("old_creat", unimplementedFunc),
1369 /* 9 */ SyscallDesc("link", unimplementedFunc),
1370 /* 10 */ SyscallDesc("unlink", unlinkFunc),
1371 /* 11 */ SyscallDesc("execv", unimplementedFunc),
1372 /* 12 */ SyscallDesc("chdir", unimplementedFunc),
1373 /* 13 */ SyscallDesc("fchdir", unimplementedFunc),
1374 /* 14 */ SyscallDesc("mknod", unimplementedFunc),
1375 /* 15 */ SyscallDesc("chmod", unimplementedFunc),
1376 /* 16 */ SyscallDesc("chown", unimplementedFunc),
1377 /* 17 */ SyscallDesc("obreak", obreakFunc),
1378 /* 18 */ SyscallDesc("pre_F64_getfsstat", unimplementedFunc),
1379 /* 19 */ SyscallDesc("lseek", lseekFunc),
1380 /* 20 */ SyscallDesc("getpid", getpidFunc),
1381 /* 21 */ SyscallDesc("mount", unimplementedFunc),
1382 /* 22 */ SyscallDesc("unmount", unimplementedFunc),
1383 /* 23 */ SyscallDesc("setuid", setuidFunc),
1384 /* 24 */ SyscallDesc("getuid", getuidFunc),
1385 /* 25 */ SyscallDesc("exec_with_loader", unimplementedFunc),
1386 /* 26 */ SyscallDesc("ptrace", unimplementedFunc),
1387 /* 27 */ SyscallDesc("recvmsg", unimplementedFunc),
1388 /* 28 */ SyscallDesc("sendmsg", unimplementedFunc),
1389 /* 29 */ SyscallDesc("recvfrom", unimplementedFunc),
1390 /* 30 */ SyscallDesc("accept", unimplementedFunc),
1391 /* 31 */ SyscallDesc("getpeername", unimplementedFunc),
1392 /* 32 */ SyscallDesc("getsockname", unimplementedFunc),
1393 /* 33 */ SyscallDesc("access", unimplementedFunc),
1394 /* 34 */ SyscallDesc("chflags", unimplementedFunc),
1395 /* 35 */ SyscallDesc("fchflags", unimplementedFunc),
1396 /* 36 */ SyscallDesc("sync", unimplementedFunc),
1397 /* 37 */ SyscallDesc("kill", unimplementedFunc),
1398 /* 38 */ SyscallDesc("old_stat", unimplementedFunc),
1399 /* 39 */ SyscallDesc("setpgid", unimplementedFunc),
1400 /* 40 */ SyscallDesc("old_lstat", unimplementedFunc),
1401 /* 41 */ SyscallDesc("dup", unimplementedFunc),
1402 /* 42 */ SyscallDesc("pipe", unimplementedFunc),
1403 /* 43 */ SyscallDesc("set_program_attributes", unimplementedFunc),
1404 /* 44 */ SyscallDesc("profil", unimplementedFunc),
1405 /* 45 */ SyscallDesc("open", openFunc<Tru64>),
1406 /* 46 */ SyscallDesc("obsolete osigaction", unimplementedFunc),
1407 /* 47 */ SyscallDesc("getgid", getgidFunc),
1408 /* 48 */ SyscallDesc("sigprocmask", ignoreFunc),
1409 /* 49 */ SyscallDesc("getlogin", unimplementedFunc),
1410 /* 50 */ SyscallDesc("setlogin", unimplementedFunc),
1411 /* 51 */ SyscallDesc("acct", unimplementedFunc),
1412 /* 52 */ SyscallDesc("sigpending", unimplementedFunc),
1413 /* 53 */ SyscallDesc("classcntl", unimplementedFunc),
1414 /* 54 */ SyscallDesc("ioctl", ioctlFunc<Tru64>),
1415 /* 55 */ SyscallDesc("reboot", unimplementedFunc),
1416 /* 56 */ SyscallDesc("revoke", unimplementedFunc),
1417 /* 57 */ SyscallDesc("symlink", unimplementedFunc),
1418 /* 58 */ SyscallDesc("readlink", unimplementedFunc),
1419 /* 59 */ SyscallDesc("execve", unimplementedFunc),
1420 /* 60 */ SyscallDesc("umask", unimplementedFunc),
1421 /* 61 */ SyscallDesc("chroot", unimplementedFunc),
1422 /* 62 */ SyscallDesc("old_fstat", unimplementedFunc),
1423 /* 63 */ SyscallDesc("getpgrp", unimplementedFunc),
1424 /* 64 */ SyscallDesc("getpagesize", getpagesizeFunc),
1425 /* 65 */ SyscallDesc("mremap", unimplementedFunc),
1426 /* 66 */ SyscallDesc("vfork", unimplementedFunc),
1427 /* 67 */ SyscallDesc("pre_F64_stat", unimplementedFunc),
1428 /* 68 */ SyscallDesc("pre_F64_lstat", unimplementedFunc),
1429 /* 69 */ SyscallDesc("sbrk", unimplementedFunc),
1430 /* 70 */ SyscallDesc("sstk", unimplementedFunc),
1431 /* 71 */ SyscallDesc("mmap", mmapFunc<Tru64>),
1432 /* 72 */ SyscallDesc("ovadvise", unimplementedFunc),
1433 /* 73 */ SyscallDesc("munmap", munmapFunc),
1434 /* 74 */ SyscallDesc("mprotect", ignoreFunc),
1435 /* 75 */ SyscallDesc("madvise", unimplementedFunc),
1436 /* 76 */ SyscallDesc("old_vhangup", unimplementedFunc),
1437 /* 77 */ SyscallDesc("kmodcall", unimplementedFunc),
1438 /* 78 */ SyscallDesc("mincore", unimplementedFunc),
1439 /* 79 */ SyscallDesc("getgroups", unimplementedFunc),
1440 /* 80 */ SyscallDesc("setgroups", unimplementedFunc),
1441 /* 81 */ SyscallDesc("old_getpgrp", unimplementedFunc),
1442 /* 82 */ SyscallDesc("setpgrp", unimplementedFunc),
1443 /* 83 */ SyscallDesc("setitimer", unimplementedFunc),
1444 /* 84 */ SyscallDesc("old_wait", unimplementedFunc),
1445 /* 85 */ SyscallDesc("table", tableFunc),
1446 /* 86 */ SyscallDesc("getitimer", unimplementedFunc),
1447 /* 87 */ SyscallDesc("gethostname", gethostnameFunc),
1448 /* 88 */ SyscallDesc("sethostname", unimplementedFunc),
1449 /* 89 */ SyscallDesc("getdtablesize", unimplementedFunc),
1450 /* 90 */ SyscallDesc("dup2", unimplementedFunc),
1451 /* 91 */ SyscallDesc("pre_F64_fstat", unimplementedFunc),
1452 /* 92 */ SyscallDesc("fcntl", fcntlFunc),
1453 /* 93 */ SyscallDesc("select", unimplementedFunc),
1454 /* 94 */ SyscallDesc("poll", unimplementedFunc),
1455 /* 95 */ SyscallDesc("fsync", unimplementedFunc),
1456 /* 96 */ SyscallDesc("setpriority", unimplementedFunc),
1457 /* 97 */ SyscallDesc("socket", unimplementedFunc),
1458 /* 98 */ SyscallDesc("connect", unimplementedFunc),
1459 /* 99 */ SyscallDesc("old_accept", unimplementedFunc),
1460 /* 100 */ SyscallDesc("getpriority", unimplementedFunc),
1461 /* 101 */ SyscallDesc("old_send", unimplementedFunc),
1462 /* 102 */ SyscallDesc("old_recv", unimplementedFunc),
1463 /* 103 */ SyscallDesc("sigreturn", sigreturnFunc,
1464 SyscallDesc::SuppressReturnValue),
1465 /* 104 */ SyscallDesc("bind", unimplementedFunc),
1466 /* 105 */ SyscallDesc("setsockopt", unimplementedFunc),
1467 /* 106 */ SyscallDesc("listen", unimplementedFunc),
1468 /* 107 */ SyscallDesc("plock", unimplementedFunc),
1469 /* 108 */ SyscallDesc("old_sigvec", unimplementedFunc),
1470 /* 109 */ SyscallDesc("old_sigblock", unimplementedFunc),
1471 /* 110 */ SyscallDesc("old_sigsetmask", unimplementedFunc),
1472 /* 111 */ SyscallDesc("sigsuspend", unimplementedFunc),
1473 /* 112 */ SyscallDesc("sigstack", ignoreFunc),
1474 /* 113 */ SyscallDesc("old_recvmsg", unimplementedFunc),
1475 /* 114 */ SyscallDesc("old_sendmsg", unimplementedFunc),
1476 /* 115 */ SyscallDesc("obsolete vtrace", unimplementedFunc),
1477 /* 116 */ SyscallDesc("gettimeofday", gettimeofdayFunc<Tru64>),
1478 /* 117 */ SyscallDesc("getrusage", getrusageFunc<Tru64>),
1479 /* 118 */ SyscallDesc("getsockopt", unimplementedFunc),
1480 /* 119 */ SyscallDesc("numa_syscalls", unimplementedFunc),
1481 /* 120 */ SyscallDesc("readv", unimplementedFunc),
1482 /* 121 */ SyscallDesc("writev", unimplementedFunc),
1483 /* 122 */ SyscallDesc("settimeofday", unimplementedFunc),
1484 /* 123 */ SyscallDesc("fchown", unimplementedFunc),
1485 /* 124 */ SyscallDesc("fchmod", unimplementedFunc),
1486 /* 125 */ SyscallDesc("old_recvfrom", unimplementedFunc),
1487 /* 126 */ SyscallDesc("setreuid", unimplementedFunc),
1488 /* 127 */ SyscallDesc("setregid", unimplementedFunc),
1489 /* 128 */ SyscallDesc("rename", renameFunc),
1490 /* 129 */ SyscallDesc("truncate", unimplementedFunc),
1491 /* 130 */ SyscallDesc("ftruncate", unimplementedFunc),
1492 /* 131 */ SyscallDesc("flock", unimplementedFunc),
1493 /* 132 */ SyscallDesc("setgid", unimplementedFunc),
1494 /* 133 */ SyscallDesc("sendto", unimplementedFunc),
1495 /* 134 */ SyscallDesc("shutdown", unimplementedFunc),
1496 /* 135 */ SyscallDesc("socketpair", unimplementedFunc),
1497 /* 136 */ SyscallDesc("mkdir", unimplementedFunc),
1498 /* 137 */ SyscallDesc("rmdir", unimplementedFunc),
1499 /* 138 */ SyscallDesc("utimes", unimplementedFunc),
1500 /* 139 */ SyscallDesc("obsolete 4.2 sigreturn", unimplementedFunc),
1501 /* 140 */ SyscallDesc("adjtime", unimplementedFunc),
1502 /* 141 */ SyscallDesc("old_getpeername", unimplementedFunc),
1503 /* 142 */ SyscallDesc("gethostid", unimplementedFunc),
1504 /* 143 */ SyscallDesc("sethostid", unimplementedFunc),
1505 /* 144 */ SyscallDesc("getrlimit", getrlimitFunc<Tru64>),
1506 /* 145 */ SyscallDesc("setrlimit", ignoreFunc),
1507 /* 146 */ SyscallDesc("old_killpg", unimplementedFunc),
1508 /* 147 */ SyscallDesc("setsid", unimplementedFunc),
1509 /* 148 */ SyscallDesc("quotactl", unimplementedFunc),
1510 /* 149 */ SyscallDesc("oldquota", unimplementedFunc),
1511 /* 150 */ SyscallDesc("old_getsockname", unimplementedFunc),
1512 /* 151 */ SyscallDesc("pread", unimplementedFunc),
1513 /* 152 */ SyscallDesc("pwrite", unimplementedFunc),
1514 /* 153 */ SyscallDesc("pid_block", unimplementedFunc),
1515 /* 154 */ SyscallDesc("pid_unblock", unimplementedFunc),
1516 /* 155 */ SyscallDesc("signal_urti", unimplementedFunc),
1517 /* 156 */ SyscallDesc("sigaction", ignoreFunc),
1518 /* 157 */ SyscallDesc("sigwaitprim", unimplementedFunc),
1519 /* 158 */ SyscallDesc("nfssvc", unimplementedFunc),
1520 /* 159 */ SyscallDesc("getdirentries", getdirentriesFunc),
1521 /* 160 */ SyscallDesc("pre_F64_statfs", unimplementedFunc),
1522 /* 161 */ SyscallDesc("pre_F64_fstatfs", unimplementedFunc),
1523 /* 162 */ SyscallDesc("unknown #162", unimplementedFunc),
1524 /* 163 */ SyscallDesc("async_daemon", unimplementedFunc),
1525 /* 164 */ SyscallDesc("getfh", unimplementedFunc),
1526 /* 165 */ SyscallDesc("getdomainname", unimplementedFunc),
1527 /* 166 */ SyscallDesc("setdomainname", unimplementedFunc),
1528 /* 167 */ SyscallDesc("unknown #167", unimplementedFunc),
1529 /* 168 */ SyscallDesc("unknown #168", unimplementedFunc),
1530 /* 169 */ SyscallDesc("exportfs", unimplementedFunc),
1531 /* 170 */ SyscallDesc("unknown #170", unimplementedFunc),
1532 /* 171 */ SyscallDesc("unknown #171", unimplementedFunc),
1533 /* 172 */ SyscallDesc("unknown #172", unimplementedFunc),
1534 /* 173 */ SyscallDesc("unknown #173", unimplementedFunc),
1535 /* 174 */ SyscallDesc("unknown #174", unimplementedFunc),
1536 /* 175 */ SyscallDesc("unknown #175", unimplementedFunc),
1537 /* 176 */ SyscallDesc("unknown #176", unimplementedFunc),
1538 /* 177 */ SyscallDesc("unknown #177", unimplementedFunc),
1539 /* 178 */ SyscallDesc("unknown #178", unimplementedFunc),
1540 /* 179 */ SyscallDesc("unknown #179", unimplementedFunc),
1541 /* 180 */ SyscallDesc("unknown #180", unimplementedFunc),
1542 /* 181 */ SyscallDesc("alt_plock", unimplementedFunc),
1543 /* 182 */ SyscallDesc("unknown #182", unimplementedFunc),
1544 /* 183 */ SyscallDesc("unknown #183", unimplementedFunc),
1545 /* 184 */ SyscallDesc("getmnt", unimplementedFunc),
1546 /* 185 */ SyscallDesc("unknown #185", unimplementedFunc),
1547 /* 186 */ SyscallDesc("unknown #186", unimplementedFunc),
1548 /* 187 */ SyscallDesc("alt_sigpending", unimplementedFunc),
1549 /* 188 */ SyscallDesc("alt_setsid", unimplementedFunc),
1550 /* 189 */ SyscallDesc("unknown #189", unimplementedFunc),
1551 /* 190 */ SyscallDesc("unknown #190", unimplementedFunc),
1552 /* 191 */ SyscallDesc("unknown #191", unimplementedFunc),
1553 /* 192 */ SyscallDesc("unknown #192", unimplementedFunc),
1554 /* 193 */ SyscallDesc("unknown #193", unimplementedFunc),
1555 /* 194 */ SyscallDesc("unknown #194", unimplementedFunc),
1556 /* 195 */ SyscallDesc("unknown #195", unimplementedFunc),
1557 /* 196 */ SyscallDesc("unknown #196", unimplementedFunc),
1558 /* 197 */ SyscallDesc("unknown #197", unimplementedFunc),
1559 /* 198 */ SyscallDesc("unknown #198", unimplementedFunc),
1560 /* 199 */ SyscallDesc("swapon", unimplementedFunc),
1561 /* 200 */ SyscallDesc("msgctl", unimplementedFunc),
1562 /* 201 */ SyscallDesc("msgget", unimplementedFunc),
1563 /* 202 */ SyscallDesc("msgrcv", unimplementedFunc),
1564 /* 203 */ SyscallDesc("msgsnd", unimplementedFunc),
1565 /* 204 */ SyscallDesc("semctl", unimplementedFunc),
1566 /* 205 */ SyscallDesc("semget", unimplementedFunc),
1567 /* 206 */ SyscallDesc("semop", unimplementedFunc),
1568 /* 207 */ SyscallDesc("uname", unameFunc),
1569 /* 208 */ SyscallDesc("lchown", unimplementedFunc),
1570 /* 209 */ SyscallDesc("shmat", unimplementedFunc),
1571 /* 210 */ SyscallDesc("shmctl", unimplementedFunc),
1572 /* 211 */ SyscallDesc("shmdt", unimplementedFunc),
1573 /* 212 */ SyscallDesc("shmget", unimplementedFunc),
1574 /* 213 */ SyscallDesc("mvalid", unimplementedFunc),
1575 /* 214 */ SyscallDesc("getaddressconf", unimplementedFunc),
1576 /* 215 */ SyscallDesc("msleep", unimplementedFunc),
1577 /* 216 */ SyscallDesc("mwakeup", unimplementedFunc),
1578 /* 217 */ SyscallDesc("msync", unimplementedFunc),
1579 /* 218 */ SyscallDesc("signal", unimplementedFunc),
1580 /* 219 */ SyscallDesc("utc_gettime", unimplementedFunc),
1581 /* 220 */ SyscallDesc("utc_adjtime", unimplementedFunc),
1582 /* 221 */ SyscallDesc("unknown #221", unimplementedFunc),
1583 /* 222 */ SyscallDesc("security", unimplementedFunc),
1584 /* 223 */ SyscallDesc("kloadcall", unimplementedFunc),
1585 /* 224 */ SyscallDesc("stat", statFunc<Tru64>),
1586 /* 225 */ SyscallDesc("lstat", lstatFunc<Tru64>),
1587 /* 226 */ SyscallDesc("fstat", fstatFunc<Tru64>),
1588 /* 227 */ SyscallDesc("statfs", unimplementedFunc),
1589 /* 228 */ SyscallDesc("fstatfs", unimplementedFunc),
1590 /* 229 */ SyscallDesc("getfsstat", unimplementedFunc),
1591 /* 230 */ SyscallDesc("gettimeofday64", unimplementedFunc),
1592 /* 231 */ SyscallDesc("settimeofday64", unimplementedFunc),
1593 /* 232 */ SyscallDesc("unknown #232", unimplementedFunc),
1594 /* 233 */ SyscallDesc("getpgid", unimplementedFunc),
1595 /* 234 */ SyscallDesc("getsid", unimplementedFunc),
1596 /* 235 */ SyscallDesc("sigaltstack", ignoreFunc),
1597 /* 236 */ SyscallDesc("waitid", unimplementedFunc),
1598 /* 237 */ SyscallDesc("priocntlset", unimplementedFunc),
1599 /* 238 */ SyscallDesc("sigsendset", unimplementedFunc),
1600 /* 239 */ SyscallDesc("set_speculative", unimplementedFunc),
1601 /* 240 */ SyscallDesc("msfs_syscall", unimplementedFunc),
1602 /* 241 */ SyscallDesc("sysinfo", unimplementedFunc),
1603 /* 242 */ SyscallDesc("uadmin", unimplementedFunc),
1604 /* 243 */ SyscallDesc("fuser", unimplementedFunc),
1605 /* 244 */ SyscallDesc("proplist_syscall", unimplementedFunc),
1606 /* 245 */ SyscallDesc("ntp_adjtime", unimplementedFunc),
1607 /* 246 */ SyscallDesc("ntp_gettime", unimplementedFunc),
1608 /* 247 */ SyscallDesc("pathconf", unimplementedFunc),
1609 /* 248 */ SyscallDesc("fpathconf", unimplementedFunc),
1610 /* 249 */ SyscallDesc("sync2", unimplementedFunc),
1611 /* 250 */ SyscallDesc("uswitch", unimplementedFunc),
1612 /* 251 */ SyscallDesc("usleep_thread", unimplementedFunc),
1613 /* 252 */ SyscallDesc("audcntl", unimplementedFunc),
1614 /* 253 */ SyscallDesc("audgen", unimplementedFunc),
1615 /* 254 */ SyscallDesc("sysfs", unimplementedFunc),
1616 /* 255 */ SyscallDesc("subsys_info", unimplementedFunc),
1617 /* 256 */ SyscallDesc("getsysinfo", getsysinfoFunc),
1618 /* 257 */ SyscallDesc("setsysinfo", unimplementedFunc),
1619 /* 258 */ SyscallDesc("afs_syscall", unimplementedFunc),
1620 /* 259 */ SyscallDesc("swapctl", unimplementedFunc),
1621 /* 260 */ SyscallDesc("memcntl", unimplementedFunc),
1622 /* 261 */ SyscallDesc("fdatasync", unimplementedFunc),
1623 /* 262 */ SyscallDesc("oflock", unimplementedFunc),
1624 /* 263 */ SyscallDesc("F64_readv", unimplementedFunc),
1625 /* 264 */ SyscallDesc("F64_writev", unimplementedFunc),
1626 /* 265 */ SyscallDesc("cdslxlate", unimplementedFunc),
1627 /* 266 */ SyscallDesc("sendfile", unimplementedFunc),
1628 };
1629
1630 const int Tru64::Num_Syscall_Descs =
1631 sizeof(Tru64::syscallDescs) / sizeof(SyscallDesc);
1632
1633 const int Tru64::Max_Syscall_Desc = Tru64::Num_Syscall_Descs - 1;
1634
1635 SyscallDesc Tru64::machSyscallDescs[] = {
1636 /* 0 */ SyscallDesc("kern_invalid", unimplementedFunc),
1637 /* 1 */ SyscallDesc("m5_mutex_lock", m5_mutex_lockFunc),
1638 /* 2 */ SyscallDesc("m5_mutex_trylock", m5_mutex_trylockFunc),
1639 /* 3 */ SyscallDesc("m5_mutex_unlock", m5_mutex_unlockFunc),
1640 /* 4 */ SyscallDesc("m5_cond_signal", m5_cond_signalFunc),
1641 /* 5 */ SyscallDesc("m5_cond_broadcast", m5_cond_broadcastFunc),
1642 /* 6 */ SyscallDesc("m5_cond_wait", m5_cond_waitFunc),
1643 /* 7 */ SyscallDesc("m5_thread_exit", m5_thread_exitFunc),
1644 /* 8 */ SyscallDesc("kern_invalid", unimplementedFunc),
1645 /* 9 */ SyscallDesc("kern_invalid", unimplementedFunc),
1646 /* 10 */ SyscallDesc("task_self", unimplementedFunc),
1647 /* 11 */ SyscallDesc("thread_reply", unimplementedFunc),
1648 /* 12 */ SyscallDesc("task_notify", unimplementedFunc),
1649 /* 13 */ SyscallDesc("thread_self", unimplementedFunc),
1650 /* 14 */ SyscallDesc("kern_invalid", unimplementedFunc),
1651 /* 15 */ SyscallDesc("kern_invalid", unimplementedFunc),
1652 /* 16 */ SyscallDesc("kern_invalid", unimplementedFunc),
1653 /* 17 */ SyscallDesc("kern_invalid", unimplementedFunc),
1654 /* 18 */ SyscallDesc("kern_invalid", unimplementedFunc),
1655 /* 19 */ SyscallDesc("kern_invalid", unimplementedFunc),
1656 /* 20 */ SyscallDesc("msg_send_trap", unimplementedFunc),
1657 /* 21 */ SyscallDesc("msg_receive_trap", unimplementedFunc),
1658 /* 22 */ SyscallDesc("msg_rpc_trap", unimplementedFunc),
1659 /* 23 */ SyscallDesc("kern_invalid", unimplementedFunc),
1660 /* 24 */ SyscallDesc("nxm_block", nxm_blockFunc),
1661 /* 25 */ SyscallDesc("nxm_unblock", nxm_unblockFunc),
1662 /* 26 */ SyscallDesc("kern_invalid", unimplementedFunc),
1663 /* 27 */ SyscallDesc("kern_invalid", unimplementedFunc),
1664 /* 28 */ SyscallDesc("kern_invalid", unimplementedFunc),
1665 /* 29 */ SyscallDesc("nxm_thread_destroy", unimplementedFunc),
1666 /* 30 */ SyscallDesc("lw_wire", unimplementedFunc),
1667 /* 31 */ SyscallDesc("lw_unwire", unimplementedFunc),
1668 /* 32 */ SyscallDesc("nxm_thread_create", nxm_thread_createFunc),
1669 /* 33 */ SyscallDesc("nxm_task_init", nxm_task_initFunc),
1670 /* 34 */ SyscallDesc("kern_invalid", unimplementedFunc),
1671 /* 35 */ SyscallDesc("nxm_idle", nxm_idleFunc),
1672 /* 36 */ SyscallDesc("nxm_wakeup_idle", unimplementedFunc),
1673 /* 37 */ SyscallDesc("nxm_set_pthid", unimplementedFunc),
1674 /* 38 */ SyscallDesc("nxm_thread_kill", unimplementedFunc),
1675 /* 39 */ SyscallDesc("nxm_thread_block", nxm_thread_blockFunc),
1676 /* 40 */ SyscallDesc("nxm_thread_wakeup", unimplementedFunc),
1677 /* 41 */ SyscallDesc("init_process", unimplementedFunc),
1678 /* 42 */ SyscallDesc("nxm_get_binding", unimplementedFunc),
1679 /* 43 */ SyscallDesc("map_fd", unimplementedFunc),
1680 /* 44 */ SyscallDesc("nxm_resched", unimplementedFunc),
1681 /* 45 */ SyscallDesc("nxm_set_cancel", unimplementedFunc),
1682 /* 46 */ SyscallDesc("nxm_set_binding", unimplementedFunc),
1683 /* 47 */ SyscallDesc("stack_create", stack_createFunc),
1684 /* 48 */ SyscallDesc("nxm_get_state", unimplementedFunc),
1685 /* 49 */ SyscallDesc("nxm_thread_suspend", unimplementedFunc),
1686 /* 50 */ SyscallDesc("nxm_thread_resume", unimplementedFunc),
1687 /* 51 */ SyscallDesc("nxm_signal_check", unimplementedFunc),
1688 /* 52 */ SyscallDesc("htg_unix_syscall", unimplementedFunc),
1689 /* 53 */ SyscallDesc("kern_invalid", unimplementedFunc),
1690 /* 54 */ SyscallDesc("kern_invalid", unimplementedFunc),
1691 /* 55 */ SyscallDesc("host_self", unimplementedFunc),
1692 /* 56 */ SyscallDesc("host_priv_self", unimplementedFunc),
1693 /* 57 */ SyscallDesc("kern_invalid", unimplementedFunc),
1694 /* 58 */ SyscallDesc("kern_invalid", unimplementedFunc),
1695 /* 59 */ SyscallDesc("swtch_pri", swtch_priFunc),
1696 /* 60 */ SyscallDesc("swtch", unimplementedFunc),
1697 /* 61 */ SyscallDesc("thread_switch", unimplementedFunc),
1698 /* 62 */ SyscallDesc("semop_fast", unimplementedFunc),
1699 /* 63 */ SyscallDesc("nxm_pshared_init", unimplementedFunc),
1700 /* 64 */ SyscallDesc("nxm_pshared_block", unimplementedFunc),
1701 /* 65 */ SyscallDesc("nxm_pshared_unblock", unimplementedFunc),
1702 /* 66 */ SyscallDesc("nxm_pshared_destroy", unimplementedFunc),
1703 /* 67 */ SyscallDesc("nxm_swtch_pri", swtch_priFunc),
1704 /* 68 */ SyscallDesc("lw_syscall", unimplementedFunc),
1705 /* 69 */ SyscallDesc("kern_invalid", unimplementedFunc),
1706 /* 70 */ SyscallDesc("mach_sctimes_0", unimplementedFunc),
1707 /* 71 */ SyscallDesc("mach_sctimes_1", unimplementedFunc),
1708 /* 72 */ SyscallDesc("mach_sctimes_2", unimplementedFunc),
1709 /* 73 */ SyscallDesc("mach_sctimes_3", unimplementedFunc),
1710 /* 74 */ SyscallDesc("mach_sctimes_4", unimplementedFunc),
1711 /* 75 */ SyscallDesc("mach_sctimes_5", unimplementedFunc),
1712 /* 76 */ SyscallDesc("mach_sctimes_6", unimplementedFunc),
1713 /* 77 */ SyscallDesc("mach_sctimes_7", unimplementedFunc),
1714 /* 78 */ SyscallDesc("mach_sctimes_8", unimplementedFunc),
1715 /* 79 */ SyscallDesc("mach_sctimes_9", unimplementedFunc),
1716 /* 80 */ SyscallDesc("mach_sctimes_10", unimplementedFunc),
1717 /* 81 */ SyscallDesc("mach_sctimes_11", unimplementedFunc),
1718 /* 82 */ SyscallDesc("mach_sctimes_port_alloc_dealloc", unimplementedFunc)
1719 };
1720
1721 const int Tru64::Num_Mach_Syscall_Descs =
1722 sizeof(Tru64::machSyscallDescs) / sizeof(SyscallDesc);
1723 const int Tru64::Max_Mach_Syscall_Desc = Tru64::Num_Mach_Syscall_Descs - 1;
1724 const int Tru64::Min_Syscall_Desc = -Tru64::Max_Mach_Syscall_Desc;
1725
1726
1727 void
1728 AlphaTru64Process::syscall(ExecContext *xc)
1729 {
1730 num_syscalls++;
1731
1732 int64_t callnum = xc->regs.intRegFile[ReturnValueReg];
1733
1734 Tru64::doSyscall(callnum, this, xc);
1735 }
1736
1737
1738 AlphaTru64Process::AlphaTru64Process(const std::string &name,
1739 ObjectFile *objFile,
1740 int stdin_fd,
1741 int stdout_fd,
1742 int stderr_fd,
1743 std::vector<std::string> &argv,
1744 std::vector<std::string> &envp)
1745 : LiveProcess(name, objFile, stdin_fd, stdout_fd, stderr_fd, argv, envp)
1746 {
1747 }