1 /* m32r exception, interrupt, and trap (EIT) support
2 Copyright (C) 1998, 2003, 2007, 2008, 2009 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/>. */
22 #include "targ-vals.h"
31 #include <sys/resource.h>
32 #include <sys/sysinfo.h>
35 #include <sys/timeb.h>
36 #include <sys/timex.h>
37 #include <sys/types.h>
39 #include <sys/utsname.h>
41 #include <linux/sysctl.h>
42 #include <linux/types.h>
43 #include <linux/unistd.h>
45 #define TRAP_ELF_SYSCALL 0
46 #define TRAP_LINUX_SYSCALL 2
47 #define TRAP_FLUSH_CACHE 12
49 /* The semantic code invokes this for invalid (unrecognized) instructions. */
52 sim_engine_invalid_insn (SIM_CPU
*current_cpu
, IADDR cia
, SEM_PC vpc
)
54 SIM_DESC sd
= CPU_STATE (current_cpu
);
57 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
59 h_bsm_set (current_cpu
, h_sm_get (current_cpu
));
60 h_bie_set (current_cpu
, h_ie_get (current_cpu
));
61 h_bcond_set (current_cpu
, h_cond_get (current_cpu
));
63 h_ie_set (current_cpu
, 0);
64 h_cond_set (current_cpu
, 0);
66 h_bpc_set (current_cpu
, cia
);
68 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
73 sim_engine_halt (sd
, current_cpu
, NULL
, cia
, sim_stopped
, SIM_SIGILL
);
77 /* Process an address exception. */
80 m32r_core_signal (SIM_DESC sd
, SIM_CPU
*current_cpu
, sim_cia cia
,
81 unsigned int map
, int nr_bytes
, address_word addr
,
82 transfer_type transfer
, sim_core_signals sig
)
84 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
86 m32rbf_h_cr_set (current_cpu
, H_CR_BBPC
,
87 m32rbf_h_cr_get (current_cpu
, H_CR_BPC
));
88 if (MACH_NUM (CPU_MACH (current_cpu
)) == MACH_M32R
)
90 m32rbf_h_bpsw_set (current_cpu
, m32rbf_h_psw_get (current_cpu
));
92 m32rbf_h_psw_set (current_cpu
, m32rbf_h_psw_get (current_cpu
) & 0x80);
94 else if (MACH_NUM (CPU_MACH (current_cpu
)) == MACH_M32RX
)
96 m32rxf_h_bpsw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
));
98 m32rxf_h_psw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
) & 0x80);
102 m32r2f_h_bpsw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
));
104 m32r2f_h_psw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
) & 0x80);
106 m32rbf_h_cr_set (current_cpu
, H_CR_BPC
, cia
);
108 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
112 sim_core_signal (sd
, current_cpu
, cia
, map
, nr_bytes
, addr
,
116 /* Read/write functions for system call interface. */
119 syscall_read_mem (host_callback
*cb
, struct cb_syscall
*sc
,
120 unsigned long taddr
, char *buf
, int bytes
)
122 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
123 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
125 return sim_core_read_buffer (sd
, cpu
, read_map
, buf
, taddr
, bytes
);
129 syscall_write_mem (host_callback
*cb
, struct cb_syscall
*sc
,
130 unsigned long taddr
, const char *buf
, int bytes
)
132 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
133 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
135 return sim_core_write_buffer (sd
, cpu
, write_map
, buf
, taddr
, bytes
);
138 /* Translate target's address to host's address. */
141 t2h_addr (host_callback
*cb
, struct cb_syscall
*sc
,
144 extern sim_core_trans_addr (SIM_DESC
, sim_cpu
*, unsigned, address_word
);
146 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
147 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
152 return sim_core_trans_addr (sd
, cpu
, read_map
, taddr
);
156 conv_endian (unsigned int tvalue
)
159 unsigned int t1
, t2
, t3
, t4
;
161 if (CURRENT_HOST_BYTE_ORDER
== LITTLE_ENDIAN
)
163 t1
= tvalue
& 0xff000000;
164 t2
= tvalue
& 0x00ff0000;
165 t3
= tvalue
& 0x0000ff00;
166 t4
= tvalue
& 0x000000ff;
179 static unsigned short
180 conv_endian16 (unsigned short tvalue
)
182 unsigned short hvalue
;
183 unsigned short t1
, t2
;
185 if (CURRENT_HOST_BYTE_ORDER
== LITTLE_ENDIAN
)
187 t1
= tvalue
& 0xff00;
188 t2
= tvalue
& 0x00ff;
200 translate_endian(void *addr
, size_t size
)
202 unsigned int *p
= (unsigned int *) addr
;
205 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
206 *p
= conv_endian(*p
);
209 *((unsigned short *) p
) = conv_endian16(*((unsigned short *) p
));
213 The result is the pc address to continue at.
214 Preprocessing like saving the various registers has already been done. */
217 m32r_trap (SIM_CPU
*current_cpu
, PCADDR pc
, int num
)
219 SIM_DESC sd
= CPU_STATE (current_cpu
);
220 host_callback
*cb
= STATE_CALLBACK (sd
);
222 #ifdef SIM_HAVE_BREAKPOINTS
223 /* Check for breakpoints "owned" by the simulator first, regardless
225 if (num
== TRAP_BREAKPOINT
)
227 /* First try sim-break.c. If it's a breakpoint the simulator "owns"
228 it doesn't return. Otherwise it returns and let's us try. */
229 sim_handle_breakpoint (sd
, current_cpu
, pc
);
236 case TRAP_ELF_SYSCALL
:
240 CB_SYSCALL_INIT (&s
);
241 s
.func
= m32rbf_h_gr_get (current_cpu
, 0);
242 s
.arg1
= m32rbf_h_gr_get (current_cpu
, 1);
243 s
.arg2
= m32rbf_h_gr_get (current_cpu
, 2);
244 s
.arg3
= m32rbf_h_gr_get (current_cpu
, 3);
246 if (s
.func
== TARGET_SYS_exit
)
248 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, s
.arg1
);
252 s
.p2
= (PTR
) current_cpu
;
253 s
.read_mem
= syscall_read_mem
;
254 s
.write_mem
= syscall_write_mem
;
256 m32rbf_h_gr_set (current_cpu
, 2, s
.errcode
);
257 m32rbf_h_gr_set (current_cpu
, 0, s
.result
);
258 m32rbf_h_gr_set (current_cpu
, 1, s
.result2
);
262 case TRAP_LINUX_SYSCALL
:
265 unsigned int func
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
;
266 int result
, result2
, errcode
;
268 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
270 /* The new pc is the trap vector entry.
271 We assume there's a branch there to some handler.
272 Use cr5 as EVB (EIT Vector Base) register. */
273 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
277 func
= m32rbf_h_gr_get (current_cpu
, 7);
278 arg1
= m32rbf_h_gr_get (current_cpu
, 0);
279 arg2
= m32rbf_h_gr_get (current_cpu
, 1);
280 arg3
= m32rbf_h_gr_get (current_cpu
, 2);
281 arg4
= m32rbf_h_gr_get (current_cpu
, 3);
282 arg5
= m32rbf_h_gr_get (current_cpu
, 4);
283 arg6
= m32rbf_h_gr_get (current_cpu
, 5);
284 arg7
= m32rbf_h_gr_get (current_cpu
, 6);
286 CB_SYSCALL_INIT (&s
);
293 s
.p2
= (PTR
) current_cpu
;
294 s
.read_mem
= syscall_read_mem
;
295 s
.write_mem
= syscall_write_mem
;
304 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, arg1
);
308 result
= read(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
313 result
= write(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
318 result
= open((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
323 result
= close(arg1
);
328 result
= creat((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
333 result
= link((char *) t2h_addr(cb
, &s
, arg1
),
334 (char *) t2h_addr(cb
, &s
, arg2
));
339 result
= unlink((char *) t2h_addr(cb
, &s
, arg1
));
344 result
= chdir((char *) t2h_addr(cb
, &s
, arg1
));
354 result
= (int) time(NULL
);
359 result
= (int) time(&t
);
365 translate_endian((void *) &t
, sizeof(t
));
366 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
)) != sizeof(t
))
376 result
= mknod((char *) t2h_addr(cb
, &s
, arg1
),
377 (mode_t
) arg2
, (dev_t
) arg3
);
382 result
= chmod((char *) t2h_addr(cb
, &s
, arg1
), (mode_t
) arg2
);
388 result
= lchown((char *) t2h_addr(cb
, &s
, arg1
),
389 (uid_t
) arg2
, (gid_t
) arg3
);
394 result
= (int) lseek(arg1
, (off_t
) arg2
, arg3
);
415 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), NULL
);
420 buf
= *((struct utimbuf
*) t2h_addr(cb
, &s
, arg2
));
421 translate_endian((void *) &buf
, sizeof(buf
));
422 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), &buf
);
429 result
= access((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
443 t
.time
= conv_endian(t
.time
);
444 t
.millitm
= conv_endian16(t
.millitm
);
445 t
.timezone
= conv_endian16(t
.timezone
);
446 t
.dstflag
= conv_endian16(t
.dstflag
);
447 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
))
461 result
= rename((char *) t2h_addr(cb
, &s
, arg1
),
462 (char *) t2h_addr(cb
, &s
, arg2
));
467 result
= mkdir((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
472 result
= rmdir((char *) t2h_addr(cb
, &s
, arg1
));
482 result
= brk((void *) arg1
);
506 result
= ioctl(arg1
, arg2
, arg3
);
511 result
= fcntl(arg1
, arg2
, arg3
);
516 result
= dup2(arg1
, arg2
);
534 result
= getrlimit(arg1
, &rlim
);
540 translate_endian((void *) &rlim
, sizeof(rlim
));
541 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rlim
, sizeof(rlim
))
554 result
= getrusage(arg1
, &usage
);
560 translate_endian((void *) &usage
, sizeof(usage
));
561 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &usage
, sizeof(usage
))
570 case __NR_gettimeofday
:
575 result
= gettimeofday(&tv
, &tz
);
581 translate_endian((void *) &tv
, sizeof(tv
));
582 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &tv
, sizeof(tv
))
589 translate_endian((void *) &tz
, sizeof(tz
));
590 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &tz
, sizeof(tz
))
599 case __NR_getgroups32
:
605 list
= (gid_t
*) malloc(arg1
* sizeof(gid_t
));
607 result
= getgroups(arg1
, list
);
613 translate_endian((void *) list
, arg1
* sizeof(gid_t
));
615 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) list
, arg1
* sizeof(gid_t
))
616 != arg1
* sizeof(gid_t
))
636 struct timeval
*ttimeoutp
;
637 struct timeval timeout
;
641 treadfdsp
= (fd_set
*) arg2
;
642 if (treadfdsp
!= NULL
)
644 readfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) treadfdsp
));
645 translate_endian((void *) &readfds
, sizeof(readfds
));
646 hreadfdsp
= &readfds
;
651 twritefdsp
= (fd_set
*) arg3
;
652 if (twritefdsp
!= NULL
)
654 writefds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) twritefdsp
));
655 translate_endian((void *) &writefds
, sizeof(writefds
));
656 hwritefdsp
= &writefds
;
661 texceptfdsp
= (fd_set
*) arg4
;
662 if (texceptfdsp
!= NULL
)
664 exceptfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) texceptfdsp
));
665 translate_endian((void *) &exceptfds
, sizeof(exceptfds
));
666 hexceptfdsp
= &exceptfds
;
671 ttimeoutp
= (struct timeval
*) arg5
;
672 timeout
= *((struct timeval
*) t2h_addr(cb
, &s
, (unsigned int) ttimeoutp
));
673 translate_endian((void *) &timeout
, sizeof(timeout
));
675 result
= select(n
, hreadfdsp
, hwritefdsp
, hexceptfdsp
, &timeout
);
681 if (treadfdsp
!= NULL
)
683 translate_endian((void *) &readfds
, sizeof(readfds
));
684 if ((s
.write_mem
) (cb
, &s
, (unsigned long) treadfdsp
,
685 (char *) &readfds
, sizeof(readfds
)) != sizeof(readfds
))
692 if (twritefdsp
!= NULL
)
694 translate_endian((void *) &writefds
, sizeof(writefds
));
695 if ((s
.write_mem
) (cb
, &s
, (unsigned long) twritefdsp
,
696 (char *) &writefds
, sizeof(writefds
)) != sizeof(writefds
))
703 if (texceptfdsp
!= NULL
)
705 translate_endian((void *) &exceptfds
, sizeof(exceptfds
));
706 if ((s
.write_mem
) (cb
, &s
, (unsigned long) texceptfdsp
,
707 (char *) &exceptfds
, sizeof(exceptfds
)) != sizeof(exceptfds
))
714 translate_endian((void *) &timeout
, sizeof(timeout
));
715 if ((s
.write_mem
) (cb
, &s
, (unsigned long) ttimeoutp
,
716 (char *) &timeout
, sizeof(timeout
)) != sizeof(timeout
))
725 result
= symlink((char *) t2h_addr(cb
, &s
, arg1
),
726 (char *) t2h_addr(cb
, &s
, arg2
));
731 result
= readlink((char *) t2h_addr(cb
, &s
, arg1
),
732 (char *) t2h_addr(cb
, &s
, arg2
),
738 result
= (int) readdir((DIR *) t2h_addr(cb
, &s
, arg1
));
745 result
= (int) mmap((void *) t2h_addr(cb
, &s
, arg1
),
746 arg2
, arg3
, arg4
, arg5
, arg6
);
751 sim_core_attach (sd
, NULL
,
752 0, access_read_write_exec
, 0,
753 result
, arg2
, 0, NULL
, NULL
);
762 int prot
, flags
, fildes
;
765 addr
= (void *) t2h_addr(cb
, &s
, arg1
);
772 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
777 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
778 sim_core_attach (sd
, NULL
,
779 0, access_read_write_exec
, 0,
780 result
, len
, 0, NULL
, NULL
);
789 int prot
, flags
, fildes
;
792 addr
= *((void **) t2h_addr(cb
, &s
, arg1
));
793 len
= *((size_t *) t2h_addr(cb
, &s
, arg1
+ 4));
794 prot
= *((int *) t2h_addr(cb
, &s
, arg1
+ 8));
795 flags
= *((int *) t2h_addr(cb
, &s
, arg1
+ 12));
796 fildes
= *((int *) t2h_addr(cb
, &s
, arg1
+ 16));
797 off
= *((off_t
*) t2h_addr(cb
, &s
, arg1
+ 20));
799 addr
= (void *) conv_endian((unsigned int) addr
);
800 len
= conv_endian(len
);
801 prot
= conv_endian(prot
);
802 flags
= conv_endian(flags
);
803 fildes
= conv_endian(fildes
);
804 off
= conv_endian(off
);
806 //addr = (void *) t2h_addr(cb, &s, (unsigned int) addr);
807 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
814 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
815 sim_core_attach (sd
, NULL
,
816 0, access_read_write_exec
, 0,
817 result
, len
, 0, NULL
, NULL
);
824 result
= munmap((void *)arg1
, arg2
);
828 sim_core_detach (sd
, NULL
, 0, arg2
, result
);
834 result
= truncate((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
839 result
= ftruncate(arg1
, arg2
);
844 result
= fchmod(arg1
, arg2
);
850 result
= fchown(arg1
, arg2
, arg3
);
856 struct statfs statbuf
;
858 result
= statfs((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
864 translate_endian((void *) &statbuf
, sizeof(statbuf
));
865 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
876 struct statfs statbuf
;
878 result
= fstatfs(arg1
, &statbuf
);
884 translate_endian((void *) &statbuf
, sizeof(statbuf
));
885 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
895 result
= syslog(arg1
, (char *) t2h_addr(cb
, &s
, arg2
));
901 struct itimerval value
, ovalue
;
903 value
= *((struct itimerval
*) t2h_addr(cb
, &s
, arg2
));
904 translate_endian((void *) &value
, sizeof(value
));
908 result
= setitimer(arg1
, &value
, NULL
);
913 result
= setitimer(arg1
, &value
, &ovalue
);
919 translate_endian((void *) &ovalue
, sizeof(ovalue
));
920 if ((s
.write_mem
) (cb
, &s
, arg3
, (char *) &ovalue
, sizeof(ovalue
))
932 struct itimerval value
;
934 result
= getitimer(arg1
, &value
);
940 translate_endian((void *) &value
, sizeof(value
));
941 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &value
, sizeof(value
))
956 result
= stat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
961 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
962 buf
= xmalloc (buflen
);
963 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
965 /* The translation failed. This is due to an internal
966 host program error, not the target's fault. */
972 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
989 result
= lstat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
994 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
995 buf
= xmalloc (buflen
);
996 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
998 /* The translation failed. This is due to an internal
999 host program error, not the target's fault. */
1005 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
1020 struct stat statbuf
;
1022 result
= fstat(arg1
, &statbuf
);
1027 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
1028 buf
= xmalloc (buflen
);
1029 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
1031 /* The translation failed. This is due to an internal
1032 host program error, not the target's fault. */
1038 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
1051 struct sysinfo info
;
1053 result
= sysinfo(&info
);
1059 info
.uptime
= conv_endian(info
.uptime
);
1060 info
.loads
[0] = conv_endian(info
.loads
[0]);
1061 info
.loads
[1] = conv_endian(info
.loads
[1]);
1062 info
.loads
[2] = conv_endian(info
.loads
[2]);
1063 info
.totalram
= conv_endian(info
.totalram
);
1064 info
.freeram
= conv_endian(info
.freeram
);
1065 info
.sharedram
= conv_endian(info
.sharedram
);
1066 info
.bufferram
= conv_endian(info
.bufferram
);
1067 info
.totalswap
= conv_endian(info
.totalswap
);
1068 info
.freeswap
= conv_endian(info
.freeswap
);
1069 info
.procs
= conv_endian16(info
.procs
);
1070 #if LINUX_VERSION_CODE >= 0x20400
1071 info
.totalhigh
= conv_endian(info
.totalhigh
);
1072 info
.freehigh
= conv_endian(info
.freehigh
);
1073 info
.mem_unit
= conv_endian(info
.mem_unit
);
1075 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &info
, sizeof(info
))
1087 result
= ipc(arg1
, arg2
, arg3
, arg4
,
1088 (void *) t2h_addr(cb
, &s
, arg5
), arg6
);
1095 result
= fsync(arg1
);
1100 /* utsname contains only arrays of char, so it is not necessary
1101 to translate endian. */
1102 result
= uname((struct utsname
*) t2h_addr(cb
, &s
, arg1
));
1110 result
= adjtimex(&buf
);
1116 translate_endian((void *) &buf
, sizeof(buf
));
1117 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &buf
, sizeof(buf
))
1127 result
= mprotect((void *) arg1
, arg2
, arg3
);
1132 result
= fchdir(arg1
);
1136 case __NR_setfsuid32
:
1138 result
= setfsuid(arg1
);
1142 case __NR_setfsgid32
:
1144 result
= setfsgid(arg1
);
1153 result
= _llseek(arg1
, arg2
, arg3
, &buf
, arg5
);
1159 translate_endian((void *) &buf
, sizeof(buf
));
1160 if ((s
.write_mem
) (cb
, &s
, t2h_addr(cb
, &s
, arg4
),
1161 (char *) &buf
, sizeof(buf
)) != sizeof(buf
))
1173 result
= getdents(arg1
, &dir
, arg3
);
1179 dir
.d_ino
= conv_endian(dir
.d_ino
);
1180 dir
.d_off
= conv_endian(dir
.d_off
);
1181 dir
.d_reclen
= conv_endian16(dir
.d_reclen
);
1182 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &dir
, sizeof(dir
))
1193 result
= flock(arg1
, arg2
);
1198 result
= msync((void *) arg1
, arg2
, arg3
);
1204 struct iovec vector
;
1206 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1207 translate_endian((void *) &vector
, sizeof(vector
));
1209 result
= readv(arg1
, &vector
, arg3
);
1216 struct iovec vector
;
1218 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1219 translate_endian((void *) &vector
, sizeof(vector
));
1221 result
= writev(arg1
, &vector
, arg3
);
1226 case __NR_fdatasync
:
1227 result
= fdatasync(arg1
);
1232 result
= mlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1237 result
= munlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1241 case __NR_nanosleep
:
1243 struct timespec req
, rem
;
1245 req
= *((struct timespec
*) t2h_addr(cb
, &s
, arg2
));
1246 translate_endian((void *) &req
, sizeof(req
));
1248 result
= nanosleep(&req
, &rem
);
1254 translate_endian((void *) &rem
, sizeof(rem
));
1255 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rem
, sizeof(rem
))
1264 case __NR_mremap
: /* FIXME */
1265 result
= (int) mremap((void *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
, arg4
);
1269 case __NR_getresuid32
:
1270 case __NR_getresuid
:
1272 uid_t ruid
, euid
, suid
;
1274 result
= getresuid(&ruid
, &euid
, &suid
);
1280 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = conv_endian(ruid
);
1281 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = conv_endian(euid
);
1282 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(suid
);
1290 ufds
= *((struct pollfd
*) t2h_addr(cb
, &s
, arg1
));
1291 ufds
.fd
= conv_endian(ufds
.fd
);
1292 ufds
.events
= conv_endian16(ufds
.events
);
1293 ufds
.revents
= conv_endian16(ufds
.revents
);
1295 result
= poll(&ufds
, arg2
, arg3
);
1300 case __NR_getresgid32
:
1301 case __NR_getresgid
:
1303 uid_t rgid
, egid
, sgid
;
1305 result
= getresgid(&rgid
, &egid
, &sgid
);
1311 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = conv_endian(rgid
);
1312 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = conv_endian(egid
);
1313 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(sgid
);
1318 result
= pread(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1323 result
= pwrite(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1329 result
= chown((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
1334 result
= (int) getcwd((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
1342 offset
= *((off_t
*) t2h_addr(cb
, &s
, arg3
));
1343 offset
= conv_endian(offset
);
1345 result
= sendfile(arg1
, arg2
, &offset
, arg3
);
1351 *((off_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(offset
);
1362 m32rbf_h_gr_set (current_cpu
, 0, -errcode
);
1364 m32rbf_h_gr_set (current_cpu
, 0, result
);
1368 case TRAP_BREAKPOINT
:
1369 sim_engine_halt (sd
, current_cpu
, NULL
, pc
,
1370 sim_stopped
, SIM_SIGTRAP
);
1373 case TRAP_FLUSH_CACHE
:
1379 /* Use cr5 as EVB (EIT Vector Base) register. */
1380 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
1385 /* Fake an "rte" insn. */
1386 /* FIXME: Should duplicate all of rte processing. */
1387 return (pc
& -4) + 4;