1 /* m32r exception, interrupt, and trap (EIT) support
2 Copyright (C) 1998-2015 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/>. */
21 #include "sim-syscall.h"
23 #include "targ-vals.h"
32 #include <sys/resource.h>
33 #include <sys/sysinfo.h>
36 #include <sys/timeb.h>
37 #include <sys/timex.h>
38 #include <sys/types.h>
40 #include <sys/utsname.h>
42 #include <linux/sysctl.h>
43 #include <linux/types.h>
44 #include <linux/unistd.h>
46 #define TRAP_ELF_SYSCALL 0
47 #define TRAP_LINUX_SYSCALL 2
48 #define TRAP_FLUSH_CACHE 12
50 /* The semantic code invokes this for invalid (unrecognized) instructions. */
53 sim_engine_invalid_insn (SIM_CPU
*current_cpu
, IADDR cia
, SEM_PC vpc
)
55 SIM_DESC sd
= CPU_STATE (current_cpu
);
58 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
60 h_bsm_set (current_cpu
, h_sm_get (current_cpu
));
61 h_bie_set (current_cpu
, h_ie_get (current_cpu
));
62 h_bcond_set (current_cpu
, h_cond_get (current_cpu
));
64 h_ie_set (current_cpu
, 0);
65 h_cond_set (current_cpu
, 0);
67 h_bpc_set (current_cpu
, cia
);
69 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
74 sim_engine_halt (sd
, current_cpu
, NULL
, cia
, sim_stopped
, SIM_SIGILL
);
78 /* Process an address exception. */
81 m32r_core_signal (SIM_DESC sd
, SIM_CPU
*current_cpu
, sim_cia cia
,
82 unsigned int map
, int nr_bytes
, address_word addr
,
83 transfer_type transfer
, sim_core_signals sig
)
85 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
87 m32rbf_h_cr_set (current_cpu
, H_CR_BBPC
,
88 m32rbf_h_cr_get (current_cpu
, H_CR_BPC
));
89 if (MACH_NUM (CPU_MACH (current_cpu
)) == MACH_M32R
)
91 m32rbf_h_bpsw_set (current_cpu
, m32rbf_h_psw_get (current_cpu
));
93 m32rbf_h_psw_set (current_cpu
, m32rbf_h_psw_get (current_cpu
) & 0x80);
95 else if (MACH_NUM (CPU_MACH (current_cpu
)) == MACH_M32RX
)
97 m32rxf_h_bpsw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
));
99 m32rxf_h_psw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
) & 0x80);
103 m32r2f_h_bpsw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
));
105 m32r2f_h_psw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
) & 0x80);
107 m32rbf_h_cr_set (current_cpu
, H_CR_BPC
, cia
);
109 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
113 sim_core_signal (sd
, current_cpu
, cia
, map
, nr_bytes
, addr
,
117 /* Translate target's address to host's address. */
120 t2h_addr (host_callback
*cb
, struct cb_syscall
*sc
,
124 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
125 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
130 return sim_core_trans_addr (sd
, cpu
, read_map
, taddr
);
134 conv_endian (unsigned int tvalue
)
137 unsigned int t1
, t2
, t3
, t4
;
139 if (CURRENT_HOST_BYTE_ORDER
== LITTLE_ENDIAN
)
141 t1
= tvalue
& 0xff000000;
142 t2
= tvalue
& 0x00ff0000;
143 t3
= tvalue
& 0x0000ff00;
144 t4
= tvalue
& 0x000000ff;
157 static unsigned short
158 conv_endian16 (unsigned short tvalue
)
160 unsigned short hvalue
;
161 unsigned short t1
, t2
;
163 if (CURRENT_HOST_BYTE_ORDER
== LITTLE_ENDIAN
)
165 t1
= tvalue
& 0xff00;
166 t2
= tvalue
& 0x00ff;
178 translate_endian(void *addr
, size_t size
)
180 unsigned int *p
= (unsigned int *) addr
;
183 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
184 *p
= conv_endian(*p
);
187 *((unsigned short *) p
) = conv_endian16(*((unsigned short *) p
));
191 The result is the pc address to continue at.
192 Preprocessing like saving the various registers has already been done. */
195 m32r_trap (SIM_CPU
*current_cpu
, PCADDR pc
, int num
)
197 SIM_DESC sd
= CPU_STATE (current_cpu
);
198 host_callback
*cb
= STATE_CALLBACK (sd
);
200 #ifdef SIM_HAVE_BREAKPOINTS
201 /* Check for breakpoints "owned" by the simulator first, regardless
203 if (num
== TRAP_BREAKPOINT
)
205 /* First try sim-break.c. If it's a breakpoint the simulator "owns"
206 it doesn't return. Otherwise it returns and let's us try. */
207 sim_handle_breakpoint (sd
, current_cpu
, pc
);
214 case TRAP_ELF_SYSCALL
:
218 CB_SYSCALL_INIT (&s
);
219 s
.func
= m32rbf_h_gr_get (current_cpu
, 0);
220 s
.arg1
= m32rbf_h_gr_get (current_cpu
, 1);
221 s
.arg2
= m32rbf_h_gr_get (current_cpu
, 2);
222 s
.arg3
= m32rbf_h_gr_get (current_cpu
, 3);
224 if (s
.func
== TARGET_SYS_exit
)
226 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, s
.arg1
);
230 s
.p2
= (PTR
) current_cpu
;
231 s
.read_mem
= sim_syscall_read_mem
;
232 s
.write_mem
= sim_syscall_write_mem
;
234 m32rbf_h_gr_set (current_cpu
, 2, s
.errcode
);
235 m32rbf_h_gr_set (current_cpu
, 0, s
.result
);
236 m32rbf_h_gr_set (current_cpu
, 1, s
.result2
);
240 case TRAP_LINUX_SYSCALL
:
243 unsigned int func
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
;
244 int result
, result2
, errcode
;
246 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
248 /* The new pc is the trap vector entry.
249 We assume there's a branch there to some handler.
250 Use cr5 as EVB (EIT Vector Base) register. */
251 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
255 func
= m32rbf_h_gr_get (current_cpu
, 7);
256 arg1
= m32rbf_h_gr_get (current_cpu
, 0);
257 arg2
= m32rbf_h_gr_get (current_cpu
, 1);
258 arg3
= m32rbf_h_gr_get (current_cpu
, 2);
259 arg4
= m32rbf_h_gr_get (current_cpu
, 3);
260 arg5
= m32rbf_h_gr_get (current_cpu
, 4);
261 arg6
= m32rbf_h_gr_get (current_cpu
, 5);
262 arg7
= m32rbf_h_gr_get (current_cpu
, 6);
264 CB_SYSCALL_INIT (&s
);
271 s
.p2
= (PTR
) current_cpu
;
272 s
.read_mem
= sim_syscall_read_mem
;
273 s
.write_mem
= sim_syscall_write_mem
;
282 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, arg1
);
286 result
= read(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
291 result
= write(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
296 result
= open((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
301 result
= close(arg1
);
306 result
= creat((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
311 result
= link((char *) t2h_addr(cb
, &s
, arg1
),
312 (char *) t2h_addr(cb
, &s
, arg2
));
317 result
= unlink((char *) t2h_addr(cb
, &s
, arg1
));
322 result
= chdir((char *) t2h_addr(cb
, &s
, arg1
));
332 result
= (int) time(NULL
);
337 result
= (int) time(&t
);
343 translate_endian((void *) &t
, sizeof(t
));
344 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
)) != sizeof(t
))
354 result
= mknod((char *) t2h_addr(cb
, &s
, arg1
),
355 (mode_t
) arg2
, (dev_t
) arg3
);
360 result
= chmod((char *) t2h_addr(cb
, &s
, arg1
), (mode_t
) arg2
);
366 result
= lchown((char *) t2h_addr(cb
, &s
, arg1
),
367 (uid_t
) arg2
, (gid_t
) arg3
);
372 result
= (int) lseek(arg1
, (off_t
) arg2
, arg3
);
393 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), NULL
);
398 buf
= *((struct utimbuf
*) t2h_addr(cb
, &s
, arg2
));
399 translate_endian((void *) &buf
, sizeof(buf
));
400 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), &buf
);
407 result
= access((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
421 t
.time
= conv_endian(t
.time
);
422 t
.millitm
= conv_endian16(t
.millitm
);
423 t
.timezone
= conv_endian16(t
.timezone
);
424 t
.dstflag
= conv_endian16(t
.dstflag
);
425 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
))
439 result
= rename((char *) t2h_addr(cb
, &s
, arg1
),
440 (char *) t2h_addr(cb
, &s
, arg2
));
445 result
= mkdir((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
450 result
= rmdir((char *) t2h_addr(cb
, &s
, arg1
));
460 result
= brk((void *) arg1
);
484 result
= ioctl(arg1
, arg2
, arg3
);
489 result
= fcntl(arg1
, arg2
, arg3
);
494 result
= dup2(arg1
, arg2
);
512 result
= getrlimit(arg1
, &rlim
);
518 translate_endian((void *) &rlim
, sizeof(rlim
));
519 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rlim
, sizeof(rlim
))
532 result
= getrusage(arg1
, &usage
);
538 translate_endian((void *) &usage
, sizeof(usage
));
539 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &usage
, sizeof(usage
))
548 case __NR_gettimeofday
:
553 result
= gettimeofday(&tv
, &tz
);
559 translate_endian((void *) &tv
, sizeof(tv
));
560 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &tv
, sizeof(tv
))
567 translate_endian((void *) &tz
, sizeof(tz
));
568 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &tz
, sizeof(tz
))
577 case __NR_getgroups32
:
583 list
= (gid_t
*) malloc(arg1
* sizeof(gid_t
));
585 result
= getgroups(arg1
, list
);
591 translate_endian((void *) list
, arg1
* sizeof(gid_t
));
593 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) list
, arg1
* sizeof(gid_t
))
594 != arg1
* sizeof(gid_t
))
614 struct timeval
*ttimeoutp
;
615 struct timeval timeout
;
619 treadfdsp
= (fd_set
*) arg2
;
620 if (treadfdsp
!= NULL
)
622 readfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) treadfdsp
));
623 translate_endian((void *) &readfds
, sizeof(readfds
));
624 hreadfdsp
= &readfds
;
629 twritefdsp
= (fd_set
*) arg3
;
630 if (twritefdsp
!= NULL
)
632 writefds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) twritefdsp
));
633 translate_endian((void *) &writefds
, sizeof(writefds
));
634 hwritefdsp
= &writefds
;
639 texceptfdsp
= (fd_set
*) arg4
;
640 if (texceptfdsp
!= NULL
)
642 exceptfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) texceptfdsp
));
643 translate_endian((void *) &exceptfds
, sizeof(exceptfds
));
644 hexceptfdsp
= &exceptfds
;
649 ttimeoutp
= (struct timeval
*) arg5
;
650 timeout
= *((struct timeval
*) t2h_addr(cb
, &s
, (unsigned int) ttimeoutp
));
651 translate_endian((void *) &timeout
, sizeof(timeout
));
653 result
= select(n
, hreadfdsp
, hwritefdsp
, hexceptfdsp
, &timeout
);
659 if (treadfdsp
!= NULL
)
661 translate_endian((void *) &readfds
, sizeof(readfds
));
662 if ((s
.write_mem
) (cb
, &s
, (unsigned long) treadfdsp
,
663 (char *) &readfds
, sizeof(readfds
)) != sizeof(readfds
))
670 if (twritefdsp
!= NULL
)
672 translate_endian((void *) &writefds
, sizeof(writefds
));
673 if ((s
.write_mem
) (cb
, &s
, (unsigned long) twritefdsp
,
674 (char *) &writefds
, sizeof(writefds
)) != sizeof(writefds
))
681 if (texceptfdsp
!= NULL
)
683 translate_endian((void *) &exceptfds
, sizeof(exceptfds
));
684 if ((s
.write_mem
) (cb
, &s
, (unsigned long) texceptfdsp
,
685 (char *) &exceptfds
, sizeof(exceptfds
)) != sizeof(exceptfds
))
692 translate_endian((void *) &timeout
, sizeof(timeout
));
693 if ((s
.write_mem
) (cb
, &s
, (unsigned long) ttimeoutp
,
694 (char *) &timeout
, sizeof(timeout
)) != sizeof(timeout
))
703 result
= symlink((char *) t2h_addr(cb
, &s
, arg1
),
704 (char *) t2h_addr(cb
, &s
, arg2
));
709 result
= readlink((char *) t2h_addr(cb
, &s
, arg1
),
710 (char *) t2h_addr(cb
, &s
, arg2
),
716 result
= (int) readdir((DIR *) t2h_addr(cb
, &s
, arg1
));
723 result
= (int) mmap((void *) t2h_addr(cb
, &s
, arg1
),
724 arg2
, arg3
, arg4
, arg5
, arg6
);
729 sim_core_attach (sd
, NULL
,
730 0, access_read_write_exec
, 0,
731 result
, arg2
, 0, NULL
, NULL
);
740 int prot
, flags
, fildes
;
743 addr
= (void *) t2h_addr(cb
, &s
, arg1
);
750 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
755 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
756 sim_core_attach (sd
, NULL
,
757 0, access_read_write_exec
, 0,
758 result
, len
, 0, NULL
, NULL
);
767 int prot
, flags
, fildes
;
770 addr
= *((void **) t2h_addr(cb
, &s
, arg1
));
771 len
= *((size_t *) t2h_addr(cb
, &s
, arg1
+ 4));
772 prot
= *((int *) t2h_addr(cb
, &s
, arg1
+ 8));
773 flags
= *((int *) t2h_addr(cb
, &s
, arg1
+ 12));
774 fildes
= *((int *) t2h_addr(cb
, &s
, arg1
+ 16));
775 off
= *((off_t
*) t2h_addr(cb
, &s
, arg1
+ 20));
777 addr
= (void *) conv_endian((unsigned int) addr
);
778 len
= conv_endian(len
);
779 prot
= conv_endian(prot
);
780 flags
= conv_endian(flags
);
781 fildes
= conv_endian(fildes
);
782 off
= conv_endian(off
);
784 //addr = (void *) t2h_addr(cb, &s, (unsigned int) addr);
785 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
792 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
793 sim_core_attach (sd
, NULL
,
794 0, access_read_write_exec
, 0,
795 result
, len
, 0, NULL
, NULL
);
802 result
= munmap((void *)arg1
, arg2
);
806 sim_core_detach (sd
, NULL
, 0, arg2
, result
);
812 result
= truncate((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
817 result
= ftruncate(arg1
, arg2
);
822 result
= fchmod(arg1
, arg2
);
828 result
= fchown(arg1
, arg2
, arg3
);
834 struct statfs statbuf
;
836 result
= statfs((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
842 translate_endian((void *) &statbuf
, sizeof(statbuf
));
843 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
854 struct statfs statbuf
;
856 result
= fstatfs(arg1
, &statbuf
);
862 translate_endian((void *) &statbuf
, sizeof(statbuf
));
863 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
873 result
= syslog(arg1
, (char *) t2h_addr(cb
, &s
, arg2
));
879 struct itimerval value
, ovalue
;
881 value
= *((struct itimerval
*) t2h_addr(cb
, &s
, arg2
));
882 translate_endian((void *) &value
, sizeof(value
));
886 result
= setitimer(arg1
, &value
, NULL
);
891 result
= setitimer(arg1
, &value
, &ovalue
);
897 translate_endian((void *) &ovalue
, sizeof(ovalue
));
898 if ((s
.write_mem
) (cb
, &s
, arg3
, (char *) &ovalue
, sizeof(ovalue
))
910 struct itimerval value
;
912 result
= getitimer(arg1
, &value
);
918 translate_endian((void *) &value
, sizeof(value
));
919 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &value
, sizeof(value
))
934 result
= stat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
939 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
940 buf
= xmalloc (buflen
);
941 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
943 /* The translation failed. This is due to an internal
944 host program error, not the target's fault. */
950 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
967 result
= lstat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
972 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
973 buf
= xmalloc (buflen
);
974 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
976 /* The translation failed. This is due to an internal
977 host program error, not the target's fault. */
983 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
1000 result
= fstat(arg1
, &statbuf
);
1005 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
1006 buf
= xmalloc (buflen
);
1007 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
1009 /* The translation failed. This is due to an internal
1010 host program error, not the target's fault. */
1016 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
1029 struct sysinfo info
;
1031 result
= sysinfo(&info
);
1037 info
.uptime
= conv_endian(info
.uptime
);
1038 info
.loads
[0] = conv_endian(info
.loads
[0]);
1039 info
.loads
[1] = conv_endian(info
.loads
[1]);
1040 info
.loads
[2] = conv_endian(info
.loads
[2]);
1041 info
.totalram
= conv_endian(info
.totalram
);
1042 info
.freeram
= conv_endian(info
.freeram
);
1043 info
.sharedram
= conv_endian(info
.sharedram
);
1044 info
.bufferram
= conv_endian(info
.bufferram
);
1045 info
.totalswap
= conv_endian(info
.totalswap
);
1046 info
.freeswap
= conv_endian(info
.freeswap
);
1047 info
.procs
= conv_endian16(info
.procs
);
1048 #if LINUX_VERSION_CODE >= 0x20400
1049 info
.totalhigh
= conv_endian(info
.totalhigh
);
1050 info
.freehigh
= conv_endian(info
.freehigh
);
1051 info
.mem_unit
= conv_endian(info
.mem_unit
);
1053 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &info
, sizeof(info
))
1065 result
= ipc(arg1
, arg2
, arg3
, arg4
,
1066 (void *) t2h_addr(cb
, &s
, arg5
), arg6
);
1073 result
= fsync(arg1
);
1078 /* utsname contains only arrays of char, so it is not necessary
1079 to translate endian. */
1080 result
= uname((struct utsname
*) t2h_addr(cb
, &s
, arg1
));
1088 result
= adjtimex(&buf
);
1094 translate_endian((void *) &buf
, sizeof(buf
));
1095 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &buf
, sizeof(buf
))
1105 result
= mprotect((void *) arg1
, arg2
, arg3
);
1110 result
= fchdir(arg1
);
1114 case __NR_setfsuid32
:
1116 result
= setfsuid(arg1
);
1120 case __NR_setfsgid32
:
1122 result
= setfsgid(arg1
);
1131 result
= _llseek(arg1
, arg2
, arg3
, &buf
, arg5
);
1137 translate_endian((void *) &buf
, sizeof(buf
));
1138 if ((s
.write_mem
) (cb
, &s
, t2h_addr(cb
, &s
, arg4
),
1139 (char *) &buf
, sizeof(buf
)) != sizeof(buf
))
1151 result
= getdents(arg1
, &dir
, arg3
);
1157 dir
.d_ino
= conv_endian(dir
.d_ino
);
1158 dir
.d_off
= conv_endian(dir
.d_off
);
1159 dir
.d_reclen
= conv_endian16(dir
.d_reclen
);
1160 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &dir
, sizeof(dir
))
1171 result
= flock(arg1
, arg2
);
1176 result
= msync((void *) arg1
, arg2
, arg3
);
1182 struct iovec vector
;
1184 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1185 translate_endian((void *) &vector
, sizeof(vector
));
1187 result
= readv(arg1
, &vector
, arg3
);
1194 struct iovec vector
;
1196 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1197 translate_endian((void *) &vector
, sizeof(vector
));
1199 result
= writev(arg1
, &vector
, arg3
);
1204 case __NR_fdatasync
:
1205 result
= fdatasync(arg1
);
1210 result
= mlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1215 result
= munlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1219 case __NR_nanosleep
:
1221 struct timespec req
, rem
;
1223 req
= *((struct timespec
*) t2h_addr(cb
, &s
, arg2
));
1224 translate_endian((void *) &req
, sizeof(req
));
1226 result
= nanosleep(&req
, &rem
);
1232 translate_endian((void *) &rem
, sizeof(rem
));
1233 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rem
, sizeof(rem
))
1242 case __NR_mremap
: /* FIXME */
1243 result
= (int) mremap((void *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
, arg4
);
1247 case __NR_getresuid32
:
1248 case __NR_getresuid
:
1250 uid_t ruid
, euid
, suid
;
1252 result
= getresuid(&ruid
, &euid
, &suid
);
1258 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = conv_endian(ruid
);
1259 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = conv_endian(euid
);
1260 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(suid
);
1268 ufds
= *((struct pollfd
*) t2h_addr(cb
, &s
, arg1
));
1269 ufds
.fd
= conv_endian(ufds
.fd
);
1270 ufds
.events
= conv_endian16(ufds
.events
);
1271 ufds
.revents
= conv_endian16(ufds
.revents
);
1273 result
= poll(&ufds
, arg2
, arg3
);
1278 case __NR_getresgid32
:
1279 case __NR_getresgid
:
1281 uid_t rgid
, egid
, sgid
;
1283 result
= getresgid(&rgid
, &egid
, &sgid
);
1289 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = conv_endian(rgid
);
1290 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = conv_endian(egid
);
1291 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(sgid
);
1296 result
= pread(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1301 result
= pwrite(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1307 result
= chown((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
1312 result
= (int) getcwd((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
1320 offset
= *((off_t
*) t2h_addr(cb
, &s
, arg3
));
1321 offset
= conv_endian(offset
);
1323 result
= sendfile(arg1
, arg2
, &offset
, arg3
);
1329 *((off_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(offset
);
1340 m32rbf_h_gr_set (current_cpu
, 0, -errcode
);
1342 m32rbf_h_gr_set (current_cpu
, 0, result
);
1346 case TRAP_BREAKPOINT
:
1347 sim_engine_halt (sd
, current_cpu
, NULL
, pc
,
1348 sim_stopped
, SIM_SIGTRAP
);
1351 case TRAP_FLUSH_CACHE
:
1357 /* Use cr5 as EVB (EIT Vector Base) register. */
1358 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
1363 /* Fake an "rte" insn. */
1364 /* FIXME: Should duplicate all of rte processing. */
1365 return (pc
& -4) + 4;