1 1.1 christos /* m32r exception, interrupt, and trap (EIT) support 2 1.11 christos Copyright (C) 1998-2024 Free Software Foundation, Inc. 3 1.10 christos Contributed by Cygnus Solutions & Renesas. 4 1.1 christos 5 1.1 christos This file is part of GDB, the GNU debugger. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.10 christos /* This must come before any other includes. */ 21 1.10 christos #include "defs.h" 22 1.10 christos 23 1.10 christos #include "portability.h" 24 1.1 christos #include "sim-main.h" 25 1.10 christos #include "sim-signal.h" 26 1.5 christos #include "sim-syscall.h" 27 1.10 christos #include "sim/callback.h" 28 1.10 christos #include "syscall.h" 29 1.10 christos #include <dirent.h> 30 1.10 christos #include <errno.h> 31 1.10 christos #include <fcntl.h> 32 1.10 christos #include <stdlib.h> 33 1.10 christos #include <time.h> 34 1.10 christos #include <unistd.h> 35 1.10 christos #include <utime.h> 36 1.10 christos /* TODO: The Linux syscall emulation needs work to support non-Linux hosts. 37 1.10 christos Use an OS hack for now so the CPU emulation is available everywhere. 38 1.10 christos NB: The emulation is also missing argument conversion (endian & bitsize) 39 1.10 christos even on Linux hosts. */ 40 1.10 christos #ifdef __linux__ 41 1.11 christos #include <syslog.h> 42 1.11 christos #include <sys/file.h> 43 1.11 christos #include <sys/fsuid.h> 44 1.11 christos #include <sys/ioctl.h> 45 1.10 christos #include <sys/mman.h> 46 1.10 christos #include <sys/poll.h> 47 1.10 christos #include <sys/resource.h> 48 1.11 christos #include <sys/sendfile.h> 49 1.10 christos #include <sys/sysinfo.h> 50 1.10 christos #include <sys/stat.h> 51 1.10 christos #include <sys/time.h> 52 1.10 christos #include <sys/timeb.h> 53 1.10 christos #include <sys/timex.h> 54 1.10 christos #include <sys/types.h> 55 1.10 christos #include <sys/uio.h> 56 1.10 christos #include <sys/utsname.h> 57 1.10 christos #include <sys/vfs.h> 58 1.10 christos #include <linux/sysctl.h> 59 1.10 christos #include <linux/types.h> 60 1.10 christos #include <linux/unistd.h> 61 1.10 christos #endif 62 1.1 christos 63 1.11 christos #include "m32r-sim.h" 64 1.11 christos 65 1.10 christos #define TRAP_LINUX_SYSCALL 2 66 1.1 christos #define TRAP_FLUSH_CACHE 12 67 1.1 christos /* The semantic code invokes this for invalid (unrecognized) instructions. */ 68 1.1 christos 69 1.1 christos SEM_PC 70 1.1 christos sim_engine_invalid_insn (SIM_CPU *current_cpu, IADDR cia, SEM_PC pc) 71 1.1 christos { 72 1.1 christos SIM_DESC sd = CPU_STATE (current_cpu); 73 1.1 christos 74 1.1 christos #if 0 75 1.1 christos if (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT) 76 1.1 christos { 77 1.1 christos h_bsm_set (current_cpu, h_sm_get (current_cpu)); 78 1.1 christos h_bie_set (current_cpu, h_ie_get (current_cpu)); 79 1.1 christos h_bcond_set (current_cpu, h_cond_get (current_cpu)); 80 1.1 christos /* sm not changed */ 81 1.1 christos h_ie_set (current_cpu, 0); 82 1.1 christos h_cond_set (current_cpu, 0); 83 1.1 christos 84 1.1 christos h_bpc_set (current_cpu, cia); 85 1.1 christos 86 1.1 christos sim_engine_restart (CPU_STATE (current_cpu), current_cpu, NULL, 87 1.1 christos EIT_RSVD_INSN_ADDR); 88 1.1 christos } 89 1.1 christos else 90 1.1 christos #endif 91 1.1 christos sim_engine_halt (sd, current_cpu, NULL, cia, sim_stopped, SIM_SIGILL); 92 1.1 christos 93 1.1 christos return pc; 94 1.1 christos } 95 1.1 christos 96 1.1 christos /* Process an address exception. */ 97 1.1 christos 98 1.1 christos void 99 1.1 christos m32r_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia, 100 1.1 christos unsigned int map, int nr_bytes, address_word addr, 101 1.1 christos transfer_type transfer, sim_core_signals sig) 102 1.1 christos { 103 1.1 christos if (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT) 104 1.1 christos { 105 1.1 christos m32rbf_h_cr_set (current_cpu, H_CR_BBPC, 106 1.1 christos m32rbf_h_cr_get (current_cpu, H_CR_BPC)); 107 1.1 christos switch (MACH_NUM (CPU_MACH (current_cpu))) 108 1.1 christos { 109 1.1 christos case MACH_M32R: 110 1.1 christos m32rbf_h_bpsw_set (current_cpu, m32rbf_h_psw_get (current_cpu)); 111 1.1 christos /* sm not changed. */ 112 1.1 christos m32rbf_h_psw_set (current_cpu, m32rbf_h_psw_get (current_cpu) & 0x80); 113 1.1 christos break; 114 1.1 christos case MACH_M32RX: 115 1.1 christos m32rxf_h_bpsw_set (current_cpu, m32rxf_h_psw_get (current_cpu)); 116 1.1 christos /* sm not changed. */ 117 1.1 christos m32rxf_h_psw_set (current_cpu, m32rxf_h_psw_get (current_cpu) & 0x80); 118 1.1 christos break; 119 1.1 christos case MACH_M32R2: 120 1.1 christos m32r2f_h_bpsw_set (current_cpu, m32r2f_h_psw_get (current_cpu)); 121 1.1 christos /* sm not changed. */ 122 1.1 christos m32r2f_h_psw_set (current_cpu, m32r2f_h_psw_get (current_cpu) & 0x80); 123 1.1 christos break; 124 1.1 christos default: 125 1.1 christos abort (); 126 1.1 christos } 127 1.10 christos 128 1.1 christos m32rbf_h_cr_set (current_cpu, H_CR_BPC, cia); 129 1.1 christos 130 1.1 christos sim_engine_restart (CPU_STATE (current_cpu), current_cpu, NULL, 131 1.1 christos EIT_ADDR_EXCP_ADDR); 132 1.1 christos } 133 1.1 christos else 134 1.1 christos sim_core_signal (sd, current_cpu, cia, map, nr_bytes, addr, 135 1.1 christos transfer, sig); 136 1.1 christos } 137 1.1 christos 138 1.10 christos /* Translate target's address to host's address. */ 140 1.10 christos 141 1.10 christos static void * 142 1.10 christos t2h_addr (host_callback *cb, struct cb_syscall *sc, 143 1.10 christos unsigned long taddr) 144 1.10 christos { 145 1.10 christos SIM_DESC sd = (SIM_DESC) sc->p1; 146 1.10 christos SIM_CPU *cpu = (SIM_CPU *) sc->p2; 147 1.10 christos 148 1.10 christos if (taddr == 0) 149 1.10 christos return NULL; 150 1.10 christos 151 1.10 christos return sim_core_trans_addr (sd, cpu, read_map, taddr); 152 1.10 christos } 153 1.10 christos 154 1.10 christos /* TODO: These functions are a big hack and assume that the host runtime has 155 1.10 christos type sizes and struct layouts that match the target. So the Linux emulation 156 1.10 christos probaly only really works in 32-bit runtimes. */ 157 1.10 christos 158 1.10 christos static void 159 1.10 christos translate_endian_h2t (void *addr, size_t size) 160 1.10 christos { 161 1.10 christos unsigned int *p = (unsigned int *) addr; 162 1.10 christos int i; 163 1.10 christos 164 1.10 christos for (i = 0; i <= size - 4; i += 4,p++) 165 1.10 christos *p = H2T_4 (*p); 166 1.10 christos 167 1.10 christos if (i <= size - 2) 168 1.10 christos *((unsigned short *) p) = H2T_2 (*((unsigned short *) p)); 169 1.10 christos } 170 1.10 christos 171 1.10 christos static void 172 1.10 christos translate_endian_t2h (void *addr, size_t size) 173 1.10 christos { 174 1.10 christos unsigned int *p = (unsigned int *) addr; 175 1.10 christos int i; 176 1.10 christos 177 1.10 christos for (i = 0; i <= size - 4; i += 4,p++) 178 1.10 christos *p = T2H_4 (*p); 179 1.10 christos 180 1.10 christos if (i <= size - 2) 181 1.10 christos *((unsigned short *) p) = T2H_2 (*((unsigned short *) p)); 182 1.10 christos } 183 1.1 christos 184 1.1 christos /* Trap support. 185 1.1 christos The result is the pc address to continue at. 186 1.1 christos Preprocessing like saving the various registers has already been done. */ 187 1.1 christos 188 1.1 christos USI 189 1.1 christos m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num) 190 1.1 christos { 191 1.1 christos SIM_DESC sd = CPU_STATE (current_cpu); 192 1.1 christos host_callback *cb = STATE_CALLBACK (sd); 193 1.1 christos 194 1.10 christos if (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT) 195 1.1 christos goto case_default; 196 1.1 christos 197 1.1 christos switch (num) 198 1.10 christos { 199 1.1 christos case TRAP_SYSCALL: 200 1.5 christos { 201 1.5 christos long result, result2; 202 1.1 christos int errcode; 203 1.5 christos 204 1.5 christos sim_syscall_multi (current_cpu, 205 1.5 christos m32rbf_h_gr_get (current_cpu, 0), 206 1.5 christos m32rbf_h_gr_get (current_cpu, 1), 207 1.5 christos m32rbf_h_gr_get (current_cpu, 2), 208 1.5 christos m32rbf_h_gr_get (current_cpu, 3), 209 1.5 christos m32rbf_h_gr_get (current_cpu, 4), 210 1.5 christos &result, &result2, &errcode); 211 1.5 christos 212 1.5 christos m32rbf_h_gr_set (current_cpu, 2, errcode); 213 1.5 christos m32rbf_h_gr_set (current_cpu, 0, result); 214 1.1 christos m32rbf_h_gr_set (current_cpu, 1, result2); 215 1.1 christos break; 216 1.1 christos } 217 1.10 christos 218 1.10 christos #ifdef __linux__ 219 1.10 christos case TRAP_LINUX_SYSCALL: 220 1.10 christos { 221 1.10 christos CB_SYSCALL s; 222 1.11 christos unsigned int func, arg1, arg2, arg3, arg4, arg5, arg6, arg7; 223 1.10 christos int result, errcode; 224 1.10 christos 225 1.10 christos if (STATE_ENVIRONMENT (sd) != USER_ENVIRONMENT) 226 1.10 christos goto case_default; 227 1.10 christos 228 1.10 christos func = m32rbf_h_gr_get (current_cpu, 7); 229 1.10 christos arg1 = m32rbf_h_gr_get (current_cpu, 0); 230 1.10 christos arg2 = m32rbf_h_gr_get (current_cpu, 1); 231 1.10 christos arg3 = m32rbf_h_gr_get (current_cpu, 2); 232 1.10 christos arg4 = m32rbf_h_gr_get (current_cpu, 3); 233 1.10 christos arg5 = m32rbf_h_gr_get (current_cpu, 4); 234 1.10 christos arg6 = m32rbf_h_gr_get (current_cpu, 5); 235 1.10 christos arg7 = m32rbf_h_gr_get (current_cpu, 6); 236 1.10 christos 237 1.10 christos CB_SYSCALL_INIT (&s); 238 1.10 christos s.func = func; 239 1.10 christos s.arg1 = arg1; 240 1.10 christos s.arg2 = arg2; 241 1.10 christos s.arg3 = arg3; 242 1.10 christos s.arg4 = arg4; 243 1.10 christos s.arg5 = arg5; 244 1.10 christos s.arg6 = arg6; 245 1.10 christos s.arg7 = arg7; 246 1.10 christos 247 1.10 christos s.p1 = sd; 248 1.10 christos s.p2 = current_cpu; 249 1.10 christos s.read_mem = sim_syscall_read_mem; 250 1.10 christos s.write_mem = sim_syscall_write_mem; 251 1.10 christos 252 1.10 christos result = 0; 253 1.10 christos errcode = 0; 254 1.10 christos 255 1.10 christos switch (func) 256 1.10 christos { 257 1.10 christos case TARGET_LINUX_SYS_exit: 258 1.10 christos sim_engine_halt (sd, current_cpu, NULL, pc, sim_exited, arg1); 259 1.10 christos break; 260 1.10 christos 261 1.10 christos case TARGET_LINUX_SYS_read: 262 1.10 christos result = read (arg1, t2h_addr (cb, &s, arg2), arg3); 263 1.10 christos errcode = errno; 264 1.10 christos break; 265 1.10 christos 266 1.10 christos case TARGET_LINUX_SYS_write: 267 1.10 christos result = write (arg1, t2h_addr (cb, &s, arg2), arg3); 268 1.10 christos errcode = errno; 269 1.10 christos break; 270 1.10 christos 271 1.10 christos case TARGET_LINUX_SYS_open: 272 1.10 christos result = open ((char *) t2h_addr (cb, &s, arg1), arg2, arg3); 273 1.10 christos errcode = errno; 274 1.10 christos break; 275 1.10 christos 276 1.10 christos case TARGET_LINUX_SYS_close: 277 1.10 christos result = close (arg1); 278 1.10 christos errcode = errno; 279 1.10 christos break; 280 1.10 christos 281 1.10 christos case TARGET_LINUX_SYS_creat: 282 1.10 christos result = creat ((char *) t2h_addr (cb, &s, arg1), arg2); 283 1.10 christos errcode = errno; 284 1.10 christos break; 285 1.10 christos 286 1.10 christos case TARGET_LINUX_SYS_link: 287 1.10 christos result = link ((char *) t2h_addr (cb, &s, arg1), 288 1.10 christos (char *) t2h_addr (cb, &s, arg2)); 289 1.10 christos errcode = errno; 290 1.10 christos break; 291 1.10 christos 292 1.10 christos case TARGET_LINUX_SYS_unlink: 293 1.10 christos result = unlink ((char *) t2h_addr (cb, &s, arg1)); 294 1.10 christos errcode = errno; 295 1.10 christos break; 296 1.10 christos 297 1.10 christos case TARGET_LINUX_SYS_chdir: 298 1.10 christos result = chdir ((char *) t2h_addr (cb, &s, arg1)); 299 1.10 christos errcode = errno; 300 1.10 christos break; 301 1.10 christos 302 1.10 christos case TARGET_LINUX_SYS_time: 303 1.10 christos { 304 1.10 christos time_t t; 305 1.10 christos 306 1.10 christos if (arg1 == 0) 307 1.10 christos { 308 1.10 christos result = (int) time (NULL); 309 1.10 christos errcode = errno; 310 1.10 christos } 311 1.10 christos else 312 1.10 christos { 313 1.10 christos result = (int) time (&t); 314 1.10 christos errcode = errno; 315 1.10 christos 316 1.10 christos if (result != 0) 317 1.10 christos break; 318 1.10 christos 319 1.10 christos t = H2T_4 (t); 320 1.10 christos if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t)) != sizeof(t)) 321 1.10 christos { 322 1.10 christos result = -1; 323 1.10 christos errcode = EINVAL; 324 1.10 christos } 325 1.10 christos } 326 1.10 christos } 327 1.10 christos break; 328 1.10 christos 329 1.10 christos case TARGET_LINUX_SYS_mknod: 330 1.10 christos result = mknod ((char *) t2h_addr (cb, &s, arg1), 331 1.10 christos (mode_t) arg2, (dev_t) arg3); 332 1.10 christos errcode = errno; 333 1.10 christos break; 334 1.10 christos 335 1.10 christos case TARGET_LINUX_SYS_chmod: 336 1.10 christos result = chmod ((char *) t2h_addr (cb, &s, arg1), (mode_t) arg2); 337 1.10 christos errcode = errno; 338 1.10 christos break; 339 1.10 christos 340 1.10 christos case TARGET_LINUX_SYS_lchown32: 341 1.10 christos case TARGET_LINUX_SYS_lchown: 342 1.10 christos result = lchown ((char *) t2h_addr (cb, &s, arg1), 343 1.10 christos (uid_t) arg2, (gid_t) arg3); 344 1.10 christos errcode = errno; 345 1.10 christos break; 346 1.10 christos 347 1.10 christos case TARGET_LINUX_SYS_lseek: 348 1.10 christos result = (int) lseek (arg1, (off_t) arg2, arg3); 349 1.10 christos errcode = errno; 350 1.10 christos break; 351 1.10 christos 352 1.10 christos case TARGET_LINUX_SYS_getpid: 353 1.10 christos result = getpid (); 354 1.10 christos errcode = errno; 355 1.10 christos break; 356 1.10 christos 357 1.10 christos case TARGET_LINUX_SYS_getuid32: 358 1.10 christos case TARGET_LINUX_SYS_getuid: 359 1.10 christos result = getuid (); 360 1.10 christos errcode = errno; 361 1.10 christos break; 362 1.10 christos 363 1.10 christos case TARGET_LINUX_SYS_utime: 364 1.10 christos { 365 1.10 christos struct utimbuf buf; 366 1.10 christos 367 1.10 christos if (arg2 == 0) 368 1.10 christos { 369 1.10 christos result = utime ((char *) t2h_addr (cb, &s, arg1), NULL); 370 1.10 christos errcode = errno; 371 1.10 christos } 372 1.10 christos else 373 1.10 christos { 374 1.10 christos buf = *((struct utimbuf *) t2h_addr (cb, &s, arg2)); 375 1.10 christos translate_endian_t2h (&buf, sizeof(buf)); 376 1.10 christos result = utime ((char *) t2h_addr (cb, &s, arg1), &buf); 377 1.10 christos errcode = errno; 378 1.10 christos } 379 1.10 christos } 380 1.10 christos break; 381 1.10 christos 382 1.10 christos case TARGET_LINUX_SYS_access: 383 1.10 christos result = access ((char *) t2h_addr (cb, &s, arg1), arg2); 384 1.10 christos errcode = errno; 385 1.10 christos break; 386 1.10 christos 387 1.10 christos case TARGET_LINUX_SYS_ftime: 388 1.10 christos { 389 1.11 christos struct timeb t; 390 1.10 christos struct timespec ts; 391 1.11 christos 392 1.10 christos result = clock_gettime (CLOCK_REALTIME, &ts); 393 1.10 christos errcode = errno; 394 1.10 christos 395 1.10 christos if (result != 0) 396 1.10 christos break; 397 1.11 christos 398 1.11 christos t.time = H2T_4 (ts.tv_sec); 399 1.11 christos t.millitm = H2T_2 (ts.tv_nsec / 1000000); 400 1.11 christos /* POSIX.1-2001 says the contents of the timezone and dstflag 401 1.11 christos members of tp after a call to ftime() are unspecified. */ 402 1.11 christos t.timezone = H2T_2 (0); 403 1.10 christos t.dstflag = H2T_2 (0); 404 1.10 christos if ((s.write_mem) (cb, &s, arg1, (char *) &t, sizeof(t)) 405 1.10 christos != sizeof(t)) 406 1.10 christos { 407 1.10 christos result = -1; 408 1.10 christos errcode = EINVAL; 409 1.10 christos } 410 1.11 christos } 411 1.10 christos break; 412 1.10 christos 413 1.10 christos case TARGET_LINUX_SYS_sync: 414 1.10 christos sync (); 415 1.10 christos result = 0; 416 1.10 christos break; 417 1.10 christos 418 1.10 christos case TARGET_LINUX_SYS_rename: 419 1.10 christos result = rename ((char *) t2h_addr (cb, &s, arg1), 420 1.10 christos (char *) t2h_addr (cb, &s, arg2)); 421 1.10 christos errcode = errno; 422 1.10 christos break; 423 1.10 christos 424 1.10 christos case TARGET_LINUX_SYS_mkdir: 425 1.10 christos result = mkdir ((char *) t2h_addr (cb, &s, arg1), arg2); 426 1.10 christos errcode = errno; 427 1.10 christos break; 428 1.10 christos 429 1.10 christos case TARGET_LINUX_SYS_rmdir: 430 1.10 christos result = rmdir ((char *) t2h_addr (cb, &s, arg1)); 431 1.10 christos errcode = errno; 432 1.10 christos break; 433 1.10 christos 434 1.10 christos case TARGET_LINUX_SYS_dup: 435 1.10 christos result = dup (arg1); 436 1.10 christos errcode = errno; 437 1.10 christos break; 438 1.10 christos 439 1.11 christos case TARGET_LINUX_SYS_brk: 440 1.10 christos result = brk ((void *) (uintptr_t) arg1); 441 1.10 christos errcode = errno; 442 1.10 christos //result = arg1; 443 1.10 christos break; 444 1.10 christos 445 1.10 christos case TARGET_LINUX_SYS_getgid32: 446 1.10 christos case TARGET_LINUX_SYS_getgid: 447 1.10 christos result = getgid (); 448 1.10 christos errcode = errno; 449 1.10 christos break; 450 1.10 christos 451 1.10 christos case TARGET_LINUX_SYS_geteuid32: 452 1.10 christos case TARGET_LINUX_SYS_geteuid: 453 1.10 christos result = geteuid (); 454 1.10 christos errcode = errno; 455 1.10 christos break; 456 1.10 christos 457 1.10 christos case TARGET_LINUX_SYS_getegid32: 458 1.10 christos case TARGET_LINUX_SYS_getegid: 459 1.10 christos result = getegid (); 460 1.10 christos errcode = errno; 461 1.10 christos break; 462 1.10 christos 463 1.10 christos case TARGET_LINUX_SYS_ioctl: 464 1.10 christos result = ioctl (arg1, arg2, arg3); 465 1.10 christos errcode = errno; 466 1.10 christos break; 467 1.10 christos 468 1.10 christos case TARGET_LINUX_SYS_fcntl: 469 1.10 christos result = fcntl (arg1, arg2, arg3); 470 1.10 christos errcode = errno; 471 1.10 christos break; 472 1.10 christos 473 1.10 christos case TARGET_LINUX_SYS_dup2: 474 1.10 christos result = dup2 (arg1, arg2); 475 1.10 christos errcode = errno; 476 1.10 christos break; 477 1.10 christos 478 1.10 christos case TARGET_LINUX_SYS_getppid: 479 1.10 christos result = getppid (); 480 1.10 christos errcode = errno; 481 1.10 christos break; 482 1.10 christos 483 1.10 christos case TARGET_LINUX_SYS_getpgrp: 484 1.10 christos result = getpgrp (); 485 1.10 christos errcode = errno; 486 1.10 christos break; 487 1.10 christos 488 1.10 christos case TARGET_LINUX_SYS_getrlimit: 489 1.10 christos { 490 1.10 christos struct rlimit rlim; 491 1.10 christos 492 1.10 christos result = getrlimit (arg1, &rlim); 493 1.10 christos errcode = errno; 494 1.10 christos 495 1.10 christos if (result != 0) 496 1.10 christos break; 497 1.10 christos 498 1.10 christos translate_endian_h2t (&rlim, sizeof(rlim)); 499 1.10 christos if ((s.write_mem) (cb, &s, arg2, (char *) &rlim, sizeof(rlim)) 500 1.10 christos != sizeof(rlim)) 501 1.10 christos { 502 1.10 christos result = -1; 503 1.10 christos errcode = EINVAL; 504 1.10 christos } 505 1.10 christos } 506 1.10 christos break; 507 1.10 christos 508 1.10 christos case TARGET_LINUX_SYS_getrusage: 509 1.10 christos { 510 1.10 christos struct rusage usage; 511 1.10 christos 512 1.10 christos result = getrusage (arg1, &usage); 513 1.10 christos errcode = errno; 514 1.10 christos 515 1.10 christos if (result != 0) 516 1.10 christos break; 517 1.10 christos 518 1.10 christos translate_endian_h2t (&usage, sizeof(usage)); 519 1.10 christos if ((s.write_mem) (cb, &s, arg2, (char *) &usage, sizeof(usage)) 520 1.10 christos != sizeof(usage)) 521 1.10 christos { 522 1.10 christos result = -1; 523 1.10 christos errcode = EINVAL; 524 1.10 christos } 525 1.10 christos } 526 1.10 christos break; 527 1.10 christos 528 1.10 christos case TARGET_LINUX_SYS_gettimeofday: 529 1.10 christos { 530 1.10 christos struct timeval tv; 531 1.10 christos struct timezone tz; 532 1.10 christos 533 1.10 christos result = gettimeofday (&tv, &tz); 534 1.10 christos errcode = errno; 535 1.10 christos 536 1.10 christos if (result != 0) 537 1.10 christos break; 538 1.10 christos 539 1.10 christos translate_endian_h2t (&tv, sizeof(tv)); 540 1.10 christos if ((s.write_mem) (cb, &s, arg1, (char *) &tv, sizeof(tv)) 541 1.10 christos != sizeof(tv)) 542 1.10 christos { 543 1.10 christos result = -1; 544 1.10 christos errcode = EINVAL; 545 1.10 christos } 546 1.10 christos 547 1.10 christos translate_endian_h2t (&tz, sizeof(tz)); 548 1.10 christos if ((s.write_mem) (cb, &s, arg2, (char *) &tz, sizeof(tz)) 549 1.10 christos != sizeof(tz)) 550 1.10 christos { 551 1.10 christos result = -1; 552 1.10 christos errcode = EINVAL; 553 1.10 christos } 554 1.10 christos } 555 1.10 christos break; 556 1.10 christos 557 1.10 christos case TARGET_LINUX_SYS_getgroups32: 558 1.10 christos case TARGET_LINUX_SYS_getgroups: 559 1.10 christos { 560 1.10 christos gid_t *list = NULL; 561 1.10 christos 562 1.10 christos if (arg1 > 0) 563 1.10 christos list = (gid_t *) malloc (arg1 * sizeof(gid_t)); 564 1.10 christos 565 1.10 christos result = getgroups (arg1, list); 566 1.10 christos errcode = errno; 567 1.10 christos 568 1.10 christos if (result != 0) 569 1.10 christos break; 570 1.10 christos 571 1.10 christos translate_endian_h2t (list, arg1 * sizeof(gid_t)); 572 1.10 christos if (arg1 > 0) 573 1.10 christos if ((s.write_mem) (cb, &s, arg2, (char *) list, arg1 * sizeof(gid_t)) 574 1.10 christos != arg1 * sizeof(gid_t)) 575 1.10 christos { 576 1.10 christos result = -1; 577 1.10 christos errcode = EINVAL; 578 1.10 christos } 579 1.10 christos } 580 1.10 christos break; 581 1.10 christos 582 1.10 christos case TARGET_LINUX_SYS_select: 583 1.10 christos { 584 1.10 christos int n; 585 1.11 christos fd_set readfds; 586 1.10 christos unsigned int treadfdsp; 587 1.10 christos fd_set *hreadfdsp; 588 1.11 christos fd_set writefds; 589 1.10 christos unsigned int twritefdsp; 590 1.10 christos fd_set *hwritefdsp; 591 1.11 christos fd_set exceptfds; 592 1.10 christos unsigned int texceptfdsp; 593 1.11 christos fd_set *hexceptfdsp; 594 1.10 christos unsigned int ttimeoutp; 595 1.10 christos struct timeval timeout; 596 1.10 christos 597 1.10 christos n = arg1; 598 1.11 christos 599 1.11 christos treadfdsp = arg2; 600 1.10 christos if (treadfdsp !=0) 601 1.11 christos { 602 1.10 christos readfds = *((fd_set *) t2h_addr (cb, &s, treadfdsp)); 603 1.10 christos translate_endian_t2h (&readfds, sizeof(readfds)); 604 1.10 christos hreadfdsp = &readfds; 605 1.10 christos } 606 1.10 christos else 607 1.10 christos hreadfdsp = NULL; 608 1.11 christos 609 1.11 christos twritefdsp = arg3; 610 1.10 christos if (twritefdsp != 0) 611 1.11 christos { 612 1.10 christos writefds = *((fd_set *) t2h_addr (cb, &s, twritefdsp)); 613 1.10 christos translate_endian_t2h (&writefds, sizeof(writefds)); 614 1.10 christos hwritefdsp = &writefds; 615 1.10 christos } 616 1.10 christos else 617 1.10 christos hwritefdsp = NULL; 618 1.11 christos 619 1.11 christos texceptfdsp = arg4; 620 1.10 christos if (texceptfdsp != 0) 621 1.11 christos { 622 1.10 christos exceptfds = *((fd_set *) t2h_addr (cb, &s, texceptfdsp)); 623 1.10 christos translate_endian_t2h (&exceptfds, sizeof(exceptfds)); 624 1.10 christos hexceptfdsp = &exceptfds; 625 1.10 christos } 626 1.10 christos else 627 1.10 christos hexceptfdsp = NULL; 628 1.11 christos 629 1.11 christos ttimeoutp = arg5; 630 1.10 christos timeout = *((struct timeval *) t2h_addr (cb, &s, ttimeoutp)); 631 1.10 christos translate_endian_t2h (&timeout, sizeof(timeout)); 632 1.10 christos 633 1.10 christos result = select (n, hreadfdsp, hwritefdsp, hexceptfdsp, &timeout); 634 1.10 christos errcode = errno; 635 1.10 christos 636 1.10 christos if (result != 0) 637 1.10 christos break; 638 1.11 christos 639 1.10 christos if (treadfdsp != 0) 640 1.10 christos { 641 1.11 christos translate_endian_h2t (&readfds, sizeof(readfds)); 642 1.10 christos if ((s.write_mem) (cb, &s, treadfdsp, 643 1.10 christos (char *) &readfds, sizeof(readfds)) != sizeof(readfds)) 644 1.10 christos { 645 1.10 christos result = -1; 646 1.10 christos errcode = EINVAL; 647 1.10 christos } 648 1.10 christos } 649 1.11 christos 650 1.10 christos if (twritefdsp != 0) 651 1.10 christos { 652 1.11 christos translate_endian_h2t (&writefds, sizeof(writefds)); 653 1.10 christos if ((s.write_mem) (cb, &s, twritefdsp, 654 1.10 christos (char *) &writefds, sizeof(writefds)) != sizeof(writefds)) 655 1.10 christos { 656 1.10 christos result = -1; 657 1.10 christos errcode = EINVAL; 658 1.10 christos } 659 1.10 christos } 660 1.11 christos 661 1.10 christos if (texceptfdsp != 0) 662 1.10 christos { 663 1.11 christos translate_endian_h2t (&exceptfds, sizeof(exceptfds)); 664 1.10 christos if ((s.write_mem) (cb, &s, texceptfdsp, 665 1.10 christos (char *) &exceptfds, sizeof(exceptfds)) != sizeof(exceptfds)) 666 1.10 christos { 667 1.10 christos result = -1; 668 1.10 christos errcode = EINVAL; 669 1.10 christos } 670 1.10 christos } 671 1.10 christos 672 1.11 christos translate_endian_h2t (&timeout, sizeof(timeout)); 673 1.10 christos if ((s.write_mem) (cb, &s, ttimeoutp, 674 1.10 christos (char *) &timeout, sizeof(timeout)) != sizeof(timeout)) 675 1.10 christos { 676 1.10 christos result = -1; 677 1.10 christos errcode = EINVAL; 678 1.10 christos } 679 1.10 christos } 680 1.10 christos break; 681 1.10 christos 682 1.10 christos case TARGET_LINUX_SYS_symlink: 683 1.10 christos result = symlink ((char *) t2h_addr (cb, &s, arg1), 684 1.10 christos (char *) t2h_addr (cb, &s, arg2)); 685 1.10 christos errcode = errno; 686 1.10 christos break; 687 1.10 christos 688 1.10 christos case TARGET_LINUX_SYS_readlink: 689 1.10 christos result = readlink ((char *) t2h_addr (cb, &s, arg1), 690 1.10 christos (char *) t2h_addr (cb, &s, arg2), 691 1.10 christos arg3); 692 1.10 christos errcode = errno; 693 1.10 christos break; 694 1.10 christos 695 1.11 christos case TARGET_LINUX_SYS_readdir: 696 1.10 christos #if SIZEOF_VOID_P == 4 697 1.10 christos result = (int) readdir ((DIR *) t2h_addr (cb, &s, arg1)); 698 1.11 christos errcode = errno; 699 1.11 christos #else 700 1.11 christos result = 0; 701 1.11 christos errcode = ENOSYS; 702 1.10 christos #endif 703 1.10 christos break; 704 1.10 christos 705 1.10 christos #if 0 706 1.10 christos case TARGET_LINUX_SYS_mmap: 707 1.10 christos { 708 1.10 christos result = (int) mmap ((void *) t2h_addr (cb, &s, arg1), 709 1.10 christos arg2, arg3, arg4, arg5, arg6); 710 1.10 christos errcode = errno; 711 1.10 christos 712 1.10 christos if (errno == 0) 713 1.10 christos { 714 1.10 christos sim_core_attach (sd, NULL, 715 1.10 christos 0, access_read_write_exec, 0, 716 1.10 christos result, arg2, 0, NULL, NULL); 717 1.10 christos } 718 1.10 christos } 719 1.10 christos break; 720 1.10 christos #endif 721 1.10 christos case TARGET_LINUX_SYS_mmap2: 722 1.11 christos { 723 1.10 christos #if SIZEOF_VOID_P == 4 /* Code assumes m32r pointer size matches host. */ 724 1.10 christos void *addr; 725 1.10 christos size_t len; 726 1.10 christos int prot, flags, fildes; 727 1.10 christos off_t off; 728 1.10 christos 729 1.10 christos addr = (void *) t2h_addr (cb, &s, arg1); 730 1.10 christos len = arg2; 731 1.10 christos prot = arg3; 732 1.10 christos flags = arg4; 733 1.10 christos fildes = arg5; 734 1.10 christos off = arg6 << 12; 735 1.10 christos 736 1.10 christos result = (int) mmap (addr, len, prot, flags, fildes, off); 737 1.10 christos errcode = errno; 738 1.10 christos if (result != -1) 739 1.10 christos { 740 1.10 christos char c; 741 1.10 christos if (sim_core_read_buffer (sd, NULL, read_map, &c, result, 1) == 0) 742 1.10 christos sim_core_attach (sd, NULL, 743 1.10 christos 0, access_read_write_exec, 0, 744 1.10 christos result, len, 0, NULL, NULL); 745 1.11 christos } 746 1.11 christos #else 747 1.11 christos result = 0; 748 1.11 christos errcode = ENOSYS; 749 1.10 christos #endif 750 1.10 christos } 751 1.10 christos break; 752 1.10 christos 753 1.10 christos case TARGET_LINUX_SYS_mmap: 754 1.11 christos { 755 1.10 christos #if SIZEOF_VOID_P == 4 /* Code assumes m32r pointer size matches host. */ 756 1.10 christos void *addr; 757 1.10 christos size_t len; 758 1.10 christos int prot, flags, fildes; 759 1.10 christos off_t off; 760 1.10 christos 761 1.10 christos addr = *((void **) t2h_addr (cb, &s, arg1)); 762 1.10 christos len = *((size_t *) t2h_addr (cb, &s, arg1 + 4)); 763 1.10 christos prot = *((int *) t2h_addr (cb, &s, arg1 + 8)); 764 1.10 christos flags = *((int *) t2h_addr (cb, &s, arg1 + 12)); 765 1.10 christos fildes = *((int *) t2h_addr (cb, &s, arg1 + 16)); 766 1.10 christos off = *((off_t *) t2h_addr (cb, &s, arg1 + 20)); 767 1.10 christos 768 1.10 christos addr = (void *) T2H_4 ((unsigned int) addr); 769 1.10 christos len = T2H_4 (len); 770 1.10 christos prot = T2H_4 (prot); 771 1.10 christos flags = T2H_4 (flags); 772 1.10 christos fildes = T2H_4 (fildes); 773 1.10 christos off = T2H_4 (off); 774 1.10 christos 775 1.10 christos //addr = (void *) t2h_addr (cb, &s, (unsigned int) addr); 776 1.10 christos result = (int) mmap (addr, len, prot, flags, fildes, off); 777 1.10 christos errcode = errno; 778 1.10 christos 779 1.10 christos //if (errno == 0) 780 1.10 christos if (result != -1) 781 1.10 christos { 782 1.10 christos char c; 783 1.10 christos if (sim_core_read_buffer (sd, NULL, read_map, &c, result, 1) == 0) 784 1.10 christos sim_core_attach (sd, NULL, 785 1.10 christos 0, access_read_write_exec, 0, 786 1.10 christos result, len, 0, NULL, NULL); 787 1.11 christos } 788 1.11 christos #else 789 1.11 christos result = 0; 790 1.11 christos errcode = ENOSYS; 791 1.10 christos #endif 792 1.10 christos } 793 1.10 christos break; 794 1.10 christos 795 1.11 christos case TARGET_LINUX_SYS_munmap: 796 1.10 christos result = munmap ((void *) (uintptr_t) arg1, arg2); 797 1.10 christos errcode = errno; 798 1.10 christos if (result != -1) 799 1.10 christos sim_core_detach (sd, NULL, 0, arg2, result); 800 1.10 christos break; 801 1.10 christos 802 1.10 christos case TARGET_LINUX_SYS_truncate: 803 1.10 christos result = truncate ((char *) t2h_addr (cb, &s, arg1), arg2); 804 1.10 christos errcode = errno; 805 1.10 christos break; 806 1.10 christos 807 1.10 christos case TARGET_LINUX_SYS_ftruncate: 808 1.10 christos result = ftruncate (arg1, arg2); 809 1.10 christos errcode = errno; 810 1.10 christos break; 811 1.10 christos 812 1.10 christos case TARGET_LINUX_SYS_fchmod: 813 1.10 christos result = fchmod (arg1, arg2); 814 1.10 christos errcode = errno; 815 1.10 christos break; 816 1.10 christos 817 1.10 christos case TARGET_LINUX_SYS_fchown32: 818 1.10 christos case TARGET_LINUX_SYS_fchown: 819 1.10 christos result = fchown (arg1, arg2, arg3); 820 1.10 christos errcode = errno; 821 1.10 christos break; 822 1.10 christos 823 1.10 christos case TARGET_LINUX_SYS_statfs: 824 1.10 christos { 825 1.10 christos struct statfs statbuf; 826 1.10 christos 827 1.10 christos result = statfs ((char *) t2h_addr (cb, &s, arg1), &statbuf); 828 1.10 christos errcode = errno; 829 1.10 christos 830 1.10 christos if (result != 0) 831 1.10 christos break; 832 1.10 christos 833 1.10 christos translate_endian_h2t (&statbuf, sizeof(statbuf)); 834 1.10 christos if ((s.write_mem) (cb, &s, arg2, (char *) &statbuf, sizeof(statbuf)) 835 1.10 christos != sizeof(statbuf)) 836 1.10 christos { 837 1.10 christos result = -1; 838 1.10 christos errcode = EINVAL; 839 1.10 christos } 840 1.10 christos } 841 1.10 christos break; 842 1.10 christos 843 1.10 christos case TARGET_LINUX_SYS_fstatfs: 844 1.10 christos { 845 1.10 christos struct statfs statbuf; 846 1.10 christos 847 1.10 christos result = fstatfs (arg1, &statbuf); 848 1.10 christos errcode = errno; 849 1.10 christos 850 1.10 christos if (result != 0) 851 1.10 christos break; 852 1.10 christos 853 1.10 christos translate_endian_h2t (&statbuf, sizeof(statbuf)); 854 1.10 christos if ((s.write_mem) (cb, &s, arg2, (char *) &statbuf, sizeof(statbuf)) 855 1.10 christos != sizeof(statbuf)) 856 1.10 christos { 857 1.10 christos result = -1; 858 1.10 christos errcode = EINVAL; 859 1.10 christos } 860 1.10 christos } 861 1.10 christos break; 862 1.10 christos 863 1.11 christos case TARGET_LINUX_SYS_syslog: 864 1.11 christos syslog (arg1, "%s", (char *) t2h_addr (cb, &s, arg2)); 865 1.10 christos result = 0; 866 1.10 christos errcode = errno; 867 1.10 christos break; 868 1.10 christos 869 1.10 christos case TARGET_LINUX_SYS_setitimer: 870 1.10 christos { 871 1.10 christos struct itimerval value, ovalue; 872 1.10 christos 873 1.10 christos value = *((struct itimerval *) t2h_addr (cb, &s, arg2)); 874 1.10 christos translate_endian_t2h (&value, sizeof(value)); 875 1.10 christos 876 1.10 christos if (arg2 == 0) 877 1.10 christos { 878 1.10 christos result = setitimer (arg1, &value, NULL); 879 1.10 christos errcode = errno; 880 1.10 christos } 881 1.10 christos else 882 1.10 christos { 883 1.10 christos result = setitimer (arg1, &value, &ovalue); 884 1.10 christos errcode = errno; 885 1.10 christos 886 1.10 christos if (result != 0) 887 1.10 christos break; 888 1.10 christos 889 1.10 christos translate_endian_h2t (&ovalue, sizeof(ovalue)); 890 1.10 christos if ((s.write_mem) (cb, &s, arg3, (char *) &ovalue, sizeof(ovalue)) 891 1.10 christos != sizeof(ovalue)) 892 1.10 christos { 893 1.10 christos result = -1; 894 1.10 christos errcode = EINVAL; 895 1.10 christos } 896 1.10 christos } 897 1.10 christos } 898 1.10 christos break; 899 1.10 christos 900 1.10 christos case TARGET_LINUX_SYS_getitimer: 901 1.10 christos { 902 1.10 christos struct itimerval value; 903 1.10 christos 904 1.10 christos result = getitimer (arg1, &value); 905 1.10 christos errcode = errno; 906 1.10 christos 907 1.10 christos if (result != 0) 908 1.10 christos break; 909 1.10 christos 910 1.10 christos translate_endian_h2t (&value, sizeof(value)); 911 1.10 christos if ((s.write_mem) (cb, &s, arg2, (char *) &value, sizeof(value)) 912 1.10 christos != sizeof(value)) 913 1.10 christos { 914 1.10 christos result = -1; 915 1.10 christos errcode = EINVAL; 916 1.10 christos } 917 1.10 christos } 918 1.10 christos break; 919 1.10 christos 920 1.10 christos case TARGET_LINUX_SYS_stat: 921 1.10 christos { 922 1.10 christos char *buf; 923 1.10 christos int buflen; 924 1.10 christos struct stat statbuf; 925 1.10 christos 926 1.10 christos result = stat ((char *) t2h_addr (cb, &s, arg1), &statbuf); 927 1.10 christos errcode = errno; 928 1.10 christos if (result < 0) 929 1.10 christos break; 930 1.10 christos 931 1.10 christos buflen = cb_host_to_target_stat (cb, NULL, NULL); 932 1.10 christos buf = xmalloc (buflen); 933 1.10 christos if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen) 934 1.10 christos { 935 1.10 christos /* The translation failed. This is due to an internal 936 1.10 christos host program error, not the target's fault. */ 937 1.10 christos free (buf); 938 1.10 christos result = -1; 939 1.10 christos errcode = ENOSYS; 940 1.10 christos break; 941 1.10 christos } 942 1.10 christos if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen) 943 1.10 christos { 944 1.10 christos free (buf); 945 1.10 christos result = -1; 946 1.10 christos errcode = EINVAL; 947 1.10 christos break; 948 1.10 christos } 949 1.10 christos free (buf); 950 1.10 christos } 951 1.10 christos break; 952 1.10 christos 953 1.10 christos case TARGET_LINUX_SYS_lstat: 954 1.10 christos { 955 1.10 christos char *buf; 956 1.10 christos int buflen; 957 1.10 christos struct stat statbuf; 958 1.10 christos 959 1.10 christos result = lstat ((char *) t2h_addr (cb, &s, arg1), &statbuf); 960 1.10 christos errcode = errno; 961 1.10 christos if (result < 0) 962 1.10 christos break; 963 1.10 christos 964 1.10 christos buflen = cb_host_to_target_stat (cb, NULL, NULL); 965 1.10 christos buf = xmalloc (buflen); 966 1.10 christos if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen) 967 1.10 christos { 968 1.10 christos /* The translation failed. This is due to an internal 969 1.10 christos host program error, not the target's fault. */ 970 1.10 christos free (buf); 971 1.10 christos result = -1; 972 1.10 christos errcode = ENOSYS; 973 1.10 christos break; 974 1.10 christos } 975 1.10 christos if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen) 976 1.10 christos { 977 1.10 christos free (buf); 978 1.10 christos result = -1; 979 1.10 christos errcode = EINVAL; 980 1.10 christos break; 981 1.10 christos } 982 1.10 christos free (buf); 983 1.10 christos } 984 1.10 christos break; 985 1.10 christos 986 1.10 christos case TARGET_LINUX_SYS_fstat: 987 1.10 christos { 988 1.10 christos char *buf; 989 1.10 christos int buflen; 990 1.10 christos struct stat statbuf; 991 1.10 christos 992 1.10 christos result = fstat (arg1, &statbuf); 993 1.10 christos errcode = errno; 994 1.10 christos if (result < 0) 995 1.10 christos break; 996 1.10 christos 997 1.10 christos buflen = cb_host_to_target_stat (cb, NULL, NULL); 998 1.10 christos buf = xmalloc (buflen); 999 1.10 christos if (cb_host_to_target_stat (cb, &statbuf, buf) != buflen) 1000 1.10 christos { 1001 1.10 christos /* The translation failed. This is due to an internal 1002 1.10 christos host program error, not the target's fault. */ 1003 1.10 christos free (buf); 1004 1.10 christos result = -1; 1005 1.10 christos errcode = ENOSYS; 1006 1.10 christos break; 1007 1.10 christos } 1008 1.10 christos if ((s.write_mem) (cb, &s, arg2, buf, buflen) != buflen) 1009 1.10 christos { 1010 1.10 christos free (buf); 1011 1.10 christos result = -1; 1012 1.10 christos errcode = EINVAL; 1013 1.10 christos break; 1014 1.10 christos } 1015 1.10 christos free (buf); 1016 1.10 christos } 1017 1.10 christos break; 1018 1.10 christos 1019 1.10 christos case TARGET_LINUX_SYS_sysinfo: 1020 1.10 christos { 1021 1.10 christos struct sysinfo info; 1022 1.10 christos 1023 1.10 christos result = sysinfo (&info); 1024 1.10 christos errcode = errno; 1025 1.10 christos 1026 1.10 christos if (result != 0) 1027 1.10 christos break; 1028 1.10 christos 1029 1.10 christos info.uptime = H2T_4 (info.uptime); 1030 1.10 christos info.loads[0] = H2T_4 (info.loads[0]); 1031 1.10 christos info.loads[1] = H2T_4 (info.loads[1]); 1032 1.10 christos info.loads[2] = H2T_4 (info.loads[2]); 1033 1.10 christos info.totalram = H2T_4 (info.totalram); 1034 1.10 christos info.freeram = H2T_4 (info.freeram); 1035 1.10 christos info.sharedram = H2T_4 (info.sharedram); 1036 1.10 christos info.bufferram = H2T_4 (info.bufferram); 1037 1.10 christos info.totalswap = H2T_4 (info.totalswap); 1038 1.10 christos info.freeswap = H2T_4 (info.freeswap); 1039 1.10 christos info.procs = H2T_2 (info.procs); 1040 1.10 christos #if LINUX_VERSION_CODE >= 0x20400 1041 1.10 christos info.totalhigh = H2T_4 (info.totalhigh); 1042 1.10 christos info.freehigh = H2T_4 (info.freehigh); 1043 1.10 christos info.mem_unit = H2T_4 (info.mem_unit); 1044 1.10 christos #endif 1045 1.10 christos if ((s.write_mem) (cb, &s, arg1, (char *) &info, sizeof(info)) 1046 1.10 christos != sizeof(info)) 1047 1.10 christos { 1048 1.10 christos result = -1; 1049 1.10 christos errcode = EINVAL; 1050 1.10 christos } 1051 1.10 christos } 1052 1.10 christos break; 1053 1.10 christos 1054 1.10 christos #if 0 1055 1.10 christos case TARGET_LINUX_SYS_ipc: 1056 1.10 christos { 1057 1.10 christos result = ipc (arg1, arg2, arg3, arg4, 1058 1.10 christos (void *) t2h_addr (cb, &s, arg5), arg6); 1059 1.10 christos errcode = errno; 1060 1.10 christos } 1061 1.10 christos break; 1062 1.10 christos #endif 1063 1.10 christos 1064 1.10 christos case TARGET_LINUX_SYS_fsync: 1065 1.10 christos result = fsync (arg1); 1066 1.10 christos errcode = errno; 1067 1.10 christos break; 1068 1.10 christos 1069 1.10 christos case TARGET_LINUX_SYS_uname: 1070 1.10 christos /* utsname contains only arrays of char, so it is not necessary 1071 1.10 christos to translate endian. */ 1072 1.10 christos result = uname ((struct utsname *) t2h_addr (cb, &s, arg1)); 1073 1.10 christos errcode = errno; 1074 1.10 christos break; 1075 1.10 christos 1076 1.10 christos case TARGET_LINUX_SYS_adjtimex: 1077 1.10 christos { 1078 1.10 christos struct timex buf; 1079 1.10 christos 1080 1.10 christos result = adjtimex (&buf); 1081 1.10 christos errcode = errno; 1082 1.10 christos 1083 1.10 christos if (result != 0) 1084 1.10 christos break; 1085 1.10 christos 1086 1.10 christos translate_endian_h2t (&buf, sizeof(buf)); 1087 1.10 christos if ((s.write_mem) (cb, &s, arg1, (char *) &buf, sizeof(buf)) 1088 1.10 christos != sizeof(buf)) 1089 1.10 christos { 1090 1.10 christos result = -1; 1091 1.10 christos errcode = EINVAL; 1092 1.10 christos } 1093 1.10 christos } 1094 1.10 christos break; 1095 1.10 christos 1096 1.11 christos case TARGET_LINUX_SYS_mprotect: 1097 1.10 christos result = mprotect ((void *) (uintptr_t) arg1, arg2, arg3); 1098 1.10 christos errcode = errno; 1099 1.10 christos break; 1100 1.10 christos 1101 1.10 christos case TARGET_LINUX_SYS_fchdir: 1102 1.10 christos result = fchdir (arg1); 1103 1.10 christos errcode = errno; 1104 1.10 christos break; 1105 1.10 christos 1106 1.10 christos case TARGET_LINUX_SYS_setfsuid32: 1107 1.10 christos case TARGET_LINUX_SYS_setfsuid: 1108 1.10 christos result = setfsuid (arg1); 1109 1.10 christos errcode = errno; 1110 1.10 christos break; 1111 1.10 christos 1112 1.10 christos case TARGET_LINUX_SYS_setfsgid32: 1113 1.10 christos case TARGET_LINUX_SYS_setfsgid: 1114 1.10 christos result = setfsgid (arg1); 1115 1.10 christos errcode = errno; 1116 1.10 christos break; 1117 1.10 christos 1118 1.10 christos #if 0 1119 1.10 christos case TARGET_LINUX_SYS__llseek: 1120 1.10 christos { 1121 1.10 christos loff_t buf; 1122 1.10 christos 1123 1.10 christos result = _llseek (arg1, arg2, arg3, &buf, arg5); 1124 1.10 christos errcode = errno; 1125 1.10 christos 1126 1.10 christos if (result != 0) 1127 1.10 christos break; 1128 1.10 christos 1129 1.10 christos translate_endian_h2t (&buf, sizeof(buf)); 1130 1.10 christos if ((s.write_mem) (cb, &s, t2h_addr (cb, &s, arg4), 1131 1.10 christos (char *) &buf, sizeof(buf)) != sizeof(buf)) 1132 1.10 christos { 1133 1.10 christos result = -1; 1134 1.10 christos errcode = EINVAL; 1135 1.10 christos } 1136 1.10 christos } 1137 1.10 christos break; 1138 1.10 christos 1139 1.10 christos case TARGET_LINUX_SYS_getdents: 1140 1.10 christos { 1141 1.10 christos struct dirent dir; 1142 1.10 christos 1143 1.10 christos result = getdents (arg1, &dir, arg3); 1144 1.10 christos errcode = errno; 1145 1.10 christos 1146 1.10 christos if (result != 0) 1147 1.10 christos break; 1148 1.10 christos 1149 1.10 christos dir.d_ino = H2T_4 (dir.d_ino); 1150 1.10 christos dir.d_off = H2T_4 (dir.d_off); 1151 1.10 christos dir.d_reclen = H2T_2 (dir.d_reclen); 1152 1.10 christos if ((s.write_mem) (cb, &s, arg2, (char *) &dir, sizeof(dir)) 1153 1.10 christos != sizeof(dir)) 1154 1.10 christos { 1155 1.10 christos result = -1; 1156 1.10 christos errcode = EINVAL; 1157 1.10 christos } 1158 1.10 christos } 1159 1.10 christos break; 1160 1.10 christos #endif 1161 1.10 christos 1162 1.10 christos case TARGET_LINUX_SYS_flock: 1163 1.10 christos result = flock (arg1, arg2); 1164 1.10 christos errcode = errno; 1165 1.10 christos break; 1166 1.10 christos 1167 1.11 christos case TARGET_LINUX_SYS_msync: 1168 1.10 christos result = msync ((void *) (uintptr_t) arg1, arg2, arg3); 1169 1.10 christos errcode = errno; 1170 1.10 christos break; 1171 1.10 christos 1172 1.10 christos case TARGET_LINUX_SYS_readv: 1173 1.10 christos { 1174 1.10 christos struct iovec vector; 1175 1.10 christos 1176 1.10 christos vector = *((struct iovec *) t2h_addr (cb, &s, arg2)); 1177 1.10 christos translate_endian_t2h (&vector, sizeof(vector)); 1178 1.10 christos 1179 1.10 christos result = readv (arg1, &vector, arg3); 1180 1.10 christos errcode = errno; 1181 1.10 christos } 1182 1.10 christos break; 1183 1.10 christos 1184 1.10 christos case TARGET_LINUX_SYS_writev: 1185 1.10 christos { 1186 1.10 christos struct iovec vector; 1187 1.10 christos 1188 1.10 christos vector = *((struct iovec *) t2h_addr (cb, &s, arg2)); 1189 1.10 christos translate_endian_t2h (&vector, sizeof(vector)); 1190 1.10 christos 1191 1.10 christos result = writev (arg1, &vector, arg3); 1192 1.10 christos errcode = errno; 1193 1.10 christos } 1194 1.10 christos break; 1195 1.10 christos 1196 1.10 christos case TARGET_LINUX_SYS_fdatasync: 1197 1.10 christos result = fdatasync (arg1); 1198 1.10 christos errcode = errno; 1199 1.10 christos break; 1200 1.10 christos 1201 1.10 christos case TARGET_LINUX_SYS_mlock: 1202 1.10 christos result = mlock ((void *) t2h_addr (cb, &s, arg1), arg2); 1203 1.10 christos errcode = errno; 1204 1.10 christos break; 1205 1.10 christos 1206 1.10 christos case TARGET_LINUX_SYS_munlock: 1207 1.10 christos result = munlock ((void *) t2h_addr (cb, &s, arg1), arg2); 1208 1.10 christos errcode = errno; 1209 1.10 christos break; 1210 1.10 christos 1211 1.10 christos case TARGET_LINUX_SYS_nanosleep: 1212 1.10 christos { 1213 1.10 christos struct timespec req, rem; 1214 1.10 christos 1215 1.10 christos req = *((struct timespec *) t2h_addr (cb, &s, arg2)); 1216 1.10 christos translate_endian_t2h (&req, sizeof(req)); 1217 1.10 christos 1218 1.10 christos result = nanosleep (&req, &rem); 1219 1.10 christos errcode = errno; 1220 1.10 christos 1221 1.10 christos if (result != 0) 1222 1.10 christos break; 1223 1.10 christos 1224 1.10 christos translate_endian_h2t (&rem, sizeof(rem)); 1225 1.10 christos if ((s.write_mem) (cb, &s, arg2, (char *) &rem, sizeof(rem)) 1226 1.10 christos != sizeof(rem)) 1227 1.10 christos { 1228 1.10 christos result = -1; 1229 1.10 christos errcode = EINVAL; 1230 1.10 christos } 1231 1.10 christos } 1232 1.10 christos break; 1233 1.10 christos 1234 1.11 christos case TARGET_LINUX_SYS_mremap: /* FIXME */ 1235 1.10 christos #if SIZEOF_VOID_P == 4 /* Code assumes m32r pointer size matches host. */ 1236 1.10 christos result = (int) mremap ((void *) t2h_addr (cb, &s, arg1), arg2, arg3, arg4); 1237 1.11 christos errcode = errno; 1238 1.11 christos #else 1239 1.11 christos result = -1; 1240 1.11 christos errcode = ENOSYS; 1241 1.10 christos #endif 1242 1.10 christos break; 1243 1.10 christos 1244 1.10 christos case TARGET_LINUX_SYS_getresuid32: 1245 1.10 christos case TARGET_LINUX_SYS_getresuid: 1246 1.10 christos { 1247 1.10 christos uid_t ruid, euid, suid; 1248 1.10 christos 1249 1.10 christos result = getresuid (&ruid, &euid, &suid); 1250 1.10 christos errcode = errno; 1251 1.10 christos 1252 1.10 christos if (result != 0) 1253 1.10 christos break; 1254 1.10 christos 1255 1.10 christos *((uid_t *) t2h_addr (cb, &s, arg1)) = H2T_4 (ruid); 1256 1.10 christos *((uid_t *) t2h_addr (cb, &s, arg2)) = H2T_4 (euid); 1257 1.10 christos *((uid_t *) t2h_addr (cb, &s, arg3)) = H2T_4 (suid); 1258 1.10 christos } 1259 1.10 christos break; 1260 1.10 christos 1261 1.10 christos case TARGET_LINUX_SYS_poll: 1262 1.10 christos { 1263 1.10 christos struct pollfd ufds; 1264 1.10 christos 1265 1.10 christos ufds = *((struct pollfd *) t2h_addr (cb, &s, arg1)); 1266 1.10 christos ufds.fd = T2H_4 (ufds.fd); 1267 1.10 christos ufds.events = T2H_2 (ufds.events); 1268 1.10 christos ufds.revents = T2H_2 (ufds.revents); 1269 1.10 christos 1270 1.10 christos result = poll (&ufds, arg2, arg3); 1271 1.10 christos errcode = errno; 1272 1.10 christos } 1273 1.10 christos break; 1274 1.10 christos 1275 1.10 christos case TARGET_LINUX_SYS_getresgid32: 1276 1.10 christos case TARGET_LINUX_SYS_getresgid: 1277 1.10 christos { 1278 1.10 christos uid_t rgid, egid, sgid; 1279 1.10 christos 1280 1.10 christos result = getresgid (&rgid, &egid, &sgid); 1281 1.10 christos errcode = errno; 1282 1.10 christos 1283 1.10 christos if (result != 0) 1284 1.10 christos break; 1285 1.10 christos 1286 1.10 christos *((uid_t *) t2h_addr (cb, &s, arg1)) = H2T_4 (rgid); 1287 1.10 christos *((uid_t *) t2h_addr (cb, &s, arg2)) = H2T_4 (egid); 1288 1.10 christos *((uid_t *) t2h_addr (cb, &s, arg3)) = H2T_4 (sgid); 1289 1.10 christos } 1290 1.10 christos break; 1291 1.10 christos 1292 1.10 christos case TARGET_LINUX_SYS_pread: 1293 1.10 christos result = pread (arg1, (void *) t2h_addr (cb, &s, arg2), arg3, arg4); 1294 1.10 christos errcode = errno; 1295 1.10 christos break; 1296 1.10 christos 1297 1.10 christos case TARGET_LINUX_SYS_pwrite: 1298 1.10 christos result = pwrite (arg1, (void *) t2h_addr (cb, &s, arg2), arg3, arg4); 1299 1.10 christos errcode = errno; 1300 1.10 christos break; 1301 1.10 christos 1302 1.10 christos case TARGET_LINUX_SYS_chown32: 1303 1.10 christos case TARGET_LINUX_SYS_chown: 1304 1.10 christos result = chown ((char *) t2h_addr (cb, &s, arg1), arg2, arg3); 1305 1.10 christos errcode = errno; 1306 1.10 christos break; 1307 1.10 christos 1308 1.11 christos case TARGET_LINUX_SYS_getcwd: 1309 1.11 christos { 1310 1.11 christos void *ret; 1311 1.11 christos 1312 1.11 christos ret = getcwd ((char *) t2h_addr (cb, &s, arg1), arg2); 1313 1.11 christos result = ret == NULL ? 0 : arg1; 1314 1.11 christos errcode = errno; 1315 1.10 christos } 1316 1.10 christos break; 1317 1.10 christos 1318 1.10 christos case TARGET_LINUX_SYS_sendfile: 1319 1.10 christos { 1320 1.10 christos off_t offset; 1321 1.10 christos 1322 1.10 christos offset = *((off_t *) t2h_addr (cb, &s, arg3)); 1323 1.10 christos offset = T2H_4 (offset); 1324 1.10 christos 1325 1.10 christos result = sendfile (arg1, arg2, &offset, arg3); 1326 1.10 christos errcode = errno; 1327 1.10 christos 1328 1.10 christos if (result != 0) 1329 1.10 christos break; 1330 1.10 christos 1331 1.10 christos *((off_t *) t2h_addr (cb, &s, arg3)) = H2T_4 (offset); 1332 1.10 christos } 1333 1.10 christos break; 1334 1.10 christos 1335 1.10 christos default: 1336 1.10 christos result = -1; 1337 1.10 christos errcode = ENOSYS; 1338 1.10 christos break; 1339 1.10 christos } 1340 1.10 christos 1341 1.10 christos if (result == -1) 1342 1.10 christos m32rbf_h_gr_set (current_cpu, 0, -errcode); 1343 1.10 christos else 1344 1.10 christos m32rbf_h_gr_set (current_cpu, 0, result); 1345 1.10 christos break; 1346 1.10 christos } 1347 1.10 christos #endif 1348 1.1 christos 1349 1.1 christos case TRAP_BREAKPOINT: 1350 1.1 christos sim_engine_halt (sd, current_cpu, NULL, pc, 1351 1.1 christos sim_stopped, SIM_SIGTRAP); 1352 1.1 christos break; 1353 1.1 christos 1354 1.1 christos case TRAP_FLUSH_CACHE: 1355 1.1 christos /* Do nothing. */ 1356 1.1 christos break; 1357 1.10 christos 1358 1.10 christos case_default: 1359 1.1 christos default: 1360 1.10 christos { 1361 1.10 christos /* The new pc is the trap vector entry. 1362 1.10 christos We assume there's a branch there to some handler. 1363 1.1 christos Use cr5 as EVB (EIT Vector Base) register. */ 1364 1.10 christos /* USI new_pc = EIT_TRAP_BASE_ADDR + num * 4; */ 1365 1.1 christos USI new_pc = m32rbf_h_cr_get (current_cpu, 5) + 0x40 + num * 4; 1366 1.1 christos return new_pc; 1367 1.1 christos } 1368 1.1 christos } 1369 1.1 christos 1370 1.1 christos /* Fake an "rte" insn. */ 1371 1.1 christos /* FIXME: Should duplicate all of rte processing. */ 1372 1.1 christos return (pc & -4) + 4; 1373 } 1374