public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/6] sim: m32r: namespace Linux syscall table
@ 2021-07-01  4:55 Mike Frysinger
  2021-07-01  4:55 ` [PATCH 2/6] sim: m32r: fix virtual environment with Linux targets Mike Frysinger
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Mike Frysinger @ 2021-07-01  4:55 UTC (permalink / raw)
  To: gdb-patches

The use of __NR_ defines in here conflicts a lot with the standard
host syscalls, sometimes leading to build errors (when the numbers
happen to be the same we get duplicate case handlers), and other
times leading to misbehavior (where the m32r syscall # is not what
is actually checked).

Namespace these using the standard that we already use: change the
__NR_ to TARGET_LINUX_SYS_ with a simple `sed`.

Also add a few missing includes so the code at least compiles.
---
 sim/m32r/syscall.h     | 546 ++++++++++++++++++++---------------------
 sim/m32r/traps-linux.c | 196 +++++++--------
 2 files changed, 372 insertions(+), 370 deletions(-)

diff --git a/sim/m32r/syscall.h b/sim/m32r/syscall.h
index 3f4252a8089f..8f0bf8d53268 100644
--- a/sim/m32r/syscall.h
+++ b/sim/m32r/syscall.h
@@ -2,280 +2,280 @@
  * This file contains the system call numbers.
  */
 
-#define __NR_exit		  1
-#define __NR_fork		  2
-#define __NR_read		  3
-#define __NR_write		  4
-#define __NR_open		  5
-#define __NR_close		  6
-#define __NR_waitpid		  7
-#define __NR_creat		  8
-#define __NR_link		  9
-#define __NR_unlink		 10
-#define __NR_execve		 11
-#define __NR_chdir		 12
-#define __NR_time		 13
-#define __NR_mknod		 14
-#define __NR_chmod		 15
-#define __NR_lchown		 16
-#define __NR_break		 17
-#define __NR_oldstat		 18
-#define __NR_lseek		 19
-#define __NR_getpid		 20
-#define __NR_mount		 21
-#define __NR_umount		 22
-#define __NR_setuid		 23
-#define __NR_getuid		 24
-#define __NR_stime		 25
-#define __NR_ptrace		 26
-#define __NR_alarm		 27
-#define __NR_oldfstat		 28
-#define __NR_pause		 29
-#define __NR_utime		 30
-#define __NR_stty		 31
-#define __NR_gtty		 32
-#define __NR_access		 33
-#define __NR_nice		 34
-#define __NR_ftime		 35
-#define __NR_sync		 36
-#define __NR_kill		 37
-#define __NR_rename		 38
-#define __NR_mkdir		 39
-#define __NR_rmdir		 40
-#define __NR_dup		 41
-#define __NR_pipe		 42
-#define __NR_times		 43
-#define __NR_prof		 44
-#define __NR_brk		 45
-#define __NR_setgid		 46
-#define __NR_getgid		 47
-#define __NR_signal		 48
-#define __NR_geteuid		 49
-#define __NR_getegid		 50
-#define __NR_acct		 51
-#define __NR_umount2		 52
-#define __NR_lock		 53
-#define __NR_ioctl		 54
-#define __NR_fcntl		 55
-#define __NR_mpx		 56
-#define __NR_setpgid		 57
-#define __NR_ulimit		 58
-#define __NR_oldolduname	 59
-#define __NR_umask		 60
-#define __NR_chroot		 61
-#define __NR_ustat		 62
-#define __NR_dup2		 63
-#define __NR_getppid		 64
-#define __NR_getpgrp		 65
-#define __NR_setsid		 66
-#define __NR_sigaction		 67
-#define __NR_sgetmask		 68
-#define __NR_ssetmask		 69
-#define __NR_setreuid		 70
-#define __NR_setregid		 71
-#define __NR_sigsuspend		 72
-#define __NR_sigpending		 73
-#define __NR_sethostname	 74
-#define __NR_setrlimit		 75
-#define __NR_getrlimit		 76
-#define __NR_getrusage		 77
-#define __NR_gettimeofday	 78
-#define __NR_settimeofday	 79
-#define __NR_getgroups		 80
-#define __NR_setgroups		 81
-#define __NR_select		 82
-#define __NR_symlink		 83
-#define __NR_oldlstat		 84
-#define __NR_readlink		 85
-#define __NR_uselib		 86
-#define __NR_swapon		 87
-#define __NR_reboot		 88
-#define __NR_readdir		 89
-#define __NR_mmap		 90
-#define __NR_munmap		 91
-#define __NR_truncate		 92
-#define __NR_ftruncate		 93
-#define __NR_fchmod		 94
-#define __NR_fchown		 95
-#define __NR_getpriority	 96
-#define __NR_setpriority	 97
-#define __NR_profil		 98
-#define __NR_statfs		 99
-#define __NR_fstatfs		100
-#define __NR_ioperm		101
-#define __NR_socketcall		102
-#define __NR_syslog		103
-#define __NR_setitimer		104
-#define __NR_getitimer		105
-#define __NR_stat		106
-#define __NR_lstat		107
-#define __NR_fstat		108
-#define __NR_olduname		109
-#define __NR_iopl		110
-#define __NR_vhangup		111
-#define __NR_idle		112
-#define __NR_vm86old		113
-#define __NR_wait4		114
-#define __NR_swapoff		115
-#define __NR_sysinfo		116
-#define __NR_ipc		117
-#define __NR_fsync		118
-#define __NR_sigreturn		119
-#define __NR_clone		120
-#define __NR_setdomainname	121
-#define __NR_uname		122
-#define __NR_modify_ldt		123
-#define __NR_adjtimex		124
-#define __NR_mprotect		125
-#define __NR_sigprocmask	126
-#define __NR_create_module	127
-#define __NR_init_module	128
-#define __NR_delete_module	129
-#define __NR_get_kernel_syms	130
-#define __NR_quotactl		131
-#define __NR_getpgid		132
-#define __NR_fchdir		133
-#define __NR_bdflush		134
-#define __NR_sysfs		135
-#define __NR_personality	136
-#define __NR_afs_syscall	137 /* Syscall for Andrew File System */
-#define __NR_setfsuid		138
-#define __NR_setfsgid		139
-#define __NR__llseek		140
-#define __NR_getdents		141
-#define __NR__newselect		142
-#define __NR_flock		143
-#define __NR_msync		144
-#define __NR_readv		145
-#define __NR_writev		146
-#define __NR_getsid		147
-#define __NR_fdatasync		148
-#define __NR__sysctl		149
-#define __NR_mlock		150
-#define __NR_munlock		151
-#define __NR_mlockall		152
-#define __NR_munlockall		153
-#define __NR_sched_setparam		154
-#define __NR_sched_getparam		155
-#define __NR_sched_setscheduler		156
-#define __NR_sched_getscheduler		157
-#define __NR_sched_yield		158
-#define __NR_sched_get_priority_max	159
-#define __NR_sched_get_priority_min	160
-#define __NR_sched_rr_get_interval	161
-#define __NR_nanosleep		162
-#define __NR_mremap		163
-#define __NR_setresuid		164
-#define __NR_getresuid		165
-#define __NR_vm86		166
-#define __NR_query_module	167
-#define __NR_poll		168
-#define __NR_nfsservctl		169
-#define __NR_setresgid		170
-#define __NR_getresgid		171
-#define __NR_prctl              172
-#define __NR_rt_sigreturn	173
-#define __NR_rt_sigaction	174
-#define __NR_rt_sigprocmask	175
-#define __NR_rt_sigpending	176
-#define __NR_rt_sigtimedwait	177
-#define __NR_rt_sigqueueinfo	178
-#define __NR_rt_sigsuspend	179
-#define __NR_pread		180
-#define __NR_pwrite		181
-#define __NR_chown		182
-#define __NR_getcwd		183
-#define __NR_capget		184
-#define __NR_capset		185
-#define __NR_sigaltstack	186
-#define __NR_sendfile		187
-#define __NR_getpmsg		188	/* some people actually want streams */
-#define __NR_putpmsg		189	/* some people actually want streams */
-#define __NR_vfork		190
+#define TARGET_LINUX_SYS_exit		  1
+#define TARGET_LINUX_SYS_fork		  2
+#define TARGET_LINUX_SYS_read		  3
+#define TARGET_LINUX_SYS_write		  4
+#define TARGET_LINUX_SYS_open		  5
+#define TARGET_LINUX_SYS_close		  6
+#define TARGET_LINUX_SYS_waitpid		  7
+#define TARGET_LINUX_SYS_creat		  8
+#define TARGET_LINUX_SYS_link		  9
+#define TARGET_LINUX_SYS_unlink		 10
+#define TARGET_LINUX_SYS_execve		 11
+#define TARGET_LINUX_SYS_chdir		 12
+#define TARGET_LINUX_SYS_time		 13
+#define TARGET_LINUX_SYS_mknod		 14
+#define TARGET_LINUX_SYS_chmod		 15
+#define TARGET_LINUX_SYS_lchown		 16
+#define TARGET_LINUX_SYS_break		 17
+#define TARGET_LINUX_SYS_oldstat		 18
+#define TARGET_LINUX_SYS_lseek		 19
+#define TARGET_LINUX_SYS_getpid		 20
+#define TARGET_LINUX_SYS_mount		 21
+#define TARGET_LINUX_SYS_umount		 22
+#define TARGET_LINUX_SYS_setuid		 23
+#define TARGET_LINUX_SYS_getuid		 24
+#define TARGET_LINUX_SYS_stime		 25
+#define TARGET_LINUX_SYS_ptrace		 26
+#define TARGET_LINUX_SYS_alarm		 27
+#define TARGET_LINUX_SYS_oldfstat		 28
+#define TARGET_LINUX_SYS_pause		 29
+#define TARGET_LINUX_SYS_utime		 30
+#define TARGET_LINUX_SYS_stty		 31
+#define TARGET_LINUX_SYS_gtty		 32
+#define TARGET_LINUX_SYS_access		 33
+#define TARGET_LINUX_SYS_nice		 34
+#define TARGET_LINUX_SYS_ftime		 35
+#define TARGET_LINUX_SYS_sync		 36
+#define TARGET_LINUX_SYS_kill		 37
+#define TARGET_LINUX_SYS_rename		 38
+#define TARGET_LINUX_SYS_mkdir		 39
+#define TARGET_LINUX_SYS_rmdir		 40
+#define TARGET_LINUX_SYS_dup		 41
+#define TARGET_LINUX_SYS_pipe		 42
+#define TARGET_LINUX_SYS_times		 43
+#define TARGET_LINUX_SYS_prof		 44
+#define TARGET_LINUX_SYS_brk		 45
+#define TARGET_LINUX_SYS_setgid		 46
+#define TARGET_LINUX_SYS_getgid		 47
+#define TARGET_LINUX_SYS_signal		 48
+#define TARGET_LINUX_SYS_geteuid		 49
+#define TARGET_LINUX_SYS_getegid		 50
+#define TARGET_LINUX_SYS_acct		 51
+#define TARGET_LINUX_SYS_umount2		 52
+#define TARGET_LINUX_SYS_lock		 53
+#define TARGET_LINUX_SYS_ioctl		 54
+#define TARGET_LINUX_SYS_fcntl		 55
+#define TARGET_LINUX_SYS_mpx		 56
+#define TARGET_LINUX_SYS_setpgid		 57
+#define TARGET_LINUX_SYS_ulimit		 58
+#define TARGET_LINUX_SYS_oldolduname	 59
+#define TARGET_LINUX_SYS_umask		 60
+#define TARGET_LINUX_SYS_chroot		 61
+#define TARGET_LINUX_SYS_ustat		 62
+#define TARGET_LINUX_SYS_dup2		 63
+#define TARGET_LINUX_SYS_getppid		 64
+#define TARGET_LINUX_SYS_getpgrp		 65
+#define TARGET_LINUX_SYS_setsid		 66
+#define TARGET_LINUX_SYS_sigaction		 67
+#define TARGET_LINUX_SYS_sgetmask		 68
+#define TARGET_LINUX_SYS_ssetmask		 69
+#define TARGET_LINUX_SYS_setreuid		 70
+#define TARGET_LINUX_SYS_setregid		 71
+#define TARGET_LINUX_SYS_sigsuspend		 72
+#define TARGET_LINUX_SYS_sigpending		 73
+#define TARGET_LINUX_SYS_sethostname	 74
+#define TARGET_LINUX_SYS_setrlimit		 75
+#define TARGET_LINUX_SYS_getrlimit		 76
+#define TARGET_LINUX_SYS_getrusage		 77
+#define TARGET_LINUX_SYS_gettimeofday	 78
+#define TARGET_LINUX_SYS_settimeofday	 79
+#define TARGET_LINUX_SYS_getgroups		 80
+#define TARGET_LINUX_SYS_setgroups		 81
+#define TARGET_LINUX_SYS_select		 82
+#define TARGET_LINUX_SYS_symlink		 83
+#define TARGET_LINUX_SYS_oldlstat		 84
+#define TARGET_LINUX_SYS_readlink		 85
+#define TARGET_LINUX_SYS_uselib		 86
+#define TARGET_LINUX_SYS_swapon		 87
+#define TARGET_LINUX_SYS_reboot		 88
+#define TARGET_LINUX_SYS_readdir		 89
+#define TARGET_LINUX_SYS_mmap		 90
+#define TARGET_LINUX_SYS_munmap		 91
+#define TARGET_LINUX_SYS_truncate		 92
+#define TARGET_LINUX_SYS_ftruncate		 93
+#define TARGET_LINUX_SYS_fchmod		 94
+#define TARGET_LINUX_SYS_fchown		 95
+#define TARGET_LINUX_SYS_getpriority	 96
+#define TARGET_LINUX_SYS_setpriority	 97
+#define TARGET_LINUX_SYS_profil		 98
+#define TARGET_LINUX_SYS_statfs		 99
+#define TARGET_LINUX_SYS_fstatfs		100
+#define TARGET_LINUX_SYS_ioperm		101
+#define TARGET_LINUX_SYS_socketcall		102
+#define TARGET_LINUX_SYS_syslog		103
+#define TARGET_LINUX_SYS_setitimer		104
+#define TARGET_LINUX_SYS_getitimer		105
+#define TARGET_LINUX_SYS_stat		106
+#define TARGET_LINUX_SYS_lstat		107
+#define TARGET_LINUX_SYS_fstat		108
+#define TARGET_LINUX_SYS_olduname		109
+#define TARGET_LINUX_SYS_iopl		110
+#define TARGET_LINUX_SYS_vhangup		111
+#define TARGET_LINUX_SYS_idle		112
+#define TARGET_LINUX_SYS_vm86old		113
+#define TARGET_LINUX_SYS_wait4		114
+#define TARGET_LINUX_SYS_swapoff		115
+#define TARGET_LINUX_SYS_sysinfo		116
+#define TARGET_LINUX_SYS_ipc		117
+#define TARGET_LINUX_SYS_fsync		118
+#define TARGET_LINUX_SYS_sigreturn		119
+#define TARGET_LINUX_SYS_clone		120
+#define TARGET_LINUX_SYS_setdomainname	121
+#define TARGET_LINUX_SYS_uname		122
+#define TARGET_LINUX_SYS_modify_ldt		123
+#define TARGET_LINUX_SYS_adjtimex		124
+#define TARGET_LINUX_SYS_mprotect		125
+#define TARGET_LINUX_SYS_sigprocmask	126
+#define TARGET_LINUX_SYS_create_module	127
+#define TARGET_LINUX_SYS_init_module	128
+#define TARGET_LINUX_SYS_delete_module	129
+#define TARGET_LINUX_SYS_get_kernel_syms	130
+#define TARGET_LINUX_SYS_quotactl		131
+#define TARGET_LINUX_SYS_getpgid		132
+#define TARGET_LINUX_SYS_fchdir		133
+#define TARGET_LINUX_SYS_bdflush		134
+#define TARGET_LINUX_SYS_sysfs		135
+#define TARGET_LINUX_SYS_personality	136
+#define TARGET_LINUX_SYS_afs_syscall	137 /* Syscall for Andrew File System */
+#define TARGET_LINUX_SYS_setfsuid		138
+#define TARGET_LINUX_SYS_setfsgid		139
+#define TARGET_LINUX_SYS__llseek		140
+#define TARGET_LINUX_SYS_getdents		141
+#define TARGET_LINUX_SYS__newselect		142
+#define TARGET_LINUX_SYS_flock		143
+#define TARGET_LINUX_SYS_msync		144
+#define TARGET_LINUX_SYS_readv		145
+#define TARGET_LINUX_SYS_writev		146
+#define TARGET_LINUX_SYS_getsid		147
+#define TARGET_LINUX_SYS_fdatasync		148
+#define TARGET_LINUX_SYS__sysctl		149
+#define TARGET_LINUX_SYS_mlock		150
+#define TARGET_LINUX_SYS_munlock		151
+#define TARGET_LINUX_SYS_mlockall		152
+#define TARGET_LINUX_SYS_munlockall		153
+#define TARGET_LINUX_SYS_sched_setparam		154
+#define TARGET_LINUX_SYS_sched_getparam		155
+#define TARGET_LINUX_SYS_sched_setscheduler		156
+#define TARGET_LINUX_SYS_sched_getscheduler		157
+#define TARGET_LINUX_SYS_sched_yield		158
+#define TARGET_LINUX_SYS_sched_get_priority_max	159
+#define TARGET_LINUX_SYS_sched_get_priority_min	160
+#define TARGET_LINUX_SYS_sched_rr_get_interval	161
+#define TARGET_LINUX_SYS_nanosleep		162
+#define TARGET_LINUX_SYS_mremap		163
+#define TARGET_LINUX_SYS_setresuid		164
+#define TARGET_LINUX_SYS_getresuid		165
+#define TARGET_LINUX_SYS_vm86		166
+#define TARGET_LINUX_SYS_query_module	167
+#define TARGET_LINUX_SYS_poll		168
+#define TARGET_LINUX_SYS_nfsservctl		169
+#define TARGET_LINUX_SYS_setresgid		170
+#define TARGET_LINUX_SYS_getresgid		171
+#define TARGET_LINUX_SYS_prctl              172
+#define TARGET_LINUX_SYS_rt_sigreturn	173
+#define TARGET_LINUX_SYS_rt_sigaction	174
+#define TARGET_LINUX_SYS_rt_sigprocmask	175
+#define TARGET_LINUX_SYS_rt_sigpending	176
+#define TARGET_LINUX_SYS_rt_sigtimedwait	177
+#define TARGET_LINUX_SYS_rt_sigqueueinfo	178
+#define TARGET_LINUX_SYS_rt_sigsuspend	179
+#define TARGET_LINUX_SYS_pread		180
+#define TARGET_LINUX_SYS_pwrite		181
+#define TARGET_LINUX_SYS_chown		182
+#define TARGET_LINUX_SYS_getcwd		183
+#define TARGET_LINUX_SYS_capget		184
+#define TARGET_LINUX_SYS_capset		185
+#define TARGET_LINUX_SYS_sigaltstack	186
+#define TARGET_LINUX_SYS_sendfile		187
+#define TARGET_LINUX_SYS_getpmsg		188	/* some people actually want streams */
+#define TARGET_LINUX_SYS_putpmsg		189	/* some people actually want streams */
+#define TARGET_LINUX_SYS_vfork		190
 
-#define __NR_pread64		180
-#define __NR_pwrite64		181
+#define TARGET_LINUX_SYS_pread64		180
+#define TARGET_LINUX_SYS_pwrite64		181
 
-#define __NR_ugetrlimit		191	/* SuS compliant getrlimit */
-#define __NR_mmap2		192
-#define __NR_truncate64		193
-#define __NR_ftruncate64	194
-#define __NR_stat64		195
-#define __NR_lstat64		196
-#define __NR_fstat64		197
-#define __NR_lchown32		198
-#define __NR_getuid32		199
-#define __NR_getgid32		200
-#define __NR_geteuid32		201
-#define __NR_getegid32		202
-#define __NR_setreuid32		203
-#define __NR_setregid32		204
-#define __NR_getgroups32	205
-#define __NR_setgroups32	206
-#define __NR_fchown32		207
-#define __NR_setresuid32	208
-#define __NR_getresuid32	209
-#define __NR_setresgid32	210
-#define __NR_getresgid32	211
-#define __NR_chown32		212
-#define __NR_setuid32		213
-#define __NR_setgid32		214
-#define __NR_setfsuid32		215
-#define __NR_setfsgid32		216
-#define __NR_pivot_root		217
-#define __NR_mincore		218
-#define __NR_madvise		219
-#define __NR_madvise1		219	/* delete when C lib stub is removed */
-#define __NR_getdents64		220
-#define __NR_fcntl64		221
+#define TARGET_LINUX_SYS_ugetrlimit		191	/* SuS compliant getrlimit */
+#define TARGET_LINUX_SYS_mmap2		192
+#define TARGET_LINUX_SYS_truncate64		193
+#define TARGET_LINUX_SYS_ftruncate64	194
+#define TARGET_LINUX_SYS_stat64		195
+#define TARGET_LINUX_SYS_lstat64		196
+#define TARGET_LINUX_SYS_fstat64		197
+#define TARGET_LINUX_SYS_lchown32		198
+#define TARGET_LINUX_SYS_getuid32		199
+#define TARGET_LINUX_SYS_getgid32		200
+#define TARGET_LINUX_SYS_geteuid32		201
+#define TARGET_LINUX_SYS_getegid32		202
+#define TARGET_LINUX_SYS_setreuid32		203
+#define TARGET_LINUX_SYS_setregid32		204
+#define TARGET_LINUX_SYS_getgroups32	205
+#define TARGET_LINUX_SYS_setgroups32	206
+#define TARGET_LINUX_SYS_fchown32		207
+#define TARGET_LINUX_SYS_setresuid32	208
+#define TARGET_LINUX_SYS_getresuid32	209
+#define TARGET_LINUX_SYS_setresgid32	210
+#define TARGET_LINUX_SYS_getresgid32	211
+#define TARGET_LINUX_SYS_chown32		212
+#define TARGET_LINUX_SYS_setuid32		213
+#define TARGET_LINUX_SYS_setgid32		214
+#define TARGET_LINUX_SYS_setfsuid32		215
+#define TARGET_LINUX_SYS_setfsgid32		216
+#define TARGET_LINUX_SYS_pivot_root		217
+#define TARGET_LINUX_SYS_mincore		218
+#define TARGET_LINUX_SYS_madvise		219
+#define TARGET_LINUX_SYS_madvise1		219	/* delete when C lib stub is removed */
+#define TARGET_LINUX_SYS_getdents64		220
+#define TARGET_LINUX_SYS_fcntl64		221
 /* 223 is unused */
-#define __NR_gettid		224
-#define __NR_readahead		225
-#define __NR_setxattr		226
-#define __NR_lsetxattr		227
-#define __NR_fsetxattr		228
-#define __NR_getxattr		229
-#define __NR_lgetxattr		230
-#define __NR_fgetxattr		231
-#define __NR_listxattr		232
-#define __NR_llistxattr		233
-#define __NR_flistxattr		234
-#define __NR_removexattr	235
-#define __NR_lremovexattr	236
-#define __NR_fremovexattr	237
-#define __NR_tkill		238
-#define __NR_sendfile64		239
-#define __NR_futex		240
-#define __NR_sched_setaffinity	241
-#define __NR_sched_getaffinity	242
-#define __NR_set_thread_area	243
-#define __NR_get_thread_area	244
-#define __NR_io_setup		245
-#define __NR_io_destroy		246
-#define __NR_io_getevents	247
-#define __NR_io_submit		248
-#define __NR_io_cancel		249
-#define __NR_fadvise64		250
+#define TARGET_LINUX_SYS_gettid		224
+#define TARGET_LINUX_SYS_readahead		225
+#define TARGET_LINUX_SYS_setxattr		226
+#define TARGET_LINUX_SYS_lsetxattr		227
+#define TARGET_LINUX_SYS_fsetxattr		228
+#define TARGET_LINUX_SYS_getxattr		229
+#define TARGET_LINUX_SYS_lgetxattr		230
+#define TARGET_LINUX_SYS_fgetxattr		231
+#define TARGET_LINUX_SYS_listxattr		232
+#define TARGET_LINUX_SYS_llistxattr		233
+#define TARGET_LINUX_SYS_flistxattr		234
+#define TARGET_LINUX_SYS_removexattr	235
+#define TARGET_LINUX_SYS_lremovexattr	236
+#define TARGET_LINUX_SYS_fremovexattr	237
+#define TARGET_LINUX_SYS_tkill		238
+#define TARGET_LINUX_SYS_sendfile64		239
+#define TARGET_LINUX_SYS_futex		240
+#define TARGET_LINUX_SYS_sched_setaffinity	241
+#define TARGET_LINUX_SYS_sched_getaffinity	242
+#define TARGET_LINUX_SYS_set_thread_area	243
+#define TARGET_LINUX_SYS_get_thread_area	244
+#define TARGET_LINUX_SYS_io_setup		245
+#define TARGET_LINUX_SYS_io_destroy		246
+#define TARGET_LINUX_SYS_io_getevents	247
+#define TARGET_LINUX_SYS_io_submit		248
+#define TARGET_LINUX_SYS_io_cancel		249
+#define TARGET_LINUX_SYS_fadvise64		250
 
-#define __NR_exit_group		252
-#define __NR_lookup_dcookie	253
-#define __NR_epoll_create	254
-#define __NR_epoll_ctl		255
-#define __NR_epoll_wait		256
-#define __NR_remap_file_pages	257
-#define __NR_set_tid_address	258
-#define __NR_timer_create	259
-#define __NR_timer_settime	(__NR_timer_create+1)
-#define __NR_timer_gettime	(__NR_timer_create+2)
-#define __NR_timer_getoverrun	(__NR_timer_create+3)
-#define __NR_timer_delete	(__NR_timer_create+4)
-#define __NR_clock_settime	(__NR_timer_create+5)
-#define __NR_clock_gettime	(__NR_timer_create+6)
-#define __NR_clock_getres	(__NR_timer_create+7)
-#define __NR_clock_nanosleep	(__NR_timer_create+8)
-#define __NR_statfs64		268
-#define __NR_fstatfs64		269
-#define __NR_tgkill		270
-#define __NR_utimes		271
-#define __NR_fadvise64_64	272
-#define __NR_vserver		273
+#define TARGET_LINUX_SYS_exit_group		252
+#define TARGET_LINUX_SYS_lookup_dcookie	253
+#define TARGET_LINUX_SYS_epoll_create	254
+#define TARGET_LINUX_SYS_epoll_ctl		255
+#define TARGET_LINUX_SYS_epoll_wait		256
+#define TARGET_LINUX_SYS_remap_file_pages	257
+#define TARGET_LINUX_SYS_set_tid_address	258
+#define TARGET_LINUX_SYS_timer_create	259
+#define TARGET_LINUX_SYS_timer_settime	(TARGET_LINUX_SYS_timer_create+1)
+#define TARGET_LINUX_SYS_timer_gettime	(TARGET_LINUX_SYS_timer_create+2)
+#define TARGET_LINUX_SYS_timer_getoverrun	(TARGET_LINUX_SYS_timer_create+3)
+#define TARGET_LINUX_SYS_timer_delete	(TARGET_LINUX_SYS_timer_create+4)
+#define TARGET_LINUX_SYS_clock_settime	(TARGET_LINUX_SYS_timer_create+5)
+#define TARGET_LINUX_SYS_clock_gettime	(TARGET_LINUX_SYS_timer_create+6)
+#define TARGET_LINUX_SYS_clock_getres	(TARGET_LINUX_SYS_timer_create+7)
+#define TARGET_LINUX_SYS_clock_nanosleep	(TARGET_LINUX_SYS_timer_create+8)
+#define TARGET_LINUX_SYS_statfs64		268
+#define TARGET_LINUX_SYS_fstatfs64		269
+#define TARGET_LINUX_SYS_tgkill		270
+#define TARGET_LINUX_SYS_utimes		271
+#define TARGET_LINUX_SYS_fadvise64_64	272
+#define TARGET_LINUX_SYS_vserver		273
diff --git a/sim/m32r/traps-linux.c b/sim/m32r/traps-linux.c
index c218582e431e..d60be7ca54b9 100644
--- a/sim/m32r/traps-linux.c
+++ b/sim/m32r/traps-linux.c
@@ -24,11 +24,13 @@
 #include "sim-main.h"
 #include "sim-signal.h"
 #include "sim-syscall.h"
+#include "sim/callback.h"
 #include "syscall.h"
 #include "targ-vals.h"
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
 #include <utime.h>
@@ -268,52 +270,52 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 
         switch (func)
           {
-          case __NR_exit:
+          case TARGET_LINUX_SYS_exit:
 	    sim_engine_halt (sd, current_cpu, NULL, pc, sim_exited, arg1);
             break;
 
-          case __NR_read:
+          case TARGET_LINUX_SYS_read:
             result = read(arg1, t2h_addr(cb, &s, arg2), arg3);
             errcode = errno;
             break;
 
-          case __NR_write:
+          case TARGET_LINUX_SYS_write:
             result = write(arg1, t2h_addr(cb, &s, arg2), arg3);
             errcode = errno;
             break;
 
-          case __NR_open:
+          case TARGET_LINUX_SYS_open:
             result = open((char *) t2h_addr(cb, &s, arg1), arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_close:
+          case TARGET_LINUX_SYS_close:
             result = close(arg1);
             errcode = errno;
             break;
 
-          case __NR_creat:
+          case TARGET_LINUX_SYS_creat:
             result = creat((char *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_link:
+          case TARGET_LINUX_SYS_link:
             result = link((char *) t2h_addr(cb, &s, arg1),
                           (char *) t2h_addr(cb, &s, arg2));
             errcode = errno;
             break;
 
-          case __NR_unlink:
+          case TARGET_LINUX_SYS_unlink:
             result = unlink((char *) t2h_addr(cb, &s, arg1));
             errcode = errno;
             break;
 
-          case __NR_chdir:
+          case TARGET_LINUX_SYS_chdir:
             result = chdir((char *) t2h_addr(cb, &s, arg1));
             errcode = errno;
             break;
 
-          case __NR_time:
+          case TARGET_LINUX_SYS_time:
             {
               time_t t;
 
@@ -340,41 +342,41 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_mknod:
+          case TARGET_LINUX_SYS_mknod:
             result = mknod((char *) t2h_addr(cb, &s, arg1),
                            (mode_t) arg2, (dev_t) arg3);
             errcode = errno;
             break;
 
-          case __NR_chmod:
+          case TARGET_LINUX_SYS_chmod:
             result = chmod((char *) t2h_addr(cb, &s, arg1), (mode_t) arg2);
             errcode = errno;
             break;
 
-          case __NR_lchown32:
-          case __NR_lchown:
+          case TARGET_LINUX_SYS_lchown32:
+          case TARGET_LINUX_SYS_lchown:
             result = lchown((char *) t2h_addr(cb, &s, arg1),
                             (uid_t) arg2, (gid_t) arg3);
             errcode = errno;
             break;
 
-          case __NR_lseek:
+          case TARGET_LINUX_SYS_lseek:
             result = (int) lseek(arg1, (off_t) arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_getpid:
+          case TARGET_LINUX_SYS_getpid:
             result = getpid();
             errcode = errno;
             break;
 
-          case __NR_getuid32:
-          case __NR_getuid:
+          case TARGET_LINUX_SYS_getuid32:
+          case TARGET_LINUX_SYS_getuid:
             result = getuid();
             errcode = errno;
             break;
 
-          case __NR_utime:
+          case TARGET_LINUX_SYS_utime:
             {
               struct utimbuf buf;
 
@@ -393,12 +395,12 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_access:
+          case TARGET_LINUX_SYS_access:
             result = access((char *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_ftime:
+          case TARGET_LINUX_SYS_ftime:
             {
               struct timeb t;
 
@@ -420,82 +422,82 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
                 }
             }
 
-          case __NR_sync:
+          case TARGET_LINUX_SYS_sync:
             sync();
             result = 0;
             break;
 
-          case __NR_rename:
+          case TARGET_LINUX_SYS_rename:
             result = rename((char *) t2h_addr(cb, &s, arg1),
                             (char *) t2h_addr(cb, &s, arg2));
             errcode = errno;
             break;
 
-          case __NR_mkdir:
+          case TARGET_LINUX_SYS_mkdir:
             result = mkdir((char *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_rmdir:
+          case TARGET_LINUX_SYS_rmdir:
             result = rmdir((char *) t2h_addr(cb, &s, arg1));
             errcode = errno;
             break;
 
-          case __NR_dup:
+          case TARGET_LINUX_SYS_dup:
             result = dup(arg1);
             errcode = errno;
             break;
 
-          case __NR_brk:
+          case TARGET_LINUX_SYS_brk:
             result = brk((void *) arg1);
             errcode = errno;
             //result = arg1;
             break;
 
-          case __NR_getgid32:
-          case __NR_getgid:
+          case TARGET_LINUX_SYS_getgid32:
+          case TARGET_LINUX_SYS_getgid:
             result = getgid();
             errcode = errno;
             break;
 
-          case __NR_geteuid32:
-          case __NR_geteuid:
+          case TARGET_LINUX_SYS_geteuid32:
+          case TARGET_LINUX_SYS_geteuid:
             result = geteuid();
             errcode = errno;
             break;
 
-          case __NR_getegid32:
-          case __NR_getegid:
+          case TARGET_LINUX_SYS_getegid32:
+          case TARGET_LINUX_SYS_getegid:
             result = getegid();
             errcode = errno;
             break;
 
-          case __NR_ioctl:
+          case TARGET_LINUX_SYS_ioctl:
             result = ioctl(arg1, arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_fcntl:
+          case TARGET_LINUX_SYS_fcntl:
             result = fcntl(arg1, arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_dup2:
+          case TARGET_LINUX_SYS_dup2:
             result = dup2(arg1, arg2);
             errcode = errno;
             break;
 
-          case __NR_getppid:
+          case TARGET_LINUX_SYS_getppid:
             result = getppid();
             errcode = errno;
             break;
 
-          case __NR_getpgrp:
+          case TARGET_LINUX_SYS_getpgrp:
             result = getpgrp();
             errcode = errno;
             break;
 
-          case __NR_getrlimit:
+          case TARGET_LINUX_SYS_getrlimit:
             {
               struct rlimit rlim;
 
@@ -515,7 +517,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_getrusage:
+          case TARGET_LINUX_SYS_getrusage:
             {
               struct rusage usage;
 
@@ -535,7 +537,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_gettimeofday:
+          case TARGET_LINUX_SYS_gettimeofday:
             {
               struct timeval tv;
               struct timezone tz;
@@ -564,8 +566,8 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_getgroups32:
-          case __NR_getgroups:
+          case TARGET_LINUX_SYS_getgroups32:
+          case TARGET_LINUX_SYS_getgroups:
             {
               gid_t *list;
 
@@ -589,7 +591,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_select:
+          case TARGET_LINUX_SYS_select:
             {
               int n;
               fd_set readfds;
@@ -689,26 +691,26 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_symlink:
+          case TARGET_LINUX_SYS_symlink:
             result = symlink((char *) t2h_addr(cb, &s, arg1),
                              (char *) t2h_addr(cb, &s, arg2));
             errcode = errno;
             break;
 
-          case __NR_readlink:
+          case TARGET_LINUX_SYS_readlink:
             result = readlink((char *) t2h_addr(cb, &s, arg1),
                               (char *) t2h_addr(cb, &s, arg2),
                               arg3);
             errcode = errno;
             break;
 
-          case __NR_readdir:
+          case TARGET_LINUX_SYS_readdir:
             result = (int) readdir((DIR *) t2h_addr(cb, &s, arg1));
             errcode = errno;
             break;
 
 #if 0
-          case __NR_mmap:
+          case TARGET_LINUX_SYS_mmap:
             {
               result = (int) mmap((void *) t2h_addr(cb, &s, arg1),
                                   arg2, arg3, arg4, arg5, arg6);
@@ -723,7 +725,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 #endif
-          case __NR_mmap2:
+          case TARGET_LINUX_SYS_mmap2:
             {
               void *addr;
               size_t len;
@@ -750,7 +752,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_mmap:
+          case TARGET_LINUX_SYS_mmap:
             {
               void *addr;
               size_t len;
@@ -787,7 +789,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_munmap:
+          case TARGET_LINUX_SYS_munmap:
             {
             result = munmap((void *)arg1, arg2);
             errcode = errno;
@@ -798,28 +800,28 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_truncate:
+          case TARGET_LINUX_SYS_truncate:
             result = truncate((char *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_ftruncate:
+          case TARGET_LINUX_SYS_ftruncate:
             result = ftruncate(arg1, arg2);
             errcode = errno;
             break;
 
-          case __NR_fchmod:
+          case TARGET_LINUX_SYS_fchmod:
             result = fchmod(arg1, arg2);
             errcode = errno;
             break;
 
-          case __NR_fchown32:
-          case __NR_fchown:
+          case TARGET_LINUX_SYS_fchown32:
+          case TARGET_LINUX_SYS_fchown:
             result = fchown(arg1, arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_statfs:
+          case TARGET_LINUX_SYS_statfs:
             {
               struct statfs statbuf;
 
@@ -839,7 +841,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_fstatfs:
+          case TARGET_LINUX_SYS_fstatfs:
             {
               struct statfs statbuf;
 
@@ -859,12 +861,12 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_syslog:
+          case TARGET_LINUX_SYS_syslog:
             result = syslog(arg1, (char *) t2h_addr(cb, &s, arg2));
             errcode = errno;
             break;
 
-          case __NR_setitimer:
+          case TARGET_LINUX_SYS_setitimer:
             {
               struct itimerval value, ovalue;
 
@@ -895,7 +897,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_getitimer:
+          case TARGET_LINUX_SYS_getitimer:
             {
               struct itimerval value;
 
@@ -915,7 +917,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_stat:
+          case TARGET_LINUX_SYS_stat:
             {
               char *buf;
               int buflen;
@@ -948,7 +950,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_lstat:
+          case TARGET_LINUX_SYS_lstat:
             {
               char *buf;
               int buflen;
@@ -981,7 +983,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_fstat:
+          case TARGET_LINUX_SYS_fstat:
             {
               char *buf;
               int buflen;
@@ -1014,7 +1016,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_sysinfo:
+          case TARGET_LINUX_SYS_sysinfo:
             {
               struct sysinfo info;
 
@@ -1050,7 +1052,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             break;
 
 #if 0
-          case __NR_ipc:
+          case TARGET_LINUX_SYS_ipc:
             {
               result = ipc(arg1, arg2, arg3, arg4,
                            (void *) t2h_addr(cb, &s, arg5), arg6);
@@ -1059,19 +1061,19 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             break;
 #endif
 
-          case __NR_fsync:
+          case TARGET_LINUX_SYS_fsync:
             result = fsync(arg1);
             errcode = errno;
             break;
 
-          case __NR_uname:
+          case TARGET_LINUX_SYS_uname:
             /* utsname contains only arrays of char, so it is not necessary
                to translate endian. */
             result = uname((struct utsname *) t2h_addr(cb, &s, arg1));
             errcode = errno;
             break;
 
-          case __NR_adjtimex:
+          case TARGET_LINUX_SYS_adjtimex:
             {
               struct timex buf;
 
@@ -1091,30 +1093,30 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_mprotect:
+          case TARGET_LINUX_SYS_mprotect:
             result = mprotect((void *) arg1, arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_fchdir:
+          case TARGET_LINUX_SYS_fchdir:
             result = fchdir(arg1);
             errcode = errno;
             break;
 
-          case __NR_setfsuid32:
-          case __NR_setfsuid:
+          case TARGET_LINUX_SYS_setfsuid32:
+          case TARGET_LINUX_SYS_setfsuid:
             result = setfsuid(arg1);
             errcode = errno;
             break;
 
-          case __NR_setfsgid32:
-          case __NR_setfsgid:
+          case TARGET_LINUX_SYS_setfsgid32:
+          case TARGET_LINUX_SYS_setfsgid:
             result = setfsgid(arg1);
             errcode = errno;
             break;
 
 #if 0
-          case __NR__llseek:
+          case TARGET_LINUX_SYS__llseek:
             {
               loff_t buf;
 
@@ -1134,7 +1136,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_getdents:
+          case TARGET_LINUX_SYS_getdents:
             {
               struct dirent dir;
 
@@ -1157,17 +1159,17 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             break;
 #endif
 
-          case __NR_flock:
+          case TARGET_LINUX_SYS_flock:
             result = flock(arg1, arg2);
             errcode = errno;
             break;
 
-          case __NR_msync:
+          case TARGET_LINUX_SYS_msync:
             result = msync((void *) arg1, arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_readv:
+          case TARGET_LINUX_SYS_readv:
             {
               struct iovec vector;
 
@@ -1179,7 +1181,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_writev:
+          case TARGET_LINUX_SYS_writev:
             {
               struct iovec vector;
 
@@ -1191,22 +1193,22 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_fdatasync:
+          case TARGET_LINUX_SYS_fdatasync:
             result = fdatasync(arg1);
             errcode = errno;
             break;
 
-          case __NR_mlock:
+          case TARGET_LINUX_SYS_mlock:
             result = mlock((void *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_munlock:
+          case TARGET_LINUX_SYS_munlock:
             result = munlock((void *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_nanosleep:
+          case TARGET_LINUX_SYS_nanosleep:
             {
               struct timespec req, rem;
 
@@ -1229,13 +1231,13 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_mremap: /* FIXME */
+          case TARGET_LINUX_SYS_mremap: /* FIXME */
             result = (int) mremap((void *) t2h_addr(cb, &s, arg1), arg2, arg3, arg4); 
             errcode = errno;
             break;
 
-          case __NR_getresuid32:
-          case __NR_getresuid:
+          case TARGET_LINUX_SYS_getresuid32:
+          case TARGET_LINUX_SYS_getresuid:
             {
               uid_t ruid, euid, suid;
 
@@ -1251,7 +1253,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_poll:
+          case TARGET_LINUX_SYS_poll:
             {
               struct pollfd ufds;
 
@@ -1265,8 +1267,8 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_getresgid32:
-          case __NR_getresgid:
+          case TARGET_LINUX_SYS_getresgid32:
+          case TARGET_LINUX_SYS_getresgid:
             {
               uid_t rgid, egid, sgid;
 
@@ -1282,28 +1284,28 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
             }
             break;
 
-          case __NR_pread:
+          case TARGET_LINUX_SYS_pread:
             result =  pread(arg1, (void *) t2h_addr(cb, &s, arg2), arg3, arg4); 
             errcode = errno;
             break;
 
-          case __NR_pwrite:
+          case TARGET_LINUX_SYS_pwrite:
             result =  pwrite(arg1, (void *) t2h_addr(cb, &s, arg2), arg3, arg4); 
             errcode = errno;
             break;
 
-          case __NR_chown32:
-          case __NR_chown:
+          case TARGET_LINUX_SYS_chown32:
+          case TARGET_LINUX_SYS_chown:
             result = chown((char *) t2h_addr(cb, &s, arg1), arg2, arg3);
             errcode = errno;
             break;
 
-          case __NR_getcwd:
+          case TARGET_LINUX_SYS_getcwd:
             result = (int) getcwd((char *) t2h_addr(cb, &s, arg1), arg2);
             errcode = errno;
             break;
 
-          case __NR_sendfile:
+          case TARGET_LINUX_SYS_sendfile:
             {
               off_t offset;
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/6] sim: m32r: fix virtual environment with Linux targets
  2021-07-01  4:55 [PATCH 1/6] sim: m32r: namespace Linux syscall table Mike Frysinger
@ 2021-07-01  4:55 ` Mike Frysinger
  2021-07-01  4:55 ` [PATCH 3/6] sim: m32r: replace custom endian helpers with sim-endian Mike Frysinger
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2021-07-01  4:55 UTC (permalink / raw)
  To: gdb-patches

We don't want to handle Linux syscalls when in the virtual environment,
just the user environment, so adjust the Linux traps logic to check for
that specifically (instead of just skipping the operating environment).

Also tweak some testcases to explicitly specify the environment they run
under rather than relying on the default matching their needs.  This gets
the tests passing for all m32r targets.
---
 sim/m32r/traps-linux.c        | 11 +++--------
 sim/testsuite/m32r/hw-trap.ms |  1 +
 sim/testsuite/m32r/trap.cgs   |  1 +
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/sim/m32r/traps-linux.c b/sim/m32r/traps-linux.c
index d60be7ca54b9..7aec04b5116f 100644
--- a/sim/m32r/traps-linux.c
+++ b/sim/m32r/traps-linux.c
@@ -231,14 +231,8 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
         unsigned int func, arg1, arg2, arg3, arg4, arg5, arg6, arg7;
         int result, result2, errcode;
 
-        if (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)
-          {
-            /* The new pc is the trap vector entry.
-               We assume there's a branch there to some handler.
-	       Use cr5 as EVB (EIT Vector Base) register.  */
-            USI new_pc = m32rbf_h_cr_get (current_cpu, 5) + 0x40 + num * 4;
-            return new_pc;
-          }
+	if (STATE_ENVIRONMENT (sd) != USER_ENVIRONMENT)
+	  goto case_default;
 
 	func = m32rbf_h_gr_get (current_cpu, 7);
 	arg1 = m32rbf_h_gr_get (current_cpu, 0);
@@ -1344,6 +1338,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
       /* Do nothing.  */
       break;
 
+    case_default:
     default :
       {
 	/* Use cr5 as EVB (EIT Vector Base) register.  */
diff --git a/sim/testsuite/m32r/hw-trap.ms b/sim/testsuite/m32r/hw-trap.ms
index 2aa200b5d709..09790248d10d 100644
--- a/sim/testsuite/m32r/hw-trap.ms
+++ b/sim/testsuite/m32r/hw-trap.ms
@@ -1,4 +1,5 @@
 # mach(): m32r m32rx
+# sim: --environment virtual
 # output(): pass\n
 
 	.include "testutils.inc"
diff --git a/sim/testsuite/m32r/trap.cgs b/sim/testsuite/m32r/trap.cgs
index 59e136a01735..f132d165367f 100644
--- a/sim/testsuite/m32r/trap.cgs
+++ b/sim/testsuite/m32r/trap.cgs
@@ -1,5 +1,6 @@
 # m32r testcase for trap #$uimm4
 # mach(): m32r m32rx
+# sim: --environment virtual
 
 	.include "testutils.inc"
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/6] sim: m32r: replace custom endian helpers with sim-endian
  2021-07-01  4:55 [PATCH 1/6] sim: m32r: namespace Linux syscall table Mike Frysinger
  2021-07-01  4:55 ` [PATCH 2/6] sim: m32r: fix virtual environment with Linux targets Mike Frysinger
