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