1 /* m32r exception, interrupt, and trap (EIT) support
2 Copyright (C) 1998-2022 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions & Renesas.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* This must come before any other includes. */
23 #include "portability.h"
25 #include "sim-signal.h"
26 #include "sim-syscall.h"
27 #include "sim/callback.h"
36 /* TODO: The Linux syscall emulation needs work to support non-Linux hosts.
37 Use an OS hack for now so the CPU emulation is available everywhere.
38 NB: The emulation is also missing argument conversion (endian & bitsize)
39 even on Linux hosts. */
43 #include <sys/resource.h>
44 #include <sys/sysinfo.h>
47 #include <sys/timeb.h>
48 #include <sys/timex.h>
49 #include <sys/types.h>
51 #include <sys/utsname.h>
53 #include <linux/sysctl.h>
54 #include <linux/types.h>
55 #include <linux/unistd.h>
58 #define TRAP_LINUX_SYSCALL 2
59 #define TRAP_FLUSH_CACHE 12
60 /* The semantic code invokes this for invalid (unrecognized) instructions. */
63 sim_engine_invalid_insn (SIM_CPU
*current_cpu
, IADDR cia
, SEM_PC pc
)
65 SIM_DESC sd
= CPU_STATE (current_cpu
);
68 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
70 h_bsm_set (current_cpu
, h_sm_get (current_cpu
));
71 h_bie_set (current_cpu
, h_ie_get (current_cpu
));
72 h_bcond_set (current_cpu
, h_cond_get (current_cpu
));
74 h_ie_set (current_cpu
, 0);
75 h_cond_set (current_cpu
, 0);
77 h_bpc_set (current_cpu
, cia
);
79 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
84 sim_engine_halt (sd
, current_cpu
, NULL
, cia
, sim_stopped
, SIM_SIGILL
);
89 /* Process an address exception. */
92 m32r_core_signal (SIM_DESC sd
, SIM_CPU
*current_cpu
, sim_cia cia
,
93 unsigned int map
, int nr_bytes
, address_word addr
,
94 transfer_type transfer
, sim_core_signals sig
)
96 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
98 m32rbf_h_cr_set (current_cpu
, H_CR_BBPC
,
99 m32rbf_h_cr_get (current_cpu
, H_CR_BPC
));
100 switch (MACH_NUM (CPU_MACH (current_cpu
)))
103 m32rbf_h_bpsw_set (current_cpu
, m32rbf_h_psw_get (current_cpu
));
104 /* sm not changed. */
105 m32rbf_h_psw_set (current_cpu
, m32rbf_h_psw_get (current_cpu
) & 0x80);
108 m32rxf_h_bpsw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
));
109 /* sm not changed. */
110 m32rxf_h_psw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
) & 0x80);
113 m32r2f_h_bpsw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
));
114 /* sm not changed. */
115 m32r2f_h_psw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
) & 0x80);
121 m32rbf_h_cr_set (current_cpu
, H_CR_BPC
, cia
);
123 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
127 sim_core_signal (sd
, current_cpu
, cia
, map
, nr_bytes
, addr
,
131 /* Translate target's address to host's address. */
134 t2h_addr (host_callback
*cb
, struct cb_syscall
*sc
,
138 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
139 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
144 return sim_core_trans_addr (sd
, cpu
, read_map
, taddr
);
147 /* TODO: These functions are a big hack and assume that the host runtime has
148 type sizes and struct layouts that match the target. So the Linux emulation
149 probaly only really works in 32-bit runtimes. */
152 translate_endian_h2t (void *addr
, size_t size
)
154 unsigned int *p
= (unsigned int *) addr
;
157 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
161 *((unsigned short *) p
) = H2T_2 (*((unsigned short *) p
));
165 translate_endian_t2h (void *addr
, size_t size
)
167 unsigned int *p
= (unsigned int *) addr
;
170 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
174 *((unsigned short *) p
) = T2H_2 (*((unsigned short *) p
));
178 The result is the pc address to continue at.
179 Preprocessing like saving the various registers has already been done. */
182 m32r_trap (SIM_CPU
*current_cpu
, PCADDR pc
, int num
)
184 SIM_DESC sd
= CPU_STATE (current_cpu
);
185 host_callback
*cb
= STATE_CALLBACK (sd
);
187 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
194 long result
, result2
;
197 sim_syscall_multi (current_cpu
,
198 m32rbf_h_gr_get (current_cpu
, 0),
199 m32rbf_h_gr_get (current_cpu
, 1),
200 m32rbf_h_gr_get (current_cpu
, 2),
201 m32rbf_h_gr_get (current_cpu
, 3),
202 m32rbf_h_gr_get (current_cpu
, 4),
203 &result
, &result2
, &errcode
);
205 m32rbf_h_gr_set (current_cpu
, 2, errcode
);
206 m32rbf_h_gr_set (current_cpu
, 0, result
);
207 m32rbf_h_gr_set (current_cpu
, 1, result2
);
212 case TRAP_LINUX_SYSCALL
:
215 unsigned int func
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
;
216 int result
, result2
, errcode
;
218 if (STATE_ENVIRONMENT (sd
) != USER_ENVIRONMENT
)
221 func
= m32rbf_h_gr_get (current_cpu
, 7);
222 arg1
= m32rbf_h_gr_get (current_cpu
, 0);
223 arg2
= m32rbf_h_gr_get (current_cpu
, 1);
224 arg3
= m32rbf_h_gr_get (current_cpu
, 2);
225 arg4
= m32rbf_h_gr_get (current_cpu
, 3);
226 arg5
= m32rbf_h_gr_get (current_cpu
, 4);
227 arg6
= m32rbf_h_gr_get (current_cpu
, 5);
228 arg7
= m32rbf_h_gr_get (current_cpu
, 6);
230 CB_SYSCALL_INIT (&s
);
241 s
.p2
= (PTR
) current_cpu
;
242 s
.read_mem
= sim_syscall_read_mem
;
243 s
.write_mem
= sim_syscall_write_mem
;
251 case TARGET_LINUX_SYS_exit
:
252 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, arg1
);
255 case TARGET_LINUX_SYS_read
:
256 result
= read (arg1
, t2h_addr (cb
, &s
, arg2
), arg3
);
260 case TARGET_LINUX_SYS_write
:
261 result
= write (arg1
, t2h_addr (cb
, &s
, arg2
), arg3
);
265 case TARGET_LINUX_SYS_open
:
266 result
= open ((char *) t2h_addr (cb
, &s
, arg1
), arg2
, arg3
);
270 case TARGET_LINUX_SYS_close
:
271 result
= close (arg1
);
275 case TARGET_LINUX_SYS_creat
:
276 result
= creat ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
280 case TARGET_LINUX_SYS_link
:
281 result
= link ((char *) t2h_addr (cb
, &s
, arg1
),
282 (char *) t2h_addr (cb
, &s
, arg2
));
286 case TARGET_LINUX_SYS_unlink
:
287 result
= unlink ((char *) t2h_addr (cb
, &s
, arg1
));
291 case TARGET_LINUX_SYS_chdir
:
292 result
= chdir ((char *) t2h_addr (cb
, &s
, arg1
));
296 case TARGET_LINUX_SYS_time
:
302 result
= (int) time (NULL
);
307 result
= (int) time (&t
);
314 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
)) != sizeof(t
))
323 case TARGET_LINUX_SYS_mknod
:
324 result
= mknod ((char *) t2h_addr (cb
, &s
, arg1
),
325 (mode_t
) arg2
, (dev_t
) arg3
);
329 case TARGET_LINUX_SYS_chmod
:
330 result
= chmod ((char *) t2h_addr (cb
, &s
, arg1
), (mode_t
) arg2
);
334 case TARGET_LINUX_SYS_lchown32
:
335 case TARGET_LINUX_SYS_lchown
:
336 result
= lchown ((char *) t2h_addr (cb
, &s
, arg1
),
337 (uid_t
) arg2
, (gid_t
) arg3
);
341 case TARGET_LINUX_SYS_lseek
:
342 result
= (int) lseek (arg1
, (off_t
) arg2
, arg3
);
346 case TARGET_LINUX_SYS_getpid
:
351 case TARGET_LINUX_SYS_getuid32
:
352 case TARGET_LINUX_SYS_getuid
:
357 case TARGET_LINUX_SYS_utime
:
363 result
= utime ((char *) t2h_addr (cb
, &s
, arg1
), NULL
);
368 buf
= *((struct utimbuf
*) t2h_addr (cb
, &s
, arg2
));
369 translate_endian_t2h (&buf
, sizeof(buf
));
370 result
= utime ((char *) t2h_addr (cb
, &s
, arg1
), &buf
);
376 case TARGET_LINUX_SYS_access
:
377 result
= access ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
381 case TARGET_LINUX_SYS_ftime
:
391 t
.time
= H2T_4 (t
.time
);
392 t
.millitm
= H2T_2 (t
.millitm
);
393 t
.timezone
= H2T_2 (t
.timezone
);
394 t
.dstflag
= H2T_2 (t
.dstflag
);
395 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
))
403 case TARGET_LINUX_SYS_sync
:
408 case TARGET_LINUX_SYS_rename
:
409 result
= rename ((char *) t2h_addr (cb
, &s
, arg1
),
410 (char *) t2h_addr (cb
, &s
, arg2
));
414 case TARGET_LINUX_SYS_mkdir
:
415 result
= mkdir ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
419 case TARGET_LINUX_SYS_rmdir
:
420 result
= rmdir ((char *) t2h_addr (cb
, &s
, arg1
));
424 case TARGET_LINUX_SYS_dup
:
429 case TARGET_LINUX_SYS_brk
:
430 result
= brk ((void *) arg1
);
435 case TARGET_LINUX_SYS_getgid32
:
436 case TARGET_LINUX_SYS_getgid
:
441 case TARGET_LINUX_SYS_geteuid32
:
442 case TARGET_LINUX_SYS_geteuid
:
447 case TARGET_LINUX_SYS_getegid32
:
448 case TARGET_LINUX_SYS_getegid
:
453 case TARGET_LINUX_SYS_ioctl
:
454 result
= ioctl (arg1
, arg2
, arg3
);
458 case TARGET_LINUX_SYS_fcntl
:
459 result
= fcntl (arg1
, arg2
, arg3
);
463 case TARGET_LINUX_SYS_dup2
:
464 result
= dup2 (arg1
, arg2
);
468 case TARGET_LINUX_SYS_getppid
:
473 case TARGET_LINUX_SYS_getpgrp
:
478 case TARGET_LINUX_SYS_getrlimit
:
482 result
= getrlimit (arg1
, &rlim
);
488 translate_endian_h2t (&rlim
, sizeof(rlim
));
489 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rlim
, sizeof(rlim
))
498 case TARGET_LINUX_SYS_getrusage
:
502 result
= getrusage (arg1
, &usage
);
508 translate_endian_h2t (&usage
, sizeof(usage
));
509 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &usage
, sizeof(usage
))
518 case TARGET_LINUX_SYS_gettimeofday
:
523 result
= gettimeofday (&tv
, &tz
);
529 translate_endian_h2t (&tv
, sizeof(tv
));
530 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &tv
, sizeof(tv
))
537 translate_endian_h2t (&tz
, sizeof(tz
));
538 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &tz
, sizeof(tz
))
547 case TARGET_LINUX_SYS_getgroups32
:
548 case TARGET_LINUX_SYS_getgroups
:
553 list
= (gid_t
*) malloc (arg1
* sizeof(gid_t
));
555 result
= getgroups (arg1
, list
);
561 translate_endian_h2t (list
, arg1
* sizeof(gid_t
));
563 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) list
, arg1
* sizeof(gid_t
))
564 != arg1
* sizeof(gid_t
))
572 case TARGET_LINUX_SYS_select
:
584 struct timeval
*ttimeoutp
;
585 struct timeval timeout
;
589 treadfdsp
= (fd_set
*) arg2
;
590 if (treadfdsp
!= NULL
)
592 readfds
= *((fd_set
*) t2h_addr (cb
, &s
, (unsigned int) treadfdsp
));
593 translate_endian_t2h (&readfds
, sizeof(readfds
));
594 hreadfdsp
= &readfds
;
599 twritefdsp
= (fd_set
*) arg3
;
600 if (twritefdsp
!= NULL
)
602 writefds
= *((fd_set
*) t2h_addr (cb
, &s
, (unsigned int) twritefdsp
));
603 translate_endian_t2h (&writefds
, sizeof(writefds
));
604 hwritefdsp
= &writefds
;
609 texceptfdsp
= (fd_set
*) arg4
;
610 if (texceptfdsp
!= NULL
)
612 exceptfds
= *((fd_set
*) t2h_addr (cb
, &s
, (unsigned int) texceptfdsp
));
613 translate_endian_t2h (&exceptfds
, sizeof(exceptfds
));
614 hexceptfdsp
= &exceptfds
;
619 ttimeoutp
= (struct timeval
*) arg5
;
620 timeout
= *((struct timeval
*) t2h_addr (cb
, &s
, (unsigned int) ttimeoutp
));
621 translate_endian_t2h (&timeout
, sizeof(timeout
));
623 result
= select (n
, hreadfdsp
, hwritefdsp
, hexceptfdsp
, &timeout
);
629 if (treadfdsp
!= NULL
)
631 translate_endian_h2t (&readfds
, sizeof(readfds
));
632 if ((s
.write_mem
) (cb
, &s
, (unsigned long) treadfdsp
,
633 (char *) &readfds
, sizeof(readfds
)) != sizeof(readfds
))
640 if (twritefdsp
!= NULL
)
642 translate_endian_h2t (&writefds
, sizeof(writefds
));
643 if ((s
.write_mem
) (cb
, &s
, (unsigned long) twritefdsp
,
644 (char *) &writefds
, sizeof(writefds
)) != sizeof(writefds
))
651 if (texceptfdsp
!= NULL
)
653 translate_endian_h2t (&exceptfds
, sizeof(exceptfds
));
654 if ((s
.write_mem
) (cb
, &s
, (unsigned long) texceptfdsp
,
655 (char *) &exceptfds
, sizeof(exceptfds
)) != sizeof(exceptfds
))
662 translate_endian_h2t (&timeout
, sizeof(timeout
));
663 if ((s
.write_mem
) (cb
, &s
, (unsigned long) ttimeoutp
,
664 (char *) &timeout
, sizeof(timeout
)) != sizeof(timeout
))
672 case TARGET_LINUX_SYS_symlink
:
673 result
= symlink ((char *) t2h_addr (cb
, &s
, arg1
),
674 (char *) t2h_addr (cb
, &s
, arg2
));
678 case TARGET_LINUX_SYS_readlink
:
679 result
= readlink ((char *) t2h_addr (cb
, &s
, arg1
),
680 (char *) t2h_addr (cb
, &s
, arg2
),
685 case TARGET_LINUX_SYS_readdir
:
686 result
= (int) readdir ((DIR *) t2h_addr (cb
, &s
, arg1
));
691 case TARGET_LINUX_SYS_mmap
:
693 result
= (int) mmap ((void *) t2h_addr (cb
, &s
, arg1
),
694 arg2
, arg3
, arg4
, arg5
, arg6
);
699 sim_core_attach (sd
, NULL
,
700 0, access_read_write_exec
, 0,
701 result
, arg2
, 0, NULL
, NULL
);
706 case TARGET_LINUX_SYS_mmap2
:
710 int prot
, flags
, fildes
;
713 addr
= (void *) t2h_addr (cb
, &s
, arg1
);
720 result
= (int) mmap (addr
, len
, prot
, flags
, fildes
, off
);
725 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
726 sim_core_attach (sd
, NULL
,
727 0, access_read_write_exec
, 0,
728 result
, len
, 0, NULL
, NULL
);
733 case TARGET_LINUX_SYS_mmap
:
737 int prot
, flags
, fildes
;
740 addr
= *((void **) t2h_addr (cb
, &s
, arg1
));
741 len
= *((size_t *) t2h_addr (cb
, &s
, arg1
+ 4));
742 prot
= *((int *) t2h_addr (cb
, &s
, arg1
+ 8));
743 flags
= *((int *) t2h_addr (cb
, &s
, arg1
+ 12));
744 fildes
= *((int *) t2h_addr (cb
, &s
, arg1
+ 16));
745 off
= *((off_t
*) t2h_addr (cb
, &s
, arg1
+ 20));
747 addr
= (void *) T2H_4 ((unsigned int) addr
);
750 flags
= T2H_4 (flags
);
751 fildes
= T2H_4 (fildes
);
754 //addr = (void *) t2h_addr (cb, &s, (unsigned int) addr);
755 result
= (int) mmap (addr
, len
, prot
, flags
, fildes
, off
);
762 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
763 sim_core_attach (sd
, NULL
,
764 0, access_read_write_exec
, 0,
765 result
, len
, 0, NULL
, NULL
);
770 case TARGET_LINUX_SYS_munmap
:
771 result
= munmap ((void *)arg1
, arg2
);
774 sim_core_detach (sd
, NULL
, 0, arg2
, result
);
777 case TARGET_LINUX_SYS_truncate
:
778 result
= truncate ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
782 case TARGET_LINUX_SYS_ftruncate
:
783 result
= ftruncate (arg1
, arg2
);
787 case TARGET_LINUX_SYS_fchmod
:
788 result
= fchmod (arg1
, arg2
);
792 case TARGET_LINUX_SYS_fchown32
:
793 case TARGET_LINUX_SYS_fchown
:
794 result
= fchown (arg1
, arg2
, arg3
);
798 case TARGET_LINUX_SYS_statfs
:
800 struct statfs statbuf
;
802 result
= statfs ((char *) t2h_addr (cb
, &s
, arg1
), &statbuf
);
808 translate_endian_h2t (&statbuf
, sizeof(statbuf
));
809 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
818 case TARGET_LINUX_SYS_fstatfs
:
820 struct statfs statbuf
;
822 result
= fstatfs (arg1
, &statbuf
);
828 translate_endian_h2t (&statbuf
, sizeof(statbuf
));
829 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
838 case TARGET_LINUX_SYS_syslog
:
839 result
= syslog (arg1
, (char *) t2h_addr (cb
, &s
, arg2
));
843 case TARGET_LINUX_SYS_setitimer
:
845 struct itimerval value
, ovalue
;
847 value
= *((struct itimerval
*) t2h_addr (cb
, &s
, arg2
));
848 translate_endian_t2h (&value
, sizeof(value
));
852 result
= setitimer (arg1
, &value
, NULL
);
857 result
= setitimer (arg1
, &value
, &ovalue
);
863 translate_endian_h2t (&ovalue
, sizeof(ovalue
));
864 if ((s
.write_mem
) (cb
, &s
, arg3
, (char *) &ovalue
, sizeof(ovalue
))
874 case TARGET_LINUX_SYS_getitimer
:
876 struct itimerval value
;
878 result
= getitimer (arg1
, &value
);
884 translate_endian_h2t (&value
, sizeof(value
));
885 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &value
, sizeof(value
))
894 case TARGET_LINUX_SYS_stat
:
900 result
= stat ((char *) t2h_addr (cb
, &s
, arg1
), &statbuf
);
905 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
906 buf
= xmalloc (buflen
);
907 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
909 /* The translation failed. This is due to an internal
910 host program error, not the target's fault. */
916 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
927 case TARGET_LINUX_SYS_lstat
:
933 result
= lstat ((char *) t2h_addr (cb
, &s
, arg1
), &statbuf
);
938 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
939 buf
= xmalloc (buflen
);
940 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
942 /* The translation failed. This is due to an internal
943 host program error, not the target's fault. */
949 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
960 case TARGET_LINUX_SYS_fstat
:
966 result
= fstat (arg1
, &statbuf
);
971 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
972 buf
= xmalloc (buflen
);
973 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
975 /* The translation failed. This is due to an internal
976 host program error, not the target's fault. */
982 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
993 case TARGET_LINUX_SYS_sysinfo
:
997 result
= sysinfo (&info
);
1003 info
.uptime
= H2T_4 (info
.uptime
);
1004 info
.loads
[0] = H2T_4 (info
.loads
[0]);
1005 info
.loads
[1] = H2T_4 (info
.loads
[1]);
1006 info
.loads
[2] = H2T_4 (info
.loads
[2]);
1007 info
.totalram
= H2T_4 (info
.totalram
);
1008 info
.freeram
= H2T_4 (info
.freeram
);
1009 info
.sharedram
= H2T_4 (info
.sharedram
);
1010 info
.bufferram
= H2T_4 (info
.bufferram
);
1011 info
.totalswap
= H2T_4 (info
.totalswap
);
1012 info
.freeswap
= H2T_4 (info
.freeswap
);
1013 info
.procs
= H2T_2 (info
.procs
);
1014 #if LINUX_VERSION_CODE >= 0x20400
1015 info
.totalhigh
= H2T_4 (info
.totalhigh
);
1016 info
.freehigh
= H2T_4 (info
.freehigh
);
1017 info
.mem_unit
= H2T_4 (info
.mem_unit
);
1019 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &info
, sizeof(info
))
1029 case TARGET_LINUX_SYS_ipc
:
1031 result
= ipc (arg1
, arg2
, arg3
, arg4
,
1032 (void *) t2h_addr (cb
, &s
, arg5
), arg6
);
1038 case TARGET_LINUX_SYS_fsync
:
1039 result
= fsync (arg1
);
1043 case TARGET_LINUX_SYS_uname
:
1044 /* utsname contains only arrays of char, so it is not necessary
1045 to translate endian. */
1046 result
= uname ((struct utsname
*) t2h_addr (cb
, &s
, arg1
));
1050 case TARGET_LINUX_SYS_adjtimex
:
1054 result
= adjtimex (&buf
);
1060 translate_endian_h2t (&buf
, sizeof(buf
));
1061 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &buf
, sizeof(buf
))
1070 case TARGET_LINUX_SYS_mprotect
:
1071 result
= mprotect ((void *) arg1
, arg2
, arg3
);
1075 case TARGET_LINUX_SYS_fchdir
:
1076 result
= fchdir (arg1
);
1080 case TARGET_LINUX_SYS_setfsuid32
:
1081 case TARGET_LINUX_SYS_setfsuid
:
1082 result
= setfsuid (arg1
);
1086 case TARGET_LINUX_SYS_setfsgid32
:
1087 case TARGET_LINUX_SYS_setfsgid
:
1088 result
= setfsgid (arg1
);
1093 case TARGET_LINUX_SYS__llseek
:
1097 result
= _llseek (arg1
, arg2
, arg3
, &buf
, arg5
);
1103 translate_endian_h2t (&buf
, sizeof(buf
));
1104 if ((s
.write_mem
) (cb
, &s
, t2h_addr (cb
, &s
, arg4
),
1105 (char *) &buf
, sizeof(buf
)) != sizeof(buf
))
1113 case TARGET_LINUX_SYS_getdents
:
1117 result
= getdents (arg1
, &dir
, arg3
);
1123 dir
.d_ino
= H2T_4 (dir
.d_ino
);
1124 dir
.d_off
= H2T_4 (dir
.d_off
);
1125 dir
.d_reclen
= H2T_2 (dir
.d_reclen
);
1126 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &dir
, sizeof(dir
))
1136 case TARGET_LINUX_SYS_flock
:
1137 result
= flock (arg1
, arg2
);
1141 case TARGET_LINUX_SYS_msync
:
1142 result
= msync ((void *) arg1
, arg2
, arg3
);
1146 case TARGET_LINUX_SYS_readv
:
1148 struct iovec vector
;
1150 vector
= *((struct iovec
*) t2h_addr (cb
, &s
, arg2
));
1151 translate_endian_t2h (&vector
, sizeof(vector
));
1153 result
= readv (arg1
, &vector
, arg3
);
1158 case TARGET_LINUX_SYS_writev
:
1160 struct iovec vector
;
1162 vector
= *((struct iovec
*) t2h_addr (cb
, &s
, arg2
));
1163 translate_endian_t2h (&vector
, sizeof(vector
));
1165 result
= writev (arg1
, &vector
, arg3
);
1170 case TARGET_LINUX_SYS_fdatasync
:
1171 result
= fdatasync (arg1
);
1175 case TARGET_LINUX_SYS_mlock
:
1176 result
= mlock ((void *) t2h_addr (cb
, &s
, arg1
), arg2
);
1180 case TARGET_LINUX_SYS_munlock
:
1181 result
= munlock ((void *) t2h_addr (cb
, &s
, arg1
), arg2
);
1185 case TARGET_LINUX_SYS_nanosleep
:
1187 struct timespec req
, rem
;
1189 req
= *((struct timespec
*) t2h_addr (cb
, &s
, arg2
));
1190 translate_endian_t2h (&req
, sizeof(req
));
1192 result
= nanosleep (&req
, &rem
);
1198 translate_endian_h2t (&rem
, sizeof(rem
));
1199 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rem
, sizeof(rem
))
1208 case TARGET_LINUX_SYS_mremap
: /* FIXME */
1209 result
= (int) mremap ((void *) t2h_addr (cb
, &s
, arg1
), arg2
, arg3
, arg4
);
1213 case TARGET_LINUX_SYS_getresuid32
:
1214 case TARGET_LINUX_SYS_getresuid
:
1216 uid_t ruid
, euid
, suid
;
1218 result
= getresuid (&ruid
, &euid
, &suid
);
1224 *((uid_t
*) t2h_addr (cb
, &s
, arg1
)) = H2T_4 (ruid
);
1225 *((uid_t
*) t2h_addr (cb
, &s
, arg2
)) = H2T_4 (euid
);
1226 *((uid_t
*) t2h_addr (cb
, &s
, arg3
)) = H2T_4 (suid
);
1230 case TARGET_LINUX_SYS_poll
:
1234 ufds
= *((struct pollfd
*) t2h_addr (cb
, &s
, arg1
));
1235 ufds
.fd
= T2H_4 (ufds
.fd
);
1236 ufds
.events
= T2H_2 (ufds
.events
);
1237 ufds
.revents
= T2H_2 (ufds
.revents
);
1239 result
= poll (&ufds
, arg2
, arg3
);
1244 case TARGET_LINUX_SYS_getresgid32
:
1245 case TARGET_LINUX_SYS_getresgid
:
1247 uid_t rgid
, egid
, sgid
;
1249 result
= getresgid (&rgid
, &egid
, &sgid
);
1255 *((uid_t
*) t2h_addr (cb
, &s
, arg1
)) = H2T_4 (rgid
);
1256 *((uid_t
*) t2h_addr (cb
, &s
, arg2
)) = H2T_4 (egid
);
1257 *((uid_t
*) t2h_addr (cb
, &s
, arg3
)) = H2T_4 (sgid
);
1261 case TARGET_LINUX_SYS_pread
:
1262 result
= pread (arg1
, (void *) t2h_addr (cb
, &s
, arg2
), arg3
, arg4
);
1266 case TARGET_LINUX_SYS_pwrite
:
1267 result
= pwrite (arg1
, (void *) t2h_addr (cb
, &s
, arg2
), arg3
, arg4
);
1271 case TARGET_LINUX_SYS_chown32
:
1272 case TARGET_LINUX_SYS_chown
:
1273 result
= chown ((char *) t2h_addr (cb
, &s
, arg1
), arg2
, arg3
);
1277 case TARGET_LINUX_SYS_getcwd
:
1278 result
= (int) getcwd ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
1282 case TARGET_LINUX_SYS_sendfile
:
1286 offset
= *((off_t
*) t2h_addr (cb
, &s
, arg3
));
1287 offset
= T2H_4 (offset
);
1289 result
= sendfile (arg1
, arg2
, &offset
, arg3
);
1295 *((off_t
*) t2h_addr (cb
, &s
, arg3
)) = H2T_4 (offset
);
1306 m32rbf_h_gr_set (current_cpu
, 0, -errcode
);
1308 m32rbf_h_gr_set (current_cpu
, 0, result
);
1313 case TRAP_BREAKPOINT
:
1314 sim_engine_halt (sd
, current_cpu
, NULL
, pc
,
1315 sim_stopped
, SIM_SIGTRAP
);
1318 case TRAP_FLUSH_CACHE
:
1325 /* The new pc is the trap vector entry.
1326 We assume there's a branch there to some handler.
1327 Use cr5 as EVB (EIT Vector Base) register. */
1328 /* USI new_pc = EIT_TRAP_BASE_ADDR + num * 4; */
1329 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
1334 /* Fake an "rte" insn. */
1335 /* FIXME: Should duplicate all of rte processing. */
1336 return (pc
& -4) + 4;