@ 2021-07-01  4:55 ` Mike Frysinger
  2021-07-01  4:55 ` [PATCH 4/6] sim: m32r: unify ELF & Linux traps logic Mike Frysinger
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2021-07-01  4:55 UTC (permalink / raw)
  To: gdb-patches

This improves the logic a bit by making the host<->target translations
a bit more clear.  The structs still bleed way too much between the two
worlds, but let's fix one thing at a time.
---
 sim/m32r/traps-linux.c | 187 ++++++++++++++++++-----------------------
 1 file changed, 80 insertions(+), 107 deletions(-)

diff --git a/sim/m32r/traps-linux.c b/sim/m32r/traps-linux.c
index 7aec04b5116f..4d86a0a4e361 100644
--- a/sim/m32r/traps-linux.c
+++ b/sim/m32r/traps-linux.c
@@ -137,61 +137,34 @@ t2h_addr (host_callback *cb, struct cb_syscall *sc,
   return sim_core_trans_addr (sd, cpu, read_map, taddr);
 }
 
-static unsigned int
-conv_endian (unsigned int tvalue)
-{
-  unsigned int hvalue;
-  unsigned int t1, t2, t3, t4;
-
-  if (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
-    {
-      t1 = tvalue & 0xff000000;
-      t2 = tvalue & 0x00ff0000;
-      t3 = tvalue & 0x0000ff00;
-      t4 = tvalue & 0x000000ff;
-
-      hvalue =  t1 >> 24;
-      hvalue += t2 >> 8;
-      hvalue += t3 << 8;
-      hvalue += t4 << 24;
-    }
-  else
-    hvalue = tvalue;
+/* TODO: These functions are a big hack and assume that the host runtime has
+   type sizes and struct layouts that match the target.  So the Linux emulation
+   probaly only really works in 32-bit runtimes.  */
 
-  return hvalue;
-}
-
-static unsigned short
-conv_endian16 (unsigned short tvalue)
+static void
+translate_endian_h2t (void *addr, size_t size)
 {
-  unsigned short hvalue;
-  unsigned short t1, t2;
-
-  if (HOST_BYTE_ORDER == BFD_ENDIAN_LITTLE)
-    {
-      t1 = tvalue & 0xff00;
-      t2 = tvalue & 0x00ff;
+  unsigned int *p = (unsigned int *) addr;
+  int i;
 
-      hvalue =  t1 >> 8;
-      hvalue += t2 << 8;
-    }
-  else
-    hvalue = tvalue;
+  for (i = 0; i <= size - 4; i += 4,p++)
+    *p = H2T_4 (*p);
 
-  return hvalue;
+  if (i <= size - 2)
+    *((unsigned short *) p) = H2T_2 (*((unsigned short *) p));
 }
 
 static void
-translate_endian(void *addr, size_t size)
+translate_endian_t2h (void *addr, size_t size)
 {
   unsigned int *p = (unsigned int *) addr;
   int i;
-  
+
   for (i = 0; i <= size - 4; i += 4,p++)
-    *p = conv_endian(*p);
-  
+    *p = T2H_4 (*p);
+
   if (i <= size - 2)
-    *((unsigned short *) p) = conv_endian16(*((unsigned short *) p));
+    *((unsigned short *) p) = T2H_2 (*((unsigned short *) p));
 }
 
 /* Trap support.
@@ -326,7 +299,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
                   if (result != 0)
                     break;
 
-                  translate_endian((void *) &t, sizeof(t));
+                  t = H2T_4 (t);
                   if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t)) != sizeof(t))
                     {
                       result = -1;
@@ -382,7 +355,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               else
                 {
                   buf = *((struct utimbuf *) t2h_addr(cb, &s, arg2));
-                  translate_endian((void *) &buf, sizeof(buf));
+                  translate_endian_t2h (&buf, sizeof(buf));
                   result = utime((char *) t2h_addr(cb, &s, arg1), &buf);
                   errcode = errno;
                 }
@@ -404,10 +377,10 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              t.time = conv_endian(t.time);
-              t.millitm = conv_endian16(t.millitm);
-              t.timezone = conv_endian16(t.timezone);
-              t.dstflag = conv_endian16(t.dstflag);
+              t.time = H2T_4 (t.time);
+              t.millitm = H2T_2 (t.millitm);
+              t.timezone = H2T_2 (t.timezone);
+              t.dstflag = H2T_2 (t.dstflag);
               if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t))
                   != sizeof(t))
                 {
@@ -501,7 +474,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              translate_endian((void *) &rlim, sizeof(rlim));
+              translate_endian_h2t (&rlim, sizeof(rlim));
               if ((s.write_mem) (cb, &s, arg2, (char *) &rlim, sizeof(rlim))
                   != sizeof(rlim))
                 {
@@ -521,7 +494,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              translate_endian((void *) &usage, sizeof(usage));
+              translate_endian_h2t (&usage, sizeof(usage));
               if ((s.write_mem) (cb, &s, arg2, (char *) &usage, sizeof(usage))
                   != sizeof(usage))
                 {
@@ -542,7 +515,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              translate_endian((void *) &tv, sizeof(tv));
+              translate_endian_h2t (&tv, sizeof(tv));
               if ((s.write_mem) (cb, &s, arg1, (char *) &tv, sizeof(tv))
                   != sizeof(tv))
                 {
@@ -550,7 +523,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
                   errcode = EINVAL;
                 }
 
-              translate_endian((void *) &tz, sizeof(tz));
+              translate_endian_h2t (&tz, sizeof(tz));
               if ((s.write_mem) (cb, &s, arg2, (char *) &tz, sizeof(tz))
                   != sizeof(tz))
                 {
@@ -574,7 +547,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              translate_endian((void *) list, arg1 * sizeof(gid_t));
+              translate_endian_h2t (list, arg1 * sizeof(gid_t));
               if (arg1 > 0)
                 if ((s.write_mem) (cb, &s, arg2, (char *) list, arg1 * sizeof(gid_t))
                     != arg1 * sizeof(gid_t))
@@ -606,7 +579,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (treadfdsp != NULL)
                 {
                   readfds = *((fd_set *) t2h_addr(cb, &s, (unsigned int) treadfdsp));
-                  translate_endian((void *) &readfds, sizeof(readfds));
+                  translate_endian_t2h (&readfds, sizeof(readfds));
                   hreadfdsp = &readfds;
                 }
               else
@@ -616,7 +589,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (twritefdsp != NULL)
                 {
                   writefds = *((fd_set *) t2h_addr(cb, &s, (unsigned int) twritefdsp));
-                  translate_endian((void *) &writefds, sizeof(writefds));
+                  translate_endian_t2h (&writefds, sizeof(writefds));
                   hwritefdsp = &writefds;
                 }
               else
@@ -626,7 +599,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (texceptfdsp != NULL)
                 {
                   exceptfds = *((fd_set *) t2h_addr(cb, &s, (unsigned int) texceptfdsp));
-                  translate_endian((void *) &exceptfds, sizeof(exceptfds));
+                  translate_endian_t2h (&exceptfds, sizeof(exceptfds));
                   hexceptfdsp = &exceptfds;
                 }
               else
@@ -634,7 +607,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               
               ttimeoutp = (struct timeval *) arg5;
               timeout = *((struct timeval *) t2h_addr(cb, &s, (unsigned int) ttimeoutp));
-              translate_endian((void *) &timeout, sizeof(timeout));
+              translate_endian_t2h (&timeout, sizeof(timeout));
 
               result = select(n, hreadfdsp, hwritefdsp, hexceptfdsp, &timeout);
               errcode = errno;
@@ -644,7 +617,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 
               if (treadfdsp != NULL)
                 {
-                  translate_endian((void *) &readfds, sizeof(readfds));
+                  translate_endian_h2t (&readfds, sizeof(readfds));
                   if ((s.write_mem) (cb, &s, (unsigned long) treadfdsp,
                        (char *) &readfds, sizeof(readfds)) != sizeof(readfds))
                     {
@@ -655,7 +628,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 
               if (twritefdsp != NULL)
                 {
-                  translate_endian((void *) &writefds, sizeof(writefds));
+                  translate_endian_h2t (&writefds, sizeof(writefds));
                   if ((s.write_mem) (cb, &s, (unsigned long) twritefdsp,
                        (char *) &writefds, sizeof(writefds)) != sizeof(writefds))
                     {
@@ -666,7 +639,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 
               if (texceptfdsp != NULL)
                 {
-                  translate_endian((void *) &exceptfds, sizeof(exceptfds));
+                  translate_endian_h2t (&exceptfds, sizeof(exceptfds));
                   if ((s.write_mem) (cb, &s, (unsigned long) texceptfdsp,
                        (char *) &exceptfds, sizeof(exceptfds)) != sizeof(exceptfds))
                     {
@@ -675,7 +648,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
                     }
                 }
 
-              translate_endian((void *) &timeout, sizeof(timeout));
+              translate_endian_h2t (&timeout, sizeof(timeout));
               if ((s.write_mem) (cb, &s, (unsigned long) ttimeoutp,
                    (char *) &timeout, sizeof(timeout)) != sizeof(timeout))
                 {
@@ -760,12 +733,12 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               fildes = *((int *)    t2h_addr(cb, &s, arg1 + 16));
               off    = *((off_t *)  t2h_addr(cb, &s, arg1 + 20));
 
-              addr   = (void *) conv_endian((unsigned int) addr);
-              len    = conv_endian(len);
-              prot   = conv_endian(prot);
-              flags  = conv_endian(flags);
-              fildes = conv_endian(fildes);
-              off    = conv_endian(off);
+              addr   = (void *) T2H_4 ((unsigned int) addr);
+              len    = T2H_4 (len);
+              prot   = T2H_4 (prot);
+              flags  = T2H_4 (flags);
+              fildes = T2H_4 (fildes);
+              off    = T2H_4 (off);
 
               //addr   = (void *) t2h_addr(cb, &s, (unsigned int) addr);
               result = (int) mmap(addr, len, prot, flags, fildes, off);
@@ -825,7 +798,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              translate_endian((void *) &statbuf, sizeof(statbuf));
+              translate_endian_h2t (&statbuf, sizeof(statbuf));
               if ((s.write_mem) (cb, &s, arg2, (char *) &statbuf, sizeof(statbuf))
                   != sizeof(statbuf))
                 {
@@ -845,7 +818,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              translate_endian((void *) &statbuf, sizeof(statbuf));
+              translate_endian_h2t (&statbuf, sizeof(statbuf));
               if ((s.write_mem) (cb, &s, arg2, (char *) &statbuf, sizeof(statbuf))
                   != sizeof(statbuf))
                 {
@@ -865,7 +838,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               struct itimerval value, ovalue;
 
               value = *((struct itimerval *) t2h_addr(cb, &s, arg2));
-              translate_endian((void *) &value, sizeof(value));
+              translate_endian_t2h (&value, sizeof(value));
 
               if (arg2 == 0)
                 {
@@ -880,7 +853,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
                   if (result != 0)
                     break;
 
-                  translate_endian((void *) &ovalue, sizeof(ovalue));
+                  translate_endian_h2t (&ovalue, sizeof(ovalue));
                   if ((s.write_mem) (cb, &s, arg3, (char *) &ovalue, sizeof(ovalue))
                       != sizeof(ovalue))
                     {
@@ -901,7 +874,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              translate_endian((void *) &value, sizeof(value));
+              translate_endian_h2t (&value, sizeof(value));
               if ((s.write_mem) (cb, &s, arg2, (char *) &value, sizeof(value))
                   != sizeof(value))
                 {
@@ -1020,21 +993,21 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              info.uptime    = conv_endian(info.uptime);
-              info.loads[0]  = conv_endian(info.loads[0]);
-              info.loads[1]  = conv_endian(info.loads[1]);
-              info.loads[2]  = conv_endian(info.loads[2]);
-              info.totalram  = conv_endian(info.totalram);
-              info.freeram   = conv_endian(info.freeram);
-              info.sharedram = conv_endian(info.sharedram);
-              info.bufferram = conv_endian(info.bufferram);
-              info.totalswap = conv_endian(info.totalswap);
-              info.freeswap  = conv_endian(info.freeswap);
-              info.procs     = conv_endian16(info.procs);
+              info.uptime    = H2T_4 (info.uptime);
+              info.loads[0]  = H2T_4 (info.loads[0]);
+              info.loads[1]  = H2T_4 (info.loads[1]);
+              info.loads[2]  = H2T_4 (info.loads[2]);
+              info.totalram  = H2T_4 (info.totalram);
+              info.freeram   = H2T_4 (info.freeram);
+              info.sharedram = H2T_4 (info.sharedram);
+              info.bufferram = H2T_4 (info.bufferram);
+              info.totalswap = H2T_4 (info.totalswap);
+              info.freeswap  = H2T_4 (info.freeswap);
+              info.procs     = H2T_2 (info.procs);
 #if LINUX_VERSION_CODE >= 0x20400
-              info.totalhigh = conv_endian(info.totalhigh);
-              info.freehigh  = conv_endian(info.freehigh);
-              info.mem_unit  = conv_endian(info.mem_unit);
+              info.totalhigh = H2T_4 (info.totalhigh);
+              info.freehigh  = H2T_4 (info.freehigh);
+              info.mem_unit  = H2T_4 (info.mem_unit);
 #endif
               if ((s.write_mem) (cb, &s, arg1, (char *) &info, sizeof(info))
                   != sizeof(info))
@@ -1077,7 +1050,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              translate_endian((void *) &buf, sizeof(buf));
+              translate_endian_h2t (&buf, sizeof(buf));
               if ((s.write_mem) (cb, &s, arg1, (char *) &buf, sizeof(buf))
                   != sizeof(buf))
                 {
@@ -1120,7 +1093,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              translate_endian((void *) &buf, sizeof(buf));
+              translate_endian_h2t (&buf, sizeof(buf));
               if ((s.write_mem) (cb, &s, t2h_addr(cb, &s, arg4),
                                  (char *) &buf, sizeof(buf)) != sizeof(buf))
                 {
@@ -1140,9 +1113,9 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              dir.d_ino = conv_endian(dir.d_ino);
-              dir.d_off = conv_endian(dir.d_off);
-              dir.d_reclen = conv_endian16(dir.d_reclen);
+              dir.d_ino = H2T_4 (dir.d_ino);
+              dir.d_off = H2T_4 (dir.d_off);
+              dir.d_reclen = H2T_2 (dir.d_reclen);
               if ((s.write_mem) (cb, &s, arg2, (char *) &dir, sizeof(dir))
                   != sizeof(dir))
                 {
@@ -1168,7 +1141,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               struct iovec vector;
 
               vector = *((struct iovec *) t2h_addr(cb, &s, arg2));
-              translate_endian((void *) &vector, sizeof(vector));
+              translate_endian_t2h (&vector, sizeof(vector));
 
               result = readv(arg1, &vector, arg3);
               errcode = errno;
@@ -1180,7 +1153,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               struct iovec vector;
 
               vector = *((struct iovec *) t2h_addr(cb, &s, arg2));
-              translate_endian((void *) &vector, sizeof(vector));
+              translate_endian_t2h (&vector, sizeof(vector));
 
               result = writev(arg1, &vector, arg3);
               errcode = errno;
@@ -1207,7 +1180,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               struct timespec req, rem;
 
               req = *((struct timespec *) t2h_addr(cb, &s, arg2));
-              translate_endian((void *) &req, sizeof(req));
+              translate_endian_t2h (&req, sizeof(req));
 
               result = nanosleep(&req, &rem);
               errcode = errno;
@@ -1215,7 +1188,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              translate_endian((void *) &rem, sizeof(rem));
+              translate_endian_h2t (&rem, sizeof(rem));
               if ((s.write_mem) (cb, &s, arg2, (char *) &rem, sizeof(rem))
                   != sizeof(rem))
                 {
@@ -1241,9 +1214,9 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              *((uid_t *) t2h_addr(cb, &s, arg1)) = conv_endian(ruid);
-              *((uid_t *) t2h_addr(cb, &s, arg2)) = conv_endian(euid);
-              *((uid_t *) t2h_addr(cb, &s, arg3)) = conv_endian(suid);
+              *((uid_t *) t2h_addr(cb, &s, arg1)) = H2T_4 (ruid);
+              *((uid_t *) t2h_addr(cb, &s, arg2)) = H2T_4 (euid);
+              *((uid_t *) t2h_addr(cb, &s, arg3)) = H2T_4 (suid);
             }
             break;
 
@@ -1252,9 +1225,9 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               struct pollfd ufds;
 
               ufds = *((struct pollfd *) t2h_addr(cb, &s, arg1));
-              ufds.fd = conv_endian(ufds.fd);
-              ufds.events = conv_endian16(ufds.events);
-              ufds.revents = conv_endian16(ufds.revents);
+              ufds.fd = T2H_4 (ufds.fd);
+              ufds.events = T2H_2 (ufds.events);
+              ufds.revents = T2H_2 (ufds.revents);
 
               result = poll(&ufds, arg2, arg3);
               errcode = errno;
@@ -1272,9 +1245,9 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              *((uid_t *) t2h_addr(cb, &s, arg1)) = conv_endian(rgid);
-              *((uid_t *) t2h_addr(cb, &s, arg2)) = conv_endian(egid);
-              *((uid_t *) t2h_addr(cb, &s, arg3)) = conv_endian(sgid);
+              *((uid_t *) t2h_addr(cb, &s, arg1)) = H2T_4 (rgid);
+              *((uid_t *) t2h_addr(cb, &s, arg2)) = H2T_4 (egid);
+              *((uid_t *) t2h_addr(cb, &s, arg3)) = H2T_4 (sgid);
             }
             break;
 
@@ -1304,7 +1277,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               off_t offset;
 
               offset = *((off_t *) t2h_addr(cb, &s, arg3));
-              offset = conv_endian(offset);
+              offset = T2H_4 (offset);
 
               result = sendfile(arg1, arg2, &offset, arg3);
               errcode = errno;
@@ -1312,7 +1285,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
               if (result != 0)
                 break;
 
-              *((off_t *) t2h_addr(cb, &s, arg3)) = conv_endian(offset);
+              *((off_t *) t2h_addr(cb, &s, arg3)) = H2T_4 (offset);
             }
             break;
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/6] sim: m32r: unify ELF & Linux traps logic
  2021-07-01  4:55 [PATCH 1/6] sim: m32r: namespace Linux syscall table Mike Frysinger
  2021-07-01  4:55 ` [PATCH 2/6] sim: m32r: fix virtual environment with Linux targets Mike Frysinger
  2021-07-01  4:55 ` [PATCH 3/6] sim: m32r: replace custom endian helpers with sim-endian Mike Frysinger
@ 2021-07-01  4:55 ` Mike Frysinger
  2021-07-12 14:20   ` John Baldwin
  2021-07-01  4:55 ` [PATCH 5/6] sim: m32r: reformat linux traps code Mike Frysinger
  2021-07-01  4:55 ` [PATCH 6/6] sim: m32r: merge with common configure script Mike Frysinger
  4 siblings, 1 reply; 10+ messages in thread
From: Mike Frysinger @ 2021-07-01  4:55 UTC (permalink / raw)
  To: gdb-patches

This makes the simulator work the same regardless of the target (bare
metal m32r-elf or Linux m32r-linux-gnu) by unifying the traps code.
It was mostly already the same with the only difference being support
for trap #2 reserved for Linux syscalls.  We can move that logic to
runtime by checking the current environment operating mode instead.
---
 sim/m32r/Makefile.in   |    5 +-
 sim/m32r/configure     |   15 -
 sim/m32r/configure.ac  |   13 -
 sim/m32r/sim-if.c      |   15 +-
 sim/m32r/sim-main.h    |    7 -
 sim/m32r/traps-linux.c | 1326 ----------------------------------------
 sim/m32r/traps.c       | 1199 +++++++++++++++++++++++++++++++++++-
 7 files changed, 1195 insertions(+), 1385 deletions(-)
 delete mode 100644 sim/m32r/traps-linux.c

diff --git a/sim/m32r/Makefile.in b/sim/m32r/Makefile.in
index eb9641ee8e67..8877edcf4ae6 100644
--- a/sim/m32r/Makefile.in
+++ b/sim/m32r/Makefile.in
@@ -22,7 +22,6 @@
 M32R_OBJS = m32r.o cpu.o decode.o sem.o model.o mloop.o
 M32RX_OBJS = m32rx.o cpux.o decodex.o modelx.o mloopx.o
 M32R2_OBJS = m32r2.o cpu2.o decode2.o model2.o mloop2.o
-TRAPS_OBJ = @traps_obj@
 
 SIM_OBJS = \
 	$(SIM_NEW_COMMON_OBJS) \
@@ -32,7 +31,7 @@ SIM_OBJS = \
 	$(M32R_OBJS) \
 	$(M32RX_OBJS) \
 	$(M32R2_OBJS) \
-	$(TRAPS_OBJ)
+	traps.o
 
 SIM_EXTRA_HW_DEVICES = m32r_cache m32r_uart
 
@@ -42,8 +41,6 @@ SIM_EXTRA_DEPS = \
 	arch.h cpuall.h m32r-sim.h $(srcdir)/../../opcodes/m32r-desc.h \
 	eng.h engx.h eng2.h
 
-SIM_EXTRA_CFLAGS = @sim_extra_cflags@
-
 SIM_EXTRA_CLEAN = m32r-clean
 
 # Code doesn't build cleanly yet.
diff --git a/sim/m32r/configure.ac b/sim/m32r/configure.ac
index d8054034abcb..99370b3a5770 100644
--- a/sim/m32r/configure.ac
+++ b/sim/m32r/configure.ac
@@ -2,17 +2,4 @@ dnl Process this file with autoconf to produce a configure script.
 AC_INIT(Makefile.in)
 AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
 
-  case "${target_alias}" in
-  m32r*-linux*)
-    traps_obj=traps-linux.o
-    sim_extra_cflags="-DM32R_LINUX"
-    ;;
-  *)
-    traps_obj=traps.o
-    sim_extra_cflags="-DM32R_ELF"
-    ;;
-  esac
-AC_SUBST(traps_obj)
-AC_SUBST(sim_extra_cflags)
-
 SIM_AC_OUTPUT
diff --git a/sim/m32r/sim-if.c b/sim/m32r/sim-if.c
index 8957e83bf334..e05b1630ace7 100644
--- a/sim/m32r/sim-if.c
+++ b/sim/m32r/sim-if.c
@@ -30,6 +30,8 @@
 
 #include "dv-m32r_uart.h"
 
+#define M32R_DEFAULT_MEM_SIZE 0x2000000 /* 32M */
+
 static void free_state (SIM_DESC);
 static void print_m32r_misc_cpu (SIM_CPU *cpu, int verbose);
 \f
@@ -158,12 +160,13 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char * const *argv,
     addr = 0;
   sim_pc_set (current_cpu, addr);
 
-#ifdef M32R_LINUX
-  m32rbf_h_cr_set (current_cpu,
-                    m32r_decode_gdb_ctrl_regnum(SPI_REGNUM), 0x1f00000);
-  m32rbf_h_cr_set (current_cpu,
-                    m32r_decode_gdb_ctrl_regnum(SPU_REGNUM), 0x1f00000);
-#endif
+  if (STATE_ENVIRONMENT (sd) == USER_ENVIRONMENT)
+    {
+      m32rbf_h_cr_set (current_cpu,
+		       m32r_decode_gdb_ctrl_regnum(SPI_REGNUM), 0x1f00000);
+      m32rbf_h_cr_set (current_cpu,
+		       m32r_decode_gdb_ctrl_regnum(SPU_REGNUM), 0x1f00000);
+    }
 
   /* Standalone mode (i.e. `run`) will take care of the argv for us in
      sim_open() -> sim_parse_args().  But in debug mode (i.e. 'target sim'
diff --git a/sim/m32r/sim-main.h b/sim/m32r/sim-main.h
index f89db483c8cf..2ce989a897a1 100644
--- a/sim/m32r/sim-main.h
+++ b/sim/m32r/sim-main.h
@@ -56,11 +56,4 @@ extern SIM_CORE_SIGNAL_FN m32r_core_signal;
 m32r_core_signal ((SD), (CPU), (CIA), (MAP), (NR_BYTES), (ADDR), \
 		  (TRANSFER), (ERROR))
 
-/* Default memory size.  */
-#ifdef M32R_LINUX
-#define M32R_DEFAULT_MEM_SIZE 0x2000000 /* 32M */
-#else
-#define M32R_DEFAULT_MEM_SIZE 0x800000 /* 8M */
-#endif
-
 #endif /* SIM_MAIN_H */
diff --git a/sim/m32r/traps-linux.c b/sim/m32r/traps-linux.c
deleted file mode 100644
index 4d86a0a4e361..000000000000
--- a/sim/m32r/traps-linux.c
+++ /dev/null
diff --git a/sim/m32r/traps.c b/sim/m32r/traps.c
index 4cec5c0d45ce..c4c1224ad276 100644
--- a/sim/m32r/traps.c
+++ b/sim/m32r/traps.c
@@ -1,6 +1,6 @@
 /* m32r exception, interrupt, and trap (EIT) support
    Copyright (C) 1998-2021 Free Software Foundation, Inc.
-   Contributed by Cygnus Solutions.
+   Contributed by Cygnus Solutions & Renesas.
 
    This file is part of GDB, the GNU debugger.
 
@@ -20,12 +20,37 @@
 /* This must come before any other includes.  */
 #include "defs.h"
 
+#include "portability.h"
 #include "sim-main.h"
 #include "sim-signal.h"
 #include "sim-syscall.h"
+#include "sim/callback.h"
+#include "syscall.h"
 #include "targ-vals.h"
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
 #include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+#include <utime.h>
+#include <sys/mman.h>
+#include <sys/poll.h>
+#include <sys/resource.h>
+#include <sys/sysinfo.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <sys/timex.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/utsname.h>
+#include <sys/vfs.h>
+#include <linux/sysctl.h>
+#include <linux/types.h>
+#include <linux/unistd.h>
 
+#define TRAP_LINUX_SYSCALL 2
 #define TRAP_FLUSH_CACHE 12
 /* The semantic code invokes this for invalid (unrecognized) instructions.  */
 
@@ -87,7 +112,7 @@ m32r_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,
 	default:
 	  abort ();
 	}
