- Clean up and factor out all of the binning code into a
[gem5.git] / arch / alpha / alpha_tru64_process.cc
1 /*
2 * Copyright (c) 2001-2004 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 int
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 int
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 int
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 int
622 getdirentriesFunc(SyscallDesc *desc, int callnum, Process *process,
623 ExecContext *xc)
624 {
625 int fd = process->sim_fd(xc->getSyscallArg(0));
626 Addr tgt_buf = xc->getSyscallArg(1);
627 int tgt_nbytes = xc->getSyscallArg(2);
628 Addr tgt_basep = xc->getSyscallArg(3);
629
630 char * const host_buf = new char[tgt_nbytes];
631
632 // just pass basep through uninterpreted.
633 TypedBufferArg<int64_t> basep(tgt_basep);
634 basep.copyIn(xc->mem);
635 long host_basep = (off_t)*basep;
636 int host_result = getdirentries(fd, host_buf, tgt_nbytes, &host_basep);
637
638 // check for error
639 if (host_result < 0) {
640 delete [] host_buf;
641 return -errno;
642 }
643
644 // no error: copy results back to target space
645 Addr tgt_buf_ptr = tgt_buf;
646 char *host_buf_ptr = host_buf;
647 char *host_buf_end = host_buf + host_result;
648 while (host_buf_ptr < host_buf_end) {
649 struct dirent *host_dp = (struct dirent *)host_buf_ptr;
650 int namelen = strlen(host_dp->d_name);
651
652 // Actual size includes padded string rounded up for alignment.
653 // Subtract 256 for dummy char array in Tru64::dirent definition.
654 // Add 1 to namelen for terminating null char.
655 int tgt_bufsize = sizeof(Tru64::dirent) - 256 + RoundUp(namelen+1, 8);
656 TypedBufferArg<Tru64::dirent> tgt_dp(tgt_buf_ptr, tgt_bufsize);
657 tgt_dp->d_ino = host_dp->d_ino;
658 tgt_dp->d_reclen = tgt_bufsize;
659 tgt_dp->d_namlen = namelen;
660 strcpy(tgt_dp->d_name, host_dp->d_name);
661 tgt_dp.copyOut(xc->mem);
662
663 tgt_buf_ptr += tgt_bufsize;
664 host_buf_ptr += host_dp->d_reclen;
665 }
666
667 delete [] host_buf;
668
669 *basep = host_basep;
670 basep.copyOut(xc->mem);
671
672 return (tgt_buf_ptr - tgt_buf);
673 }
674
675 /// Target sigreturn() handler.
676 static int
677 sigreturnFunc(SyscallDesc *desc, int callnum, Process *process,
678 ExecContext *xc)
679 {
680 RegFile *regs = &xc->regs;
681 TypedBufferArg<Tru64::sigcontext> sc(xc->getSyscallArg(0));
682
683 sc.copyIn(xc->mem);
684
685 // Restore state from sigcontext structure.
686 // Note that we'll advance PC <- NPC before the end of the cycle,
687 // so we need to restore the desired PC into NPC.
688 // The current regs->pc will get clobbered.
689 regs->npc = sc->sc_pc;
690
691 for (int i = 0; i < 31; ++i) {
692 regs->intRegFile[i] = sc->sc_regs[i];
693 regs->floatRegFile.q[i] = sc->sc_fpregs[i];
694 }
695
696 regs->miscRegs.fpcr = sc->sc_fpcr;
697
698 return 0;
699 }
700
701 /// Target table() handler.
702 static int
703 tableFunc(SyscallDesc *desc, int callnum, Process *process,
704 ExecContext *xc)
705 {
706 int id = xc->getSyscallArg(0); // table ID
707 int index = xc->getSyscallArg(1); // index into table
708 // arg 2 is buffer pointer; type depends on table ID
709 int nel = xc->getSyscallArg(3); // number of elements
710 int lel = xc->getSyscallArg(4); // expected element size
711
712 switch (id) {
713 case Tru64::TBL_SYSINFO: {
714 if (index != 0 || nel != 1 || lel != sizeof(Tru64::tbl_sysinfo))
715 return -EINVAL;
716 TypedBufferArg<Tru64::tbl_sysinfo> elp(xc->getSyscallArg(2));
717
718 const int clk_hz = one_million;
719 elp->si_user = curTick / (ticksPerSecond / clk_hz);
720 elp->si_nice = 0;
721 elp->si_sys = 0;
722 elp->si_idle = 0;
723 elp->wait = 0;
724 elp->si_hz = clk_hz;
725 elp->si_phz = clk_hz;
726 elp->si_boottime = seconds_since_epoch; // seconds since epoch?
727 elp->si_max_procs = process->numCpus();
728 elp.copyOut(xc->mem);
729 return 0;
730 }
731
732 default:
733 cerr << "table(): id " << id << " unknown." << endl;
734 return -EINVAL;
735 }
736 }
737
738 /// Array of syscall descriptors, indexed by call number.
739 static SyscallDesc syscallDescs[];
740
741 /// Number of syscalls in syscallDescs[].
742 static const int Num_Syscall_Descs;
743
744 /// Max supported syscall number.
745 static const int Max_Syscall_Desc;
746
747 //
748 // Mach syscalls -- identified by negated syscall numbers
749 //
750
751 /// Create a stack region for a thread.
752 static int
753 stack_createFunc(SyscallDesc *desc, int callnum, Process *process,
754 ExecContext *xc)
755 {
756 TypedBufferArg<Tru64::vm_stack> argp(xc->getSyscallArg(0));
757
758 argp.copyIn(xc->mem);
759
760 // if the user chose an address, just let them have it. Otherwise
761 // pick one for them.
762 if (argp->address == 0) {
763 argp->address = process->next_thread_stack_base;
764 int stack_size = (argp->rsize + argp->ysize + argp->gsize);
765 process->next_thread_stack_base -= stack_size;
766 argp.copyOut(xc->mem);
767 }
768
769 return 0;
770 }
771
772 /// NXM library version stamp.
773 static
774 const int NXM_LIB_VERSION = 301003;
775
776 /// This call sets up the interface between the user and kernel
777 /// schedulers by creating a shared-memory region. The shared memory
778 /// region has several structs, some global, some per-RAD, some per-VP.
779 static int
780 nxm_task_initFunc(SyscallDesc *desc, int callnum, Process *process,
781 ExecContext *xc)
782 {
783 TypedBufferArg<Tru64::nxm_task_attr> attrp(xc->getSyscallArg(0));
784 TypedBufferArg<Addr> configptr_ptr(xc->getSyscallArg(1));
785
786 attrp.copyIn(xc->mem);
787
788 if (attrp->nxm_version != NXM_LIB_VERSION) {
789 cerr << "nxm_task_init: thread library version mismatch! "
790 << "got " << attrp->nxm_version
791 << ", expected " << NXM_LIB_VERSION << endl;
792 abort();
793 }
794
795 if (attrp->flags != Tru64::NXM_TASK_INIT_VP) {
796 cerr << "nxm_task_init: bad flag value " << attrp->flags
797 << " (expected " << Tru64::NXM_TASK_INIT_VP << ")" << endl;
798 abort();
799 }
800
801 const Addr base_addr = 0x12000; // was 0x3f0000000LL;
802 Addr cur_addr = base_addr; // next addresses to use
803 // first comes the config_info struct
804 Addr config_addr = cur_addr;
805 cur_addr += sizeof(Tru64::nxm_config_info);
806 // next comes the per-cpu state vector
807 Addr slot_state_addr = cur_addr;
808 int slot_state_size =
809 process->numCpus() * sizeof(Tru64::nxm_slot_state_t);
810 cur_addr += slot_state_size;
811 // now the per-RAD state struct (we only support one RAD)
812 cur_addr = 0x14000; // bump up addr for alignment
813 Addr rad_state_addr = cur_addr;
814 int rad_state_size =
815 (sizeof(Tru64::nxm_shared)
816 + (process->numCpus()-1) * sizeof(Tru64::nxm_sched_state));
817 cur_addr += rad_state_size;
818
819 // now initialize a config_info struct and copy it out to user space
820 TypedBufferArg<Tru64::nxm_config_info> config(config_addr);
821
822 config->nxm_nslots_per_rad = process->numCpus();
823 config->nxm_nrads = 1; // only one RAD in our system!
824 config->nxm_slot_state = slot_state_addr;
825 config->nxm_rad[0] = rad_state_addr;
826
827 config.copyOut(xc->mem);
828
829 // initialize the slot_state array and copy it out
830 TypedBufferArg<Tru64::nxm_slot_state_t> slot_state(slot_state_addr,
831 slot_state_size);
832 for (int i = 0; i < process->numCpus(); ++i) {
833 // CPU 0 is bound to the calling process; all others are available
834 slot_state[i] =
835 (i == 0) ? Tru64::NXM_SLOT_BOUND : Tru64::NXM_SLOT_AVAIL;
836 }
837
838 slot_state.copyOut(xc->mem);
839
840 // same for the per-RAD "shared" struct. Note that we need to
841 // allocate extra bytes for the per-VP array which is embedded at
842 // the end.
843 TypedBufferArg<Tru64::nxm_shared> rad_state(rad_state_addr,
844 rad_state_size);
845
846 rad_state->nxm_callback = attrp->nxm_callback;
847 rad_state->nxm_version = attrp->nxm_version;
848 rad_state->nxm_uniq_offset = attrp->nxm_uniq_offset;
849 for (int i = 0; i < process->numCpus(); ++i) {
850 Tru64::nxm_sched_state *ssp = &rad_state->nxm_ss[i];
851 ssp->nxm_u.sigmask = 0;
852 ssp->nxm_u.sig = 0;
853 ssp->nxm_u.flags = 0;
854 ssp->nxm_u.cancel_state = 0;
855 ssp->nxm_u.nxm_ssig = 0;
856 ssp->nxm_bits = 0;
857 ssp->nxm_quantum = attrp->nxm_quantum;
858 ssp->nxm_set_quantum = attrp->nxm_quantum;
859 ssp->nxm_sysevent = 0;
860
861 if (i == 0) {
862 uint64_t uniq = xc->regs.miscRegs.uniq;
863 ssp->nxm_u.pth_id = uniq + attrp->nxm_uniq_offset;
864 ssp->nxm_u.nxm_active = uniq | 1;
865 }
866 else {
867 ssp->nxm_u.pth_id = 0;
868 ssp->nxm_u.nxm_active = 0;
869 }
870 }
871
872 rad_state.copyOut(xc->mem);
873
874 //
875 // copy pointer to shared config area out to user
876 //
877 *configptr_ptr = config_addr;
878 configptr_ptr.copyOut(xc->mem);
879
880 return 0;
881 }
882
883 /// Initialize execution context.
884 static void
885 init_exec_context(ExecContext *ec,
886 Tru64::nxm_thread_attr *attrp, uint64_t uniq_val)
887 {
888 memset(&ec->regs, 0, sizeof(ec->regs));
889
890 ec->regs.intRegFile[ArgumentReg0] = attrp->registers.a0;
891 ec->regs.intRegFile[27/*t12*/] = attrp->registers.pc;
892 ec->regs.intRegFile[StackPointerReg] = attrp->registers.sp;
893 ec->regs.miscRegs.uniq = uniq_val;
894
895 ec->regs.pc = attrp->registers.pc;
896 ec->regs.npc = attrp->registers.pc + sizeof(MachInst);
897
898 ec->activate();
899 }
900
901 /// Create thread.
902 static int
903 nxm_thread_createFunc(SyscallDesc *desc, int callnum, Process *process,
904 ExecContext *xc)
905 {
906 TypedBufferArg<Tru64::nxm_thread_attr> attrp(xc->getSyscallArg(0));
907 TypedBufferArg<uint64_t> kidp(xc->getSyscallArg(1));
908 int thread_index = xc->getSyscallArg(2);
909
910 // get attribute args
911 attrp.copyIn(xc->mem);
912
913 if (attrp->version != NXM_LIB_VERSION) {
914 cerr << "nxm_thread_create: thread library version mismatch! "
915 << "got " << attrp->version
916 << ", expected " << NXM_LIB_VERSION << endl;
917 abort();
918 }
919
920 if (thread_index < 0 | thread_index > process->numCpus()) {
921 cerr << "nxm_thread_create: bad thread index " << thread_index
922 << endl;
923 abort();
924 }
925
926 // On a real machine, the per-RAD shared structure is in
927 // shared memory, so both the user and kernel can get at it.
928 // We don't have that luxury, so we just copy it in and then
929 // back out again.
930 int rad_state_size =
931 (sizeof(Tru64::nxm_shared) +
932 (process->numCpus()-1) * sizeof(Tru64::nxm_sched_state));
933
934 TypedBufferArg<Tru64::nxm_shared> rad_state(0x14000,
935 rad_state_size);
936 rad_state.copyIn(xc->mem);
937
938 uint64_t uniq_val = attrp->pthid - rad_state->nxm_uniq_offset;
939
940 if (attrp->type == Tru64::NXM_TYPE_MANAGER) {
941 // DEC pthreads seems to always create one of these (in
942 // addition to N application threads), but we don't use it,
943 // so don't bother creating it.
944
945 // This is supposed to be a port number. Make something up.
946 *kidp = 99;
947 kidp.copyOut(xc->mem);
948
949 return 0;
950 } else if (attrp->type == Tru64::NXM_TYPE_VP) {
951 // A real "virtual processor" kernel thread. Need to fork
952 // this thread on another CPU.
953 Tru64::nxm_sched_state *ssp = &rad_state->nxm_ss[thread_index];
954
955 if (ssp->nxm_u.nxm_active != 0)
956 return Tru64::KERN_NOT_RECEIVER;
957
958 ssp->nxm_u.pth_id = attrp->pthid;
959 ssp->nxm_u.nxm_active = uniq_val | 1;
960
961 rad_state.copyOut(xc->mem);
962
963 Addr slot_state_addr = 0x12000 + sizeof(Tru64::nxm_config_info);
964 int slot_state_size =
965 process->numCpus() * sizeof(Tru64::nxm_slot_state_t);
966
967 TypedBufferArg<Tru64::nxm_slot_state_t>
968 slot_state(slot_state_addr,
969 slot_state_size);
970
971 slot_state.copyIn(xc->mem);
972
973 if (slot_state[thread_index] != Tru64::NXM_SLOT_AVAIL) {
974 cerr << "nxm_thread_createFunc: requested VP slot "
975 << thread_index << " not available!" << endl;
976 fatal("");
977 }
978
979 slot_state[thread_index] = Tru64::NXM_SLOT_BOUND;
980
981 slot_state.copyOut(xc->mem);
982
983 // Find a free simulator execution context.
984 for (int i = 0; i < process->numCpus(); ++i) {
985 ExecContext *xc = process->execContexts[i];
986
987 if (xc->status() == ExecContext::Unallocated) {
988 // inactive context... grab it
989 init_exec_context(xc, attrp, uniq_val);
990
991 // This is supposed to be a port number, but we'll try
992 // and get away with just sticking the thread index
993 // here.
994 *kidp = thread_index;
995 kidp.copyOut(xc->mem);
996
997 return 0;
998 }
999 }
1000
1001 // fell out of loop... no available inactive context
1002 cerr << "nxm_thread_create: no idle contexts available." << endl;
1003 abort();
1004 } else {
1005 cerr << "nxm_thread_create: can't handle thread type "
1006 << attrp->type << endl;
1007 abort();
1008 }
1009
1010 return 0;
1011 }
1012
1013 /// Thread idle call (like yield()).
1014 static int
1015 nxm_idleFunc(SyscallDesc *desc, int callnum, Process *process,
1016 ExecContext *xc)
1017 {
1018 return 0;
1019 }
1020
1021 /// Block thread.
1022 static int
1023 nxm_thread_blockFunc(SyscallDesc *desc, int callnum, Process *process,
1024 ExecContext *xc)
1025 {
1026 uint64_t tid = xc->getSyscallArg(0);
1027 uint64_t secs = xc->getSyscallArg(1);
1028 uint64_t flags = xc->getSyscallArg(2);
1029 uint64_t action = xc->getSyscallArg(3);
1030 uint64_t usecs = xc->getSyscallArg(4);
1031
1032 cout << xc->cpu->name() << ": nxm_thread_block " << tid << " " << secs
1033 << " " << flags << " " << action << " " << usecs << endl;
1034
1035 return 0;
1036 }
1037
1038 /// block.
1039 static int
1040 nxm_blockFunc(SyscallDesc *desc, int callnum, Process *process,
1041 ExecContext *xc)
1042 {
1043 Addr uaddr = xc->getSyscallArg(0);
1044 uint64_t val = xc->getSyscallArg(1);
1045 uint64_t secs = xc->getSyscallArg(2);
1046 uint64_t usecs = xc->getSyscallArg(3);
1047 uint64_t flags = xc->getSyscallArg(4);
1048
1049 BaseCPU *cpu = xc->cpu;
1050
1051 cout << cpu->name() << ": nxm_block "
1052 << hex << uaddr << dec << " " << val
1053 << " " << secs << " " << usecs
1054 << " " << flags << endl;
1055
1056 return 0;
1057 }
1058
1059 /// Unblock thread.
1060 static int
1061 nxm_unblockFunc(SyscallDesc *desc, int callnum, Process *process,
1062 ExecContext *xc)
1063 {
1064 Addr uaddr = xc->getSyscallArg(0);
1065
1066 cout << xc->cpu->name() << ": nxm_unblock "
1067 << hex << uaddr << dec << endl;
1068
1069 return 0;
1070 }
1071
1072 /// Switch thread priority.
1073 static int
1074 swtch_priFunc(SyscallDesc *desc, int callnum, Process *process,
1075 ExecContext *xc)
1076 {
1077 // Attempts to switch to another runnable thread (if there is
1078 // one). Returns false if there are no other threads to run
1079 // (i.e., the thread can reasonably spin-wait) or true if there
1080 // are other threads.
1081 //
1082 // Since we assume at most one "kernel" thread per CPU, it's
1083 // always safe to return false here.
1084 return false;
1085 }
1086
1087
1088 /// Activate exec context waiting on a channel. Just activate one
1089 /// by default.
1090 static int
1091 activate_waiting_context(Addr uaddr, Process *process,
1092 bool activate_all = false)
1093 {
1094 int num_activated = 0;
1095
1096 list<Process::WaitRec>::iterator i = process->waitList.begin();
1097 list<Process::WaitRec>::iterator end = process->waitList.end();
1098
1099 while (i != end && (num_activated == 0 || activate_all)) {
1100 if (i->waitChan == uaddr) {
1101 // found waiting process: make it active
1102 ExecContext *newCtx = i->waitingContext;
1103 assert(newCtx->status() == ExecContext::Suspended);
1104 newCtx->activate();
1105
1106 // get rid of this record
1107 i = process->waitList.erase(i);
1108
1109 ++num_activated;
1110 } else {
1111 ++i;
1112 }
1113 }
1114
1115 return num_activated;
1116 }
1117
1118 /// M5 hacked-up lock acquire.
1119 static void
1120 m5_lock_mutex(Addr uaddr, Process *process, ExecContext *xc)
1121 {
1122 TypedBufferArg<uint64_t> lockp(uaddr);
1123
1124 lockp.copyIn(xc->mem);
1125
1126 if (*lockp == 0) {
1127 // lock is free: grab it
1128 *lockp = 1;
1129 lockp.copyOut(xc->mem);
1130 } else {
1131 // lock is busy: disable until free
1132 process->waitList.push_back(Process::WaitRec(uaddr, xc));
1133 xc->suspend();
1134 }
1135 }
1136
1137 /// M5 unlock call.
1138 static void
1139 m5_unlock_mutex(Addr uaddr, Process *process, ExecContext *xc)
1140 {
1141 TypedBufferArg<uint64_t> lockp(uaddr);
1142
1143 lockp.copyIn(xc->mem);
1144 assert(*lockp != 0);
1145
1146 // Check for a process waiting on the lock.
1147 int num_waiting = activate_waiting_context(uaddr, process);
1148
1149 // clear lock field if no waiting context is taking over the lock
1150 if (num_waiting == 0) {
1151 *lockp = 0;
1152 lockp.copyOut(xc->mem);
1153 }
1154 }
1155
1156 /// Lock acquire syscall handler.
1157 static int
1158 m5_mutex_lockFunc(SyscallDesc *desc, int callnum, Process *process,
1159 ExecContext *xc)
1160 {
1161 Addr uaddr = xc->getSyscallArg(0);
1162
1163 m5_lock_mutex(uaddr, process, xc);
1164
1165 // Return 0 since we will always return to the user with the lock
1166 // acquired. We will just keep the context inactive until that is
1167 // true.
1168 return 0;
1169 }
1170
1171 /// Try lock (non-blocking).
1172 static int
1173 m5_mutex_trylockFunc(SyscallDesc *desc, int callnum, Process *process,
1174 ExecContext *xc)
1175 {
1176 Addr uaddr = xc->getSyscallArg(0);
1177 TypedBufferArg<uint64_t> lockp(uaddr);
1178
1179 lockp.copyIn(xc->mem);
1180
1181 if (*lockp == 0) {
1182 // lock is free: grab it
1183 *lockp = 1;
1184 lockp.copyOut(xc->mem);
1185 return 0;
1186 } else {
1187 return 1;
1188 }
1189 }
1190
1191 /// Unlock syscall handler.
1192 static int
1193 m5_mutex_unlockFunc(SyscallDesc *desc, int callnum, Process *process,
1194 ExecContext *xc)
1195 {
1196 Addr uaddr = xc->getSyscallArg(0);
1197
1198 m5_unlock_mutex(uaddr, process, xc);
1199
1200 return 0;
1201 }
1202
1203 /// Signal ocndition.
1204 static int
1205 m5_cond_signalFunc(SyscallDesc *desc, int callnum, Process *process,
1206 ExecContext *xc)
1207 {
1208 Addr cond_addr = xc->getSyscallArg(0);
1209
1210 // Wake up one process waiting on the condition variable.
1211 activate_waiting_context(cond_addr, process);
1212
1213 return 0;
1214 }
1215
1216 /// Wake up all processes waiting on the condition variable.
1217 static int
1218 m5_cond_broadcastFunc(SyscallDesc *desc, int callnum, Process *process,
1219 ExecContext *xc)
1220 {
1221 Addr cond_addr = xc->getSyscallArg(0);
1222
1223 activate_waiting_context(cond_addr, process, true);
1224
1225 return 0;
1226 }
1227
1228 /// Wait on a condition.
1229 static int
1230 m5_cond_waitFunc(SyscallDesc *desc, int callnum, Process *process,
1231 ExecContext *xc)
1232 {
1233 Addr cond_addr = xc->getSyscallArg(0);
1234 Addr lock_addr = xc->getSyscallArg(1);
1235 TypedBufferArg<uint64_t> condp(cond_addr);
1236 TypedBufferArg<uint64_t> lockp(lock_addr);
1237
1238 // user is supposed to acquire lock before entering
1239 lockp.copyIn(xc->mem);
1240 assert(*lockp != 0);
1241
1242 m5_unlock_mutex(lock_addr, process, xc);
1243
1244 process->waitList.push_back(Process::WaitRec(cond_addr, xc));
1245 xc->suspend();
1246
1247 return 0;
1248 }
1249
1250 /// Thread exit.
1251 static int
1252 m5_thread_exitFunc(SyscallDesc *desc, int callnum, Process *process,
1253 ExecContext *xc)
1254 {
1255 assert(xc->status() == ExecContext::Active);
1256 xc->deallocate();
1257
1258 return 0;
1259 }
1260
1261 /// Array of syscall descriptors for Mach syscalls, indexed by
1262 /// (negated) call number.
1263 static SyscallDesc machSyscallDescs[];
1264
1265 /// Number of syscalls in machSyscallDescs[].
1266 static const int Num_Mach_Syscall_Descs;
1267
1268 /// Max supported Mach syscall number.
1269 static const int Max_Mach_Syscall_Desc;
1270
1271 /// Since negated values are used to identify Mach syscalls, the
1272 /// minimum (signed) valid syscall number is the negated max Mach
1273 /// syscall number.
1274 static const int Min_Syscall_Desc;
1275
1276 /// Do the specified syscall. Just looks the call number up in
1277 /// the table and invokes the appropriate handler.
1278 static void
1279 doSyscall(int callnum, Process *process, ExecContext *xc)
1280 {
1281 if (callnum < Min_Syscall_Desc || callnum > Max_Syscall_Desc) {
1282 cerr << "Syscall " << callnum << " out of range" << endl;
1283 abort();
1284 }
1285
1286 SyscallDesc *desc =
1287 (callnum < 0) ?
1288 &machSyscallDescs[-callnum] : &syscallDescs[callnum];
1289
1290 desc->doSyscall(callnum, process, xc);
1291 }
1292
1293 /// Indirect syscall invocation (call #0).
1294 static int
1295 indirectSyscallFunc(SyscallDesc *desc, int callnum, Process *process,
1296 ExecContext *xc)
1297 {
1298 int new_callnum = xc->getSyscallArg(0);
1299
1300 for (int i = 0; i < 5; ++i)
1301 xc->setSyscallArg(i, xc->getSyscallArg(i+1));
1302
1303 doSyscall(new_callnum, process, xc);
1304
1305 return 0;
1306 }
1307
1308 }; // class Tru64
1309
1310
1311 // open(2) flags translation table
1312 OpenFlagTransTable Tru64::openFlagTable[] = {
1313 #ifdef _MSC_VER
1314 { Tru64::TGT_O_RDONLY, _O_RDONLY },
1315 { Tru64::TGT_O_WRONLY, _O_WRONLY },
1316 { Tru64::TGT_O_RDWR, _O_RDWR },
1317 { Tru64::TGT_O_APPEND, _O_APPEND },
1318 { Tru64::TGT_O_CREAT, _O_CREAT },
1319 { Tru64::TGT_O_TRUNC, _O_TRUNC },
1320 { Tru64::TGT_O_EXCL, _O_EXCL },
1321 #ifdef _O_NONBLOCK
1322 { Tru64::TGT_O_NONBLOCK, _O_NONBLOCK },
1323 #endif
1324 #ifdef _O_NOCTTY
1325 { Tru64::TGT_O_NOCTTY, _O_NOCTTY },
1326 #endif
1327 #ifdef _O_SYNC
1328 { Tru64::TGT_O_SYNC, _O_SYNC },
1329 #endif
1330 #else /* !_MSC_VER */
1331 { Tru64::TGT_O_RDONLY, O_RDONLY },
1332 { Tru64::TGT_O_WRONLY, O_WRONLY },
1333 { Tru64::TGT_O_RDWR, O_RDWR },
1334 { Tru64::TGT_O_APPEND, O_APPEND },
1335 { Tru64::TGT_O_CREAT, O_CREAT },
1336 { Tru64::TGT_O_TRUNC, O_TRUNC },
1337 { Tru64::TGT_O_EXCL, O_EXCL },
1338 { Tru64::TGT_O_NONBLOCK, O_NONBLOCK },
1339 { Tru64::TGT_O_NOCTTY, O_NOCTTY },
1340 #ifdef O_SYNC
1341 { Tru64::TGT_O_SYNC, O_SYNC },
1342 #endif
1343 #endif /* _MSC_VER */
1344 };
1345
1346 const int Tru64::NUM_OPEN_FLAGS = (sizeof(Tru64::openFlagTable)/sizeof(Tru64::openFlagTable[0]));
1347
1348 const char *Tru64::hostname = "m5.eecs.umich.edu";
1349
1350 SyscallDesc Tru64::syscallDescs[] = {
1351 /* 0 */ SyscallDesc("syscall (#0)", indirectSyscallFunc,
1352 SyscallDesc::SuppressReturnValue),
1353 /* 1 */ SyscallDesc("exit", exitFunc),
1354 /* 2 */ SyscallDesc("fork", unimplementedFunc),
1355 /* 3 */ SyscallDesc("read", readFunc),
1356 /* 4 */ SyscallDesc("write", writeFunc),
1357 /* 5 */ SyscallDesc("old_open", unimplementedFunc),
1358 /* 6 */ SyscallDesc("close", closeFunc),
1359 /* 7 */ SyscallDesc("wait4", unimplementedFunc),
1360 /* 8 */ SyscallDesc("old_creat", unimplementedFunc),
1361 /* 9 */ SyscallDesc("link", unimplementedFunc),
1362 /* 10 */ SyscallDesc("unlink", unlinkFunc),
1363 /* 11 */ SyscallDesc("execv", unimplementedFunc),
1364 /* 12 */ SyscallDesc("chdir", unimplementedFunc),
1365 /* 13 */ SyscallDesc("fchdir", unimplementedFunc),
1366 /* 14 */ SyscallDesc("mknod", unimplementedFunc),
1367 /* 15 */ SyscallDesc("chmod", unimplementedFunc),
1368 /* 16 */ SyscallDesc("chown", unimplementedFunc),
1369 /* 17 */ SyscallDesc("obreak", obreakFunc),
1370 /* 18 */ SyscallDesc("pre_F64_getfsstat", unimplementedFunc),
1371 /* 19 */ SyscallDesc("lseek", lseekFunc),
1372 /* 20 */ SyscallDesc("getpid", getpidFunc),
1373 /* 21 */ SyscallDesc("mount", unimplementedFunc),
1374 /* 22 */ SyscallDesc("unmount", unimplementedFunc),
1375 /* 23 */ SyscallDesc("setuid", setuidFunc),
1376 /* 24 */ SyscallDesc("getuid", getuidFunc),
1377 /* 25 */ SyscallDesc("exec_with_loader", unimplementedFunc),
1378 /* 26 */ SyscallDesc("ptrace", unimplementedFunc),
1379 /* 27 */ SyscallDesc("recvmsg", unimplementedFunc),
1380 /* 28 */ SyscallDesc("sendmsg", unimplementedFunc),
1381 /* 29 */ SyscallDesc("recvfrom", unimplementedFunc),
1382 /* 30 */ SyscallDesc("accept", unimplementedFunc),
1383 /* 31 */ SyscallDesc("getpeername", unimplementedFunc),
1384 /* 32 */ SyscallDesc("getsockname", unimplementedFunc),
1385 /* 33 */ SyscallDesc("access", unimplementedFunc),
1386 /* 34 */ SyscallDesc("chflags", unimplementedFunc),
1387 /* 35 */ SyscallDesc("fchflags", unimplementedFunc),
1388 /* 36 */ SyscallDesc("sync", unimplementedFunc),
1389 /* 37 */ SyscallDesc("kill", unimplementedFunc),
1390 /* 38 */ SyscallDesc("old_stat", unimplementedFunc),
1391 /* 39 */ SyscallDesc("setpgid", unimplementedFunc),
1392 /* 40 */ SyscallDesc("old_lstat", unimplementedFunc),
1393 /* 41 */ SyscallDesc("dup", unimplementedFunc),
1394 /* 42 */ SyscallDesc("pipe", unimplementedFunc),
1395 /* 43 */ SyscallDesc("set_program_attributes", unimplementedFunc),
1396 /* 44 */ SyscallDesc("profil", unimplementedFunc),
1397 /* 45 */ SyscallDesc("open", openFunc<Tru64>),
1398 /* 46 */ SyscallDesc("obsolete osigaction", unimplementedFunc),
1399 /* 47 */ SyscallDesc("getgid", getgidFunc),
1400 /* 48 */ SyscallDesc("sigprocmask", ignoreFunc),
1401 /* 49 */ SyscallDesc("getlogin", unimplementedFunc),
1402 /* 50 */ SyscallDesc("setlogin", unimplementedFunc),
1403 /* 51 */ SyscallDesc("acct", unimplementedFunc),
1404 /* 52 */ SyscallDesc("sigpending", unimplementedFunc),
1405 /* 53 */ SyscallDesc("classcntl", unimplementedFunc),
1406 /* 54 */ SyscallDesc("ioctl", ioctlFunc<Tru64>),
1407 /* 55 */ SyscallDesc("reboot", unimplementedFunc),
1408 /* 56 */ SyscallDesc("revoke", unimplementedFunc),
1409 /* 57 */ SyscallDesc("symlink", unimplementedFunc),
1410 /* 58 */ SyscallDesc("readlink", unimplementedFunc),
1411 /* 59 */ SyscallDesc("execve", unimplementedFunc),
1412 /* 60 */ SyscallDesc("umask", unimplementedFunc),
1413 /* 61 */ SyscallDesc("chroot", unimplementedFunc),
1414 /* 62 */ SyscallDesc("old_fstat", unimplementedFunc),
1415 /* 63 */ SyscallDesc("getpgrp", unimplementedFunc),
1416 /* 64 */ SyscallDesc("getpagesize", getpagesizeFunc),
1417 /* 65 */ SyscallDesc("mremap", unimplementedFunc),
1418 /* 66 */ SyscallDesc("vfork", unimplementedFunc),
1419 /* 67 */ SyscallDesc("pre_F64_stat", unimplementedFunc),
1420 /* 68 */ SyscallDesc("pre_F64_lstat", unimplementedFunc),
1421 /* 69 */ SyscallDesc("sbrk", unimplementedFunc),
1422 /* 70 */ SyscallDesc("sstk", unimplementedFunc),
1423 /* 71 */ SyscallDesc("mmap", mmapFunc<Tru64>),
1424 /* 72 */ SyscallDesc("ovadvise", unimplementedFunc),
1425 /* 73 */ SyscallDesc("munmap", munmapFunc),
1426 /* 74 */ SyscallDesc("mprotect", ignoreFunc),
1427 /* 75 */ SyscallDesc("madvise", unimplementedFunc),
1428 /* 76 */ SyscallDesc("old_vhangup", unimplementedFunc),
1429 /* 77 */ SyscallDesc("kmodcall", unimplementedFunc),
1430 /* 78 */ SyscallDesc("mincore", unimplementedFunc),
1431 /* 79 */ SyscallDesc("getgroups", unimplementedFunc),
1432 /* 80 */ SyscallDesc("setgroups", unimplementedFunc),
1433 /* 81 */ SyscallDesc("old_getpgrp", unimplementedFunc),
1434 /* 82 */ SyscallDesc("setpgrp", unimplementedFunc),
1435 /* 83 */ SyscallDesc("setitimer", unimplementedFunc),
1436 /* 84 */ SyscallDesc("old_wait", unimplementedFunc),
1437 /* 85 */ SyscallDesc("table", tableFunc),
1438 /* 86 */ SyscallDesc("getitimer", unimplementedFunc),
1439 /* 87 */ SyscallDesc("gethostname", gethostnameFunc),
1440 /* 88 */ SyscallDesc("sethostname", unimplementedFunc),
1441 /* 89 */ SyscallDesc("getdtablesize", unimplementedFunc),
1442 /* 90 */ SyscallDesc("dup2", unimplementedFunc),
1443 /* 91 */ SyscallDesc("pre_F64_fstat", unimplementedFunc),
1444 /* 92 */ SyscallDesc("fcntl", fcntlFunc),
1445 /* 93 */ SyscallDesc("select", unimplementedFunc),
1446 /* 94 */ SyscallDesc("poll", unimplementedFunc),
1447 /* 95 */ SyscallDesc("fsync", unimplementedFunc),
1448 /* 96 */ SyscallDesc("setpriority", unimplementedFunc),
1449 /* 97 */ SyscallDesc("socket", unimplementedFunc),
1450 /* 98 */ SyscallDesc("connect", unimplementedFunc),
1451 /* 99 */ SyscallDesc("old_accept", unimplementedFunc),
1452 /* 100 */ SyscallDesc("getpriority", unimplementedFunc),
1453 /* 101 */ SyscallDesc("old_send", unimplementedFunc),
1454 /* 102 */ SyscallDesc("old_recv", unimplementedFunc),
1455 /* 103 */ SyscallDesc("sigreturn", sigreturnFunc,
1456 SyscallDesc::SuppressReturnValue),
1457 /* 104 */ SyscallDesc("bind", unimplementedFunc),
1458 /* 105 */ SyscallDesc("setsockopt", unimplementedFunc),
1459 /* 106 */ SyscallDesc("listen", unimplementedFunc),
1460 /* 107 */ SyscallDesc("plock", unimplementedFunc),
1461 /* 108 */ SyscallDesc("old_sigvec", unimplementedFunc),
1462 /* 109 */ SyscallDesc("old_sigblock", unimplementedFunc),
1463 /* 110 */ SyscallDesc("old_sigsetmask", unimplementedFunc),
1464 /* 111 */ SyscallDesc("sigsuspend", unimplementedFunc),
1465 /* 112 */ SyscallDesc("sigstack", ignoreFunc),
1466 /* 113 */ SyscallDesc("old_recvmsg", unimplementedFunc),
1467 /* 114 */ SyscallDesc("old_sendmsg", unimplementedFunc),
1468 /* 115 */ SyscallDesc("obsolete vtrace", unimplementedFunc),
1469 /* 116 */ SyscallDesc("gettimeofday", gettimeofdayFunc<Tru64>),
1470 /* 117 */ SyscallDesc("getrusage", getrusageFunc<Tru64>),
1471 /* 118 */ SyscallDesc("getsockopt", unimplementedFunc),
1472 /* 119 */ SyscallDesc("numa_syscalls", unimplementedFunc),
1473 /* 120 */ SyscallDesc("readv", unimplementedFunc),
1474 /* 121 */ SyscallDesc("writev", unimplementedFunc),
1475 /* 122 */ SyscallDesc("settimeofday", unimplementedFunc),
1476 /* 123 */ SyscallDesc("fchown", unimplementedFunc),
1477 /* 124 */ SyscallDesc("fchmod", unimplementedFunc),
1478 /* 125 */ SyscallDesc("old_recvfrom", unimplementedFunc),
1479 /* 126 */ SyscallDesc("setreuid", unimplementedFunc),
1480 /* 127 */ SyscallDesc("setregid", unimplementedFunc),
1481 /* 128 */ SyscallDesc("rename", renameFunc),
1482 /* 129 */ SyscallDesc("truncate", unimplementedFunc),
1483 /* 130 */ SyscallDesc("ftruncate", unimplementedFunc),
1484 /* 131 */ SyscallDesc("flock", unimplementedFunc),
1485 /* 132 */ SyscallDesc("setgid", unimplementedFunc),
1486 /* 133 */ SyscallDesc("sendto", unimplementedFunc),
1487 /* 134 */ SyscallDesc("shutdown", unimplementedFunc),
1488 /* 135 */ SyscallDesc("socketpair", unimplementedFunc),
1489 /* 136 */ SyscallDesc("mkdir", unimplementedFunc),
1490 /* 137 */ SyscallDesc("rmdir", unimplementedFunc),
1491 /* 138 */ SyscallDesc("utimes", unimplementedFunc),
1492 /* 139 */ SyscallDesc("obsolete 4.2 sigreturn", unimplementedFunc),
1493 /* 140 */ SyscallDesc("adjtime", unimplementedFunc),
1494 /* 141 */ SyscallDesc("old_getpeername", unimplementedFunc),
1495 /* 142 */ SyscallDesc("gethostid", unimplementedFunc),
1496 /* 143 */ SyscallDesc("sethostid", unimplementedFunc),
1497 /* 144 */ SyscallDesc("getrlimit", getrlimitFunc<Tru64>),
1498 /* 145 */ SyscallDesc("setrlimit", ignoreFunc),
1499 /* 146 */ SyscallDesc("old_killpg", unimplementedFunc),
1500 /* 147 */ SyscallDesc("setsid", unimplementedFunc),
1501 /* 148 */ SyscallDesc("quotactl", unimplementedFunc),
1502 /* 149 */ SyscallDesc("oldquota", unimplementedFunc),
1503 /* 150 */ SyscallDesc("old_getsockname", unimplementedFunc),
1504 /* 151 */ SyscallDesc("pread", unimplementedFunc),
1505 /* 152 */ SyscallDesc("pwrite", unimplementedFunc),
1506 /* 153 */ SyscallDesc("pid_block", unimplementedFunc),
1507 /* 154 */ SyscallDesc("pid_unblock", unimplementedFunc),
1508 /* 155 */ SyscallDesc("signal_urti", unimplementedFunc),
1509 /* 156 */ SyscallDesc("sigaction", ignoreFunc),
1510 /* 157 */ SyscallDesc("sigwaitprim", unimplementedFunc),
1511 /* 158 */ SyscallDesc("nfssvc", unimplementedFunc),
1512 /* 159 */ SyscallDesc("getdirentries", getdirentriesFunc),
1513 /* 160 */ SyscallDesc("pre_F64_statfs", unimplementedFunc),
1514 /* 161 */ SyscallDesc("pre_F64_fstatfs", unimplementedFunc),
1515 /* 162 */ SyscallDesc("unknown #162", unimplementedFunc),
1516 /* 163 */ SyscallDesc("async_daemon", unimplementedFunc),
1517 /* 164 */ SyscallDesc("getfh", unimplementedFunc),
1518 /* 165 */ SyscallDesc("getdomainname", unimplementedFunc),
1519 /* 166 */ SyscallDesc("setdomainname", unimplementedFunc),
1520 /* 167 */ SyscallDesc("unknown #167", unimplementedFunc),
1521 /* 168 */ SyscallDesc("unknown #168", unimplementedFunc),
1522 /* 169 */ SyscallDesc("exportfs", unimplementedFunc),
1523 /* 170 */ SyscallDesc("unknown #170", unimplementedFunc),
1524 /* 171 */ SyscallDesc("unknown #171", unimplementedFunc),
1525 /* 172 */ SyscallDesc("unknown #172", unimplementedFunc),
1526 /* 173 */ SyscallDesc("unknown #173", unimplementedFunc),
1527 /* 174 */ SyscallDesc("unknown #174", unimplementedFunc),
1528 /* 175 */ SyscallDesc("unknown #175", unimplementedFunc),
1529 /* 176 */ SyscallDesc("unknown #176", unimplementedFunc),
1530 /* 177 */ SyscallDesc("unknown #177", unimplementedFunc),
1531 /* 178 */ SyscallDesc("unknown #178", unimplementedFunc),
1532 /* 179 */ SyscallDesc("unknown #179", unimplementedFunc),
1533 /* 180 */ SyscallDesc("unknown #180", unimplementedFunc),
1534 /* 181 */ SyscallDesc("alt_plock", unimplementedFunc),
1535 /* 182 */ SyscallDesc("unknown #182", unimplementedFunc),
1536 /* 183 */ SyscallDesc("unknown #183", unimplementedFunc),
1537 /* 184 */ SyscallDesc("getmnt", unimplementedFunc),
1538 /* 185 */ SyscallDesc("unknown #185", unimplementedFunc),
1539 /* 186 */ SyscallDesc("unknown #186", unimplementedFunc),
1540 /* 187 */ SyscallDesc("alt_sigpending", unimplementedFunc),
1541 /* 188 */ SyscallDesc("alt_setsid", unimplementedFunc),
1542 /* 189 */ SyscallDesc("unknown #189", unimplementedFunc),
1543 /* 190 */ SyscallDesc("unknown #190", unimplementedFunc),
1544 /* 191 */ SyscallDesc("unknown #191", unimplementedFunc),
1545 /* 192 */ SyscallDesc("unknown #192", unimplementedFunc),
1546 /* 193 */ SyscallDesc("unknown #193", unimplementedFunc),
1547 /* 194 */ SyscallDesc("unknown #194", unimplementedFunc),
1548 /* 195 */ SyscallDesc("unknown #195", unimplementedFunc),
1549 /* 196 */ SyscallDesc("unknown #196", unimplementedFunc),
1550 /* 197 */ SyscallDesc("unknown #197", unimplementedFunc),
1551 /* 198 */ SyscallDesc("unknown #198", unimplementedFunc),
1552 /* 199 */ SyscallDesc("swapon", unimplementedFunc),
1553 /* 200 */ SyscallDesc("msgctl", unimplementedFunc),
1554 /* 201 */ SyscallDesc("msgget", unimplementedFunc),
1555 /* 202 */ SyscallDesc("msgrcv", unimplementedFunc),
1556 /* 203 */ SyscallDesc("msgsnd", unimplementedFunc),
1557 /* 204 */ SyscallDesc("semctl", unimplementedFunc),
1558 /* 205 */ SyscallDesc("semget", unimplementedFunc),
1559 /* 206 */ SyscallDesc("semop", unimplementedFunc),
1560 /* 207 */ SyscallDesc("uname", unameFunc),
1561 /* 208 */ SyscallDesc("lchown", unimplementedFunc),
1562 /* 209 */ SyscallDesc("shmat", unimplementedFunc),
1563 /* 210 */ SyscallDesc("shmctl", unimplementedFunc),
1564 /* 211 */ SyscallDesc("shmdt", unimplementedFunc),
1565 /* 212 */ SyscallDesc("shmget", unimplementedFunc),
1566 /* 213 */ SyscallDesc("mvalid", unimplementedFunc),
1567 /* 214 */ SyscallDesc("getaddressconf", unimplementedFunc),
1568 /* 215 */ SyscallDesc("msleep", unimplementedFunc),
1569 /* 216 */ SyscallDesc("mwakeup", unimplementedFunc),
1570 /* 217 */ SyscallDesc("msync", unimplementedFunc),
1571 /* 218 */ SyscallDesc("signal", unimplementedFunc),
1572 /* 219 */ SyscallDesc("utc_gettime", unimplementedFunc),
1573 /* 220 */ SyscallDesc("utc_adjtime", unimplementedFunc),
1574 /* 221 */ SyscallDesc("unknown #221", unimplementedFunc),
1575 /* 222 */ SyscallDesc("security", unimplementedFunc),
1576 /* 223 */ SyscallDesc("kloadcall", unimplementedFunc),
1577 /* 224 */ SyscallDesc("stat", statFunc<Tru64>),
1578 /* 225 */ SyscallDesc("lstat", lstatFunc<Tru64>),
1579 /* 226 */ SyscallDesc("fstat", fstatFunc<Tru64>),
1580 /* 227 */ SyscallDesc("statfs", unimplementedFunc),
1581 /* 228 */ SyscallDesc("fstatfs", unimplementedFunc),
1582 /* 229 */ SyscallDesc("getfsstat", unimplementedFunc),
1583 /* 230 */ SyscallDesc("gettimeofday64", unimplementedFunc),
1584 /* 231 */ SyscallDesc("settimeofday64", unimplementedFunc),
1585 /* 232 */ SyscallDesc("unknown #232", unimplementedFunc),
1586 /* 233 */ SyscallDesc("getpgid", unimplementedFunc),
1587 /* 234 */ SyscallDesc("getsid", unimplementedFunc),
1588 /* 235 */ SyscallDesc("sigaltstack", ignoreFunc),
1589 /* 236 */ SyscallDesc("waitid", unimplementedFunc),
1590 /* 237 */ SyscallDesc("priocntlset", unimplementedFunc),
1591 /* 238 */ SyscallDesc("sigsendset", unimplementedFunc),
1592 /* 239 */ SyscallDesc("set_speculative", unimplementedFunc),
1593 /* 240 */ SyscallDesc("msfs_syscall", unimplementedFunc),
1594 /* 241 */ SyscallDesc("sysinfo", unimplementedFunc),
1595 /* 242 */ SyscallDesc("uadmin", unimplementedFunc),
1596 /* 243 */ SyscallDesc("fuser", unimplementedFunc),
1597 /* 244 */ SyscallDesc("proplist_syscall", unimplementedFunc),
1598 /* 245 */ SyscallDesc("ntp_adjtime", unimplementedFunc),
1599 /* 246 */ SyscallDesc("ntp_gettime", unimplementedFunc),
1600 /* 247 */ SyscallDesc("pathconf", unimplementedFunc),
1601 /* 248 */ SyscallDesc("fpathconf", unimplementedFunc),
1602 /* 249 */ SyscallDesc("sync2", unimplementedFunc),
1603 /* 250 */ SyscallDesc("uswitch", unimplementedFunc),
1604 /* 251 */ SyscallDesc("usleep_thread", unimplementedFunc),
1605 /* 252 */ SyscallDesc("audcntl", unimplementedFunc),
1606 /* 253 */ SyscallDesc("audgen", unimplementedFunc),
1607 /* 254 */ SyscallDesc("sysfs", unimplementedFunc),
1608 /* 255 */ SyscallDesc("subsys_info", unimplementedFunc),
1609 /* 256 */ SyscallDesc("getsysinfo", getsysinfoFunc),
1610 /* 257 */ SyscallDesc("setsysinfo", unimplementedFunc),
1611 /* 258 */ SyscallDesc("afs_syscall", unimplementedFunc),
1612 /* 259 */ SyscallDesc("swapctl", unimplementedFunc),
1613 /* 260 */ SyscallDesc("memcntl", unimplementedFunc),
1614 /* 261 */ SyscallDesc("fdatasync", unimplementedFunc),
1615 /* 262 */ SyscallDesc("oflock", unimplementedFunc),
1616 /* 263 */ SyscallDesc("F64_readv", unimplementedFunc),
1617 /* 264 */ SyscallDesc("F64_writev", unimplementedFunc),
1618 /* 265 */ SyscallDesc("cdslxlate", unimplementedFunc),
1619 /* 266 */ SyscallDesc("sendfile", unimplementedFunc),
1620 };
1621
1622 const int Tru64::Num_Syscall_Descs =
1623 sizeof(Tru64::syscallDescs) / sizeof(SyscallDesc);
1624
1625 const int Tru64::Max_Syscall_Desc = Tru64::Num_Syscall_Descs - 1;
1626
1627 SyscallDesc Tru64::machSyscallDescs[] = {
1628 /* 0 */ SyscallDesc("kern_invalid", unimplementedFunc),
1629 /* 1 */ SyscallDesc("m5_mutex_lock", m5_mutex_lockFunc),
1630 /* 2 */ SyscallDesc("m5_mutex_trylock", m5_mutex_trylockFunc),
1631 /* 3 */ SyscallDesc("m5_mutex_unlock", m5_mutex_unlockFunc),
1632 /* 4 */ SyscallDesc("m5_cond_signal", m5_cond_signalFunc),
1633 /* 5 */ SyscallDesc("m5_cond_broadcast", m5_cond_broadcastFunc),
1634 /* 6 */ SyscallDesc("m5_cond_wait", m5_cond_waitFunc),
1635 /* 7 */ SyscallDesc("m5_thread_exit", m5_thread_exitFunc),
1636 /* 8 */ SyscallDesc("kern_invalid", unimplementedFunc),
1637 /* 9 */ SyscallDesc("kern_invalid", unimplementedFunc),
1638 /* 10 */ SyscallDesc("task_self", unimplementedFunc),
1639 /* 11 */ SyscallDesc("thread_reply", unimplementedFunc),
1640 /* 12 */ SyscallDesc("task_notify", unimplementedFunc),
1641 /* 13 */ SyscallDesc("thread_self", unimplementedFunc),
1642 /* 14 */ SyscallDesc("kern_invalid", unimplementedFunc),
1643 /* 15 */ SyscallDesc("kern_invalid", unimplementedFunc),
1644 /* 16 */ SyscallDesc("kern_invalid", unimplementedFunc),
1645 /* 17 */ SyscallDesc("kern_invalid", unimplementedFunc),
1646 /* 18 */ SyscallDesc("kern_invalid", unimplementedFunc),
1647 /* 19 */ SyscallDesc("kern_invalid", unimplementedFunc),
1648 /* 20 */ SyscallDesc("msg_send_trap", unimplementedFunc),
1649 /* 21 */ SyscallDesc("msg_receive_trap", unimplementedFunc),
1650 /* 22 */ SyscallDesc("msg_rpc_trap", unimplementedFunc),
1651 /* 23 */ SyscallDesc("kern_invalid", unimplementedFunc),
1652 /* 24 */ SyscallDesc("nxm_block", nxm_blockFunc),
1653 /* 25 */ SyscallDesc("nxm_unblock", nxm_unblockFunc),
1654 /* 26 */ SyscallDesc("kern_invalid", unimplementedFunc),
1655 /* 27 */ SyscallDesc("kern_invalid", unimplementedFunc),
1656 /* 28 */ SyscallDesc("kern_invalid", unimplementedFunc),
1657 /* 29 */ SyscallDesc("nxm_thread_destroy", unimplementedFunc),
1658 /* 30 */ SyscallDesc("lw_wire", unimplementedFunc),
1659 /* 31 */ SyscallDesc("lw_unwire", unimplementedFunc),
1660 /* 32 */ SyscallDesc("nxm_thread_create", nxm_thread_createFunc),
1661 /* 33 */ SyscallDesc("nxm_task_init", nxm_task_initFunc),
1662 /* 34 */ SyscallDesc("kern_invalid", unimplementedFunc),
1663 /* 35 */ SyscallDesc("nxm_idle", nxm_idleFunc),
1664 /* 36 */ SyscallDesc("nxm_wakeup_idle", unimplementedFunc),
1665 /* 37 */ SyscallDesc("nxm_set_pthid", unimplementedFunc),
1666 /* 38 */ SyscallDesc("nxm_thread_kill", unimplementedFunc),
1667 /* 39 */ SyscallDesc("nxm_thread_block", nxm_thread_blockFunc),
1668 /* 40 */ SyscallDesc("nxm_thread_wakeup", unimplementedFunc),
1669 /* 41 */ SyscallDesc("init_process", unimplementedFunc),
1670 /* 42 */ SyscallDesc("nxm_get_binding", unimplementedFunc),
1671 /* 43 */ SyscallDesc("map_fd", unimplementedFunc),
1672 /* 44 */ SyscallDesc("nxm_resched", unimplementedFunc),
1673 /* 45 */ SyscallDesc("nxm_set_cancel", unimplementedFunc),
1674 /* 46 */ SyscallDesc("nxm_set_binding", unimplementedFunc),
1675 /* 47 */ SyscallDesc("stack_create", stack_createFunc),
1676 /* 48 */ SyscallDesc("nxm_get_state", unimplementedFunc),
1677 /* 49 */ SyscallDesc("nxm_thread_suspend", unimplementedFunc),
1678 /* 50 */ SyscallDesc("nxm_thread_resume", unimplementedFunc),
1679 /* 51 */ SyscallDesc("nxm_signal_check", unimplementedFunc),
1680 /* 52 */ SyscallDesc("htg_unix_syscall", unimplementedFunc),
1681 /* 53 */ SyscallDesc("kern_invalid", unimplementedFunc),
1682 /* 54 */ SyscallDesc("kern_invalid", unimplementedFunc),
1683 /* 55 */ SyscallDesc("host_self", unimplementedFunc),
1684 /* 56 */ SyscallDesc("host_priv_self", unimplementedFunc),
1685 /* 57 */ SyscallDesc("kern_invalid", unimplementedFunc),
1686 /* 58 */ SyscallDesc("kern_invalid", unimplementedFunc),
1687 /* 59 */ SyscallDesc("swtch_pri", swtch_priFunc),
1688 /* 60 */ SyscallDesc("swtch", unimplementedFunc),
1689 /* 61 */ SyscallDesc("thread_switch", unimplementedFunc),
1690 /* 62 */ SyscallDesc("semop_fast", unimplementedFunc),
1691 /* 63 */ SyscallDesc("nxm_pshared_init", unimplementedFunc),
1692 /* 64 */ SyscallDesc("nxm_pshared_block", unimplementedFunc),
1693 /* 65 */ SyscallDesc("nxm_pshared_unblock", unimplementedFunc),
1694 /* 66 */ SyscallDesc("nxm_pshared_destroy", unimplementedFunc),
1695 /* 67 */ SyscallDesc("nxm_swtch_pri", swtch_priFunc),
1696 /* 68 */ SyscallDesc("lw_syscall", unimplementedFunc),
1697 /* 69 */ SyscallDesc("kern_invalid", unimplementedFunc),
1698 /* 70 */ SyscallDesc("mach_sctimes_0", unimplementedFunc),
1699 /* 71 */ SyscallDesc("mach_sctimes_1", unimplementedFunc),
1700 /* 72 */ SyscallDesc("mach_sctimes_2", unimplementedFunc),
1701 /* 73 */ SyscallDesc("mach_sctimes_3", unimplementedFunc),
1702 /* 74 */ SyscallDesc("mach_sctimes_4", unimplementedFunc),
1703 /* 75 */ SyscallDesc("mach_sctimes_5", unimplementedFunc),
1704 /* 76 */ SyscallDesc("mach_sctimes_6", unimplementedFunc),
1705 /* 77 */ SyscallDesc("mach_sctimes_7", unimplementedFunc),
1706 /* 78 */ SyscallDesc("mach_sctimes_8", unimplementedFunc),
1707 /* 79 */ SyscallDesc("mach_sctimes_9", unimplementedFunc),
1708 /* 80 */ SyscallDesc("mach_sctimes_10", unimplementedFunc),
1709 /* 81 */ SyscallDesc("mach_sctimes_11", unimplementedFunc),
1710 /* 82 */ SyscallDesc("mach_sctimes_port_alloc_dealloc", unimplementedFunc)
1711 };
1712
1713 const int Tru64::Num_Mach_Syscall_Descs =
1714 sizeof(Tru64::machSyscallDescs) / sizeof(SyscallDesc);
1715 const int Tru64::Max_Mach_Syscall_Desc = Tru64::Num_Mach_Syscall_Descs - 1;
1716 const int Tru64::Min_Syscall_Desc = -Tru64::Max_Mach_Syscall_Desc;
1717
1718
1719 void
1720 AlphaTru64Process::syscall(ExecContext *xc)
1721 {
1722 num_syscalls++;
1723
1724 int64_t callnum = xc->regs.intRegFile[ReturnValueReg];
1725
1726 Tru64::doSyscall(callnum, this, xc);
1727 }
1728
1729
1730 AlphaTru64Process::AlphaTru64Process(const std::string &name,
1731 ObjectFile *objFile,
1732 int stdin_fd,
1733 int stdout_fd,
1734 int stderr_fd,
1735 std::vector<std::string> &argv,
1736 std::vector<std::string> &envp)
1737 : LiveProcess(name, objFile, stdin_fd, stdout_fd, stderr_fd, argv, envp)
1738 {
1739 }