forked from arjunjm/SimpleScalar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyscall.c
3520 lines (3119 loc) · 94.9 KB
/
syscall.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* syscall.c - proxy system call handler routines */
/* SimpleScalar(TM) Tool Suite
* Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC.
* All Rights Reserved.
*
* THIS IS A LEGAL DOCUMENT, BY USING SIMPLESCALAR,
* YOU ARE AGREEING TO THESE TERMS AND CONDITIONS.
*
* No portion of this work may be used by any commercial entity, or for any
* commercial purpose, without the prior, written permission of SimpleScalar,
* LLC (info@simplescalar.com). Nonprofit and noncommercial use is permitted
* as described below.
*
* 1. SimpleScalar is provided AS IS, with no warranty of any kind, express
* or implied. The user of the program accepts full responsibility for the
* application of the program and the use of any results.
*
* 2. Nonprofit and noncommercial use is encouraged. SimpleScalar may be
* downloaded, compiled, executed, copied, and modified solely for nonprofit,
* educational, noncommercial research, and noncommercial scholarship
* purposes provided that this notice in its entirety accompanies all copies.
* Copies of the modified software can be delivered to persons who use it
* solely for nonprofit, educational, noncommercial research, and
* noncommercial scholarship purposes provided that this notice in its
* entirety accompanies all copies.
*
* 3. ALL COMMERCIAL USE, AND ALL USE BY FOR PROFIT ENTITIES, IS EXPRESSLY
* PROHIBITED WITHOUT A LICENSE FROM SIMPLESCALAR, LLC (info@simplescalar.com).
*
* 4. No nonprofit user may place any restrictions on the use of this software,
* including as modified by the user, by any other authorized user.
*
* 5. Noncommercial and nonprofit users may distribute copies of SimpleScalar
* in compiled or executable form as set forth in Section 2, provided that
* either: (A) it is accompanied by the corresponding machine-readable source
* code, or (B) it is accompanied by a written offer, with no time limit, to
* give anyone a machine-readable copy of the corresponding source code in
* return for reimbursement of the cost of distribution. This written offer
* must permit verbatim duplication by anyone, or (C) it is distributed by
* someone who received only the executable form, and is accompanied by a
* copy of the written offer of source code.
*
* 6. SimpleScalar was developed by Todd M. Austin, Ph.D. The tool suite is
* currently maintained by SimpleScalar LLC (info@simplescalar.com). US Mail:
* 2395 Timbercrest Court, Ann Arbor, MI 48105.
*
* Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC.
*/
#include <stdio.h>
#include <stdlib.h>
/* only enable a minimal set of systen call proxies if on limited
hosts or if in cross endian live execution mode */
#ifndef MIN_SYSCALL_MODE
#if defined(_MSC_VER) || defined(__CYGWIN32__) || defined(MD_CROSS_ENDIAN)
#define MIN_SYSCALL_MODE
#endif
#endif /* !MIN_SYSCALL_MODE */
/* live execution only support on same-endian hosts... */
#ifdef _MSC_VER
#include <io.h>
#else /* !_MSC_VER */
#include <unistd.h>
#endif
#include <fcntl.h>
#include <sys/types.h>
#ifndef _MSC_VER
#include <sys/param.h>
#endif
#include <errno.h>
#include <time.h>
#ifndef _MSC_VER
#include <sys/time.h>
#endif
#ifndef _MSC_VER
#include <sys/resource.h>
#endif
#include <signal.h>
#ifndef _MSC_VER
#include <sys/file.h>
#endif
#include <sys/stat.h>
#ifndef _MSC_VER
#include <sys/uio.h>
#endif
#include <setjmp.h>
#ifndef _MSC_VER
#include <sys/times.h>
#endif
#include <limits.h>
#ifndef _MSC_VER
#include <sys/ioctl.h>
#endif
#if defined(__FreeBSD__)
#include <utime.h>
#include <dirent.h>
#endif
#if defined(linux)
#include <utime.h>
#include <dirent.h>
#include <sys/vfs.h>
#endif
#if defined(_AIX)
#include <sys/statfs.h>
#else /* !_AIX */
#ifndef _MSC_VER
#include <sys/mount.h>
#endif
#endif /* !_AIX */
#if !defined(linux) && !defined(sparc) && !defined(hpux) && !defined(__hpux) && !defined(__CYGWIN32__) && !defined(ultrix)
#ifndef _MSC_VER
#include <sys/select.h>
#endif
#endif
#ifdef linux
#include <sgtty.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/in.h>
#endif /* linux */
#ifdef __FreeBSD__
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/in.h>
#endif /* __FreeBSD__ */
#if defined(__svr4__)
#include <sys/dirent.h>
#include <sys/filio.h>
#elif defined(__osf__)
#include <dirent.h>
/* -- For some weird reason, getdirentries() is not declared in any
* -- header file under /usr/include on the Alpha boxen that I tried
* -- SS-Alpha on. But the function exists in the libraries.
*/
int getdirentries(int fd, char *buf, int nbytes, long *basep);
#endif
#if defined(__svr4__) || defined(__osf__)
#include <sys/statvfs.h>
#define statfs statvfs
#include <sys/time.h>
#include <utime.h>
#include <sgtty.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#if defined(sparc) && defined(__unix__)
#if defined(__svr4__) || defined(__USLC__)
#include <dirent.h>
#else
#include <sys/dir.h>
#endif
/* dorks */
#undef NL0
#undef NL1
#undef CR0
#undef CR1
#undef CR2
#undef CR3
#undef TAB0
#undef TAB1
#undef TAB2
#undef XTABS
#undef BS0
#undef BS1
#undef FF0
#undef FF1
#undef ECHO
#undef NOFLSH
#undef TOSTOP
#undef FLUSHO
#undef PENDIN
#endif
#if defined(hpux) || defined(__hpux)
#undef CR0
#endif
#ifdef __FreeBSD__
#include <termios.h>
/*#include <sys/ioctl_compat.h>*/
#else
#ifndef _MSC_VER
#include <termio.h>
#endif
#endif
#if defined(hpux) || defined(__hpux)
/* et tu, dorks! */
#undef HUPCL
#undef ECHO
#undef B50
#undef B75
#undef B110
#undef B134
#undef B150
#undef B200
#undef B300
#undef B600
#undef B1200
#undef B1800
#undef B2400
#undef B4800
#undef B9600
#undef B19200
#undef B38400
#undef NL0
#undef NL1
#undef CR0
#undef CR1
#undef CR2
#undef CR3
#undef TAB0
#undef TAB1
#undef BS0
#undef BS1
#undef FF0
#undef FF1
#undef EXTA
#undef EXTB
#undef B900
#undef B3600
#undef B7200
#undef XTABS
#include <sgtty.h>
#include <utime.h>
#endif
#include <sys/socket.h>
#include <sys/poll.h>
#ifdef _MSC_VER
#define access _access
#define chmod _chmod
#define chdir _chdir
#define unlink _unlink
#define open _open
#define creat _creat
#define pipe _pipe
#define dup _dup
#define dup2 _dup2
#define stat _stat
#define fstat _fstat
#define lseek _lseek
#define read _read
#define write _write
#define close _close
#define getpid _getpid
#define utime _utime
#include <sys/utime.h>
#endif /* _MSC_VER */
#include "host.h"
#include "misc.h"
#include "machine.h"
#include "regs.h"
#include "memory.h"
#include "loader.h"
#include "sim.h"
#include "endian.h"
#include "eio.h"
#include "syscall.h"
#define OSF_SYS_syscall 0
/* OSF_SYS_exit moved to alpha.h */
#define OSF_SYS_fork 2
#define OSF_SYS_read 3
/* OSF_SYS_write moved to alpha.h */
#define OSF_SYS_old_open 5 /* 5 is old open */
#define OSF_SYS_close 6
#define OSF_SYS_wait4 7
#define OSF_SYS_old_creat 8 /* 8 is old creat */
#define OSF_SYS_link 9
#define OSF_SYS_unlink 10
#define OSF_SYS_execv 11
#define OSF_SYS_chdir 12
#define OSF_SYS_fchdir 13
#define OSF_SYS_mknod 14
#define OSF_SYS_chmod 15
#define OSF_SYS_chown 16
#define OSF_SYS_obreak 17
#define OSF_SYS_getfsstat 18
#define OSF_SYS_lseek 19
#define OSF_SYS_getpid 20
#define OSF_SYS_mount 21
#define OSF_SYS_unmount 22
#define OSF_SYS_setuid 23
#define OSF_SYS_getuid 24
#define OSF_SYS_exec_with_loader 25
#define OSF_SYS_ptrace 26
#ifdef COMPAT_43
#define OSF_SYS_nrecvmsg 27
#define OSF_SYS_nsendmsg 28
#define OSF_SYS_nrecvfrom 29
#define OSF_SYS_naccept 30
#define OSF_SYS_ngetpeername 31
#define OSF_SYS_ngetsockname 32
#else
#define OSF_SYS_recvmsg 27
#define OSF_SYS_sendmsg 28
#define OSF_SYS_recvfrom 29
#define OSF_SYS_accept 30
#define OSF_SYS_getpeername 31
#define OSF_SYS_getsockname 32
#endif
#define OSF_SYS_access 33
#define OSF_SYS_chflags 34
#define OSF_SYS_fchflags 35
#define OSF_SYS_sync 36
#define OSF_SYS_kill 37
#define OSF_SYS_old_stat 38 /* 38 is old stat */
#define OSF_SYS_setpgid 39
#define OSF_SYS_old_lstat 40 /* 40 is old lstat */
#define OSF_SYS_dup 41
#define OSF_SYS_pipe 42
#define OSF_SYS_set_program_attributes 43
#define OSF_SYS_profil 44
#define OSF_SYS_open 45
/* 46 is obsolete osigaction */
#define OSF_SYS_getgid 47
#define OSF_SYS_sigprocmask 48
#define OSF_SYS_getlogin 49
#define OSF_SYS_setlogin 50
#define OSF_SYS_acct 51
#define OSF_SYS_sigpending 52
#define OSF_SYS_ioctl 54
#define OSF_SYS_reboot 55
#define OSF_SYS_revoke 56
#define OSF_SYS_symlink 57
#define OSF_SYS_readlink 58
#define OSF_SYS_execve 59
#define OSF_SYS_umask 60
#define OSF_SYS_chroot 61
#define OSF_SYS_old_fstat 62 /* 62 is old fstat */
#define OSF_SYS_getpgrp 63
#define OSF_SYS_getpagesize 64
#define OSF_SYS_mremap 65
#define OSF_SYS_vfork 66
#define OSF_SYS_stat 67
#define OSF_SYS_lstat 68
#define OSF_SYS_sbrk 69
#define OSF_SYS_sstk 70
#define OSF_SYS_mmap 71
#define OSF_SYS_ovadvise 72
#define OSF_SYS_munmap 73
#define OSF_SYS_mprotect 74
#define OSF_SYS_madvise 75
#define OSF_SYS_old_vhangup 76 /* 76 is old vhangup */
#define OSF_SYS_kmodcall 77
#define OSF_SYS_mincore 78
#define OSF_SYS_getgroups 79
#define OSF_SYS_setgroups 80
#define OSF_SYS_old_getpgrp 81 /* 81 is old getpgrp */
#define OSF_SYS_setpgrp 82
#define OSF_SYS_setitimer 83
#define OSF_SYS_old_wait 84 /* 84 is old wait */
#define OSF_SYS_table 85
#define OSF_SYS_getitimer 86
#define OSF_SYS_gethostname 87
#define OSF_SYS_sethostname 88
#define OSF_SYS_getdtablesize 89
#define OSF_SYS_dup2 90
#define OSF_SYS_fstat 91
#define OSF_SYS_fcntl 92
#define OSF_SYS_select 93
#define OSF_SYS_poll 94
#define OSF_SYS_fsync 95
#define OSF_SYS_setpriority 96
#define OSF_SYS_socket 97
#define OSF_SYS_connect 98
#ifdef COMPAT_43
#define OSF_SYS_accept 99
#else
#define OSF_SYS_old_accept 99 /* 99 is old accept */
#endif
#define OSF_SYS_getpriority 100
#ifdef COMPAT_43
#define OSF_SYS_send 101
#define OSF_SYS_recv 102
#else
#define OSF_SYS_old_send 101 /* 101 is old send */
#define OSF_SYS_old_recv 102 /* 102 is old recv */
#endif
#define OSF_SYS_sigreturn 103
#define OSF_SYS_bind 104
#define OSF_SYS_setsockopt 105
#define OSF_SYS_listen 106
#define OSF_SYS_plock 107
#define OSF_SYS_old_sigvec 108 /* 108 is old sigvec */
#define OSF_SYS_old_sigblock 109 /* 109 is old sigblock */
#define OSF_SYS_old_sigsetmask 110 /* 110 is old sigsetmask */
#define OSF_SYS_sigsuspend 111
#define OSF_SYS_sigstack 112
#ifdef COMPAT_43
#define OSF_SYS_recvmsg 113
#define OSF_SYS_sendmsg 114
#else
#define OSF_SYS_old_recvmsg 113 /* 113 is old recvmsg */
#define OSF_SYS_old_sendmsg 114 /* 114 is old sendmsg */
#endif
/* 115 is obsolete vtrace */
#define OSF_SYS_gettimeofday 116
#define OSF_SYS_getrusage 117
#define OSF_SYS_getsockopt 118
#define OSF_SYS_readv 120
#define OSF_SYS_writev 121
#define OSF_SYS_settimeofday 122
#define OSF_SYS_fchown 123
#define OSF_SYS_fchmod 124
#ifdef COMPAT_43
#define OSF_SYS_recvfrom 125
#else
#define OSF_SYS_old_recvfrom 125 /* 125 is old recvfrom */
#endif
#define OSF_SYS_setreuid 126
#define OSF_SYS_setregid 127
#define OSF_SYS_rename 128
#define OSF_SYS_truncate 129
#define OSF_SYS_ftruncate 130
#define OSF_SYS_flock 131
#define OSF_SYS_setgid 132
#define OSF_SYS_sendto 133
#define OSF_SYS_shutdown 134
#define OSF_SYS_socketpair 135
#define OSF_SYS_mkdir 136
#define OSF_SYS_rmdir 137
#define OSF_SYS_utimes 138
/* 139 is obsolete 4.2 sigreturn */
#define OSF_SYS_adjtime 140
#ifdef COMPAT_43
#define OSF_SYS_getpeername 141
#else
#define OSF_SYS_old_getpeername 141 /* 141 is old getpeername */
#endif
#define OSF_SYS_gethostid 142
#define OSF_SYS_sethostid 143
#define OSF_SYS_getrlimit 144
#define OSF_SYS_setrlimit 145
#define OSF_SYS_old_killpg 146 /* 146 is old killpg */
#define OSF_SYS_setsid 147
#define OSF_SYS_quotactl 148
#define OSF_SYS_oldquota 149
#ifdef COMPAT_43
#define OSF_SYS_getsockname 150
#else
#define OSF_SYS_old_getsockname 150 /* 150 is old getsockname */
#endif
#define OSF_SYS_pid_block 153
#define OSF_SYS_pid_unblock 154
#define OSF_SYS_sigaction 156
#define OSF_SYS_sigwaitprim 157
#define OSF_SYS_nfssvc 158
#define OSF_SYS_getdirentries 159
#define OSF_SYS_statfs 160
#define OSF_SYS_fstatfs 161
#define OSF_SYS_async_daemon 163
#define OSF_SYS_getfh 164
#define OSF_SYS_getdomainname 165
#define OSF_SYS_setdomainname 166
#define OSF_SYS_exportfs 169
#define OSF_SYS_alt_plock 181 /* 181 is alternate plock */
#define OSF_SYS_getmnt 184
#define OSF_SYS_alt_sigpending 187 /* 187 is alternate sigpending */
#define OSF_SYS_alt_setsid 188 /* 188 is alternate setsid */
#define OSF_SYS_swapon 199
#define OSF_SYS_msgctl 200
#define OSF_SYS_msgget 201
#define OSF_SYS_msgrcv 202
#define OSF_SYS_msgsnd 203
#define OSF_SYS_semctl 204
#define OSF_SYS_semget 205
#define OSF_SYS_semop 206
#define OSF_SYS_uname 207
#define OSF_SYS_lchown 208
#define OSF_SYS_shmat 209
#define OSF_SYS_shmctl 210
#define OSF_SYS_shmdt 211
#define OSF_SYS_shmget 212
#define OSF_SYS_mvalid 213
#define OSF_SYS_getaddressconf 214
#define OSF_SYS_msleep 215
#define OSF_SYS_mwakeup 216
#define OSF_SYS_msync 217
#define OSF_SYS_signal 218
#define OSF_SYS_utc_gettime 219
#define OSF_SYS_utc_adjtime 220
#define OSF_SYS_security 222
#define OSF_SYS_kloadcall 223
#define OSF_SYS_getpgid 233
#define OSF_SYS_getsid 234
#define OSF_SYS_sigaltstack 235
#define OSF_SYS_waitid 236
#define OSF_SYS_priocntlset 237
#define OSF_SYS_sigsendset 238
#define OSF_SYS_set_speculative 239
#define OSF_SYS_msfs_syscall 240
#define OSF_SYS_sysinfo 241
#define OSF_SYS_uadmin 242
#define OSF_SYS_fuser 243
#define OSF_SYS_proplist_syscall 244
#define OSF_SYS_ntp_adjtime 245
#define OSF_SYS_ntp_gettime 246
#define OSF_SYS_pathconf 247
#define OSF_SYS_fpathconf 248
#define OSF_SYS_uswitch 250
#define OSF_SYS_usleep_thread 251
#define OSF_SYS_audcntl 252
#define OSF_SYS_audgen 253
#define OSF_SYS_sysfs 254
#define OSF_SYS_subOSF_SYS_info 255
#define OSF_SYS_getsysinfo 256
#define OSF_SYS_setsysinfo 257
#define OSF_SYS_afs_syscall 258
#define OSF_SYS_swapctl 259
#define OSF_SYS_memcntl 260
#define OSF_SYS_fdatasync 261
/* translate system call arguments */
struct xlate_table_t
{
int target_val;
int host_val;
};
int
xlate_arg(int target_val, struct xlate_table_t *map, int map_sz, char *name)
{
int i;
for (i=0; i < map_sz; i++)
{
if (target_val == map[i].target_val)
return map[i].host_val;
}
/* not found, issue warning and return target_val */
warn("could not translate argument for `%s': %d", name, target_val);
return target_val;
}
/* internal system call buffer size, used primarily for file name arguments,
argument larger than this will be truncated */
#define MAXBUFSIZE 1024
/* total bytes to copy from a valid pointer argument for ioctl() calls,
syscall.c does not decode ioctl() calls to determine the size of the
arguments that reside in memory, instead, the ioctl() proxy simply copies
NUM_IOCTL_BYTES bytes from the pointer argument to host memory */
#define NUM_IOCTL_BYTES 128
/* OSF ioctl() requests */
#define OSF_TIOCGETP 0x40067408
#define OSF_FIONREAD 0x4004667f
/* target stat() buffer definition, the host stat buffer format is
automagically mapped to/from this format in syscall.c */
struct osf_statbuf
{
word_t osf_st_dev;
word_t osf_st_ino;
word_t osf_st_mode;
half_t osf_st_nlink;
half_t pad0; /* to match Alpha/AXP padding... */
word_t osf_st_uid;
word_t osf_st_gid;
word_t osf_st_rdev;
word_t pad1; /* to match Alpha/AXP padding... */
qword_t osf_st_size;
word_t osf_st_atime;
word_t osf_st_spare1;
word_t osf_st_mtime;
word_t osf_st_spare2;
word_t osf_st_ctime;
word_t osf_st_spare3;
word_t osf_st_blksize;
word_t osf_st_blocks;
word_t osf_st_gennum;
word_t osf_st_spare4;
};
struct osf_sgttyb {
byte_t sg_ispeed; /* input speed */
byte_t sg_ospeed; /* output speed */
byte_t sg_erase; /* erase character */
byte_t sg_kill; /* kill character */
shalf_t sg_flags; /* mode flags */
};
#define OSF_NSIG 32
#define OSF_SIG_BLOCK 1
#define OSF_SIG_UNBLOCK 2
#define OSF_SIG_SETMASK 3
struct osf_sigcontext {
qword_t sc_onstack; /* sigstack state to restore */
qword_t sc_mask; /* signal mask to restore */
qword_t sc_pc; /* pc at time of signal */
qword_t sc_ps; /* psl to retore */
qword_t sc_regs[32]; /* processor regs 0 to 31 */
qword_t sc_ownedfp; /* fp has been used */
qword_t sc_fpregs[32]; /* fp regs 0 to 31 */
qword_t sc_fpcr; /* floating point control register */
qword_t sc_fp_control; /* software fpcr */
};
struct osf_statfs {
shalf_t f_type; /* type of filesystem (see below) */
shalf_t f_flags; /* copy of mount flags */
word_t f_fsize; /* fundamental filesystem block size */
word_t f_bsize; /* optimal transfer block size */
word_t f_blocks; /* total data blocks in file system, */
/* note: may not represent fs size. */
word_t f_bfree; /* free blocks in fs */
word_t f_bavail; /* free blocks avail to non-su */
word_t f_files; /* total file nodes in file system */
word_t f_ffree; /* free file nodes in fs */
qword_t f_fsid; /* file system id */
word_t f_spare[9]; /* spare for later */
};
struct osf_timeval
{
sword_t osf_tv_sec; /* seconds */
sword_t osf_tv_usec; /* microseconds */
};
struct osf_timezone
{
sword_t osf_tz_minuteswest; /* minutes west of Greenwich */
sword_t osf_tz_dsttime; /* type of dst correction */
};
/* target getrusage() buffer definition, the host stat buffer format is
automagically mapped to/from this format in syscall.c */
struct osf_rusage
{
struct osf_timeval osf_ru_utime;
struct osf_timeval osf_ru_stime;
sword_t osf_ru_maxrss;
sword_t osf_ru_ixrss;
sword_t osf_ru_idrss;
sword_t osf_ru_isrss;
sword_t osf_ru_minflt;
sword_t osf_ru_majflt;
sword_t osf_ru_nswap;
sword_t osf_ru_inblock;
sword_t osf_ru_oublock;
sword_t osf_ru_msgsnd;
sword_t osf_ru_msgrcv;
sword_t osf_ru_nsignals;
sword_t osf_ru_nvcsw;
sword_t osf_ru_nivcsw;
};
struct osf_rlimit
{
qword_t osf_rlim_cur; /* current (soft) limit */
qword_t osf_rlim_max; /* maximum value for rlim_cur */
};
struct osf_sockaddr
{
half_t sa_family; /* address family, AF_xxx */
byte_t sa_data[24]; /* 14 bytes of protocol address */
};
struct osf_iovec
{
md_addr_t iov_base; /* starting address */
word_t iov_len; /* length in bytes */
word_t pad;
};
/* returns size of DIRENT structure */
#define OSF_DIRENT_SZ(STR) \
(sizeof(word_t) + 2*sizeof(half_t) + (((strlen(STR) + 1) + 3)/4)*4)
/* was: (sizeof(word_t) + 2*sizeof(half_t) + strlen(STR) + 1) */
struct osf_dirent
{
word_t d_ino; /* file number of entry */
half_t d_reclen; /* length of this record */
half_t d_namlen; /* length of string in d_name */
char d_name[256]; /* DUMMY NAME LENGTH */
/* the real maximum length is */
/* returned by pathconf() */
/* At this time, this MUST */
/* be 256 -- the kernel */
/* requires it */
};
/* open(2) flags for Alpha/AXP OSF target, syscall.c automagically maps
between these codes to/from host open(2) flags */
#define OSF_O_RDONLY 0x0000
#define OSF_O_WRONLY 0x0001
#define OSF_O_RDWR 0x0002
#define OSF_O_NONBLOCK 0x0004
#define OSF_O_APPEND 0x0008
#define OSF_O_CREAT 0x0200
#define OSF_O_TRUNC 0x0400
#define OSF_O_EXCL 0x0800
#define OSF_O_NOCTTY 0x1000
#define OSF_O_SYNC 0x4000
/* open(2) flags translation table for SimpleScalar target */
struct {
int osf_flag;
int local_flag;
} osf_flag_table[] = {
/* target flag */ /* host flag */
#ifdef _MSC_VER
{ OSF_O_RDONLY, _O_RDONLY },
{ OSF_O_WRONLY, _O_WRONLY },
{ OSF_O_RDWR, _O_RDWR },
{ OSF_O_APPEND, _O_APPEND },
{ OSF_O_CREAT, _O_CREAT },
{ OSF_O_TRUNC, _O_TRUNC },
{ OSF_O_EXCL, _O_EXCL },
#ifdef _O_NONBLOCK
{ OSF_O_NONBLOCK, _O_NONBLOCK },
#endif
#ifdef _O_NOCTTY
{ OSF_O_NOCTTY, _O_NOCTTY },
#endif
#ifdef _O_SYNC
{ OSF_O_SYNC, _O_SYNC },
#endif
#else /* !_MSC_VER */
{ OSF_O_RDONLY, O_RDONLY },
{ OSF_O_WRONLY, O_WRONLY },
{ OSF_O_RDWR, O_RDWR },
{ OSF_O_APPEND, O_APPEND },
{ OSF_O_CREAT, O_CREAT },
{ OSF_O_TRUNC, O_TRUNC },
{ OSF_O_EXCL, O_EXCL },
{ OSF_O_NONBLOCK, O_NONBLOCK },
{ OSF_O_NOCTTY, O_NOCTTY },
#ifdef O_SYNC
{ OSF_O_SYNC, O_SYNC },
#endif
#endif /* _MSC_VER */
};
#define OSF_NFLAGS (sizeof(osf_flag_table)/sizeof(osf_flag_table[0]))
qword_t sigmask = 0;
qword_t sigaction_array[OSF_NSIG] =
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
/* setsockopt option names */
#define OSF_SO_DEBUG 0x0001
#define OSF_SO_ACCEPTCONN 0x0002
#define OSF_SO_REUSEADDR 0x0004
#define OSF_SO_KEEPALIVE 0x0008
#define OSF_SO_DONTROUTE 0x0010
#define OSF_SO_BROADCAST 0x0020
#define OSF_SO_USELOOPBACK 0x0040
#define OSF_SO_LINGER 0x0080
#define OSF_SO_OOBINLINE 0x0100
#define OSF_SO_REUSEPORT 0x0200
struct xlate_table_t sockopt_map[] =
{
{ OSF_SO_DEBUG, SO_DEBUG },
#ifdef SO_ACCEPTCONN
{ OSF_SO_ACCEPTCONN, SO_ACCEPTCONN },
#endif
{ OSF_SO_REUSEADDR, SO_REUSEADDR },
{ OSF_SO_KEEPALIVE, SO_KEEPALIVE },
{ OSF_SO_DONTROUTE, SO_DONTROUTE },
{ OSF_SO_BROADCAST, SO_BROADCAST },
#ifdef SO_USELOOPBACK
{ OSF_SO_USELOOPBACK, SO_USELOOPBACK },
#endif
{ OSF_SO_LINGER, SO_LINGER },
{ OSF_SO_OOBINLINE, SO_OOBINLINE },
#ifdef SO_REUSEPORT
{ OSF_SO_REUSEPORT, SO_REUSEPORT }
#endif
};
/* setsockopt TCP options */
#define OSF_TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
#define OSF_TCP_MAXSEG 0x02 /* maximum segment size */
#define OSF_TCP_RPTR2RXT 0x03 /* set repeat count for R2 RXT timer */
#define OSF_TCP_KEEPIDLE 0x04 /* secs before initial keepalive probe */
#define OSF_TCP_KEEPINTVL 0x05 /* seconds between keepalive probes */
#define OSF_TCP_KEEPCNT 0x06 /* num of keepalive probes before drop */
#define OSF_TCP_KEEPINIT 0x07 /* initial connect timeout (seconds) */
#define OSF_TCP_PUSH 0x08 /* set push bit in outbnd data packets */
#define OSF_TCP_NODELACK 0x09 /* don't delay send to coalesce packets */
struct xlate_table_t tcpopt_map[] =
{
{ OSF_TCP_NODELAY, TCP_NODELAY },
{ OSF_TCP_MAXSEG, TCP_MAXSEG },
#ifdef TCP_RPTR2RXT
{ OSF_TCP_RPTR2RXT, TCP_RPTR2RXT },
#endif
#ifdef TCP_KEEPIDLE
{ OSF_TCP_KEEPIDLE, TCP_KEEPIDLE },
#endif
#ifdef TCP_KEEPINTVL
{ OSF_TCP_KEEPINTVL, TCP_KEEPINTVL },
#endif
#ifdef TCP_KEEPCNT
{ OSF_TCP_KEEPCNT, TCP_KEEPCNT },
#endif
#ifdef TCP_KEEPINIT
{ OSF_TCP_KEEPINIT, TCP_KEEPINIT },
#endif
#ifdef TCP_PUSH
{ OSF_TCP_PUSH, TCP_PUSH },
#endif
#ifdef TCP_NODELACK
{ OSF_TCP_NODELACK, TCP_NODELACK }
#endif
};
/* setsockopt level names */
#define OSF_SOL_SOCKET 0xffff /* options for socket level */
#define OSF_SOL_IP 0 /* dummy for IP */
#define OSF_SOL_TCP 6 /* tcp */
#define OSF_SOL_UDP 17 /* user datagram protocol */
struct xlate_table_t socklevel_map[] =
{
#if defined(__svr4__) || defined(__osf__) || defined(__FreeBSD__)
{ OSF_SOL_SOCKET, SOL_SOCKET },
{ OSF_SOL_IP, IPPROTO_IP },
{ OSF_SOL_TCP, IPPROTO_TCP },
{ OSF_SOL_UDP, IPPROTO_UDP }
#else
{ OSF_SOL_SOCKET, SOL_SOCKET },
{ OSF_SOL_IP, SOL_IP },
{ OSF_SOL_TCP, SOL_TCP },
{ OSF_SOL_UDP, SOL_UDP }
#endif
};
/* socket() address families */
#define OSF_AF_UNSPEC 0
#define OSF_AF_UNIX 1 /* Unix domain sockets */
#define OSF_AF_INET 2 /* internet IP protocol */
#define OSF_AF_IMPLINK 3 /* arpanet imp addresses */
#define OSF_AF_PUP 4 /* pup protocols: e.g. BSP */
#define OSF_AF_CHAOS 5 /* mit CHAOS protocols */
#define OSF_AF_NS 6 /* XEROX NS protocols */
#define OSF_AF_ISO 7 /* ISO protocols */
struct xlate_table_t family_map[] =
{
{ OSF_AF_UNSPEC, AF_UNSPEC },
{ OSF_AF_UNIX, AF_UNIX },
{ OSF_AF_INET, AF_INET },
#ifdef AF_IMPLINK
{ OSF_AF_IMPLINK, AF_IMPLINK },
#endif
#ifdef AF_PUP
{ OSF_AF_PUP, AF_PUP },
#endif
#ifdef AF_CHAOS
{ OSF_AF_CHAOS, AF_CHAOS },
#endif
#ifdef AF_NS
{ OSF_AF_NS, AF_NS },
#endif
#ifdef AF_ISO
{ OSF_AF_ISO, AF_ISO }
#endif
};
/* socket() socket types */
#define OSF_SOCK_STREAM 1 /* stream (connection) socket */
#define OSF_SOCK_DGRAM 2 /* datagram (conn.less) socket */
#define OSF_SOCK_RAW 3 /* raw socket */
#define OSF_SOCK_RDM 4 /* reliably-delivered message */
#define OSF_SOCK_SEQPACKET 5 /* sequential packet socket */
struct xlate_table_t socktype_map[] =
{
{ OSF_SOCK_STREAM, SOCK_STREAM },
{ OSF_SOCK_DGRAM, SOCK_DGRAM },
{ OSF_SOCK_RAW, SOCK_RAW },
{ OSF_SOCK_RDM, SOCK_RDM },
{ OSF_SOCK_SEQPACKET, SOCK_SEQPACKET }
};
/* OSF table() call. Right now, we only support TBL_SYSINFO queries */
#define OSF_TBL_SYSINFO 12
struct osf_tbl_sysinfo
{
long si_user; /* user time */
long si_nice; /* nice time */
long si_sys; /* system time */
long si_idle; /* idle time */
long si_hz;
long si_phz;
long si_boottime; /* boot time in seconds */
long wait; /* wait time */
};
/* OSF SYSCALL -- standard system call sequence
the kernel expects arguments to be passed with the normal C calling
sequence; v0 should contain the system call number; on return from the
kernel mode, a3 will be 0 to indicate no error and non-zero to indicate an
error; if an error occurred v0 will contain an errno; if the kernel return
an error, setup a valid gp and jmp to _cerror */
/* syscall proxy handler, architect registers and memory are assumed to be
precise when this function is called, register and memory are updated with
the results of the sustem call */
void
sys_syscall(struct regs_t *regs, /* registers to access */
mem_access_fn mem_fn, /* generic memory accessor */
struct mem_t *mem, /* memory space to access */
md_inst_t inst, /* system call inst */
int traceable) /* traceable system call? */
{
qword_t syscode = regs->regs_R[MD_REG_V0];
/* fix for syscall() which uses CALL_PAL CALLSYS for making system calls */
if (syscode == OSF_SYS_syscall)
syscode = regs->regs_R[MD_REG_A0];
/* first, check if an EIO trace is being consumed... */
if (traceable && sim_eio_fd != NULL)
{
eio_read_trace(sim_eio_fd, sim_num_insn, regs, mem_fn, mem, inst);
/* kludge fix for sigreturn(), it modifies all registers */
if (syscode == OSF_SYS_sigreturn)
{
int i;
struct osf_sigcontext sc;
md_addr_t sc_addr = regs->regs_R[MD_REG_A0];
mem_bcopy(mem_fn, mem, Read, sc_addr,
&sc, sizeof(struct osf_sigcontext));
regs->regs_NPC = sc.sc_pc;
for (i=0; i < 32; ++i)
regs->regs_R[i] = sc.sc_regs[i];
for (i=0; i < 32; ++i)
regs->regs_F.q[i] = sc.sc_fpregs[i];
regs->regs_C.fpcr = sc.sc_fpcr;
}
/* fini... */
return;
}
/* no, OK execute the live system call... */
switch (syscode)
{
case OSF_SYS_exit:
/* exit jumps to the target set in main() */
longjmp(sim_exit_buf,
/* exitcode + fudge */(regs->regs_R[MD_REG_A0] & 0xff) + 1);
break;
case OSF_SYS_read:
{
char *buf;
/* allocate same-sized input buffer in host memory */
if (!(buf =
(char *)calloc(/*nbytes*/regs->regs_R[MD_REG_A2], sizeof(char))))
fatal("out of memory in SYS_read");
/* read data from file */
do {
/*nread*/regs->regs_R[MD_REG_V0] =
read(/*fd*/regs->regs_R[MD_REG_A0], buf,
/*nbytes*/regs->regs_R[MD_REG_A2]);
} while (/*nread*/regs->regs_R[MD_REG_V0] == -1
&& errno == EAGAIN);
/* check for error condition */
if (regs->regs_R[MD_REG_V0] != (qword_t)-1)
regs->regs_R[MD_REG_A3] = 0;
else /* got an error, return details */
{
regs->regs_R[MD_REG_A3] = -1;
regs->regs_R[MD_REG_V0] = errno;
}
/* copy results back into host memory */
mem_bcopy(mem_fn, mem, Write,
/*buf*/regs->regs_R[MD_REG_A1], buf, /*nread*/regs->regs_R[MD_REG_A2]);