1 /* m32r exception, interrupt, and trap (EIT) support
2 Copyright (C) 1998-2023 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>
60 #define TRAP_LINUX_SYSCALL 2
61 #define TRAP_FLUSH_CACHE 12
62 /* The semantic code invokes this for invalid (unrecognized) instructions. */
65 sim_engine_invalid_insn (SIM_CPU
*current_cpu
, IADDR cia
, SEM_PC pc
)
67 SIM_DESC sd
= CPU_STATE (current_cpu
);
70 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
72 h_bsm_set (current_cpu
, h_sm_get (current_cpu
));
73 h_bie_set (current_cpu
, h_ie_get (current_cpu
));
74 h_bcond_set (current_cpu
, h_cond_get (current_cpu
));
76 h_ie_set (current_cpu
, 0);
77 h_cond_set (current_cpu
, 0);
79 h_bpc_set (current_cpu
, cia
);
81 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
86 sim_engine_halt (sd
, current_cpu
, NULL
, cia
, sim_stopped
, SIM_SIGILL
);
91 /* Process an address exception. */
94 m32r_core_signal (SIM_DESC sd
, SIM_CPU
*current_cpu
, sim_cia cia
,
95 unsigned int map
, int nr_bytes
, address_word addr
,
96 transfer_type transfer
, sim_core_signals sig
)
98 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
100 m32rbf_h_cr_set (current_cpu
, H_CR_BBPC
,
101 m32rbf_h_cr_get (current_cpu
, H_CR_BPC
));
102 switch (MACH_NUM (CPU_MACH (current_cpu
)))
105 m32rbf_h_bpsw_set (current_cpu
, m32rbf_h_psw_get (current_cpu
));
106 /* sm not changed. */
107 m32rbf_h_psw_set (current_cpu
, m32rbf_h_psw_get (current_cpu
) & 0x80);
110 m32rxf_h_bpsw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
));
111 /* sm not changed. */
112 m32rxf_h_psw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
) & 0x80);
115 m32r2f_h_bpsw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
));
116 /* sm not changed. */
117 m32r2f_h_psw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
) & 0x80);
123 m32rbf_h_cr_set (current_cpu
, H_CR_BPC
, cia
);
125 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
129 sim_core_signal (sd
, current_cpu
, cia
, map
, nr_bytes
, addr
,
133 /* Translate target's address to host's address. */
136 t2h_addr (host_callback
*cb
, struct cb_syscall
*sc
,
140 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
141 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
146 return sim_core_trans_addr (sd
, cpu
, read_map
, taddr
);
149 /* TODO: These functions are a big hack and assume that the host runtime has
150 type sizes and struct layouts that match the target. So the Linux emulation
151 probaly only really works in 32-bit runtimes. */
154 translate_endian_h2t (void *addr
, size_t size
)
156 unsigned int *p
= (unsigned int *) addr
;
159 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
163 *((unsigned short *) p
) = H2T_2 (*((unsigned short *) p
));
167 translate_endian_t2h (void *addr
, size_t size
)
169 unsigned int *p
= (unsigned int *) addr
;
172 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
176 *((unsigned short *) p
) = T2H_2 (*((unsigned short *) p
));
180 The result is the pc address to continue at.
181 Preprocessing like saving the various registers has already been done. */
184 m32r_trap (SIM_CPU
*current_cpu
, PCADDR pc
, int num
)
186 SIM_DESC sd
= CPU_STATE (current_cpu
);
187 host_callback
*cb
= STATE_CALLBACK (sd
);
189 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
196 long result
, result2
;
199 sim_syscall_multi (current_cpu
,
200 m32rbf_h_gr_get (current_cpu
, 0),
201 m32rbf_h_gr_get (current_cpu
, 1),
202 m32rbf_h_gr_get (current_cpu
, 2),
203 m32rbf_h_gr_get (current_cpu
, 3),
204 m32rbf_h_gr_get (current_cpu
, 4),
205 &result
, &result2
, &errcode
);
207 m32rbf_h_gr_set (current_cpu
, 2, errcode
);
208 m32rbf_h_gr_set (current_cpu
, 0, result
);
209 m32rbf_h_gr_set (current_cpu
, 1, result2
);
214 case TRAP_LINUX_SYSCALL
:
217 unsigned int func
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
;
218 int result
, result2
, errcode
;
220 if (STATE_ENVIRONMENT (sd
) != USER_ENVIRONMENT
)
223 func
= m32rbf_h_gr_get (current_cpu
, 7);
224 arg1
= m32rbf_h_gr_get (current_cpu
, 0);
225 arg2
= m32rbf_h_gr_get (current_cpu
, 1);
226 arg3
= m32rbf_h_gr_get (current_cpu
, 2);
227 arg4
= m32rbf_h_gr_get (current_cpu
, 3);
228 arg5
= m32rbf_h_gr_get (current_cpu
, 4);
229 arg6
= m32rbf_h_gr_get (current_cpu
, 5);
230 arg7
= m32rbf_h_gr_get (current_cpu
, 6);
232 CB_SYSCALL_INIT (&s
);
244 s
.read_mem
= sim_syscall_read_mem
;
245 s
.write_mem
= sim_syscall_write_mem
;
253 case TARGET_LINUX_SYS_exit
:
254 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, arg1
);
257 case TARGET_LINUX_SYS_read
:
258 result
= read (arg1
, t2h_addr (cb
, &s
, arg2
), arg3
);
262 case TARGET_LINUX_SYS_write
:
263 result
= write (arg1
, t2h_addr (cb
, &s
, arg2
), arg3
);
267 case TARGET_LINUX_SYS_open
:
268 result
= open ((char *) t2h_addr (cb
, &s
, arg1
), arg2
, arg3
);
272 case TARGET_LINUX_SYS_close
:
273 result
= close (arg1
);
277 case TARGET_LINUX_SYS_creat
:
278 result
= creat ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
282 case TARGET_LINUX_SYS_link
:
283 result
= link ((char *) t2h_addr (cb
, &s
, arg1
),
284 (char *) t2h_addr (cb
, &s
, arg2
));
288 case TARGET_LINUX_SYS_unlink
:
289 result
= unlink ((char *) t2h_addr (cb
, &s
, arg1
));
293 case TARGET_LINUX_SYS_chdir
:
294 result
= chdir ((char *) t2h_addr (cb
, &s
, arg1
));
298 case TARGET_LINUX_SYS_time
:
304 result
= (int) time (NULL
);
309 result
= (int) time (&t
);
316 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
)) != sizeof(t
))
325 case TARGET_LINUX_SYS_mknod
:
326 result
= mknod ((char *) t2h_addr (cb
, &s
, arg1
),
327 (mode_t
) arg2
, (dev_t
) arg3
);
331 case TARGET_LINUX_SYS_chmod
:
332 result
= chmod ((char *) t2h_addr (cb
, &s
, arg1
), (mode_t
) arg2
);
336 case TARGET_LINUX_SYS_lchown32
:
337 case TARGET_LINUX_SYS_lchown
:
338 result
= lchown ((char *) t2h_addr (cb
, &s
, arg1
),
339 (uid_t
) arg2
, (gid_t
) arg3
);
343 case TARGET_LINUX_SYS_lseek
:
344 result
= (int) lseek (arg1
, (off_t
) arg2
, arg3
);
348 case TARGET_LINUX_SYS_getpid
:
353 case TARGET_LINUX_SYS_getuid32
:
354 case TARGET_LINUX_SYS_getuid
:
359 case TARGET_LINUX_SYS_utime
:
365 result
= utime ((char *) t2h_addr (cb
, &s
, arg1
), NULL
);
370 buf
= *((struct utimbuf
*) t2h_addr (cb
, &s
, arg2
));
371 translate_endian_t2h (&buf
, sizeof(buf
));
372 result
= utime ((char *) t2h_addr (cb
, &s
, arg1
), &buf
);
378 case TARGET_LINUX_SYS_access
:
379 result
= access ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
383 case TARGET_LINUX_SYS_ftime
:
393 t
.time
= H2T_4 (t
.time
);
394 t
.millitm
= H2T_2 (t
.millitm
);
395 t
.timezone
= H2T_2 (t
.timezone
);
396 t
.dstflag
= H2T_2 (t
.dstflag
);
397 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
))
405 case TARGET_LINUX_SYS_sync
:
410 case TARGET_LINUX_SYS_rename
:
411 result
= rename ((char *) t2h_addr (cb
, &s
, arg1
),
412 (char *) t2h_addr (cb
, &s
, arg2
));
416 case TARGET_LINUX_SYS_mkdir
:
417 result
= mkdir ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
421 case TARGET_LINUX_SYS_rmdir
:
422 result
= rmdir ((char *) t2h_addr (cb
, &s
, arg1
));
426 case TARGET_LINUX_SYS_dup
:
431 case TARGET_LINUX_SYS_brk
:
432 result
= brk ((void *) arg1
);
437 case TARGET_LINUX_SYS_getgid32
:
438 case TARGET_LINUX_SYS_getgid
:
443 case TARGET_LINUX_SYS_geteuid32
:
444 case TARGET_LINUX_SYS_geteuid
:
449 case TARGET_LINUX_SYS_getegid32
:
450 case TARGET_LINUX_SYS_getegid
:
455 case TARGET_LINUX_SYS_ioctl
:
456 result
= ioctl (arg1
, arg2
, arg3
);
460 case TARGET_LINUX_SYS_fcntl
:
461 result
= fcntl (arg1
, arg2
, arg3
);
465 case TARGET_LINUX_SYS_dup2
:
466 result
= dup2 (arg1
, arg2
);
470 case TARGET_LINUX_SYS_getppid
:
475 case TARGET_LINUX_SYS_getpgrp
:
480 case TARGET_LINUX_SYS_getrlimit
:
484 result
= getrlimit (arg1
, &rlim
);
490 translate_endian_h2t (&rlim
, sizeof(rlim
));
491 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rlim
, sizeof(rlim
))
500 case TARGET_LINUX_SYS_getrusage
:
504 result
= getrusage (arg1
, &usage
);
510 translate_endian_h2t (&usage
, sizeof(usage
));
511 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &usage
, sizeof(usage
))
520 case TARGET_LINUX_SYS_gettimeofday
:
525 result
= gettimeofday (&tv
, &tz
);
531 translate_endian_h2t (&tv
, sizeof(tv
));
532 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &tv
, sizeof(tv
))
539 translate_endian_h2t (&tz
, sizeof(tz
));
540 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &tz
, sizeof(tz
))
549 case TARGET_LINUX_SYS_getgroups32
:
550 case TARGET_LINUX_SYS_getgroups
:
555 list
= (gid_t
*) malloc (arg1
* sizeof(gid_t
));
557 result
= getgroups (arg1
, list
);
563 translate_endian_h2t (list
, arg1
* sizeof(gid_t
));
565 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) list
, arg1
* sizeof(gid_t
))
566 != arg1
* sizeof(gid_t
))
574 case TARGET_LINUX_SYS_select
:
586 struct timeval
*ttimeoutp
;
587 struct timeval timeout
;
591 treadfdsp
= (fd_set
*) arg2
;
592 if (treadfdsp
!= NULL
)
594 readfds
= *((fd_set
*) t2h_addr (cb
, &s
, (unsigned int) treadfdsp
));
595 translate_endian_t2h (&readfds
, sizeof(readfds
));
596 hreadfdsp
= &readfds
;
601 twritefdsp
= (fd_set
*) arg3
;
602 if (twritefdsp
!= NULL
)
604 writefds
= *((fd_set
*) t2h_addr (cb
, &s
, (unsigned int) twritefdsp
));
605 translate_endian_t2h (&writefds
, sizeof(writefds
));
606 hwritefdsp
= &writefds
;
611 texceptfdsp
= (fd_set
*) arg4
;
612 if (texceptfdsp
!= NULL
)
614 exceptfds
= *((fd_set
*) t2h_addr (cb
, &s
, (unsigned int) texceptfdsp
));
615 translate_endian_t2h (&exceptfds
, sizeof(exceptfds
));
616 hexceptfdsp
= &exceptfds
;
621 ttimeoutp
= (struct timeval
*) arg5
;
622 timeout
= *((struct timeval
*) t2h_addr (cb
, &s
, (unsigned int) ttimeoutp
));
623 translate_endian_t2h (&timeout
, sizeof(timeout
));
625 result
= select (n
, hreadfdsp
, hwritefdsp
, hexceptfdsp
, &timeout
);
631 if (treadfdsp
!= NULL
)
633 translate_endian_h2t (&readfds
, sizeof(readfds
));
634 if ((s
.write_mem
) (cb
, &s
, (unsigned long) treadfdsp
,
635 (char *) &readfds
, sizeof(readfds
)) != sizeof(readfds
))
642 if (twritefdsp
!= NULL
)
644 translate_endian_h2t (&writefds
, sizeof(writefds
));
645 if ((s
.write_mem
) (cb
, &s
, (unsigned long) twritefdsp
,
646 (char *) &writefds
, sizeof(writefds
)) != sizeof(writefds
))
653 if (texceptfdsp
!= NULL
)
655 translate_endian_h2t (&exceptfds
, sizeof(exceptfds
));
656 if ((s
.write_mem
) (cb
, &s
, (unsigned long) texceptfdsp
,
657 (char *) &exceptfds
, sizeof(exceptfds
)) != sizeof(exceptfds
))
664 translate_endian_h2t (&timeout
, sizeof(timeout
));
665 if ((s
.write_mem
) (cb
, &s
, (unsigned long) ttimeoutp
,
666 (char *) &timeout
, sizeof(timeout
)) != sizeof(timeout
))
674 case TARGET_LINUX_SYS_symlink
:
675 result
= symlink ((char *) t2h_addr (cb
, &s
, arg1
),
676 (char *) t2h_addr (cb
, &s
, arg2
));
680 case TARGET_LINUX_SYS_readlink
:
681 result
= readlink ((char *) t2h_addr (cb
, &s
, arg1
),
682 (char *) t2h_addr (cb
, &s
, arg2
),
687 case TARGET_LINUX_SYS_readdir
:
688 result
= (int) readdir ((DIR *) t2h_addr (cb
, &s
, arg1
));
693 case TARGET_LINUX_SYS_mmap
:
695 result
= (int) mmap ((void *) t2h_addr (cb
, &s
, arg1
),
696 arg2
, arg3
, arg4
, arg5
, arg6
);
701 sim_core_attach (sd
, NULL
,
702 0, access_read_write_exec
, 0,
703 result
, arg2
, 0, NULL
, NULL
);
708 case TARGET_LINUX_SYS_mmap2
:
712 int prot
, flags
, fildes
;
715 addr
= (void *) t2h_addr (cb
, &s
, arg1
);
722 result
= (int) mmap (addr
, len
, prot
, flags
, fildes
, off
);
727 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
728 sim_core_attach (sd
, NULL
,
729 0, access_read_write_exec
, 0,
730 result
, len
, 0, NULL
, NULL
);
735 case TARGET_LINUX_SYS_mmap
:
739 int prot
, flags
, fildes
;
742 addr
= *((void **) t2h_addr (cb
, &s
, arg1
));
743 len
= *((size_t *) t2h_addr (cb
, &s
, arg1
+ 4));
744 prot
= *((int *) t2h_addr (cb
, &s
, arg1
+ 8));
745 flags
= *((int *) t2h_addr (cb
, &s
, arg1
+ 12));
746 fildes
= *((int *) t2h_addr (cb
, &s
, arg1
+ 16));
747 off
= *((off_t
*) t2h_addr (cb
, &s
, arg1
+ 20));
749 addr
= (void *) T2H_4 ((unsigned int) addr
);
752 flags
= T2H_4 (flags
);
753 fildes
= T2H_4 (fildes
);
756 //addr = (void *) t2h_addr (cb, &s, (unsigned int) addr);
757 result
= (int) mmap (addr
, len
, prot
, flags
, fildes
, off
);
764 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
765 sim_core_attach (sd
, NULL
,
766 0, access_read_write_exec
, 0,
767 result
, len
, 0, NULL
, NULL
);
772 case TARGET_LINUX_SYS_munmap
:
773 result
= munmap ((void *)arg1
, arg2
);
776 sim_core_detach (sd
, NULL
, 0, arg2
, result
);
779 case TARGET_LINUX_SYS_truncate
:
780 result
= truncate ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
784 case TARGET_LINUX_SYS_ftruncate
:
785 result
= ftruncate (arg1
, arg2
);
789 case TARGET_LINUX_SYS_fchmod
:
790 result
= fchmod (arg1
, arg2
);
794 case TARGET_LINUX_SYS_fchown32
:
795 case TARGET_LINUX_SYS_fchown
:
796 result
= fchown (arg1
, arg2
, arg3
);
800 case TARGET_LINUX_SYS_statfs
:
802 struct statfs statbuf
;
804 result
= statfs ((char *) t2h_addr (cb
, &s
, arg1
), &statbuf
);
810 translate_endian_h2t (&statbuf
, sizeof(statbuf
));
811 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
820 case TARGET_LINUX_SYS_fstatfs
:
822 struct statfs statbuf
;
824 result
= fstatfs (arg1
, &statbuf
);
830 translate_endian_h2t (&statbuf
, sizeof(statbuf
));
831 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
840 case TARGET_LINUX_SYS_syslog
:
841 result
= syslog (arg1
, (char *) t2h_addr (cb
, &s
, arg2
));
845 case TARGET_LINUX_SYS_setitimer
:
847 struct itimerval value
, ovalue
;
849 value
= *((struct itimerval
*) t2h_addr (cb
, &s
, arg2
));
850 translate_endian_t2h (&value
, sizeof(value
));
854 result
= setitimer (arg1
, &value
, NULL
);
859 result
= setitimer (arg1
, &value
, &ovalue
);
865 translate_endian_h2t (&ovalue
, sizeof(ovalue
));
866 if ((s
.write_mem
) (cb
, &s
, arg3
, (char *) &ovalue
, sizeof(ovalue
))
876 case TARGET_LINUX_SYS_getitimer
:
878 struct itimerval value
;
880 result
= getitimer (arg1
, &value
);
886 translate_endian_h2t (&value
, sizeof(value
));
887 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &value
, sizeof(value
))
896 case TARGET_LINUX_SYS_stat
:
902 result
= stat ((char *) t2h_addr (cb
, &s
, arg1
), &statbuf
);
907 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
908 buf
= xmalloc (buflen
);
909 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
911 /* The translation failed. This is due to an internal
912 host program error, not the target's fault. */
918 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
929 case TARGET_LINUX_SYS_lstat
:
935 result
= lstat ((char *) t2h_addr (cb
, &s
, arg1
), &statbuf
);
940 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
941 buf
= xmalloc (buflen
);
942 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
944 /* The translation failed. This is due to an internal
945 host program error, not the target's fault. */
951 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
962 case TARGET_LINUX_SYS_fstat
:
968 result
= fstat (arg1
, &statbuf
);
973 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
974 buf
= xmalloc (buflen
);
975 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
977 /* The translation failed. This is due to an internal
978 host program error, not the target's fault. */
984 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
995 case TARGET_LINUX_SYS_sysinfo
:
999 result
= sysinfo (&info
);
1005 info
.uptime
= H2T_4 (info
.uptime
);
1006 info
.loads
[0] = H2T_4 (info
.loads
[0]);
1007 info
.loads
[1] = H2T_4 (info
.loads
[1]);
1008 info
.loads
[2] = H2T_4 (info
.loads
[2]);
1009 info
.totalram
= H2T_4 (info
.totalram
);
1010 info
.freeram
= H2T_4 (info
.freeram
);
1011 info
.sharedram
= H2T_4 (info
.sharedram
);
1012 info
.bufferram
= H2T_4 (info
.bufferram
);
1013 info
.totalswap
= H2T_4 (info
.totalswap
);
1014 info
.freeswap
= H2T_4 (info
.freeswap
);
1015 info
.procs
= H2T_2 (info
.procs
);
1016 #if LINUX_VERSION_CODE >= 0x20400
1017 info
.totalhigh
= H2T_4 (info
.totalhigh
);
1018 info
.freehigh
= H2T_4 (info
.freehigh
);
1019 info
.mem_unit
= H2T_4 (info
.mem_unit
);
1021 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &info
, sizeof(info
))
1031 case TARGET_LINUX_SYS_ipc
:
1033 result
= ipc (arg1
, arg2
, arg3
, arg4
,
1034 (void *) t2h_addr (cb
, &s
, arg5
), arg6
);
1040 case TARGET_LINUX_SYS_fsync
:
1041 result
= fsync (arg1
);
1045 case TARGET_LINUX_SYS_uname
:
1046 /* utsname contains only arrays of char, so it is not necessary
1047 to translate endian. */
1048 result
= uname ((struct utsname
*) t2h_addr (cb
, &s
, arg1
));
1052 case TARGET_LINUX_SYS_adjtimex
:
1056 result
= adjtimex (&buf
);
1062 translate_endian_h2t (&buf
, sizeof(buf
));
1063 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &buf
, sizeof(buf
))
1072 case TARGET_LINUX_SYS_mprotect
:
1073 result
= mprotect ((void *) arg1
, arg2
, arg3
);
1077 case TARGET_LINUX_SYS_fchdir
:
1078 result
= fchdir (arg1
);
1082 case TARGET_LINUX_SYS_setfsuid32
:
1083 case TARGET_LINUX_SYS_setfsuid
:
1084 result
= setfsuid (arg1
);
1088 case TARGET_LINUX_SYS_setfsgid32
:
1089 case TARGET_LINUX_SYS_setfsgid
:
1090 result
= setfsgid (arg1
);
1095 case TARGET_LINUX_SYS__llseek
:
1099 result
= _llseek (arg1
, arg2
, arg3
, &buf
, arg5
);
1105 translate_endian_h2t (&buf
, sizeof(buf
));
1106 if ((s
.write_mem
) (cb
, &s
, t2h_addr (cb
, &s
, arg4
),
1107 (char *) &buf
, sizeof(buf
)) != sizeof(buf
))
1115 case TARGET_LINUX_SYS_getdents
:
1119 result
= getdents (arg1
, &dir
, arg3
);
1125 dir
.d_ino
= H2T_4 (dir
.d_ino
);
1126 dir
.d_off
= H2T_4 (dir
.d_off
);
1127 dir
.d_reclen
= H2T_2 (dir
.d_reclen
);
1128 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &dir
, sizeof(dir
))
1138 case TARGET_LINUX_SYS_flock
:
1139 result
= flock (arg1
, arg2
);
1143 case TARGET_LINUX_SYS_msync
:
1144 result
= msync ((void *) arg1
, arg2
, arg3
);
1148 case TARGET_LINUX_SYS_readv
:
1150 struct iovec vector
;
1152 vector
= *((struct iovec
*) t2h_addr (cb
, &s
, arg2
));
1153 translate_endian_t2h (&vector
, sizeof(vector
));
1155 result
= readv (arg1
, &vector
, arg3
);
1160 case TARGET_LINUX_SYS_writev
:
1162 struct iovec vector
;
1164 vector
= *((struct iovec
*) t2h_addr (cb
, &s
, arg2
));
1165 translate_endian_t2h (&vector
, sizeof(vector
));
1167 result
= writev (arg1
, &vector
, arg3
);
1172 case TARGET_LINUX_SYS_fdatasync
:
1173 result
= fdatasync (arg1
);
1177 case TARGET_LINUX_SYS_mlock
:
1178 result
= mlock ((void *) t2h_addr (cb
, &s
, arg1
), arg2
);
1182 case TARGET_LINUX_SYS_munlock
:
1183 result
= munlock ((void *) t2h_addr (cb
, &s
, arg1
), arg2
);
1187 case TARGET_LINUX_SYS_nanosleep
:
1189 struct timespec req
, rem
;
1191 req
= *((struct timespec
*) t2h_addr (cb
, &s
, arg2
));
1192 translate_endian_t2h (&req
, sizeof(req
));
1194 result
= nanosleep (&req
, &rem
);
1200 translate_endian_h2t (&rem
, sizeof(rem
));
1201 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rem
, sizeof(rem
))
1210 case TARGET_LINUX_SYS_mremap
: /* FIXME */
1211 result
= (int) mremap ((void *) t2h_addr (cb
, &s
, arg1
), arg2
, arg3
, arg4
);
1215 case TARGET_LINUX_SYS_getresuid32
:
1216 case TARGET_LINUX_SYS_getresuid
:
1218 uid_t ruid
, euid
, suid
;
1220 result
= getresuid (&ruid
, &euid
, &suid
);
1226 *((uid_t
*) t2h_addr (cb
, &s
, arg1
)) = H2T_4 (ruid
);
1227 *((uid_t
*) t2h_addr (cb
, &s
, arg2
)) = H2T_4 (euid
);
1228 *((uid_t
*) t2h_addr (cb
, &s
, arg3
)) = H2T_4 (suid
);
1232 case TARGET_LINUX_SYS_poll
:
1236 ufds
= *((struct pollfd
*) t2h_addr (cb
, &s
, arg1
));
1237 ufds
.fd
= T2H_4 (ufds
.fd
);
1238 ufds
.events
= T2H_2 (ufds
.events
);
1239 ufds
.revents
= T2H_2 (ufds
.revents
);
1241 result
= poll (&ufds
, arg2
, arg3
);
1246 case TARGET_LINUX_SYS_getresgid32
:
1247 case TARGET_LINUX_SYS_getresgid
:
1249 uid_t rgid
, egid
, sgid
;
1251 result
= getresgid (&rgid
, &egid
, &sgid
);
1257 *((uid_t
*) t2h_addr (cb
, &s
, arg1
)) = H2T_4 (rgid
);
1258 *((uid_t
*) t2h_addr (cb
, &s
, arg2
)) = H2T_4 (egid
);
1259 *((uid_t
*) t2h_addr (cb
, &s
, arg3
)) = H2T_4 (sgid
);
1263 case TARGET_LINUX_SYS_pread
:
1264 result
= pread (arg1
, (void *) t2h_addr (cb
, &s
, arg2
), arg3
, arg4
);
1268 case TARGET_LINUX_SYS_pwrite
:
1269 result
= pwrite (arg1
, (void *) t2h_addr (cb
, &s
, arg2
), arg3
, arg4
);
1273 case TARGET_LINUX_SYS_chown32
:
1274 case TARGET_LINUX_SYS_chown
:
1275 result
= chown ((char *) t2h_addr (cb
, &s
, arg1
), arg2
, arg3
);
1279 case TARGET_LINUX_SYS_getcwd
:
1280 result
= (int) getcwd ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
1284 case TARGET_LINUX_SYS_sendfile
:
1288 offset
= *((off_t
*) t2h_addr (cb
, &s
, arg3
));
1289 offset
= T2H_4 (offset
);
1291 result
= sendfile (arg1
, arg2
, &offset
, arg3
);
1297 *((off_t
*) t2h_addr (cb
, &s
, arg3
)) = H2T_4 (offset
);
1308 m32rbf_h_gr_set (current_cpu
, 0, -errcode
);
1310 m32rbf_h_gr_set (current_cpu
, 0, result
);
1315 case TRAP_BREAKPOINT
:
1316 sim_engine_halt (sd
, current_cpu
, NULL
, pc
,
1317 sim_stopped
, SIM_SIGTRAP
);
1320 case TRAP_FLUSH_CACHE
:
1327 /* The new pc is the trap vector entry.
1328 We assume there's a branch there to some handler.
1329 Use cr5 as EVB (EIT Vector Base) register. */
1330 /* USI new_pc = EIT_TRAP_BASE_ADDR + num * 4; */
1331 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
1336 /* Fake an "rte" insn. */
1337 /* FIXME: Should duplicate all of rte processing. */
1338 return (pc
& -4) + 4;