-	    
+
       m32rbf_h_cr_set (current_cpu, H_CR_BPC, cia);
 
       sim_engine_restart (CPU_STATE (current_cpu), current_cpu, NULL,
@@ -98,6 +123,52 @@ m32r_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,
 		     transfer, sig);
 }
 \f
+/* Translate target's address to host's address.  */
+
+static void *
+t2h_addr (host_callback *cb, struct cb_syscall *sc,
+	  unsigned long taddr)
+{
+  void *addr;
+  SIM_DESC sd = (SIM_DESC) sc->p1;
+  SIM_CPU *cpu = (SIM_CPU *) sc->p2;
+
+  if (taddr == 0)
+    return NULL;
+
+  return sim_core_trans_addr (sd, cpu, read_map, taddr);
+}
+
+/* TODO: These functions are a big hack and assume that the host runtime has
+   type sizes and struct layouts that match the target.  So the Linux emulation
+   probaly only really works in 32-bit runtimes.  */
+
+static void
+translate_endian_h2t (void *addr, size_t size)
+{
+  unsigned int *p = (unsigned int *) addr;
+  int i;
+
+  for (i = 0; i <= size - 4; i += 4,p++)
+    *p = H2T_4 (*p);
+
+  if (i <= size - 2)
+    *((unsigned short *) p) = H2T_2 (*((unsigned short *) p));
+}
+
+static void
+translate_endian_t2h (void *addr, size_t size)
+{
+  unsigned int *p = (unsigned int *) addr;
+  int i;
+
+  for (i = 0; i <= size - 4; i += 4,p++)
+    *p = T2H_4 (*p);
+
+  if (i <= size - 2)
+    *((unsigned short *) p) = T2H_2 (*((unsigned short *) p));
+}
+
 /* Trap support.
    The result is the pc address to continue at.
    Preprocessing like saving the various registers has already been done.  */
