1 /* m32r exception, interrupt, and trap (EIT) support
2 Copyright (C) 1998-2021 Free Software Foundation, Inc.
3 Contributed by 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"
29 #include "targ-vals.h"
39 #include <sys/resource.h>
40 #include <sys/sysinfo.h>
43 #include <sys/timeb.h>
44 #include <sys/timex.h>
45 #include <sys/types.h>
47 #include <sys/utsname.h>
49 #include <linux/sysctl.h>
50 #include <linux/types.h>
51 #include <linux/unistd.h>
53 #define TRAP_ELF_SYSCALL 0
54 #define TRAP_LINUX_SYSCALL 2
55 #define TRAP_FLUSH_CACHE 12
57 /* The semantic code invokes this for invalid (unrecognized) instructions. */
60 sim_engine_invalid_insn (SIM_CPU
*current_cpu
, IADDR cia
, SEM_PC vpc
)
62 SIM_DESC sd
= CPU_STATE (current_cpu
);
65 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
67 h_bsm_set (current_cpu
, h_sm_get (current_cpu
));
68 h_bie_set (current_cpu
, h_ie_get (current_cpu
));
69 h_bcond_set (current_cpu
, h_cond_get (current_cpu
));
71 h_ie_set (current_cpu
, 0);
72 h_cond_set (current_cpu
, 0);
74 h_bpc_set (current_cpu
, cia
);
76 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
81 sim_engine_halt (sd
, current_cpu
, NULL
, cia
, sim_stopped
, SIM_SIGILL
);
85 /* Process an address exception. */
88 m32r_core_signal (SIM_DESC sd
, SIM_CPU
*current_cpu
, sim_cia cia
,
89 unsigned int map
, int nr_bytes
, address_word addr
,
90 transfer_type transfer
, sim_core_signals sig
)
92 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
94 m32rbf_h_cr_set (current_cpu
, H_CR_BBPC
,
95 m32rbf_h_cr_get (current_cpu
, H_CR_BPC
));
96 if (MACH_NUM (CPU_MACH (current_cpu
)) == MACH_M32R
)
98 m32rbf_h_bpsw_set (current_cpu
, m32rbf_h_psw_get (current_cpu
));
100 m32rbf_h_psw_set (current_cpu
, m32rbf_h_psw_get (current_cpu
) & 0x80);
102 else if (MACH_NUM (CPU_MACH (current_cpu
)) == MACH_M32RX
)
104 m32rxf_h_bpsw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
));
106 m32rxf_h_psw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
) & 0x80);
110 m32r2f_h_bpsw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
));
112 m32r2f_h_psw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
) & 0x80);
114 m32rbf_h_cr_set (current_cpu
, H_CR_BPC
, cia
);
116 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
120 sim_core_signal (sd
, current_cpu
, cia
, map
, nr_bytes
, addr
,
124 /* Translate target's address to host's address. */
127 t2h_addr (host_callback
*cb
, struct cb_syscall
*sc
,
131 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
132 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
137 return sim_core_trans_addr (sd
, cpu
, read_map
, taddr
);
140 /* TODO: These functions are a big hack and assume that the host runtime has
141 type sizes and struct layouts that match the target. So the Linux emulation
142 probaly only really works in 32-bit runtimes. */
145 translate_endian_h2t (void *addr
, size_t size
)
147 unsigned int *p
= (unsigned int *) addr
;
150 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
154 *((unsigned short *) p
) = H2T_2 (*((unsigned short *) p
));
158 translate_endian_t2h (void *addr
, size_t size
)
160 unsigned int *p
= (unsigned int *) addr
;
163 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
167 *((unsigned short *) p
) = T2H_2 (*((unsigned short *) p
));
171 The result is the pc address to continue at.
172 Preprocessing like saving the various registers has already been done. */
175 m32r_trap (SIM_CPU
*current_cpu
, PCADDR pc
, int num
)
177 SIM_DESC sd
= CPU_STATE (current_cpu
);
178 host_callback
*cb
= STATE_CALLBACK (sd
);
182 case TRAP_ELF_SYSCALL
:
184 long result
, result2
;
187 sim_syscall_multi (current_cpu
,
188 m32rbf_h_gr_get (current_cpu
, 0),
189 m32rbf_h_gr_get (current_cpu
, 1),
190 m32rbf_h_gr_get (current_cpu
, 2),
191 m32rbf_h_gr_get (current_cpu
, 3),
192 m32rbf_h_gr_get (current_cpu
, 4),
193 &result
, &result2
, &errcode
);
195 m32rbf_h_gr_set (current_cpu
, 2, errcode
);
196 m32rbf_h_gr_set (current_cpu
, 0, result
);
197 m32rbf_h_gr_set (current_cpu
, 1, result2
);
201 case TRAP_LINUX_SYSCALL
:
204 unsigned int func
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
;
205 int result
, result2
, errcode
;
207 if (STATE_ENVIRONMENT (sd
) != USER_ENVIRONMENT
)
210 func
= m32rbf_h_gr_get (current_cpu
, 7);
211 arg1
= m32rbf_h_gr_get (current_cpu
, 0);
212 arg2
= m32rbf_h_gr_get (current_cpu
, 1);
213 arg3
= m32rbf_h_gr_get (current_cpu
, 2);
214 arg4
= m32rbf_h_gr_get (current_cpu
, 3);
215 arg5
= m32rbf_h_gr_get (current_cpu
, 4);
216 arg6
= m32rbf_h_gr_get (current_cpu
, 5);
217 arg7
= m32rbf_h_gr_get (current_cpu
, 6);
219 CB_SYSCALL_INIT (&s
);
230 s
.p2
= (PTR
) current_cpu
;
231 s
.read_mem
= sim_syscall_read_mem
;
232 s
.write_mem
= sim_syscall_write_mem
;
240 case TARGET_LINUX_SYS_exit
:
241 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, arg1
);
244 case TARGET_LINUX_SYS_read
:
245 result
= read(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
249 case TARGET_LINUX_SYS_write
:
250 result
= write(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
254 case TARGET_LINUX_SYS_open
:
255 result
= open((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
259 case TARGET_LINUX_SYS_close
:
260 result
= close(arg1
);
264 case TARGET_LINUX_SYS_creat
:
265 result
= creat((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
269 case TARGET_LINUX_SYS_link
:
270 result
= link((char *) t2h_addr(cb
, &s
, arg1
),
271 (char *) t2h_addr(cb
, &s
, arg2
));
275 case TARGET_LINUX_SYS_unlink
:
276 result
= unlink((char *) t2h_addr(cb
, &s
, arg1
));
280 case TARGET_LINUX_SYS_chdir
:
281 result
= chdir((char *) t2h_addr(cb
, &s
, arg1
));
285 case TARGET_LINUX_SYS_time
:
291 result
= (int) time(NULL
);
296 result
= (int) time(&t
);
303 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
)) != sizeof(t
))
312 case TARGET_LINUX_SYS_mknod
:
313 result
= mknod((char *) t2h_addr(cb
, &s
, arg1
),
314 (mode_t
) arg2
, (dev_t
) arg3
);
318 case TARGET_LINUX_SYS_chmod
:
319 result
= chmod((char *) t2h_addr(cb
, &s
, arg1
), (mode_t
) arg2
);
323 case TARGET_LINUX_SYS_lchown32
:
324 case TARGET_LINUX_SYS_lchown
:
325 result
= lchown((char *) t2h_addr(cb
, &s
, arg1
),
326 (uid_t
) arg2
, (gid_t
) arg3
);
330 case TARGET_LINUX_SYS_lseek
:
331 result
= (int) lseek(arg1
, (off_t
) arg2
, arg3
);
335 case TARGET_LINUX_SYS_getpid
:
340 case TARGET_LINUX_SYS_getuid32
:
341 case TARGET_LINUX_SYS_getuid
:
346 case TARGET_LINUX_SYS_utime
:
352 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), NULL
);
357 buf
= *((struct utimbuf
*) t2h_addr(cb
, &s
, arg2
));
358 translate_endian_t2h (&buf
, sizeof(buf
));
359 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), &buf
);
365 case TARGET_LINUX_SYS_access
:
366 result
= access((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
370 case TARGET_LINUX_SYS_ftime
:
380 t
.time
= H2T_4 (t
.time
);
381 t
.millitm
= H2T_2 (t
.millitm
);
382 t
.timezone
= H2T_2 (t
.timezone
);
383 t
.dstflag
= H2T_2 (t
.dstflag
);
384 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
))
392 case TARGET_LINUX_SYS_sync
:
397 case TARGET_LINUX_SYS_rename
:
398 result
= rename((char *) t2h_addr(cb
, &s
, arg1
),
399 (char *) t2h_addr(cb
, &s
, arg2
));
403 case TARGET_LINUX_SYS_mkdir
:
404 result
= mkdir((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
408 case TARGET_LINUX_SYS_rmdir
:
409 result
= rmdir((char *) t2h_addr(cb
, &s
, arg1
));
413 case TARGET_LINUX_SYS_dup
:
418 case TARGET_LINUX_SYS_brk
:
419 result
= brk((void *) arg1
);
424 case TARGET_LINUX_SYS_getgid32
:
425 case TARGET_LINUX_SYS_getgid
:
430 case TARGET_LINUX_SYS_geteuid32
:
431 case TARGET_LINUX_SYS_geteuid
:
436 case TARGET_LINUX_SYS_getegid32
:
437 case TARGET_LINUX_SYS_getegid
:
442 case TARGET_LINUX_SYS_ioctl
:
443 result
= ioctl(arg1
, arg2
, arg3
);
447 case TARGET_LINUX_SYS_fcntl
:
448 result
= fcntl(arg1
, arg2
, arg3
);
452 case TARGET_LINUX_SYS_dup2
:
453 result
= dup2(arg1
, arg2
);
457 case TARGET_LINUX_SYS_getppid
:
462 case TARGET_LINUX_SYS_getpgrp
:
467 case TARGET_LINUX_SYS_getrlimit
:
471 result
= getrlimit(arg1
, &rlim
);
477 translate_endian_h2t (&rlim
, sizeof(rlim
));
478 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rlim
, sizeof(rlim
))
487 case TARGET_LINUX_SYS_getrusage
:
491 result
= getrusage(arg1
, &usage
);
497 translate_endian_h2t (&usage
, sizeof(usage
));
498 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &usage
, sizeof(usage
))
507 case TARGET_LINUX_SYS_gettimeofday
:
512 result
= gettimeofday(&tv
, &tz
);
518 translate_endian_h2t (&tv
, sizeof(tv
));
519 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &tv
, sizeof(tv
))
526 translate_endian_h2t (&tz
, sizeof(tz
));
527 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &tz
, sizeof(tz
))
536 case TARGET_LINUX_SYS_getgroups32
:
537 case TARGET_LINUX_SYS_getgroups
:
542 list
= (gid_t
*) malloc(arg1
* sizeof(gid_t
));
544 result
= getgroups(arg1
, list
);
550 translate_endian_h2t (list
, arg1
* sizeof(gid_t
));
552 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) list
, arg1
* sizeof(gid_t
))
553 != arg1
* sizeof(gid_t
))
561 case TARGET_LINUX_SYS_select
:
573 struct timeval
*ttimeoutp
;
574 struct timeval timeout
;
578 treadfdsp
= (fd_set
*) arg2
;
579 if (treadfdsp
!= NULL
)
581 readfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) treadfdsp
));
582 translate_endian_t2h (&readfds
, sizeof(readfds
));
583 hreadfdsp
= &readfds
;
588 twritefdsp
= (fd_set
*) arg3
;
589 if (twritefdsp
!= NULL
)
591 writefds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) twritefdsp
));
592 translate_endian_t2h (&writefds
, sizeof(writefds
));
593 hwritefdsp
= &writefds
;
598 texceptfdsp
= (fd_set
*) arg4
;
599 if (texceptfdsp
!= NULL
)
601 exceptfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) texceptfdsp
));
602 translate_endian_t2h (&exceptfds
, sizeof(exceptfds
));
603 hexceptfdsp
= &exceptfds
;
608 ttimeoutp
= (struct timeval
*) arg5
;
609 timeout
= *((struct timeval
*) t2h_addr(cb
, &s
, (unsigned int) ttimeoutp
));
610 translate_endian_t2h (&timeout
, sizeof(timeout
));
612 result
= select(n
, hreadfdsp
, hwritefdsp
, hexceptfdsp
, &timeout
);
618 if (treadfdsp
!= NULL
)
620 translate_endian_h2t (&readfds
, sizeof(readfds
));
621 if ((s
.write_mem
) (cb
, &s
, (unsigned long) treadfdsp
,
622 (char *) &readfds
, sizeof(readfds
)) != sizeof(readfds
))
629 if (twritefdsp
!= NULL
)
631 translate_endian_h2t (&writefds
, sizeof(writefds
));
632 if ((s
.write_mem
) (cb
, &s
, (unsigned long) twritefdsp
,
633 (char *) &writefds
, sizeof(writefds
)) != sizeof(writefds
))
640 if (texceptfdsp
!= NULL
)
642 translate_endian_h2t (&exceptfds
, sizeof(exceptfds
));
643 if ((s
.write_mem
) (cb
, &s
, (unsigned long) texceptfdsp
,
644 (char *) &exceptfds
, sizeof(exceptfds
)) != sizeof(exceptfds
))
651 translate_endian_h2t (&timeout
, sizeof(timeout
));
652 if ((s
.write_mem
) (cb
, &s
, (unsigned long) ttimeoutp
,
653 (char *) &timeout
, sizeof(timeout
)) != sizeof(timeout
))
661 case TARGET_LINUX_SYS_symlink
:
662 result
= symlink((char *) t2h_addr(cb
, &s
, arg1
),
663 (char *) t2h_addr(cb
, &s
, arg2
));
667 case TARGET_LINUX_SYS_readlink
:
668 result
= readlink((char *) t2h_addr(cb
, &s
, arg1
),
669 (char *) t2h_addr(cb
, &s
, arg2
),
674 case TARGET_LINUX_SYS_readdir
:
675 result
= (int) readdir((DIR *) t2h_addr(cb
, &s
, arg1
));
680 case TARGET_LINUX_SYS_mmap
:
682 result
= (int) mmap((void *) t2h_addr(cb
, &s
, arg1
),
683 arg2
, arg3
, arg4
, arg5
, arg6
);
688 sim_core_attach (sd
, NULL
,
689 0, access_read_write_exec
, 0,
690 result
, arg2
, 0, NULL
, NULL
);
695 case TARGET_LINUX_SYS_mmap2
:
699 int prot
, flags
, fildes
;
702 addr
= (void *) t2h_addr(cb
, &s
, arg1
);
709 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
714 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
715 sim_core_attach (sd
, NULL
,
716 0, access_read_write_exec
, 0,
717 result
, len
, 0, NULL
, NULL
);
722 case TARGET_LINUX_SYS_mmap
:
726 int prot
, flags
, fildes
;
729 addr
= *((void **) t2h_addr(cb
, &s
, arg1
));
730 len
= *((size_t *) t2h_addr(cb
, &s
, arg1
+ 4));
731 prot
= *((int *) t2h_addr(cb
, &s
, arg1
+ 8));
732 flags
= *((int *) t2h_addr(cb
, &s
, arg1
+ 12));
733 fildes
= *((int *) t2h_addr(cb
, &s
, arg1
+ 16));
734 off
= *((off_t
*) t2h_addr(cb
, &s
, arg1
+ 20));
736 addr
= (void *) T2H_4 ((unsigned int) addr
);
739 flags
= T2H_4 (flags
);
740 fildes
= T2H_4 (fildes
);
743 //addr = (void *) t2h_addr(cb, &s, (unsigned int) addr);
744 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
751 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
752 sim_core_attach (sd
, NULL
,
753 0, access_read_write_exec
, 0,
754 result
, len
, 0, NULL
, NULL
);
759 case TARGET_LINUX_SYS_munmap
:
761 result
= munmap((void *)arg1
, arg2
);
765 sim_core_detach (sd
, NULL
, 0, arg2
, result
);
770 case TARGET_LINUX_SYS_truncate
:
771 result
= truncate((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
775 case TARGET_LINUX_SYS_ftruncate
:
776 result
= ftruncate(arg1
, arg2
);
780 case TARGET_LINUX_SYS_fchmod
:
781 result
= fchmod(arg1
, arg2
);
785 case TARGET_LINUX_SYS_fchown32
:
786 case TARGET_LINUX_SYS_fchown
:
787 result
= fchown(arg1
, arg2
, arg3
);
791 case TARGET_LINUX_SYS_statfs
:
793 struct statfs statbuf
;
795 result
= statfs((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
801 translate_endian_h2t (&statbuf
, sizeof(statbuf
));
802 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
811 case TARGET_LINUX_SYS_fstatfs
:
813 struct statfs statbuf
;
815 result
= fstatfs(arg1
, &statbuf
);
821 translate_endian_h2t (&statbuf
, sizeof(statbuf
));
822 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
831 case TARGET_LINUX_SYS_syslog
:
832 result
= syslog(arg1
, (char *) t2h_addr(cb
, &s
, arg2
));
836 case TARGET_LINUX_SYS_setitimer
:
838 struct itimerval value
, ovalue
;
840 value
= *((struct itimerval
*) t2h_addr(cb
, &s
, arg2
));
841 translate_endian_t2h (&value
, sizeof(value
));
845 result
= setitimer(arg1
, &value
, NULL
);
850 result
= setitimer(arg1
, &value
, &ovalue
);
856 translate_endian_h2t (&ovalue
, sizeof(ovalue
));
857 if ((s
.write_mem
) (cb
, &s
, arg3
, (char *) &ovalue
, sizeof(ovalue
))
867 case TARGET_LINUX_SYS_getitimer
:
869 struct itimerval value
;
871 result
= getitimer(arg1
, &value
);
877 translate_endian_h2t (&value
, sizeof(value
));
878 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &value
, sizeof(value
))
887 case TARGET_LINUX_SYS_stat
:
893 result
= stat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
898 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
899 buf
= xmalloc (buflen
);
900 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
902 /* The translation failed. This is due to an internal
903 host program error, not the target's fault. */
909 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
920 case TARGET_LINUX_SYS_lstat
:
926 result
= lstat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
931 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
932 buf
= xmalloc (buflen
);
933 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
935 /* The translation failed. This is due to an internal
936 host program error, not the target's fault. */
942 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
953 case TARGET_LINUX_SYS_fstat
:
959 result
= fstat(arg1
, &statbuf
);
964 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
965 buf
= xmalloc (buflen
);
966 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
968 /* The translation failed. This is due to an internal
969 host program error, not the target's fault. */
975 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
986 case TARGET_LINUX_SYS_sysinfo
:
990 result
= sysinfo(&info
);
996 info
.uptime
= H2T_4 (info
.uptime
);
997 info
.loads
[0] = H2T_4 (info
.loads
[0]);
998 info
.loads
[1] = H2T_4 (info
.loads
[1]);
999 info
.loads
[2] = H2T_4 (info
.loads
[2]);
1000 info
.totalram
= H2T_4 (info
.totalram
);
1001 info
.freeram
= H2T_4 (info
.freeram
);
1002 info
.sharedram
= H2T_4 (info
.sharedram
);
1003 info
.bufferram
= H2T_4 (info
.bufferram
);
1004 info
.totalswap
= H2T_4 (info
.totalswap
);
1005 info
.freeswap
= H2T_4 (info
.freeswap
);
1006 info
.procs
= H2T_2 (info
.procs
);
1007 #if LINUX_VERSION_CODE >= 0x20400
1008 info
.totalhigh
= H2T_4 (info
.totalhigh
);
1009 info
.freehigh
= H2T_4 (info
.freehigh
);
1010 info
.mem_unit
= H2T_4 (info
.mem_unit
);
1012 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &info
, sizeof(info
))
1022 case TARGET_LINUX_SYS_ipc
:
1024 result
= ipc(arg1
, arg2
, arg3
, arg4
,
1025 (void *) t2h_addr(cb
, &s
, arg5
), arg6
);
1031 case TARGET_LINUX_SYS_fsync
:
1032 result
= fsync(arg1
);
1036 case TARGET_LINUX_SYS_uname
:
1037 /* utsname contains only arrays of char, so it is not necessary
1038 to translate endian. */
1039 result
= uname((struct utsname
*) t2h_addr(cb
, &s
, arg1
));
1043 case TARGET_LINUX_SYS_adjtimex
:
1047 result
= adjtimex(&buf
);
1053 translate_endian_h2t (&buf
, sizeof(buf
));
1054 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &buf
, sizeof(buf
))
1063 case TARGET_LINUX_SYS_mprotect
:
1064 result
= mprotect((void *) arg1
, arg2
, arg3
);
1068 case TARGET_LINUX_SYS_fchdir
:
1069 result
= fchdir(arg1
);
1073 case TARGET_LINUX_SYS_setfsuid32
:
1074 case TARGET_LINUX_SYS_setfsuid
:
1075 result
= setfsuid(arg1
);
1079 case TARGET_LINUX_SYS_setfsgid32
:
1080 case TARGET_LINUX_SYS_setfsgid
:
1081 result
= setfsgid(arg1
);
1086 case TARGET_LINUX_SYS__llseek
:
1090 result
= _llseek(arg1
, arg2
, arg3
, &buf
, arg5
);
1096 translate_endian_h2t (&buf
, sizeof(buf
));
1097 if ((s
.write_mem
) (cb
, &s
, t2h_addr(cb
, &s
, arg4
),
1098 (char *) &buf
, sizeof(buf
)) != sizeof(buf
))
1106 case TARGET_LINUX_SYS_getdents
:
1110 result
= getdents(arg1
, &dir
, arg3
);
1116 dir
.d_ino
= H2T_4 (dir
.d_ino
);
1117 dir
.d_off
= H2T_4 (dir
.d_off
);
1118 dir
.d_reclen
= H2T_2 (dir
.d_reclen
);
1119 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &dir
, sizeof(dir
))
1129 case TARGET_LINUX_SYS_flock
:
1130 result
= flock(arg1
, arg2
);
1134 case TARGET_LINUX_SYS_msync
:
1135 result
= msync((void *) arg1
, arg2
, arg3
);
1139 case TARGET_LINUX_SYS_readv
:
1141 struct iovec vector
;
1143 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1144 translate_endian_t2h (&vector
, sizeof(vector
));
1146 result
= readv(arg1
, &vector
, arg3
);
1151 case TARGET_LINUX_SYS_writev
:
1153 struct iovec vector
;
1155 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1156 translate_endian_t2h (&vector
, sizeof(vector
));
1158 result
= writev(arg1
, &vector
, arg3
);
1163 case TARGET_LINUX_SYS_fdatasync
:
1164 result
= fdatasync(arg1
);
1168 case TARGET_LINUX_SYS_mlock
:
1169 result
= mlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1173 case TARGET_LINUX_SYS_munlock
:
1174 result
= munlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1178 case TARGET_LINUX_SYS_nanosleep
:
1180 struct timespec req
, rem
;
1182 req
= *((struct timespec
*) t2h_addr(cb
, &s
, arg2
));
1183 translate_endian_t2h (&req
, sizeof(req
));
1185 result
= nanosleep(&req
, &rem
);
1191 translate_endian_h2t (&rem
, sizeof(rem
));
1192 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rem
, sizeof(rem
))
1201 case TARGET_LINUX_SYS_mremap
: /* FIXME */
1202 result
= (int) mremap((void *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
, arg4
);
1206 case TARGET_LINUX_SYS_getresuid32
:
1207 case TARGET_LINUX_SYS_getresuid
:
1209 uid_t ruid
, euid
, suid
;
1211 result
= getresuid(&ruid
, &euid
, &suid
);
1217 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = H2T_4 (ruid
);
1218 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = H2T_4 (euid
);
1219 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = H2T_4 (suid
);
1223 case TARGET_LINUX_SYS_poll
:
1227 ufds
= *((struct pollfd
*) t2h_addr(cb
, &s
, arg1
));
1228 ufds
.fd
= T2H_4 (ufds
.fd
);
1229 ufds
.events
= T2H_2 (ufds
.events
);
1230 ufds
.revents
= T2H_2 (ufds
.revents
);
1232 result
= poll(&ufds
, arg2
, arg3
);
1237 case TARGET_LINUX_SYS_getresgid32
:
1238 case TARGET_LINUX_SYS_getresgid
:
1240 uid_t rgid
, egid
, sgid
;
1242 result
= getresgid(&rgid
, &egid
, &sgid
);
1248 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = H2T_4 (rgid
);
1249 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = H2T_4 (egid
);
1250 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = H2T_4 (sgid
);
1254 case TARGET_LINUX_SYS_pread
:
1255 result
= pread(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1259 case TARGET_LINUX_SYS_pwrite
:
1260 result
= pwrite(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1264 case TARGET_LINUX_SYS_chown32
:
1265 case TARGET_LINUX_SYS_chown
:
1266 result
= chown((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
1270 case TARGET_LINUX_SYS_getcwd
:
1271 result
= (int) getcwd((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
1275 case TARGET_LINUX_SYS_sendfile
:
1279 offset
= *((off_t
*) t2h_addr(cb
, &s
, arg3
));
1280 offset
= T2H_4 (offset
);
1282 result
= sendfile(arg1
, arg2
, &offset
, arg3
);
1288 *((off_t
*) t2h_addr(cb
, &s
, arg3
)) = H2T_4 (offset
);
1299 m32rbf_h_gr_set (current_cpu
, 0, -errcode
);
1301 m32rbf_h_gr_set (current_cpu
, 0, result
);
1305 case TRAP_BREAKPOINT
:
1306 sim_engine_halt (sd
, current_cpu
, NULL
, pc
,
1307 sim_stopped
, SIM_SIGTRAP
);
1310 case TRAP_FLUSH_CACHE
:
1317 /* Use cr5 as EVB (EIT Vector Base) register. */
1318 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
1323 /* Fake an "rte" insn. */
1324 /* FIXME: Should duplicate all of rte processing. */
1325 return (pc
& -4) + 4;