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