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