@@ -109,18 +180,11 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
   host_callback *cb = STATE_CALLBACK (sd);
 
   if (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)
-    {
-      /* The new pc is the trap vector entry.
-	 We assume there's a branch there to some handler.
-         Use cr5 as EVB (EIT Vector Base) register.  */
-      /* USI new_pc = EIT_TRAP_BASE_ADDR + num * 4; */
-      USI new_pc = m32rbf_h_cr_get (current_cpu, 5) + 0x40 + num * 4;
-      return new_pc;
-    }
+    goto case_default;
 
   switch (num)
     {
-    case TRAP_SYSCALL :
+    case TRAP_SYSCALL:
       {
 	long result, result2;
 	int errcode;
@@ -139,6 +203,1110 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 	break;
       }
 
+    case TRAP_LINUX_SYSCALL:
+      {
+	CB_SYSCALL s;
+        unsigned int func, arg1, arg2, arg3, arg4, arg5, arg6, arg7;
+        int result, result2, errcode;
+
+	if (STATE_ENVIRONMENT (sd) != USER_ENVIRONMENT)
+	  goto case_default;
+
+	func = m32rbf_h_gr_get (current_cpu, 7);
+	arg1 = m32rbf_h_gr_get (current_cpu, 0);
+	arg2 = m32rbf_h_gr_get (current_cpu, 1);
+	arg3 = m32rbf_h_gr_get (current_cpu, 2);
+	arg4 = m32rbf_h_gr_get (current_cpu, 3);
+	arg5 = m32rbf_h_gr_get (current_cpu, 4);
+	arg6 = m32rbf_h_gr_get (current_cpu, 5);
+	arg7 = m32rbf_h_gr_get (current_cpu, 6);
+
+        CB_SYSCALL_INIT (&s);
+        s.func = func;
+        s.arg1 = arg1;
+        s.arg2 = arg2;
+        s.arg3 = arg3;
+        s.arg4 = arg4;
+        s.arg5 = arg5;
+        s.arg6 = arg6;
+        s.arg7 = arg7;
+
+        s.p1 = (PTR) sd;
+        s.p2 = (PTR) current_cpu;
+        s.read_mem = sim_syscall_read_mem;
+        s.write_mem = sim_syscall_write_mem;
+
+        result = 0;
+        result2 = 0;
+        errcode = 0;
+
+        switch (func)
+          {
+          case TARGET_LINUX_SYS_exit:
+	    sim_engine_halt (sd, current_cpu, NULL, pc, sim_exited, arg1);
+            break;
+
+          case TARGET_LINUX_SYS_read:
+            result = read(arg1, t2h_addr(cb, &s, arg2), arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_write:
+            result = write(arg1, t2h_addr(cb, &s, arg2), arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_open:
+            result = open((char *) t2h_addr(cb, &s, arg1), arg2, arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_close:
+            result = close(arg1);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_creat:
+            result = creat((char *) t2h_addr(cb, &s, arg1), arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_link:
+            result = link((char *) t2h_addr(cb, &s, arg1),
+                          (char *) t2h_addr(cb, &s, arg2));
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_unlink:
+            result = unlink((char *) t2h_addr(cb, &s, arg1));
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_chdir:
+            result = chdir((char *) t2h_addr(cb, &s, arg1));
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_time:
+            {
+              time_t t;
+
+              if (arg1 == 0)
+                {
+                  result = (int) time(NULL);
+                  errcode = errno;
+                }
+              else
+                {
+                  result = (int) time(&t);
+                  errcode = errno;
+
+                  if (result != 0)
+                    break;
+
+                  t = H2T_4 (t);
+                  if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t)) != sizeof(t))
+                    {
+                      result = -1;
+                      errcode = EINVAL;
+                    }
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_mknod:
+            result = mknod((char *) t2h_addr(cb, &s, arg1),
+                           (mode_t) arg2, (dev_t) arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_chmod:
+            result = chmod((char *) t2h_addr(cb, &s, arg1), (mode_t) arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_lchown32:
+          case TARGET_LINUX_SYS_lchown:
+            result = lchown((char *) t2h_addr(cb, &s, arg1),
+                            (uid_t) arg2, (gid_t) arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_lseek:
+            result = (int) lseek(arg1, (off_t) arg2, arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_getpid:
+            result = getpid();
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_getuid32:
+          case TARGET_LINUX_SYS_getuid:
+            result = getuid();
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_utime:
+            {
+              struct utimbuf buf;
+
+              if (arg2 == 0)
+                {
+                  result = utime((char *) t2h_addr(cb, &s, arg1), NULL);
+                  errcode = errno;
+                }
+              else
+                {
+                  buf = *((struct utimbuf *) t2h_addr(cb, &s, arg2));
+                  translate_endian_t2h (&buf, sizeof(buf));
+                  result = utime((char *) t2h_addr(cb, &s, arg1), &buf);
+                  errcode = errno;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_access:
+            result = access((char *) t2h_addr(cb, &s, arg1), arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_ftime:
+            {
+              struct timeb t;
+
+              result = ftime(&t);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              t.time = H2T_4 (t.time);
+              t.millitm = H2T_2 (t.millitm);
+              t.timezone = H2T_2 (t.timezone);
+              t.dstflag = H2T_2 (t.dstflag);
+              if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t))
+                  != sizeof(t))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+
+          case TARGET_LINUX_SYS_sync:
+            sync();
+            result = 0;
+            break;
+
+          case TARGET_LINUX_SYS_rename:
+            result = rename((char *) t2h_addr(cb, &s, arg1),
+                            (char *) t2h_addr(cb, &s, arg2));
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_mkdir:
+            result = mkdir((char *) t2h_addr(cb, &s, arg1), arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_rmdir:
+            result = rmdir((char *) t2h_addr(cb, &s, arg1));
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_dup:
+            result = dup(arg1);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_brk:
+            result = brk((void *) arg1);
+            errcode = errno;
+            //result = arg1;
+            break;
+
+          case TARGET_LINUX_SYS_getgid32:
+          case TARGET_LINUX_SYS_getgid:
+            result = getgid();
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_geteuid32:
+          case TARGET_LINUX_SYS_geteuid:
+            result = geteuid();
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_getegid32:
+          case TARGET_LINUX_SYS_getegid:
+            result = getegid();
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_ioctl:
+            result = ioctl(arg1, arg2, arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_fcntl:
+            result = fcntl(arg1, arg2, arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_dup2:
+            result = dup2(arg1, arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_getppid:
+            result = getppid();
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_getpgrp:
+            result = getpgrp();
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_getrlimit:
+            {
+              struct rlimit rlim;
+
+              result = getrlimit(arg1, &rlim);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              translate_endian_h2t (&rlim, sizeof(rlim));
+              if ((s.write_mem) (cb, &s, arg2, (char *) &rlim, sizeof(rlim))
+                  != sizeof(rlim))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_getrusage:
+            {
+              struct rusage usage;
+
+              result = getrusage(arg1, &usage);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              translate_endian_h2t (&usage, sizeof(usage));
+              if ((s.write_mem) (cb, &s, arg2, (char *) &usage, sizeof(usage))
+                  != sizeof(usage))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_gettimeofday:
+            {
+              struct timeval tv;
+              struct timezone tz;
+              
+              result = gettimeofday(&tv, &tz);
+              errcode = errno;
+              
+              if (result != 0)
+                break;
+
+              translate_endian_h2t (&tv, sizeof(tv));
+              if ((s.write_mem) (cb, &s, arg1, (char *) &tv, sizeof(tv))
+                  != sizeof(tv))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+
+              translate_endian_h2t (&tz, sizeof(tz));
+              if ((s.write_mem) (cb, &s, arg2, (char *) &tz, sizeof(tz))
+                  != sizeof(tz))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_getgroups32:
+          case TARGET_LINUX_SYS_getgroups:
+            {
+              gid_t *list;
+
+              if (arg1 > 0)
+                list = (gid_t *) malloc(arg1 * sizeof(gid_t));
+
+              result = getgroups(arg1, list);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              translate_endian_h2t (list, arg1 * sizeof(gid_t));
+              if (arg1 > 0)
+                if ((s.write_mem) (cb, &s, arg2, (char *) list, arg1 * sizeof(gid_t))
+                    != arg1 * sizeof(gid_t))
+                  {
+                    result = -1;
+                     errcode = EINVAL;
+                  }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_select:
+            {
+              int n;
+              fd_set readfds;
+              fd_set *treadfdsp;
+              fd_set *hreadfdsp;
+              fd_set writefds;
+              fd_set *twritefdsp;
+              fd_set *hwritefdsp;
+              fd_set exceptfds;
+              fd_set *texceptfdsp;
+              fd_set *hexceptfdsp;
+              struct timeval *ttimeoutp;
+              struct timeval timeout;
+              
+              n = arg1;
+
+              treadfdsp = (fd_set *) arg2;
+              if (treadfdsp != NULL)
+                {
+                  readfds = *((fd_set *) t2h_addr(cb, &s, (unsigned int) treadfdsp));
+                  translate_endian_t2h (&readfds, sizeof(readfds));
+                  hreadfdsp = &readfds;
+                }
+              else
+                hreadfdsp = NULL;
+              
+              twritefdsp  = (fd_set *) arg3;
+              if (twritefdsp != NULL)
+                {
+                  writefds = *((fd_set *) t2h_addr(cb, &s, (unsigned int) twritefdsp));
+                  translate_endian_t2h (&writefds, sizeof(writefds));
+                  hwritefdsp = &writefds;
+                }
+              else
+                hwritefdsp = NULL;
+              
+              texceptfdsp = (fd_set *) arg4;
+              if (texceptfdsp != NULL)
+                {
+                  exceptfds = *((fd_set *) t2h_addr(cb, &s, (unsigned int) texceptfdsp));
+                  translate_endian_t2h (&exceptfds, sizeof(exceptfds));
+                  hexceptfdsp = &exceptfds;
+                }
+              else
+                hexceptfdsp = NULL;
+              
+              ttimeoutp = (struct timeval *) arg5;
+              timeout = *((struct timeval *) t2h_addr(cb, &s, (unsigned int) ttimeoutp));
+              translate_endian_t2h (&timeout, sizeof(timeout));
+
+              result = select(n, hreadfdsp, hwritefdsp, hexceptfdsp, &timeout);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              if (treadfdsp != NULL)
+                {
+                  translate_endian_h2t (&readfds, sizeof(readfds));
+                  if ((s.write_mem) (cb, &s, (unsigned long) treadfdsp,
+                       (char *) &readfds, sizeof(readfds)) != sizeof(readfds))
+                    {
+                      result = -1;
+                      errcode = EINVAL;
+                    }
+                }
+
+              if (twritefdsp != NULL)
+                {
+                  translate_endian_h2t (&writefds, sizeof(writefds));
+                  if ((s.write_mem) (cb, &s, (unsigned long) twritefdsp,
+                       (char *) &writefds, sizeof(writefds)) != sizeof(writefds))
+                    {
+                      result = -1;
+                      errcode = EINVAL;
+                    }
+                }
+
+              if (texceptfdsp != NULL)
+                {
+                  translate_endian_h2t (&exceptfds, sizeof(exceptfds));
+                  if ((s.write_mem) (cb, &s, (unsigned long) texceptfdsp,
+                       (char *) &exceptfds, sizeof(exceptfds)) != sizeof(exceptfds))
+                    {
+                      result = -1;
+                      errcode = EINVAL;
+                    }
+                }
+
+              translate_endian_h2t (&timeout, sizeof(timeout));
+              if ((s.write_mem) (cb, &s, (unsigned long) ttimeoutp,
+                   (char *) &timeout, sizeof(timeout)) != sizeof(timeout))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_symlink:
+            result = symlink((char *) t2h_addr(cb, &s, arg1),
+                             (char *) t2h_addr(cb, &s, arg2));
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_readlink:
+            result = readlink((char *) t2h_addr(cb, &s, arg1),
+                              (char *) t2h_addr(cb, &s, arg2),
+                              arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_readdir:
+            result = (int) readdir((DIR *) t2h_addr(cb, &s, arg1));
+            errcode = errno;
+            break;
+
+#if 0
+          case TARGET_LINUX_SYS_mmap:
+            {
+              result = (int) mmap((void *) t2h_addr(cb, &s, arg1),
+                                  arg2, arg3, arg4, arg5, arg6);
+              errcode = errno;
+
+              if (errno == 0)
+                {
+                  sim_core_attach (sd, NULL,
+                                   0, access_read_write_exec, 0,
+                                   result, arg2, 0, NULL, NULL);
+                }
+            }
+            break;
+#endif
+          case TARGET_LINUX_SYS_mmap2:
+            {
+              void *addr;
+              size_t len;
+              int prot, flags, fildes;
+              off_t off;
+              
+              addr   = (void *)  t2h_addr(cb, &s, arg1);
+              len    = arg2;
+              prot   = arg3;
+              flags  = arg4;
+              fildes = arg5;
+              off    = arg6 << 12;
+
+	      result = (int) mmap(addr, len, prot, flags, fildes, off);
+              errcode = errno;
+              if (result != -1)
+                {
+                  char c;
+		  if (sim_core_read_buffer (sd, NULL, read_map, &c, result, 1) == 0)
+                    sim_core_attach (sd, NULL,
+                                     0, access_read_write_exec, 0,
+                                     result, len, 0, NULL, NULL);
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_mmap:
+            {
+              void *addr;
+              size_t len;
+              int prot, flags, fildes;
+              off_t off;
+              
+              addr   = *((void **)  t2h_addr(cb, &s, arg1));
+              len    = *((size_t *) t2h_addr(cb, &s, arg1 + 4));
+              prot   = *((int *)    t2h_addr(cb, &s, arg1 + 8));
+              flags  = *((int *)    t2h_addr(cb, &s, arg1 + 12));
+              fildes = *((int *)    t2h_addr(cb, &s, arg1 + 16));
+              off    = *((off_t *)  t2h_addr(cb, &s, arg1 + 20));
+
+              addr   = (void *) T2H_4 ((unsigned int) addr);
+              len    = T2H_4 (len);
+              prot   = T2H_4 (prot);
+              flags  = T2H_4 (flags);
+              fildes = T2H_4 (fildes);
+              off    = T2H_4 (off);
+
+              //addr   = (void *) t2h_addr(cb, &s, (unsigned int) addr);
+              result = (int) mmap(addr, len, prot, flags, fildes, off);
+              errcode = errno;
+
+              //if (errno == 0)
+              if (result != -1)
+                {
+                  char c;
+		  if (sim_core_read_buffer (sd, NULL, read_map, &c, result, 1) == 0)
+                    sim_core_attach (sd, NULL,
+                                     0, access_read_write_exec, 0,
+                                     result, len, 0, NULL, NULL);
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_munmap:
+            {
+            result = munmap((void *)arg1, arg2);
+            errcode = errno;
+            if (result != -1)
+              {
+                sim_core_detach (sd, NULL, 0, arg2, result);
+              }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_truncate:
+            result = truncate((char *) t2h_addr(cb, &s, arg1), arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_ftruncate:
+            result = ftruncate(arg1, arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_fchmod:
+            result = fchmod(arg1, arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_fchown32:
+          case TARGET_LINUX_SYS_fchown:
+            result = fchown(arg1, arg2, arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_statfs:
+            {
+              struct statfs statbuf;
+
+              result = statfs((char *) t2h_addr(cb, &s, arg1), &statbuf);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              translate_endian_h2t (&statbuf, sizeof(statbuf));
+              if ((s.write_mem) (cb, &s, arg2, (char *) &statbuf, sizeof(statbuf))
+                  != sizeof(statbuf))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_fstatfs:
+            {
+              struct statfs statbuf;
+
+              result = fstatfs(arg1, &statbuf);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              translate_endian_h2t (&statbuf, sizeof(statbuf));
+              if ((s.write_mem) (cb, &s, arg2, (char *) &statbuf, sizeof(statbuf))
+                  != sizeof(statbuf))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_syslog:
+            result = syslog(arg1, (char *) t2h_addr(cb, &s, arg2));
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_setitimer:
+            {
+              struct itimerval value, ovalue;
+
+              value = *((struct itimerval *) t2h_addr(cb, &s, arg2));
+              translate_endian_t2h (&value, sizeof(value));
+
+              if (arg2 == 0)
+                {
+                  result = setitimer(arg1, &value, NULL);
+                  errcode = errno;
+                }
+              else
+                {
+                  result = setitimer(arg1, &value, &ovalue);
+                  errcode = errno;
+
+                  if (result != 0)
+                    break;
+
+                  translate_endian_h2t (&ovalue, sizeof(ovalue));
+                  if ((s.write_mem) (cb, &s, arg3, (char *) &ovalue, sizeof(ovalue))
+                      != sizeof(ovalue))
+                    {
+                      result = -1;
+                      errcode = EINVAL;
+                    }
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_getitimer:
+            {
+              struct itimerval value;
+
+              result = getitimer(arg1, &value);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              translate_endian_h2t (&value, sizeof(value));
+              if ((s.write_mem) (cb, &s, arg2, (char *) &value, sizeof(value))
+                  != sizeof(value))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_stat:
+            {
+              char *buf;
+              int buflen;
+              struct stat statbuf;
+
+              result = stat((char *) t2h_addr(cb, &s, arg1), &statbuf);
+              errcode = errno;
+              if (result < 0)
+                break;
+
+              buflen = cb_host_to_target_stat (cb, NULL, NULL);
+              buf = xmalloc (buflen);
+              if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)
+                {
+                  /* The translation failed.  This is due to an internal
+                     host program error, not the target's fault.  */
+                  free (buf);
+                  result = -1;
+                  errcode = ENOSYS;
+                  break;
+                }
+              if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)
+                {
+                  free (buf);
+                  result = -1;
+                  errcode = EINVAL;
+                  break;
+                }
+              free (buf);
+            }
+            break;
+
+          case TARGET_LINUX_SYS_lstat:
+            {
+              char *buf;
+              int buflen;
+              struct stat statbuf;
+
+              result = lstat((char *) t2h_addr(cb, &s, arg1), &statbuf);
+              errcode = errno;
+              if (result < 0)
+                break;
+
+              buflen = cb_host_to_target_stat (cb, NULL, NULL);
+              buf = xmalloc (buflen);
+              if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)
+                {
+                  /* The translation failed.  This is due to an internal
+                     host program error, not the target's fault.  */
+                  free (buf);
+                  result = -1;
+                  errcode = ENOSYS;
+                  break;
+                }
+              if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)
+                {
+                  free (buf);
+                  result = -1;
+                  errcode = EINVAL;
+                  break;
+                }
+              free (buf);
+            }
+            break;
+
+          case TARGET_LINUX_SYS_fstat:
+            {
+              char *buf;
+              int buflen;
+              struct stat statbuf;
+
+              result = fstat(arg1, &statbuf);
+              errcode = errno;
+              if (result < 0)
+                break;
+
+              buflen = cb_host_to_target_stat (cb, NULL, NULL);
+              buf = xmalloc (buflen);
+              if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)
+                {
+                  /* The translation failed.  This is due to an internal
+                     host program error, not the target's fault.  */
+                  free (buf);
+                  result = -1;
+                  errcode = ENOSYS;
+                  break;
+                }
+              if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)
+                {
+                  free (buf);
+                  result = -1;
+                  errcode = EINVAL;
+                  break;
+                }
+              free (buf);
+            }
+            break;
+
+          case TARGET_LINUX_SYS_sysinfo:
+            {
+              struct sysinfo info;
+
+              result = sysinfo(&info);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              info.uptime    = H2T_4 (info.uptime);
+              info.loads[0]  = H2T_4 (info.loads[0]);
+              info.loads[1]  = H2T_4 (info.loads[1]);
+              info.loads[2]  = H2T_4 (info.loads[2]);
+              info.totalram  = H2T_4 (info.totalram);
+              info.freeram   = H2T_4 (info.freeram);
+              info.sharedram = H2T_4 (info.sharedram);
+              info.bufferram = H2T_4 (info.bufferram);
+              info.totalswap = H2T_4 (info.totalswap);
+              info.freeswap  = H2T_4 (info.freeswap);
+              info.procs     = H2T_2 (info.procs);
+#if LINUX_VERSION_CODE >= 0x20400
+              info.totalhigh = H2T_4 (info.totalhigh);
+              info.freehigh  = H2T_4 (info.freehigh);
+              info.mem_unit  = H2T_4 (info.mem_unit);
+#endif
+              if ((s.write_mem) (cb, &s, arg1, (char *) &info, sizeof(info))
+                  != sizeof(info))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+#if 0
+          case TARGET_LINUX_SYS_ipc:
+            {
+              result = ipc(arg1, arg2, arg3, arg4,
+                           (void *) t2h_addr(cb, &s, arg5), arg6);
+              errcode = errno;
+            }
+            break;
+#endif
+
+          case TARGET_LINUX_SYS_fsync:
+            result = fsync(arg1);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_uname:
+            /* utsname contains only arrays of char, so it is not necessary
+               to translate endian. */
+            result = uname((struct utsname *) t2h_addr(cb, &s, arg1));
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_adjtimex:
+            {
+              struct timex buf;
+
+              result = adjtimex(&buf);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              translate_endian_h2t (&buf, sizeof(buf));
+              if ((s.write_mem) (cb, &s, arg1, (char *) &buf, sizeof(buf))
+                  != sizeof(buf))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_mprotect:
+            result = mprotect((void *) arg1, arg2, arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_fchdir:
+            result = fchdir(arg1);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_setfsuid32:
+          case TARGET_LINUX_SYS_setfsuid:
+            result = setfsuid(arg1);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_setfsgid32:
+          case TARGET_LINUX_SYS_setfsgid:
+            result = setfsgid(arg1);
+            errcode = errno;
+            break;
+
+#if 0
+          case TARGET_LINUX_SYS__llseek:
+            {
+              loff_t buf;
+
+              result = _llseek(arg1, arg2, arg3, &buf, arg5);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              translate_endian_h2t (&buf, sizeof(buf));
+              if ((s.write_mem) (cb, &s, t2h_addr(cb, &s, arg4),
+                                 (char *) &buf, sizeof(buf)) != sizeof(buf))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_getdents:
+            {
+              struct dirent dir;
+
+              result = getdents(arg1, &dir, arg3);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              dir.d_ino = H2T_4 (dir.d_ino);
+              dir.d_off = H2T_4 (dir.d_off);
+              dir.d_reclen = H2T_2 (dir.d_reclen);
+              if ((s.write_mem) (cb, &s, arg2, (char *) &dir, sizeof(dir))
+                  != sizeof(dir))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+#endif
+
+          case TARGET_LINUX_SYS_flock:
+            result = flock(arg1, arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_msync:
+            result = msync((void *) arg1, arg2, arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_readv:
+            {
+              struct iovec vector;
+
+              vector = *((struct iovec *) t2h_addr(cb, &s, arg2));
+              translate_endian_t2h (&vector, sizeof(vector));
+
+              result = readv(arg1, &vector, arg3);
+              errcode = errno;
+            }
+            break;
+
+          case TARGET_LINUX_SYS_writev:
+            {
+              struct iovec vector;
+
+              vector = *((struct iovec *) t2h_addr(cb, &s, arg2));
+              translate_endian_t2h (&vector, sizeof(vector));
+
+              result = writev(arg1, &vector, arg3);
+              errcode = errno;
+            }
+            break;
+
+          case TARGET_LINUX_SYS_fdatasync:
+            result = fdatasync(arg1);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_mlock:
+            result = mlock((void *) t2h_addr(cb, &s, arg1), arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_munlock:
+            result = munlock((void *) t2h_addr(cb, &s, arg1), arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_nanosleep:
+            {
+              struct timespec req, rem;
+
+              req = *((struct timespec *) t2h_addr(cb, &s, arg2));
+              translate_endian_t2h (&req, sizeof(req));
+
+              result = nanosleep(&req, &rem);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              translate_endian_h2t (&rem, sizeof(rem));
+              if ((s.write_mem) (cb, &s, arg2, (char *) &rem, sizeof(rem))
+                  != sizeof(rem))
+                {
+                  result = -1;
+                  errcode = EINVAL;
+                }
+            }
+            break;
+
+          case TARGET_LINUX_SYS_mremap: /* FIXME */
+            result = (int) mremap((void *) t2h_addr(cb, &s, arg1), arg2, arg3, arg4); 
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_getresuid32:
+          case TARGET_LINUX_SYS_getresuid:
+            {
+              uid_t ruid, euid, suid;
+
+              result = getresuid(&ruid, &euid, &suid);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              *((uid_t *) t2h_addr(cb, &s, arg1)) = H2T_4 (ruid);
+              *((uid_t *) t2h_addr(cb, &s, arg2)) = H2T_4 (euid);
+              *((uid_t *) t2h_addr(cb, &s, arg3)) = H2T_4 (suid);
+            }
+            break;
+
+          case TARGET_LINUX_SYS_poll:
+            {
+              struct pollfd ufds;
+
+              ufds = *((struct pollfd *) t2h_addr(cb, &s, arg1));
+              ufds.fd = T2H_4 (ufds.fd);
+              ufds.events = T2H_2 (ufds.events);
+              ufds.revents = T2H_2 (ufds.revents);
+
+              result = poll(&ufds, arg2, arg3);
+              errcode = errno;
+            }
+            break;
+
+          case TARGET_LINUX_SYS_getresgid32:
+          case TARGET_LINUX_SYS_getresgid:
+            {
+              uid_t rgid, egid, sgid;
+
+              result = getresgid(&rgid, &egid, &sgid);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              *((uid_t *) t2h_addr(cb, &s, arg1)) = H2T_4 (rgid);
+              *((uid_t *) t2h_addr(cb, &s, arg2)) = H2T_4 (egid);
+              *((uid_t *) t2h_addr(cb, &s, arg3)) = H2T_4 (sgid);
+            }
+            break;
+
+          case TARGET_LINUX_SYS_pread:
+            result =  pread(arg1, (void *) t2h_addr(cb, &s, arg2), arg3, arg4); 
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_pwrite:
+            result =  pwrite(arg1, (void *) t2h_addr(cb, &s, arg2), arg3, arg4); 
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_chown32:
+          case TARGET_LINUX_SYS_chown:
+            result = chown((char *) t2h_addr(cb, &s, arg1), arg2, arg3);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_getcwd:
+            result = (int) getcwd((char *) t2h_addr(cb, &s, arg1), arg2);
+            errcode = errno;
+            break;
+
+          case TARGET_LINUX_SYS_sendfile:
+            {
+              off_t offset;
+
+              offset = *((off_t *) t2h_addr(cb, &s, arg3));
+              offset = T2H_4 (offset);
+
+              result = sendfile(arg1, arg2, &offset, arg3);
+              errcode = errno;
+
+              if (result != 0)
+                break;
+
+              *((off_t *) t2h_addr(cb, &s, arg3)) = H2T_4 (offset);
+            }
+            break;
+
+          default:
+            result = -1;
+            errcode = ENOSYS;
+            break;
+          }
+        
+        if (result == -1)
+	  m32rbf_h_gr_set (current_cpu, 0, -errcode);
+        else
+	  m32rbf_h_gr_set (current_cpu, 0, result);
+	break;
+      }
+
     case TRAP_BREAKPOINT:
       sim_engine_halt (sd, current_cpu, NULL, pc,
 		       sim_stopped, SIM_SIGTRAP);
@@ -148,11 +1316,14 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
       /* Do nothing.  */
       break;
 
-    default :
+    case_default:
+    default:
       {
+	/* The new pc is the trap vector entry.
+	   We assume there's a branch there to some handler.
+	   Use cr5 as EVB (EIT Vector Base) register.  */
 	/* USI new_pc = EIT_TRAP_BASE_ADDR + num * 4; */
-        /* Use cr5 as EVB (EIT Vector Base) register.  */
-        USI new_pc = m32rbf_h_cr_get (current_cpu, 5) + 0x40 + num * 4;
+	USI new_pc = m32rbf_h_cr_get (current_cpu, 5) + 0x40 + num * 4;
 	return new_pc;
       }
     }
-- 
2.31.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 5/6] sim: m32r: reformat linux traps code
  2021-07-01  4:55 [PATCH 1/6] sim: m32r: namespace Linux syscall table Mike Frysinger
                   ` (2 preceding siblings ...)
  2021-07-01  4:55 ` [PATCH 4/6] sim: m32r: unify ELF & Linux traps logic Mike Frysinger
@ 2021-07-01  4:55 ` Mike Frysinger
  2021-07-01  4:55 ` [PATCH 6/6] sim: m32r: merge with common configure script Mike Frysinger
  4 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2021-07-01  4:55 UTC (permalink / raw)
  To: gdb-patches

Do this as a sep commit to try and make the history easier to review.
---
 sim/m32r/traps.c | 2130 +++++++++++++++++++++++-----------------------
 1 file changed, 1063 insertions(+), 1067 deletions(-)

diff --git a/sim/m32r/traps.c b/sim/m32r/traps.c
index c4c1224ad276..b9912f95106e 100644
--- a/sim/m32r/traps.c
+++ b/sim/m32r/traps.c
@@ -206,8 +206,8 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
     case TRAP_LINUX_SYSCALL:
       {
 	CB_SYSCALL s;
-        unsigned int func, arg1, arg2, arg3, arg4, arg5, arg6, arg7;
-        int result, result2, errcode;
+	unsigned int func, arg1, arg2, arg3, arg4, arg5, arg6, arg7;
+	int result, result2, errcode;
 
 	if (STATE_ENVIRONMENT (sd) != USER_ENVIRONMENT)
 	  goto case_default;
@@ -221,1088 +221,1084 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 	arg6 = m32rbf_h_gr_get (current_cpu, 5);
 	arg7 = m32rbf_h_gr_get (current_cpu, 6);
 
-        CB_SYSCALL_INIT (&s);
-        s.func = func;
-        s.arg1 = arg1;
-        s.arg2 = arg2;
-        s.arg3 = arg3;
-        s.arg4 = arg4;
-        s.arg5 = arg5;
-        s.arg6 = arg6;
-        s.arg7 = arg7;
-
-        s.p1 = (PTR) sd;
-        s.p2 = (PTR) current_cpu;
-        s.read_mem = sim_syscall_read_mem;
-        s.write_mem = sim_syscall_write_mem;
-
-        result = 0;
-        result2 = 0;
-        errcode = 0;
-
-        switch (func)
-          {
-          case TARGET_LINUX_SYS_exit:
+	CB_SYSCALL_INIT (&s);
+	s.func = func;
+	s.arg1 = arg1;
+	s.arg2 = arg2;
+	s.arg3 = arg3;
+	s.arg4 = arg4;
+	s.arg5 = arg5;
+	s.arg6 = arg6;
+	s.arg7 = arg7;
+
+	s.p1 = (PTR) sd;
+	s.p2 = (PTR) current_cpu;
+	s.read_mem = sim_syscall_read_mem;
+	s.write_mem = sim_syscall_write_mem;
+
+	result = 0;
+	result2 = 0;
+	errcode = 0;
+
+	switch (func)
+	  {
+	  case TARGET_LINUX_SYS_exit:
 	    sim_engine_halt (sd, current_cpu, NULL, pc, sim_exited, arg1);
-            break;
-
-          case TARGET_LINUX_SYS_read:
-            result = read(arg1, t2h_addr(cb, &s, arg2), arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_write:
-            result = write(arg1, t2h_addr(cb, &s, arg2), arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_open:
-            result = open((char *) t2h_addr(cb, &s, arg1), arg2, arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_close:
-            result = close(arg1);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_creat:
-            result = creat((char *) t2h_addr(cb, &s, arg1), arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_link:
-            result = link((char *) t2h_addr(cb, &s, arg1),
-                          (char *) t2h_addr(cb, &s, arg2));
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_unlink:
-            result = unlink((char *) t2h_addr(cb, &s, arg1));
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_chdir:
-            result = chdir((char *) t2h_addr(cb, &s, arg1));
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_time:
-            {
-              time_t t;
-
-              if (arg1 == 0)
-                {
-                  result = (int) time(NULL);
-                  errcode = errno;
-                }
-              else
-                {
-                  result = (int) time(&t);
-                  errcode = errno;
-
-                  if (result != 0)
-                    break;
-
-                  t = H2T_4 (t);
-                  if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t)) != sizeof(t))
-                    {
-                      result = -1;
-                      errcode = EINVAL;
-                    }
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_mknod:
-            result = mknod((char *) t2h_addr(cb, &s, arg1),
-                           (mode_t) arg2, (dev_t) arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_chmod:
-            result = chmod((char *) t2h_addr(cb, &s, arg1), (mode_t) arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_lchown32:
-          case TARGET_LINUX_SYS_lchown:
-            result = lchown((char *) t2h_addr(cb, &s, arg1),
-                            (uid_t) arg2, (gid_t) arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_lseek:
-            result = (int) lseek(arg1, (off_t) arg2, arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_getpid:
-            result = getpid();
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_getuid32:
-          case TARGET_LINUX_SYS_getuid:
-            result = getuid();
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_utime:
-            {
-              struct utimbuf buf;
-
-              if (arg2 == 0)
-                {
-                  result = utime((char *) t2h_addr(cb, &s, arg1), NULL);
-                  errcode = errno;
-                }
-              else
-                {
-                  buf = *((struct utimbuf *) t2h_addr(cb, &s, arg2));
-                  translate_endian_t2h (&buf, sizeof(buf));
-                  result = utime((char *) t2h_addr(cb, &s, arg1), &buf);
-                  errcode = errno;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_access:
-            result = access((char *) t2h_addr(cb, &s, arg1), arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_ftime:
-            {
-              struct timeb t;
-
-              result = ftime(&t);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              t.time = H2T_4 (t.time);
-              t.millitm = H2T_2 (t.millitm);
-              t.timezone = H2T_2 (t.timezone);
-              t.dstflag = H2T_2 (t.dstflag);
-              if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t))
-                  != sizeof(t))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-
-          case TARGET_LINUX_SYS_sync:
-            sync();
-            result = 0;
-            break;
-
-          case TARGET_LINUX_SYS_rename:
-            result = rename((char *) t2h_addr(cb, &s, arg1),
-                            (char *) t2h_addr(cb, &s, arg2));
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_mkdir:
-            result = mkdir((char *) t2h_addr(cb, &s, arg1), arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_rmdir:
-            result = rmdir((char *) t2h_addr(cb, &s, arg1));
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_dup:
-            result = dup(arg1);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_brk:
-            result = brk((void *) arg1);
-            errcode = errno;
-            //result = arg1;
-            break;
-
-          case TARGET_LINUX_SYS_getgid32:
-          case TARGET_LINUX_SYS_getgid:
-            result = getgid();
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_geteuid32:
-          case TARGET_LINUX_SYS_geteuid:
-            result = geteuid();
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_getegid32:
-          case TARGET_LINUX_SYS_getegid:
-            result = getegid();
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_ioctl:
-            result = ioctl(arg1, arg2, arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_fcntl:
-            result = fcntl(arg1, arg2, arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_dup2:
-            result = dup2(arg1, arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_getppid:
-            result = getppid();
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_getpgrp:
-            result = getpgrp();
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_getrlimit:
-            {
-              struct rlimit rlim;
-
-              result = getrlimit(arg1, &rlim);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              translate_endian_h2t (&rlim, sizeof(rlim));
-              if ((s.write_mem) (cb, &s, arg2, (char *) &rlim, sizeof(rlim))
-                  != sizeof(rlim))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_getrusage:
-            {
-              struct rusage usage;
-
-              result = getrusage(arg1, &usage);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              translate_endian_h2t (&usage, sizeof(usage));
-              if ((s.write_mem) (cb, &s, arg2, (char *) &usage, sizeof(usage))
-                  != sizeof(usage))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_gettimeofday:
-            {
-              struct timeval tv;
-              struct timezone tz;
-              
-              result = gettimeofday(&tv, &tz);
-              errcode = errno;
-              
-              if (result != 0)
-                break;
-
-              translate_endian_h2t (&tv, sizeof(tv));
-              if ((s.write_mem) (cb, &s, arg1, (char *) &tv, sizeof(tv))
-                  != sizeof(tv))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-
-              translate_endian_h2t (&tz, sizeof(tz));
-              if ((s.write_mem) (cb, &s, arg2, (char *) &tz, sizeof(tz))
-                  != sizeof(tz))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_getgroups32:
-          case TARGET_LINUX_SYS_getgroups:
-            {
-              gid_t *list;
-
-              if (arg1 > 0)
-                list = (gid_t *) malloc(arg1 * sizeof(gid_t));
-
-              result = getgroups(arg1, list);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              translate_endian_h2t (list, arg1 * sizeof(gid_t));
-              if (arg1 > 0)
-                if ((s.write_mem) (cb, &s, arg2, (char *) list, arg1 * sizeof(gid_t))
-                    != arg1 * sizeof(gid_t))
-                  {
-                    result = -1;
-                     errcode = EINVAL;
-                  }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_select:
-            {
-              int n;
-              fd_set readfds;
-              fd_set *treadfdsp;
-              fd_set *hreadfdsp;
-              fd_set writefds;
-              fd_set *twritefdsp;
-              fd_set *hwritefdsp;
-              fd_set exceptfds;
-              fd_set *texceptfdsp;
-              fd_set *hexceptfdsp;
-              struct timeval *ttimeoutp;
-              struct timeval timeout;
-              
-              n = arg1;
-
-              treadfdsp = (fd_set *) arg2;
-              if (treadfdsp != NULL)
-                {
-                  readfds = *((fd_set *) t2h_addr(cb, &s, (unsigned int) treadfdsp));
-                  translate_endian_t2h (&readfds, sizeof(readfds));
-                  hreadfdsp = &readfds;
-                }
-              else
-                hreadfdsp = NULL;
-              
-              twritefdsp  = (fd_set *) arg3;
-              if (twritefdsp != NULL)
-                {
-                  writefds = *((fd_set *) t2h_addr(cb, &s, (unsigned int) twritefdsp));
-                  translate_endian_t2h (&writefds, sizeof(writefds));
-                  hwritefdsp = &writefds;
-                }
-              else
-                hwritefdsp = NULL;
-              
-              texceptfdsp = (fd_set *) arg4;
-              if (texceptfdsp != NULL)
-                {
-                  exceptfds = *((fd_set *) t2h_addr(cb, &s, (unsigned int) texceptfdsp));
-                  translate_endian_t2h (&exceptfds, sizeof(exceptfds));
-                  hexceptfdsp = &exceptfds;
-                }
-              else
-                hexceptfdsp = NULL;
-              
-              ttimeoutp = (struct timeval *) arg5;
-              timeout = *((struct timeval *) t2h_addr(cb, &s, (unsigned int) ttimeoutp));
-              translate_endian_t2h (&timeout, sizeof(timeout));
-
-              result = select(n, hreadfdsp, hwritefdsp, hexceptfdsp, &timeout);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              if (treadfdsp != NULL)
-                {
-                  translate_endian_h2t (&readfds, sizeof(readfds));
-                  if ((s.write_mem) (cb, &s, (unsigned long) treadfdsp,
-                       (char *) &readfds, sizeof(readfds)) != sizeof(readfds))
-                    {
-                      result = -1;
-                      errcode = EINVAL;
-                    }
-                }
-
-              if (twritefdsp != NULL)
-                {
-                  translate_endian_h2t (&writefds, sizeof(writefds));
-                  if ((s.write_mem) (cb, &s, (unsigned long) twritefdsp,
-                       (char *) &writefds, sizeof(writefds)) != sizeof(writefds))
-                    {
-                      result = -1;
-                      errcode = EINVAL;
-                    }
-                }
-
-              if (texceptfdsp != NULL)
-                {
-                  translate_endian_h2t (&exceptfds, sizeof(exceptfds));
-                  if ((s.write_mem) (cb, &s, (unsigned long) texceptfdsp,
-                       (char *) &exceptfds, sizeof(exceptfds)) != sizeof(exceptfds))
-                    {
-                      result = -1;
-                      errcode = EINVAL;
-                    }
-                }
-
-              translate_endian_h2t (&timeout, sizeof(timeout));
-              if ((s.write_mem) (cb, &s, (unsigned long) ttimeoutp,
-                   (char *) &timeout, sizeof(timeout)) != sizeof(timeout))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_symlink:
-            result = symlink((char *) t2h_addr(cb, &s, arg1),
-                             (char *) t2h_addr(cb, &s, arg2));
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_readlink:
-            result = readlink((char *) t2h_addr(cb, &s, arg1),
-                              (char *) t2h_addr(cb, &s, arg2),
-                              arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_readdir:
-            result = (int) readdir((DIR *) t2h_addr(cb, &s, arg1));
-            errcode = errno;
-            break;
+	    break;
+
+	  case TARGET_LINUX_SYS_read:
+	    result = read (arg1, t2h_addr (cb, &s, arg2), arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_write:
+	    result = write (arg1, t2h_addr (cb, &s, arg2), arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_open:
+	    result = open ((char *) t2h_addr (cb, &s, arg1), arg2, arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_close:
+	    result = close (arg1);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_creat:
+	    result = creat ((char *) t2h_addr (cb, &s, arg1), arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_link:
+	    result = link ((char *) t2h_addr (cb, &s, arg1),
+			   (char *) t2h_addr (cb, &s, arg2));
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_unlink:
+	    result = unlink ((char *) t2h_addr (cb, &s, arg1));
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_chdir:
+	    result = chdir ((char *) t2h_addr (cb, &s, arg1));
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_time:
+	    {
+	      time_t t;
+
+	      if (arg1 == 0)
+		{
+		  result = (int) time (NULL);
+		  errcode = errno;
+		}
+	      else
+		{
+		  result = (int) time (&t);
+		  errcode = errno;
+
+		  if (result != 0)
+		    break;
+
+		  t = H2T_4 (t);
+		  if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t)) != sizeof(t))
+		    {
+		      result = -1;
+		      errcode = EINVAL;
+		    }
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_mknod:
+	    result = mknod ((char *) t2h_addr (cb, &s, arg1),
+			    (mode_t) arg2, (dev_t) arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_chmod:
+	    result = chmod ((char *) t2h_addr (cb, &s, arg1), (mode_t) arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_lchown32:
+	  case TARGET_LINUX_SYS_lchown:
+	    result = lchown ((char *) t2h_addr (cb, &s, arg1),
+			     (uid_t) arg2, (gid_t) arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_lseek:
+	    result = (int) lseek (arg1, (off_t) arg2, arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_getpid:
+	    result = getpid ();
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_getuid32:
+	  case TARGET_LINUX_SYS_getuid:
+	    result = getuid ();
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_utime:
+	    {
+	      struct utimbuf buf;
+
+	      if (arg2 == 0)
+		{
+		  result = utime ((char *) t2h_addr (cb, &s, arg1), NULL);
+		  errcode = errno;
+		}
+	      else
+		{
+		  buf = *((struct utimbuf *) t2h_addr (cb, &s, arg2));
+		  translate_endian_t2h (&buf, sizeof(buf));
+		  result = utime ((char *) t2h_addr (cb, &s, arg1), &buf);
+		  errcode = errno;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_access:
+	    result = access ((char *) t2h_addr (cb, &s, arg1), arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_ftime:
+	    {
+	      struct timeb t;
+
+	      result = ftime (&t);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      t.time = H2T_4 (t.time);
+	      t.millitm = H2T_2 (t.millitm);
+	      t.timezone = H2T_2 (t.timezone);
+	      t.dstflag = H2T_2 (t.dstflag);
+	      if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t))
+		  != sizeof(t))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+
+	  case TARGET_LINUX_SYS_sync:
+	    sync ();
+	    result = 0;
+	    break;
+
+	  case TARGET_LINUX_SYS_rename:
+	    result = rename ((char *) t2h_addr (cb, &s, arg1),
+			     (char *) t2h_addr (cb, &s, arg2));
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_mkdir:
+	    result = mkdir ((char *) t2h_addr (cb, &s, arg1), arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_rmdir:
+	    result = rmdir ((char *) t2h_addr (cb, &s, arg1));
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_dup:
+	    result = dup (arg1);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_brk:
+	    result = brk ((void *) arg1);
+	    errcode = errno;
+	    //result = arg1;
+	    break;
+
+	  case TARGET_LINUX_SYS_getgid32:
+	  case TARGET_LINUX_SYS_getgid:
+	    result = getgid ();
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_geteuid32:
+	  case TARGET_LINUX_SYS_geteuid:
+	    result = geteuid ();
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_getegid32:
+	  case TARGET_LINUX_SYS_getegid:
+	    result = getegid ();
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_ioctl:
+	    result = ioctl (arg1, arg2, arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_fcntl:
+	    result = fcntl (arg1, arg2, arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_dup2:
+	    result = dup2 (arg1, arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_getppid:
+	    result = getppid ();
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_getpgrp:
+	    result = getpgrp ();
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_getrlimit:
+	    {
+	      struct rlimit rlim;
+
+	      result = getrlimit (arg1, &rlim);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      translate_endian_h2t (&rlim, sizeof(rlim));
+	      if ((s.write_mem) (cb, &s, arg2, (char *) &rlim, sizeof(rlim))
+		  != sizeof(rlim))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_getrusage:
+	    {
+	      struct rusage usage;
+
+	      result = getrusage (arg1, &usage);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      translate_endian_h2t (&usage, sizeof(usage));
+	      if ((s.write_mem) (cb, &s, arg2, (char *) &usage, sizeof(usage))
+		  != sizeof(usage))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_gettimeofday:
+	    {
+	      struct timeval tv;
+	      struct timezone tz;
+
+	      result = gettimeofday (&tv, &tz);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      translate_endian_h2t (&tv, sizeof(tv));
+	      if ((s.write_mem) (cb, &s, arg1, (char *) &tv, sizeof(tv))
+		  != sizeof(tv))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+
+	      translate_endian_h2t (&tz, sizeof(tz));
+	      if ((s.write_mem) (cb, &s, arg2, (char *) &tz, sizeof(tz))
+		  != sizeof(tz))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_getgroups32:
+	  case TARGET_LINUX_SYS_getgroups:
+	    {
+	      gid_t *list;
+
+	      if (arg1 > 0)
+		list = (gid_t *) malloc (arg1 * sizeof(gid_t));
+
+	      result = getgroups (arg1, list);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      translate_endian_h2t (list, arg1 * sizeof(gid_t));
+	      if (arg1 > 0)
+		if ((s.write_mem) (cb, &s, arg2, (char *) list, arg1 * sizeof(gid_t))
+		    != arg1 * sizeof(gid_t))
+		  {
+		    result = -1;
+		     errcode = EINVAL;
+		  }
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_select:
+	    {
+	      int n;
+	      fd_set readfds;
+	      fd_set *treadfdsp;
+	      fd_set *hreadfdsp;
+	      fd_set writefds;
+	      fd_set *twritefdsp;
+	      fd_set *hwritefdsp;
+	      fd_set exceptfds;
+	      fd_set *texceptfdsp;
+	      fd_set *hexceptfdsp;
+	      struct timeval *ttimeoutp;
+	      struct timeval timeout;
+
+	      n = arg1;
+
+	      treadfdsp = (fd_set *) arg2;
+	      if (treadfdsp != NULL)
+		{
+		  readfds = *((fd_set *) t2h_addr (cb, &s, (unsigned int) treadfdsp));
+		  translate_endian_t2h (&readfds, sizeof(readfds));
+		  hreadfdsp = &readfds;
+		}
+	      else
+		hreadfdsp = NULL;
+
+	      twritefdsp  = (fd_set *) arg3;
+	      if (twritefdsp != NULL)
+		{
+		  writefds = *((fd_set *) t2h_addr (cb, &s, (unsigned int) twritefdsp));
+		  translate_endian_t2h (&writefds, sizeof(writefds));
+		  hwritefdsp = &writefds;
+		}
+	      else
+		hwritefdsp = NULL;
+
+	      texceptfdsp = (fd_set *) arg4;
+	      if (texceptfdsp != NULL)
+		{
+		  exceptfds = *((fd_set *) t2h_addr (cb, &s, (unsigned int) texceptfdsp));
+		  translate_endian_t2h (&exceptfds, sizeof(exceptfds));
+		  hexceptfdsp = &exceptfds;
+		}
+	      else
+		hexceptfdsp = NULL;
+
+	      ttimeoutp = (struct timeval *) arg5;
+	      timeout = *((struct timeval *) t2h_addr (cb, &s, (unsigned int) ttimeoutp));
+	      translate_endian_t2h (&timeout, sizeof(timeout));
+
+	      result = select (n, hreadfdsp, hwritefdsp, hexceptfdsp, &timeout);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      if (treadfdsp != NULL)
+		{
+		  translate_endian_h2t (&readfds, sizeof(readfds));
+		  if ((s.write_mem) (cb, &s, (unsigned long) treadfdsp,
+		       (char *) &readfds, sizeof(readfds)) != sizeof(readfds))
+		    {
+		      result = -1;
+		      errcode = EINVAL;
+		    }
+		}
+
+	      if (twritefdsp != NULL)
+		{
+		  translate_endian_h2t (&writefds, sizeof(writefds));
+		  if ((s.write_mem) (cb, &s, (unsigned long) twritefdsp,
+		       (char *) &writefds, sizeof(writefds)) != sizeof(writefds))
+		    {
+		      result = -1;
+		      errcode = EINVAL;
+		    }
+		}
+
+	      if (texceptfdsp != NULL)
+		{
+		  translate_endian_h2t (&exceptfds, sizeof(exceptfds));
+		  if ((s.write_mem) (cb, &s, (unsigned long) texceptfdsp,
+		       (char *) &exceptfds, sizeof(exceptfds)) != sizeof(exceptfds))
+		    {
+		      result = -1;
+		      errcode = EINVAL;
+		    }
+		}
+
+	      translate_endian_h2t (&timeout, sizeof(timeout));
+	      if ((s.write_mem) (cb, &s, (unsigned long) ttimeoutp,
+		   (char *) &timeout, sizeof(timeout)) != sizeof(timeout))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_symlink:
+	    result = symlink ((char *) t2h_addr (cb, &s, arg1),
+			      (char *) t2h_addr (cb, &s, arg2));
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_readlink:
+	    result = readlink ((char *) t2h_addr (cb, &s, arg1),
+			       (char *) t2h_addr (cb, &s, arg2),
+			       arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_readdir:
+	    result = (int) readdir ((DIR *) t2h_addr (cb, &s, arg1));
+	    errcode = errno;
+	    break;
 
 #if 0
-          case TARGET_LINUX_SYS_mmap:
-            {
-              result = (int) mmap((void *) t2h_addr(cb, &s, arg1),
-                                  arg2, arg3, arg4, arg5, arg6);
-              errcode = errno;
-
-              if (errno == 0)
-                {
-                  sim_core_attach (sd, NULL,
-                                   0, access_read_write_exec, 0,
-                                   result, arg2, 0, NULL, NULL);
-                }
-            }
-            break;
+	  case TARGET_LINUX_SYS_mmap:
+	    {
+	      result = (int) mmap ((void *) t2h_addr (cb, &s, arg1),
+				   arg2, arg3, arg4, arg5, arg6);
+	      errcode = errno;
+
+	      if (errno == 0)
+		{
+		  sim_core_attach (sd, NULL,
+				   0, access_read_write_exec, 0,
+				   result, arg2, 0, NULL, NULL);
+		}
+	    }
+	    break;
 #endif
-          case TARGET_LINUX_SYS_mmap2:
-            {
-              void *addr;
-              size_t len;
-              int prot, flags, fildes;
-              off_t off;
-              
-              addr   = (void *)  t2h_addr(cb, &s, arg1);
-              len    = arg2;
-              prot   = arg3;
-              flags  = arg4;
-              fildes = arg5;
-              off    = arg6 << 12;
-
-	      result = (int) mmap(addr, len, prot, flags, fildes, off);
-              errcode = errno;
-              if (result != -1)
-                {
-                  char c;
+	  case TARGET_LINUX_SYS_mmap2:
+	    {
+	      void *addr;
+	      size_t len;
+	      int prot, flags, fildes;
+	      off_t off;
+
+	      addr   = (void *) t2h_addr (cb, &s, arg1);
+	      len    = arg2;
+	      prot   = arg3;
+	      flags  = arg4;
+	      fildes = arg5;
+	      off    = arg6 << 12;
+
+	      result = (int) mmap (addr, len, prot, flags, fildes, off);
+	      errcode = errno;
+	      if (result != -1)
+		{
+		  char c;
 		  if (sim_core_read_buffer (sd, NULL, read_map, &c, result, 1) == 0)
-                    sim_core_attach (sd, NULL,
-                                     0, access_read_write_exec, 0,
-                                     result, len, 0, NULL, NULL);
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_mmap:
-            {
-              void *addr;
-              size_t len;
-              int prot, flags, fildes;
-              off_t off;
-              
-              addr   = *((void **)  t2h_addr(cb, &s, arg1));
-              len    = *((size_t *) t2h_addr(cb, &s, arg1 + 4));
-              prot   = *((int *)    t2h_addr(cb, &s, arg1 + 8));
-              flags  = *((int *)    t2h_addr(cb, &s, arg1 + 12));
-              fildes = *((int *)    t2h_addr(cb, &s, arg1 + 16));
-              off    = *((off_t *)  t2h_addr(cb, &s, arg1 + 20));
-
-              addr   = (void *) T2H_4 ((unsigned int) addr);
-              len    = T2H_4 (len);
-              prot   = T2H_4 (prot);
-              flags  = T2H_4 (flags);
-              fildes = T2H_4 (fildes);
-              off    = T2H_4 (off);
-
-              //addr   = (void *) t2h_addr(cb, &s, (unsigned int) addr);
-              result = (int) mmap(addr, len, prot, flags, fildes, off);
-              errcode = errno;
-
-              //if (errno == 0)
-              if (result != -1)
-                {
-                  char c;
+		    sim_core_attach (sd, NULL,
+				     0, access_read_write_exec, 0,
+				     result, len, 0, NULL, NULL);
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_mmap:
+	    {
+	      void *addr;
+	      size_t len;
+	      int prot, flags, fildes;
+	      off_t off;
+
+	      addr   = *((void **)  t2h_addr (cb, &s, arg1));
+	      len    = *((size_t *) t2h_addr (cb, &s, arg1 + 4));
+	      prot   = *((int *)    t2h_addr (cb, &s, arg1 + 8));
+	      flags  = *((int *)    t2h_addr (cb, &s, arg1 + 12));
+	      fildes = *((int *)    t2h_addr (cb, &s, arg1 + 16));
+	      off    = *((off_t *)  t2h_addr (cb, &s, arg1 + 20));
+
+	      addr   = (void *) T2H_4 ((unsigned int) addr);
+	      len    = T2H_4 (len);
+	      prot   = T2H_4 (prot);
+	      flags  = T2H_4 (flags);
+	      fildes = T2H_4 (fildes);
+	      off    = T2H_4 (off);
+
+	      //addr   = (void *) t2h_addr (cb, &s, (unsigned int) addr);
+	      result = (int) mmap (addr, len, prot, flags, fildes, off);
+	      errcode = errno;
+
+	      //if (errno == 0)
+	      if (result != -1)
+		{
+		  char c;
 		  if (sim_core_read_buffer (sd, NULL, read_map, &c, result, 1) == 0)
-                    sim_core_attach (sd, NULL,
-                                     0, access_read_write_exec, 0,
-                                     result, len, 0, NULL, NULL);
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_munmap:
-            {
-            result = munmap((void *)arg1, arg2);
-            errcode = errno;
-            if (result != -1)
-              {
-                sim_core_detach (sd, NULL, 0, arg2, result);
-              }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_truncate:
-            result = truncate((char *) t2h_addr(cb, &s, arg1), arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_ftruncate:
-            result = ftruncate(arg1, arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_fchmod:
-            result = fchmod(arg1, arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_fchown32:
-          case TARGET_LINUX_SYS_fchown:
-            result = fchown(arg1, arg2, arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_statfs:
-            {
-              struct statfs statbuf;
-
-              result = statfs((char *) t2h_addr(cb, &s, arg1), &statbuf);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              translate_endian_h2t (&statbuf, sizeof(statbuf));
-              if ((s.write_mem) (cb, &s, arg2, (char *) &statbuf, sizeof(statbuf))
-                  != sizeof(statbuf))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_fstatfs:
-            {
-              struct statfs statbuf;
-
-              result = fstatfs(arg1, &statbuf);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              translate_endian_h2t (&statbuf, sizeof(statbuf));
-              if ((s.write_mem) (cb, &s, arg2, (char *) &statbuf, sizeof(statbuf))
-                  != sizeof(statbuf))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_syslog:
-            result = syslog(arg1, (char *) t2h_addr(cb, &s, arg2));
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_setitimer:
-            {
-              struct itimerval value, ovalue;
-
-              value = *((struct itimerval *) t2h_addr(cb, &s, arg2));
-              translate_endian_t2h (&value, sizeof(value));
-
-              if (arg2 == 0)
-                {
-                  result = setitimer(arg1, &value, NULL);
-                  errcode = errno;
-                }
-              else
-                {
-                  result = setitimer(arg1, &value, &ovalue);
-                  errcode = errno;
-
-                  if (result != 0)
-                    break;
-
-                  translate_endian_h2t (&ovalue, sizeof(ovalue));
-                  if ((s.write_mem) (cb, &s, arg3, (char *) &ovalue, sizeof(ovalue))
-                      != sizeof(ovalue))
-                    {
-                      result = -1;
-                      errcode = EINVAL;
-                    }
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_getitimer:
-            {
-              struct itimerval value;
-
-              result = getitimer(arg1, &value);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              translate_endian_h2t (&value, sizeof(value));
-              if ((s.write_mem) (cb, &s, arg2, (char *) &value, sizeof(value))
-                  != sizeof(value))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_stat:
-            {
-              char *buf;
-              int buflen;
-              struct stat statbuf;
-
-              result = stat((char *) t2h_addr(cb, &s, arg1), &statbuf);
-              errcode = errno;
-              if (result < 0)
-                break;
-
-              buflen = cb_host_to_target_stat (cb, NULL, NULL);
-              buf = xmalloc (buflen);
-              if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)
-                {
-                  /* The translation failed.  This is due to an internal
-                     host program error, not the target's fault.  */
-                  free (buf);
-                  result = -1;
-                  errcode = ENOSYS;
-                  break;
-                }
-              if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)
-                {
-                  free (buf);
-                  result = -1;
-                  errcode = EINVAL;
-                  break;
-                }
-              free (buf);
-            }
-            break;
-
-          case TARGET_LINUX_SYS_lstat:
-            {
-              char *buf;
-              int buflen;
-              struct stat statbuf;
-
-              result = lstat((char *) t2h_addr(cb, &s, arg1), &statbuf);
-              errcode = errno;
-              if (result < 0)
-                break;
-
-              buflen = cb_host_to_target_stat (cb, NULL, NULL);
-              buf = xmalloc (buflen);
-              if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)
-                {
-                  /* The translation failed.  This is due to an internal
-                     host program error, not the target's fault.  */
-                  free (buf);
-                  result = -1;
-                  errcode = ENOSYS;
-                  break;
-                }
-              if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)
-                {
-                  free (buf);
-                  result = -1;
-                  errcode = EINVAL;
-                  break;
-                }
-              free (buf);
-            }
-            break;
-
-          case TARGET_LINUX_SYS_fstat:
-            {
-              char *buf;
-              int buflen;
-              struct stat statbuf;
-
-              result = fstat(arg1, &statbuf);
-              errcode = errno;
-              if (result < 0)
-                break;
-
-              buflen = cb_host_to_target_stat (cb, NULL, NULL);
-              buf = xmalloc (buflen);
-              if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)
-                {
-                  /* The translation failed.  This is due to an internal
-                     host program error, not the target's fault.  */
-                  free (buf);
-                  result = -1;
-                  errcode = ENOSYS;
-                  break;
-                }
-              if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)
-                {
-                  free (buf);
-                  result = -1;
-                  errcode = EINVAL;
-                  break;
-                }
-              free (buf);
-            }
-            break;
-
-          case TARGET_LINUX_SYS_sysinfo:
-            {
-              struct sysinfo info;
-
-              result = sysinfo(&info);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              info.uptime    = H2T_4 (info.uptime);
-              info.loads[0]  = H2T_4 (info.loads[0]);
-              info.loads[1]  = H2T_4 (info.loads[1]);
-              info.loads[2]  = H2T_4 (info.loads[2]);
-              info.totalram  = H2T_4 (info.totalram);
-              info.freeram   = H2T_4 (info.freeram);
-              info.sharedram = H2T_4 (info.sharedram);
-              info.bufferram = H2T_4 (info.bufferram);
-              info.totalswap = H2T_4 (info.totalswap);
-              info.freeswap  = H2T_4 (info.freeswap);
-              info.procs     = H2T_2 (info.procs);
+		    sim_core_attach (sd, NULL,
+				     0, access_read_write_exec, 0,
+				     result, len, 0, NULL, NULL);
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_munmap:
+	    result = munmap ((void *)arg1, arg2);
+	    errcode = errno;
+	    if (result != -1)
+	      sim_core_detach (sd, NULL, 0, arg2, result);
+	    break;
+
+	  case TARGET_LINUX_SYS_truncate:
+	    result = truncate ((char *) t2h_addr (cb, &s, arg1), arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_ftruncate:
+	    result = ftruncate (arg1, arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_fchmod:
+	    result = fchmod (arg1, arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_fchown32:
+	  case TARGET_LINUX_SYS_fchown:
+	    result = fchown (arg1, arg2, arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_statfs:
+	    {
+	      struct statfs statbuf;
+
+	      result = statfs ((char *) t2h_addr (cb, &s, arg1), &statbuf);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      translate_endian_h2t (&statbuf, sizeof(statbuf));
+	      if ((s.write_mem) (cb, &s, arg2, (char *) &statbuf, sizeof(statbuf))
+		  != sizeof(statbuf))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_fstatfs:
+	    {
+	      struct statfs statbuf;
+
+	      result = fstatfs (arg1, &statbuf);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      translate_endian_h2t (&statbuf, sizeof(statbuf));
+	      if ((s.write_mem) (cb, &s, arg2, (char *) &statbuf, sizeof(statbuf))
+		  != sizeof(statbuf))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_syslog:
+	    result = syslog (arg1, (char *) t2h_addr (cb, &s, arg2));
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_setitimer:
+	    {
+	      struct itimerval value, ovalue;
+
+	      value = *((struct itimerval *) t2h_addr (cb, &s, arg2));
+	      translate_endian_t2h (&value, sizeof(value));
+
+	      if (arg2 == 0)
+		{
+		  result = setitimer (arg1, &value, NULL);
+		  errcode = errno;
+		}
+	      else
+		{
+		  result = setitimer (arg1, &value, &ovalue);
+		  errcode = errno;
+
+		  if (result != 0)
+		    break;
+
+		  translate_endian_h2t (&ovalue, sizeof(ovalue));
+		  if ((s.write_mem) (cb, &s, arg3, (char *) &ovalue, sizeof(ovalue))
+		      != sizeof(ovalue))
+		    {
+		      result = -1;
+		      errcode = EINVAL;
+		    }
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_getitimer:
+	    {
+	      struct itimerval value;
+
+	      result = getitimer (arg1, &value);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      translate_endian_h2t (&value, sizeof(value));
+	      if ((s.write_mem) (cb, &s, arg2, (char *) &value, sizeof(value))
+		  != sizeof(value))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_stat:
+	    {
+	      char *buf;
+	      int buflen;
+	      struct stat statbuf;
+
+	      result = stat ((char *) t2h_addr (cb, &s, arg1), &statbuf);
+	      errcode = errno;
+	      if (result < 0)
+		break;
+
+	      buflen = cb_host_to_target_stat (cb, NULL, NULL);
+	      buf = xmalloc (buflen);
+	      if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)
+		{
+		  /* The translation failed.  This is due to an internal
+		     host program error, not the target's fault.  */
+		  free (buf);
+		  result = -1;
+		  errcode = ENOSYS;
+		  break;
+		}
+	      if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)
+		{
+		  free (buf);
+		  result = -1;
+		  errcode = EINVAL;
+		  break;
+		}
+	      free (buf);
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_lstat:
+	    {
+	      char *buf;
+	      int buflen;
+	      struct stat statbuf;
+
+	      result = lstat ((char *) t2h_addr (cb, &s, arg1), &statbuf);
+	      errcode = errno;
+	      if (result < 0)
+		break;
+
+	      buflen = cb_host_to_target_stat (cb, NULL, NULL);
+	      buf = xmalloc (buflen);
+	      if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)
+		{
+		  /* The translation failed.  This is due to an internal
+		     host program error, not the target's fault.  */
+		  free (buf);
+		  result = -1;
+		  errcode = ENOSYS;
+		  break;
+		}
+	      if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)
+		{
+		  free (buf);
+		  result = -1;
+		  errcode = EINVAL;
+		  break;
+		}
+	      free (buf);
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_fstat:
+	    {
+	      char *buf;
+	      int buflen;
+	      struct stat statbuf;
+
+	      result = fstat (arg1, &statbuf);
+	      errcode = errno;
+	      if (result < 0)
+		break;
+
+	      buflen = cb_host_to_target_stat (cb, NULL, NULL);
+	      buf = xmalloc (buflen);
+	      if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen)
+		{
+		  /* The translation failed.  This is due to an internal
+		     host program error, not the target's fault.  */
+		  free (buf);
+		  result = -1;
+		  errcode = ENOSYS;
+		  break;
+		}
+	      if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen)
+		{
+		  free (buf);
+		  result = -1;
+		  errcode = EINVAL;
+		  break;
+		}
+	      free (buf);
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_sysinfo:
+	    {
+	      struct sysinfo info;
+
+	      result = sysinfo (&info);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      info.uptime    = H2T_4 (info.uptime);
+	      info.loads[0]  = H2T_4 (info.loads[0]);
+	      info.loads[1]  = H2T_4 (info.loads[1]);
+	      info.loads[2]  = H2T_4 (info.loads[2]);
+	      info.totalram  = H2T_4 (info.totalram);
+	      info.freeram   = H2T_4 (info.freeram);
+	      info.sharedram = H2T_4 (info.sharedram);
+	      info.bufferram = H2T_4 (info.bufferram);
+	      info.totalswap = H2T_4 (info.totalswap);
+	      info.freeswap  = H2T_4 (info.freeswap);
+	      info.procs     = H2T_2 (info.procs);
 #if LINUX_VERSION_CODE >= 0x20400
-              info.totalhigh = H2T_4 (info.totalhigh);
-              info.freehigh  = H2T_4 (info.freehigh);
-              info.mem_unit  = H2T_4 (info.mem_unit);
+	      info.totalhigh = H2T_4 (info.totalhigh);
+	      info.freehigh  = H2T_4 (info.freehigh);
+	      info.mem_unit  = H2T_4 (info.mem_unit);
 #endif
-              if ((s.write_mem) (cb, &s, arg1, (char *) &info, sizeof(info))
-                  != sizeof(info))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
+	      if ((s.write_mem) (cb, &s, arg1, (char *) &info, sizeof(info))
+		  != sizeof(info))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
 
 #if 0
-          case TARGET_LINUX_SYS_ipc:
-            {
-              result = ipc(arg1, arg2, arg3, arg4,
-                           (void *) t2h_addr(cb, &s, arg5), arg6);
-              errcode = errno;
-            }
-            break;
+	  case TARGET_LINUX_SYS_ipc:
+	    {
+	      result = ipc (arg1, arg2, arg3, arg4,
+			    (void *) t2h_addr (cb, &s, arg5), arg6);
+	      errcode = errno;
+	    }
+	    break;
 #endif
 
-          case TARGET_LINUX_SYS_fsync:
-            result = fsync(arg1);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_uname:
-            /* utsname contains only arrays of char, so it is not necessary
-               to translate endian. */
-            result = uname((struct utsname *) t2h_addr(cb, &s, arg1));
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_adjtimex:
-            {
-              struct timex buf;
-
-              result = adjtimex(&buf);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              translate_endian_h2t (&buf, sizeof(buf));
-              if ((s.write_mem) (cb, &s, arg1, (char *) &buf, sizeof(buf))
-                  != sizeof(buf))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_mprotect:
-            result = mprotect((void *) arg1, arg2, arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_fchdir:
-            result = fchdir(arg1);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_setfsuid32:
-          case TARGET_LINUX_SYS_setfsuid:
-            result = setfsuid(arg1);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_setfsgid32:
-          case TARGET_LINUX_SYS_setfsgid:
-            result = setfsgid(arg1);
-            errcode = errno;
-            break;
+	  case TARGET_LINUX_SYS_fsync:
+	    result = fsync (arg1);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_uname:
+	    /* utsname contains only arrays of char, so it is not necessary
+	       to translate endian. */
+	    result = uname ((struct utsname *) t2h_addr (cb, &s, arg1));
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_adjtimex:
+	    {
+	      struct timex buf;
+
+	      result = adjtimex (&buf);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      translate_endian_h2t (&buf, sizeof(buf));
+	      if ((s.write_mem) (cb, &s, arg1, (char *) &buf, sizeof(buf))
+		  != sizeof(buf))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_mprotect:
+	    result = mprotect ((void *) arg1, arg2, arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_fchdir:
+	    result = fchdir (arg1);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_setfsuid32:
+	  case TARGET_LINUX_SYS_setfsuid:
+	    result = setfsuid (arg1);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_setfsgid32:
+	  case TARGET_LINUX_SYS_setfsgid:
+	    result = setfsgid (arg1);
+	    errcode = errno;
+	    break;
 
 #if 0
-          case TARGET_LINUX_SYS__llseek:
-            {
-              loff_t buf;
-
-              result = _llseek(arg1, arg2, arg3, &buf, arg5);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              translate_endian_h2t (&buf, sizeof(buf));
-              if ((s.write_mem) (cb, &s, t2h_addr(cb, &s, arg4),
-                                 (char *) &buf, sizeof(buf)) != sizeof(buf))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_getdents:
-            {
-              struct dirent dir;
-
-              result = getdents(arg1, &dir, arg3);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              dir.d_ino = H2T_4 (dir.d_ino);
-              dir.d_off = H2T_4 (dir.d_off);
-              dir.d_reclen = H2T_2 (dir.d_reclen);
-              if ((s.write_mem) (cb, &s, arg2, (char *) &dir, sizeof(dir))
-                  != sizeof(dir))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
+	  case TARGET_LINUX_SYS__llseek:
+	    {
+	      loff_t buf;
+
+	      result = _llseek (arg1, arg2, arg3, &buf, arg5);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      translate_endian_h2t (&buf, sizeof(buf));
+	      if ((s.write_mem) (cb, &s, t2h_addr (cb, &s, arg4),
+				 (char *) &buf, sizeof(buf)) != sizeof(buf))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_getdents:
+	    {
+	      struct dirent dir;
+
+	      result = getdents (arg1, &dir, arg3);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      dir.d_ino = H2T_4 (dir.d_ino);
+	      dir.d_off = H2T_4 (dir.d_off);
+	      dir.d_reclen = H2T_2 (dir.d_reclen);
+	      if ((s.write_mem) (cb, &s, arg2, (char *) &dir, sizeof(dir))
+		  != sizeof(dir))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
 #endif
 
-          case TARGET_LINUX_SYS_flock:
-            result = flock(arg1, arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_msync:
-            result = msync((void *) arg1, arg2, arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_readv:
-            {
-              struct iovec vector;
-
-              vector = *((struct iovec *) t2h_addr(cb, &s, arg2));
-              translate_endian_t2h (&vector, sizeof(vector));
-
-              result = readv(arg1, &vector, arg3);
-              errcode = errno;
-            }
-            break;
-
-          case TARGET_LINUX_SYS_writev:
-            {
-              struct iovec vector;
-
-              vector = *((struct iovec *) t2h_addr(cb, &s, arg2));
-              translate_endian_t2h (&vector, sizeof(vector));
-
-              result = writev(arg1, &vector, arg3);
-              errcode = errno;
-            }
-            break;
-
-          case TARGET_LINUX_SYS_fdatasync:
-            result = fdatasync(arg1);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_mlock:
-            result = mlock((void *) t2h_addr(cb, &s, arg1), arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_munlock:
-            result = munlock((void *) t2h_addr(cb, &s, arg1), arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_nanosleep:
-            {
-              struct timespec req, rem;
-
-              req = *((struct timespec *) t2h_addr(cb, &s, arg2));
-              translate_endian_t2h (&req, sizeof(req));
-
-              result = nanosleep(&req, &rem);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              translate_endian_h2t (&rem, sizeof(rem));
-              if ((s.write_mem) (cb, &s, arg2, (char *) &rem, sizeof(rem))
-                  != sizeof(rem))
-                {
-                  result = -1;
-                  errcode = EINVAL;
-                }
-            }
-            break;
-
-          case TARGET_LINUX_SYS_mremap: /* FIXME */
-            result = (int) mremap((void *) t2h_addr(cb, &s, arg1), arg2, arg3, arg4); 
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_getresuid32:
-          case TARGET_LINUX_SYS_getresuid:
-            {
-              uid_t ruid, euid, suid;
-
-              result = getresuid(&ruid, &euid, &suid);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              *((uid_t *) t2h_addr(cb, &s, arg1)) = H2T_4 (ruid);
-              *((uid_t *) t2h_addr(cb, &s, arg2)) = H2T_4 (euid);
-              *((uid_t *) t2h_addr(cb, &s, arg3)) = H2T_4 (suid);
-            }
-            break;
-
-          case TARGET_LINUX_SYS_poll:
-            {
-              struct pollfd ufds;
-
-              ufds = *((struct pollfd *) t2h_addr(cb, &s, arg1));
-              ufds.fd = T2H_4 (ufds.fd);
-              ufds.events = T2H_2 (ufds.events);
-              ufds.revents = T2H_2 (ufds.revents);
-
-              result = poll(&ufds, arg2, arg3);
-              errcode = errno;
-            }
-            break;
-
-          case TARGET_LINUX_SYS_getresgid32:
-          case TARGET_LINUX_SYS_getresgid:
-            {
-              uid_t rgid, egid, sgid;
-
-              result = getresgid(&rgid, &egid, &sgid);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              *((uid_t *) t2h_addr(cb, &s, arg1)) = H2T_4 (rgid);
-              *((uid_t *) t2h_addr(cb, &s, arg2)) = H2T_4 (egid);
-              *((uid_t *) t2h_addr(cb, &s, arg3)) = H2T_4 (sgid);
-            }
-            break;
-
-          case TARGET_LINUX_SYS_pread:
-            result =  pread(arg1, (void *) t2h_addr(cb, &s, arg2), arg3, arg4); 
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_pwrite:
-            result =  pwrite(arg1, (void *) t2h_addr(cb, &s, arg2), arg3, arg4); 
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_chown32:
-          case TARGET_LINUX_SYS_chown:
-            result = chown((char *) t2h_addr(cb, &s, arg1), arg2, arg3);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_getcwd:
-            result = (int) getcwd((char *) t2h_addr(cb, &s, arg1), arg2);
-            errcode = errno;
-            break;
-
-          case TARGET_LINUX_SYS_sendfile:
-            {
-              off_t offset;
-
-              offset = *((off_t *) t2h_addr(cb, &s, arg3));
-              offset = T2H_4 (offset);
-
-              result = sendfile(arg1, arg2, &offset, arg3);
-              errcode = errno;
-
-              if (result != 0)
-                break;
-
-              *((off_t *) t2h_addr(cb, &s, arg3)) = H2T_4 (offset);
-            }
-            break;
-
-          default:
-            result = -1;
-            errcode = ENOSYS;
-            break;
-          }
-        
-        if (result == -1)
+	  case TARGET_LINUX_SYS_flock:
+	    result = flock (arg1, arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_msync:
+	    result = msync ((void *) arg1, arg2, arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_readv:
+	    {
+	      struct iovec vector;
+
+	      vector = *((struct iovec *) t2h_addr (cb, &s, arg2));
+	      translate_endian_t2h (&vector, sizeof(vector));
+
+	      result = readv (arg1, &vector, arg3);
+	      errcode = errno;
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_writev:
+	    {
+	      struct iovec vector;
+
+	      vector = *((struct iovec *) t2h_addr (cb, &s, arg2));
+	      translate_endian_t2h (&vector, sizeof(vector));
+
+	      result = writev (arg1, &vector, arg3);
+	      errcode = errno;
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_fdatasync:
+	    result = fdatasync (arg1);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_mlock:
+	    result = mlock ((void *) t2h_addr (cb, &s, arg1), arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_munlock:
+	    result = munlock ((void *) t2h_addr (cb, &s, arg1), arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_nanosleep:
+	    {
+	      struct timespec req, rem;
+
+	      req = *((struct timespec *) t2h_addr (cb, &s, arg2));
+	      translate_endian_t2h (&req, sizeof(req));
+
+	      result = nanosleep (&req, &rem);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      translate_endian_h2t (&rem, sizeof(rem));
+	      if ((s.write_mem) (cb, &s, arg2, (char *) &rem, sizeof(rem))
+		  != sizeof(rem))
+		{
+		  result = -1;
+		  errcode = EINVAL;
+		}
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_mremap: /* FIXME */
+	    result = (int) mremap ((void *) t2h_addr (cb, &s, arg1), arg2, arg3, arg4);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_getresuid32:
+	  case TARGET_LINUX_SYS_getresuid:
+	    {
+	      uid_t ruid, euid, suid;
+
+	      result = getresuid (&ruid, &euid, &suid);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      *((uid_t *) t2h_addr (cb, &s, arg1)) = H2T_4 (ruid);
+	      *((uid_t *) t2h_addr (cb, &s, arg2)) = H2T_4 (euid);
+	      *((uid_t *) t2h_addr (cb, &s, arg3)) = H2T_4 (suid);
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_poll:
+	    {
+	      struct pollfd ufds;
+
+	      ufds = *((struct pollfd *) t2h_addr (cb, &s, arg1));
+	      ufds.fd = T2H_4 (ufds.fd);
+	      ufds.events = T2H_2 (ufds.events);
+	      ufds.revents = T2H_2 (ufds.revents);
+
+	      result = poll (&ufds, arg2, arg3);
+	      errcode = errno;
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_getresgid32:
+	  case TARGET_LINUX_SYS_getresgid:
+	    {
+	      uid_t rgid, egid, sgid;
+
+	      result = getresgid (&rgid, &egid, &sgid);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      *((uid_t *) t2h_addr (cb, &s, arg1)) = H2T_4 (rgid);
+	      *((uid_t *) t2h_addr (cb, &s, arg2)) = H2T_4 (egid);
+	      *((uid_t *) t2h_addr (cb, &s, arg3)) = H2T_4 (sgid);
+	    }
+	    break;
+
+	  case TARGET_LINUX_SYS_pread:
+	    result =  pread (arg1, (void *) t2h_addr (cb, &s, arg2), arg3, arg4);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_pwrite:
+	    result =  pwrite (arg1, (void *) t2h_addr (cb, &s, arg2), arg3, arg4);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_chown32:
+	  case TARGET_LINUX_SYS_chown:
+	    result = chown ((char *) t2h_addr (cb, &s, arg1), arg2, arg3);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_getcwd:
+	    result = (int) getcwd ((char *) t2h_addr (cb, &s, arg1), arg2);
+	    errcode = errno;
+	    break;
+
+	  case TARGET_LINUX_SYS_sendfile:
+	    {
+	      off_t offset;
+
+	      offset = *((off_t *) t2h_addr (cb, &s, arg3));
+	      offset = T2H_4 (offset);
+
+	      result = sendfile (arg1, arg2, &offset, arg3);
+	      errcode = errno;
+
+	      if (result != 0)
+		break;
+
+	      *((off_t *) t2h_addr (cb, &s, arg3)) = H2T_4 (offset);
+	    }
+	    break;
+
+	  default:
+	    result = -1;
+	    errcode = ENOSYS;
+	    break;
+	  }
+
+	if (result == -1)
 	  m32rbf_h_gr_set (current_cpu, 0, -errcode);
-        else
+	else
 	  m32rbf_h_gr_set (current_cpu, 0, result);
 	break;
       }
-- 
2.31.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 6/6] sim: m32r: merge with common configure script
  2021-07-01  4:55 [PATCH 1/6] sim: m32r: namespace Linux syscall table Mike Frysinger
                   ` (3 preceding siblings ...)
  2021-07-01  4:55 ` [PATCH 5/6] sim: m32r: reformat linux traps code Mike Frysinger
@ 2021-07-01  4:55 ` Mike Frysinger
  4 siblings, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2021-07-01  4:55 UTC (permalink / raw)
  To: gdb-patches

Now that the traps code has been unified, the configure script has no
unique logic in it, so it can be merged into the single common one.
---
 sim/Makefile.in       |    4 +-
 sim/configure         |   24 +-
 sim/configure.ac      |    2 +-
 sim/m32r/aclocal.m4   |   15 -
 sim/m32r/configure    | 2876 -----------------------------------------
 sim/m32r/configure.ac |    5 -
 6 files changed, 24 insertions(+), 2902 deletions(-)
 delete mode 100644 sim/m32r/aclocal.m4
 delete mode 100755 sim/m32r/configure
 delete mode 100644 sim/m32r/configure.ac

diff --git a/sim/configure.ac b/sim/configure.ac
index 9d0c9f5dd445..febedfc7a0e8 100644
--- a/sim/configure.ac
+++ b/sim/configure.ac
@@ -125,7 +125,7 @@ if test "${enable_sim}" != no; then
     SIM_TARGET([iq2000-*-*], [iq2000])
     SIM_TARGET([lm32-*-*], [lm32])
     SIM_TARGET([m32c-*-*], [m32c])
-    SIM_TARGET([m32r-*-*], [m32r], [true])
+    SIM_TARGET([m32r-*-*], [m32r])
     SIM_TARGET([m68hc11-*-*|m6811-*-*], [m68hc11])
     SIM_TARGET([mcore-*-*], [mcore])
     SIM_TARGET([microblaze-*-*], [microblaze])
diff --git a/sim/m32r/configure.ac b/sim/m32r/configure.ac
deleted file mode 100644
index 99370b3a5770..000000000000
--- a/sim/m32r/configure.ac
+++ /dev/null
@@ -1,5 +0,0 @@
-dnl Process this file with autoconf to produce a configure script.
-AC_INIT(Makefile.in)
-AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config])
-
-SIM_AC_OUTPUT
-- 
2.31.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/6] sim: m32r: unify ELF & Linux traps logic
  2021-07-01  4:55 ` [PATCH 4/6] sim: m32r: unify ELF & Linux traps logic Mike Frysinger
@ 2021-07-12 14:20   ` John Baldwin
  2021-08-18  8:05     ` Mike Frysinger
  2021-08-20  1:04     ` [PATCH] sim: m32r: add __linux__ hack for non-Linux hosts Mike Frysinger
  0 siblings, 2 replies; 10+ messages in thread
From: John Baldwin @ 2021-07-12 14:20 UTC (permalink / raw)
  To: Mike Frysinger, gdb-patches

On 6/30/21 9:55 PM, Mike Frysinger via Gdb-patches wrote:
> This makes the simulator work the same regardless of the target (bare
> metal m32r-elf or Linux m32r-linux-gnu) by unifying the traps code.
> It was mostly already the same with the only difference being support
> for trap #2 reserved for Linux syscalls.  We can move that logic to
> runtime by checking the current environment operating mode instead.

This breaks the build on non-Linux hosts as <sys/sysinfo.h> and
sysinfo() are only available on Linux hosts.  Specifically, this is
the error I get now trying to build 'master' on a FreeBSD host:

gmake[4]: Entering directory '/usr/home/john/work/git/gdb/obj/sim/m32r'
   CC     traps.o
/home/john/work/git/gdb/sim/m32r/traps.c:40:10: fatal error: 'sys/sysinfo.h' file not found
#include <sys/sysinfo.h>
          ^~~~~~~~~~~~~~~
1 error generated.
gmake[4]: *** [Makefile:537: traps.o] Error 1
gmake[4]: Leaving directory '/usr/home/john/work/git/gdb/obj/sim/m32r'

I was going to add the autoconf glue for a HAVE_SYSINFO to wrap the
#include and the emulation of the associated syscall, but I wasn't
quite sure where to put it (or if we really want to to support the
syscall emulation on non-Linux hosts in general)?

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/6] sim: m32r: unify ELF & Linux traps logic
  2021-07-12 14:20   ` John Baldwin
@ 2021-08-18  8:05     ` Mike Frysinger
  2021-08-20  1:04     ` [PATCH] sim: m32r: add __linux__ hack for non-Linux hosts Mike Frysinger
  1 sibling, 0 replies; 10+ messages in thread
From: Mike Frysinger @ 2021-08-18  8:05 UTC (permalink / raw)
  To: John Baldwin; +Cc: gdb-patches

On 12 Jul 2021 10:20, John Baldwin wrote:
> On 6/30/21 9:55 PM, Mike Frysinger via Gdb-patches wrote:
> > This makes the simulator work the same regardless of the target (bare
> > metal m32r-elf or Linux m32r-linux-gnu) by unifying the traps code.
> > It was mostly already the same with the only difference being support
> > for trap #2 reserved for Linux syscalls.  We can move that logic to
> > runtime by checking the current environment operating mode instead.
> 
> This breaks the build on non-Linux hosts as <sys/sysinfo.h> and
> sysinfo() are only available on Linux hosts.  Specifically, this is
> the error I get now trying to build 'master' on a FreeBSD host:

fairly certain m32r-linux toolchains have been broken this way forever.
this change brings that breakage to all m32r targets.  you didn't say
what target you're configuring for ...

> gmake[4]: Entering directory '/usr/home/john/work/git/gdb/obj/sim/m32r'
>    CC     traps.o
> /home/john/work/git/gdb/sim/m32r/traps.c:40:10: fatal error: 'sys/sysinfo.h' file not found
> #include <sys/sysinfo.h>
>           ^~~~~~~~~~~~~~~
> 1 error generated.
> gmake[4]: *** [Makefile:537: traps.o] Error 1
> gmake[4]: Leaving directory '/usr/home/john/work/git/gdb/obj/sim/m32r'
> 
> I was going to add the autoconf glue for a HAVE_SYSINFO to wrap the
> #include and the emulation of the associated syscall, but I wasn't
> quite sure where to put it (or if we really want to to support the
> syscall emulation on non-Linux hosts in general)?

yes, we want to keep the target emulation independent of the host runtime.
that's the whole point of the sim :).  otherwise, why would we have m32r
cpus executing on non-m32r (e.g. x86_64) cpus ?

that said, this file needs a bit of tlc.  it fails to properly translate
target values (arguments & return) when calling the OS functions.  so it
really only works when executed on a linux host with the same endian and
random linux ABI settings (e.g. enums/defines happen to match).

i was trying to do minimal work to keep things from blowing up so i could
unblock other things i was trying to migrate, but seems i missed the mark
here.  at this point, i would be OK with a giant "#ifdef __linux__" block
around the headers and specific syscall emulations with a TODO comment
explaining what needs to get fixed up before we can expose it further.
-mike

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] sim: m32r: add __linux__ hack for non-Linux hosts
  2021-07-12 14:20   ` John Baldwin
  2021-08-18  8:05     ` Mike Frysinger
@ 2021-08-20  1:04     ` Mike Frysinger
  2021-08-20 17:56       ` John Baldwin
  1 sibling, 1 reply; 10+ messages in thread
From: Mike Frysinger @ 2021-08-20  1:04 UTC (permalink / raw)
  To: gdb-patches

The m32r Linux syscall emulation logic assumes the host environment
directly matches -- it's being run on 32-bit little endian Linux.
This breaks building for non-Linux systems, so put all the code in
__linux__ ifdef checks.  This code needs a lot of love to make it
work everywhere, but let's at least unbreak it for non-Linux hosts.
---
 sim/m32r/traps.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sim/m32r/traps.c b/sim/m32r/traps.c
index b9912f95106e..2d7738b1f3cc 100644
--- a/sim/m32r/traps.c
+++ b/sim/m32r/traps.c
@@ -34,6 +34,11 @@
 #include <time.h>
 #include <unistd.h>
 #include <utime.h>
+/* TODO: The Linux syscall emulation needs work to support non-Linux hosts.
+   Use an OS hack for now so the CPU emulation is available everywhere.
+   NB: The emulation is also missing argument conversion (endian & bitsize)
+   even on Linux hosts.  */
+#ifdef __linux__
 #include <sys/mman.h>
 #include <sys/poll.h>
 #include <sys/resource.h>
@@ -49,6 +54,7 @@
 #include <linux/sysctl.h>
 #include <linux/types.h>
 #include <linux/unistd.h>
+#endif
 
 #define TRAP_LINUX_SYSCALL 2
 #define TRAP_FLUSH_CACHE 12
@@ -203,6 +209,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 	break;
       }
 
+#ifdef __linux__
     case TRAP_LINUX_SYSCALL:
       {
 	CB_SYSCALL s;
@@ -1302,6 +1309,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
 	  m32rbf_h_gr_set (current_cpu, 0, result);
 	break;
       }
+#endif
 
     case TRAP_BREAKPOINT:
       sim_engine_halt (sd, current_cpu, NULL, pc,
-- 
2.31.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] sim: m32r: add __linux__ hack for non-Linux hosts
  2021-08-20  1:04     ` [PATCH] sim: m32r: add __linux__ hack for non-Linux hosts Mike Frysinger
@ 2021-08-20 17:56       ` John Baldwin
  0 siblings, 0 replies; 10+ messages in thread
From: John Baldwin @ 2021-08-20 17:56 UTC (permalink / raw)
  To: Mike Frysinger, gdb-patches

On 8/19/21 6:04 PM, Mike Frysinger wrote:
> The m32r Linux syscall emulation logic assumes the host environment
> directly matches -- it's being run on 32-bit little endian Linux.
> This breaks building for non-Linux systems, so put all the code in
> __linux__ ifdef checks.  This code needs a lot of love to make it
> work everywhere, but let's at least unbreak it for non-Linux hosts.

Thanks, this fixes the build for me on FreeBSD.

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-08-20 17:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01  4:55 [PATCH 1/6] sim: m32r: namespace Linux syscall table Mike Frysinger
2021-07-01  4:55 ` [PATCH 2/6] sim: m32r: fix virtual environment with Linux targets Mike Frysinger
2021-07-01  4:55 ` [PATCH 3/6] sim: m32r: replace custom endian helpers with sim-endian Mike Frysinger
2021-07-01  4:55 ` [PATCH 4/6] sim: m32r: unify ELF & Linux traps logic Mike Frysinger
2021-07-12 14:20   ` John Baldwin
2021-08-18  8:05     ` Mike Frysinger
2021-08-20  1:04     ` [PATCH] sim: m32r: add __linux__ hack for non-Linux hosts Mike Frysinger
2021-08-20 17:56       ` John Baldwin
2021-07-01  4:55 ` [PATCH 5/6] sim: m32r: reformat linux traps code Mike Frysinger
2021-07-01  4:55 ` [PATCH 6/6] sim: m32r: merge with common configure script Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).