]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/m32r/traps-linux.c
1 /* m32r exception, interrupt, and trap (EIT) support
2 Copyright (C) 1998, 2003, 2007 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 2, or (at your option)
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 along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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 /* Read/write functions for system call interface. */
120 syscall_read_mem (host_callback
*cb
, struct cb_syscall
*sc
,
121 unsigned long taddr
, char *buf
, int bytes
)
123 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
124 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
126 return sim_core_read_buffer (sd
, cpu
, read_map
, buf
, taddr
, bytes
);
130 syscall_write_mem (host_callback
*cb
, struct cb_syscall
*sc
,
131 unsigned long taddr
, const char *buf
, int bytes
)
133 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
134 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
136 return sim_core_write_buffer (sd
, cpu
, write_map
, buf
, taddr
, bytes
);
139 /* Translate target's address to host's address. */
142 t2h_addr (host_callback
*cb
, struct cb_syscall
*sc
,
145 extern sim_core_trans_addr (SIM_DESC
, sim_cpu
*, unsigned, address_word
);
147 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
148 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
153 return sim_core_trans_addr (sd
, cpu
, read_map
, taddr
);
157 conv_endian (unsigned int tvalue
)
160 unsigned int t1
, t2
, t3
, t4
;
162 if (CURRENT_HOST_BYTE_ORDER
== LITTLE_ENDIAN
)
164 t1
= tvalue
& 0xff000000;
165 t2
= tvalue
& 0x00ff0000;
166 t3
= tvalue
& 0x0000ff00;
167 t4
= tvalue
& 0x000000ff;
180 static unsigned short
181 conv_endian16 (unsigned short tvalue
)
183 unsigned short hvalue
;
184 unsigned short t1
, t2
;
186 if (CURRENT_HOST_BYTE_ORDER
== LITTLE_ENDIAN
)
188 t1
= tvalue
& 0xff00;
189 t2
= tvalue
& 0x00ff;
201 translate_endian(void *addr
, size_t size
)
203 unsigned int *p
= (unsigned int *) addr
;
206 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
207 *p
= conv_endian(*p
);
210 *((unsigned short *) p
) = conv_endian16(*((unsigned short *) p
));
214 The result is the pc address to continue at.
215 Preprocessing like saving the various registers has already been done. */
218 m32r_trap (SIM_CPU
*current_cpu
, PCADDR pc
, int num
)
220 SIM_DESC sd
= CPU_STATE (current_cpu
);
221 host_callback
*cb
= STATE_CALLBACK (sd
);
223 #ifdef SIM_HAVE_BREAKPOINTS
224 /* Check for breakpoints "owned" by the simulator first, regardless
226 if (num
== TRAP_BREAKPOINT
)
228 /* First try sim-break.c. If it's a breakpoint the simulator "owns"
229 it doesn't return. Otherwise it returns and let's us try. */
230 sim_handle_breakpoint (sd
, current_cpu
, pc
);
237 case TRAP_ELF_SYSCALL
:
241 CB_SYSCALL_INIT (&s
);
242 s
.func
= m32rbf_h_gr_get (current_cpu
, 0);
243 s
.arg1
= m32rbf_h_gr_get (current_cpu
, 1);
244 s
.arg2
= m32rbf_h_gr_get (current_cpu
, 2);
245 s
.arg3
= m32rbf_h_gr_get (current_cpu
, 3);
247 if (s
.func
== TARGET_SYS_exit
)
249 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, s
.arg1
);
253 s
.p2
= (PTR
) current_cpu
;
254 s
.read_mem
= syscall_read_mem
;
255 s
.write_mem
= syscall_write_mem
;
257 m32rbf_h_gr_set (current_cpu
, 2, s
.errcode
);
258 m32rbf_h_gr_set (current_cpu
, 0, s
.result
);
259 m32rbf_h_gr_set (current_cpu
, 1, s
.result2
);
263 case TRAP_LINUX_SYSCALL
:
266 unsigned int func
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
;
267 int result
, result2
, errcode
;
269 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
271 /* The new pc is the trap vector entry.
272 We assume there's a branch there to some handler.
273 Use cr5 as EVB (EIT Vector Base) register. */
274 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
278 func
= m32rbf_h_gr_get (current_cpu
, 7);
279 arg1
= m32rbf_h_gr_get (current_cpu
, 0);
280 arg2
= m32rbf_h_gr_get (current_cpu
, 1);
281 arg3
= m32rbf_h_gr_get (current_cpu
, 2);
282 arg4
= m32rbf_h_gr_get (current_cpu
, 3);
283 arg5
= m32rbf_h_gr_get (current_cpu
, 4);
284 arg6
= m32rbf_h_gr_get (current_cpu
, 5);
285 arg7
= m32rbf_h_gr_get (current_cpu
, 6);
287 CB_SYSCALL_INIT (&s
);
294 s
.p2
= (PTR
) current_cpu
;
295 s
.read_mem
= syscall_read_mem
;
296 s
.write_mem
= syscall_write_mem
;
305 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, arg1
);
309 result
= read(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
314 result
= write(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
319 result
= open((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
324 result
= close(arg1
);
329 result
= creat((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
334 result
= link((char *) t2h_addr(cb
, &s
, arg1
),
335 (char *) t2h_addr(cb
, &s
, arg2
));
340 result
= unlink((char *) t2h_addr(cb
, &s
, arg1
));
345 result
= chdir((char *) t2h_addr(cb
, &s
, arg1
));
355 result
= (int) time(NULL
);
360 result
= (int) time(&t
);
366 translate_endian((void *) &t
, sizeof(t
));
367 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
)) != sizeof(t
))
377 result
= mknod((char *) t2h_addr(cb
, &s
, arg1
),
378 (mode_t
) arg2
, (dev_t
) arg3
);
383 result
= chmod((char *) t2h_addr(cb
, &s
, arg1
), (mode_t
) arg2
);
389 result
= lchown((char *) t2h_addr(cb
, &s
, arg1
),
390 (uid_t
) arg2
, (gid_t
) arg3
);
395 result
= (int) lseek(arg1
, (off_t
) arg2
, arg3
);
416 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), NULL
);
421 buf
= *((struct utimbuf
*) t2h_addr(cb
, &s
, arg2
));
422 translate_endian((void *) &buf
, sizeof(buf
));
423 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), &buf
);
430 result
= access((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
444 t
.time
= conv_endian(t
.time
);
445 t
.millitm
= conv_endian16(t
.millitm
);
446 t
.timezone
= conv_endian16(t
.timezone
);
447 t
.dstflag
= conv_endian16(t
.dstflag
);
448 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
))
462 result
= rename((char *) t2h_addr(cb
, &s
, arg1
),
463 (char *) t2h_addr(cb
, &s
, arg2
));
468 result
= mkdir((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
473 result
= rmdir((char *) t2h_addr(cb
, &s
, arg1
));
483 result
= brk((void *) arg1
);
507 result
= ioctl(arg1
, arg2
, arg3
);
512 result
= fcntl(arg1
, arg2
, arg3
);
517 result
= dup2(arg1
, arg2
);
535 result
= getrlimit(arg1
, &rlim
);
541 translate_endian((void *) &rlim
, sizeof(rlim
));
542 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rlim
, sizeof(rlim
))
555 result
= getrusage(arg1
, &usage
);
561 translate_endian((void *) &usage
, sizeof(usage
));
562 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &usage
, sizeof(usage
))
571 case __NR_gettimeofday
:
576 result
= gettimeofday(&tv
, &tz
);
582 translate_endian((void *) &tv
, sizeof(tv
));
583 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &tv
, sizeof(tv
))
590 translate_endian((void *) &tz
, sizeof(tz
));
591 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &tz
, sizeof(tz
))
600 case __NR_getgroups32
:
606 list
= (gid_t
*) malloc(arg1
* sizeof(gid_t
));
608 result
= getgroups(arg1
, list
);
614 translate_endian((void *) list
, arg1
* sizeof(gid_t
));
616 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) list
, arg1
* sizeof(gid_t
))
617 != arg1
* sizeof(gid_t
))
637 struct timeval
*ttimeoutp
;
638 struct timeval timeout
;
642 treadfdsp
= (fd_set
*) arg2
;
643 if (treadfdsp
!= NULL
)
645 readfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) treadfdsp
));
646 translate_endian((void *) &readfds
, sizeof(readfds
));
647 hreadfdsp
= &readfds
;
652 twritefdsp
= (fd_set
*) arg3
;
653 if (twritefdsp
!= NULL
)
655 writefds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) twritefdsp
));
656 translate_endian((void *) &writefds
, sizeof(writefds
));
657 hwritefdsp
= &writefds
;
662 texceptfdsp
= (fd_set
*) arg4
;
663 if (texceptfdsp
!= NULL
)
665 exceptfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) texceptfdsp
));
666 translate_endian((void *) &exceptfds
, sizeof(exceptfds
));
667 hexceptfdsp
= &exceptfds
;
672 ttimeoutp
= (struct timeval
*) arg5
;
673 timeout
= *((struct timeval
*) t2h_addr(cb
, &s
, (unsigned int) ttimeoutp
));
674 translate_endian((void *) &timeout
, sizeof(timeout
));
676 result
= select(n
, hreadfdsp
, hwritefdsp
, hexceptfdsp
, &timeout
);
682 if (treadfdsp
!= NULL
)
684 translate_endian((void *) &readfds
, sizeof(readfds
));
685 if ((s
.write_mem
) (cb
, &s
, (unsigned long) treadfdsp
,
686 (char *) &readfds
, sizeof(readfds
)) != sizeof(readfds
))
693 if (twritefdsp
!= NULL
)
695 translate_endian((void *) &writefds
, sizeof(writefds
));
696 if ((s
.write_mem
) (cb
, &s
, (unsigned long) twritefdsp
,
697 (char *) &writefds
, sizeof(writefds
)) != sizeof(writefds
))
704 if (texceptfdsp
!= NULL
)
706 translate_endian((void *) &exceptfds
, sizeof(exceptfds
));
707 if ((s
.write_mem
) (cb
, &s
, (unsigned long) texceptfdsp
,
708 (char *) &exceptfds
, sizeof(exceptfds
)) != sizeof(exceptfds
))
715 translate_endian((void *) &timeout
, sizeof(timeout
));
716 if ((s
.write_mem
) (cb
, &s
, (unsigned long) ttimeoutp
,
717 (char *) &timeout
, sizeof(timeout
)) != sizeof(timeout
))
726 result
= symlink((char *) t2h_addr(cb
, &s
, arg1
),
727 (char *) t2h_addr(cb
, &s
, arg2
));
732 result
= readlink((char *) t2h_addr(cb
, &s
, arg1
),
733 (char *) t2h_addr(cb
, &s
, arg2
),
739 result
= (int) readdir((DIR *) t2h_addr(cb
, &s
, arg1
));
746 result
= (int) mmap((void *) t2h_addr(cb
, &s
, arg1
),
747 arg2
, arg3
, arg4
, arg5
, arg6
);
752 sim_core_attach (sd
, NULL
,
753 0, access_read_write_exec
, 0,
754 result
, arg2
, 0, NULL
, NULL
);
763 int prot
, flags
, fildes
;
766 addr
= (void *) t2h_addr(cb
, &s
, arg1
);
773 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
778 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
779 sim_core_attach (sd
, NULL
,
780 0, access_read_write_exec
, 0,
781 result
, len
, 0, NULL
, NULL
);
790 int prot
, flags
, fildes
;
793 addr
= *((void **) t2h_addr(cb
, &s
, arg1
));
794 len
= *((size_t *) t2h_addr(cb
, &s
, arg1
+ 4));
795 prot
= *((int *) t2h_addr(cb
, &s
, arg1
+ 8));
796 flags
= *((int *) t2h_addr(cb
, &s
, arg1
+ 12));
797 fildes
= *((int *) t2h_addr(cb
, &s
, arg1
+ 16));
798 off
= *((off_t
*) t2h_addr(cb
, &s
, arg1
+ 20));
800 addr
= (void *) conv_endian((unsigned int) addr
);
801 len
= conv_endian(len
);
802 prot
= conv_endian(prot
);
803 flags
= conv_endian(flags
);
804 fildes
= conv_endian(fildes
);
805 off
= conv_endian(off
);
807 //addr = (void *) t2h_addr(cb, &s, (unsigned int) addr);
808 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
815 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
816 sim_core_attach (sd
, NULL
,
817 0, access_read_write_exec
, 0,
818 result
, len
, 0, NULL
, NULL
);
825 result
= munmap((void *)arg1
, arg2
);
829 sim_core_detach (sd
, NULL
, 0, arg2
, result
);
835 result
= truncate((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
840 result
= ftruncate(arg1
, arg2
);
845 result
= fchmod(arg1
, arg2
);
851 result
= fchown(arg1
, arg2
, arg3
);
857 struct statfs statbuf
;
859 result
= statfs((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
865 translate_endian((void *) &statbuf
, sizeof(statbuf
));
866 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
877 struct statfs statbuf
;
879 result
= fstatfs(arg1
, &statbuf
);
885 translate_endian((void *) &statbuf
, sizeof(statbuf
));
886 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
896 result
= syslog(arg1
, (char *) t2h_addr(cb
, &s
, arg2
));
902 struct itimerval value
, ovalue
;
904 value
= *((struct itimerval
*) t2h_addr(cb
, &s
, arg2
));
905 translate_endian((void *) &value
, sizeof(value
));
909 result
= setitimer(arg1
, &value
, NULL
);
914 result
= setitimer(arg1
, &value
, &ovalue
);
920 translate_endian((void *) &ovalue
, sizeof(ovalue
));
921 if ((s
.write_mem
) (cb
, &s
, arg3
, (char *) &ovalue
, sizeof(ovalue
))
933 struct itimerval value
;
935 result
= getitimer(arg1
, &value
);
941 translate_endian((void *) &value
, sizeof(value
));
942 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &value
, sizeof(value
))
957 result
= stat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
962 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
963 buf
= xmalloc (buflen
);
964 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
966 /* The translation failed. This is due to an internal
967 host program error, not the target's fault. */
973 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
990 result
= lstat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
995 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
996 buf
= xmalloc (buflen
);
997 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
999 /* The translation failed. This is due to an internal
1000 host program error, not the target's fault. */
1006 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
1021 struct stat statbuf
;
1023 result
= fstat(arg1
, &statbuf
);
1028 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
1029 buf
= xmalloc (buflen
);
1030 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
1032 /* The translation failed. This is due to an internal
1033 host program error, not the target's fault. */
1039 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
1052 struct sysinfo info
;
1054 result
= sysinfo(&info
);
1060 info
.uptime
= conv_endian(info
.uptime
);
1061 info
.loads
[0] = conv_endian(info
.loads
[0]);
1062 info
.loads
[1] = conv_endian(info
.loads
[1]);
1063 info
.loads
[2] = conv_endian(info
.loads
[2]);
1064 info
.totalram
= conv_endian(info
.totalram
);
1065 info
.freeram
= conv_endian(info
.freeram
);
1066 info
.sharedram
= conv_endian(info
.sharedram
);
1067 info
.bufferram
= conv_endian(info
.bufferram
);
1068 info
.totalswap
= conv_endian(info
.totalswap
);
1069 info
.freeswap
= conv_endian(info
.freeswap
);
1070 info
.procs
= conv_endian16(info
.procs
);
1071 #if LINUX_VERSION_CODE >= 0x20400
1072 info
.totalhigh
= conv_endian(info
.totalhigh
);
1073 info
.freehigh
= conv_endian(info
.freehigh
);
1074 info
.mem_unit
= conv_endian(info
.mem_unit
);
1076 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &info
, sizeof(info
))
1088 result
= ipc(arg1
, arg2
, arg3
, arg4
,
1089 (void *) t2h_addr(cb
, &s
, arg5
), arg6
);
1096 result
= fsync(arg1
);
1101 /* utsname contains only arrays of char, so it is not necessary
1102 to translate endian. */
1103 result
= uname((struct utsname
*) t2h_addr(cb
, &s
, arg1
));
1111 result
= adjtimex(&buf
);
1117 translate_endian((void *) &buf
, sizeof(buf
));
1118 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &buf
, sizeof(buf
))
1128 result
= mprotect((void *) arg1
, arg2
, arg3
);
1133 result
= fchdir(arg1
);
1137 case __NR_setfsuid32
:
1139 result
= setfsuid(arg1
);
1143 case __NR_setfsgid32
:
1145 result
= setfsgid(arg1
);
1154 result
= _llseek(arg1
, arg2
, arg3
, &buf
, arg5
);
1160 translate_endian((void *) &buf
, sizeof(buf
));
1161 if ((s
.write_mem
) (cb
, &s
, t2h_addr(cb
, &s
, arg4
),
1162 (char *) &buf
, sizeof(buf
)) != sizeof(buf
))
1174 result
= getdents(arg1
, &dir
, arg3
);
1180 dir
.d_ino
= conv_endian(dir
.d_ino
);
1181 dir
.d_off
= conv_endian(dir
.d_off
);
1182 dir
.d_reclen
= conv_endian16(dir
.d_reclen
);
1183 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &dir
, sizeof(dir
))
1194 result
= flock(arg1
, arg2
);
1199 result
= msync((void *) arg1
, arg2
, arg3
);
1205 struct iovec vector
;
1207 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1208 translate_endian((void *) &vector
, sizeof(vector
));
1210 result
= readv(arg1
, &vector
, arg3
);
1217 struct iovec vector
;
1219 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1220 translate_endian((void *) &vector
, sizeof(vector
));
1222 result
= writev(arg1
, &vector
, arg3
);
1227 case __NR_fdatasync
:
1228 result
= fdatasync(arg1
);
1233 result
= mlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1238 result
= munlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1242 case __NR_nanosleep
:
1244 struct timespec req
, rem
;
1246 req
= *((struct timespec
*) t2h_addr(cb
, &s
, arg2
));
1247 translate_endian((void *) &req
, sizeof(req
));
1249 result
= nanosleep(&req
, &rem
);
1255 translate_endian((void *) &rem
, sizeof(rem
));
1256 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rem
, sizeof(rem
))
1265 case __NR_mremap
: /* FIXME */
1266 result
= (int) mremap((void *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
, arg4
);
1270 case __NR_getresuid32
:
1271 case __NR_getresuid
:
1273 uid_t ruid
, euid
, suid
;
1275 result
= getresuid(&ruid
, &euid
, &suid
);
1281 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = conv_endian(ruid
);
1282 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = conv_endian(euid
);
1283 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(suid
);
1291 ufds
= *((struct pollfd
*) t2h_addr(cb
, &s
, arg1
));
1292 ufds
.fd
= conv_endian(ufds
.fd
);
1293 ufds
.events
= conv_endian16(ufds
.events
);
1294 ufds
.revents
= conv_endian16(ufds
.revents
);
1296 result
= poll(&ufds
, arg2
, arg3
);
1301 case __NR_getresgid32
:
1302 case __NR_getresgid
:
1304 uid_t rgid
, egid
, sgid
;
1306 result
= getresgid(&rgid
, &egid
, &sgid
);
1312 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = conv_endian(rgid
);
1313 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = conv_endian(egid
);
1314 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(sgid
);
1319 result
= pread(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1324 result
= pwrite(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1330 result
= chown((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
1335 result
= (int) getcwd((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
1343 offset
= *((off_t
*) t2h_addr(cb
, &s
, arg3
));
1344 offset
= conv_endian(offset
);
1346 result
= sendfile(arg1
, arg2
, &offset
, arg3
);
1352 *((off_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(offset
);
1363 m32rbf_h_gr_set (current_cpu
, 0, -errcode
);
1365 m32rbf_h_gr_set (current_cpu
, 0, result
);
1369 case TRAP_BREAKPOINT
:
1370 sim_engine_halt (sd
, current_cpu
, NULL
, pc
,
1371 sim_stopped
, SIM_SIGTRAP
);
1374 case TRAP_FLUSH_CACHE
:
1380 /* Use cr5 as EVB (EIT Vector Base) register. */
1381 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
1386 /* Fake an "rte" insn. */
1387 /* FIXME: Should duplicate all of rte processing. */
1388 return (pc
& -4) + 4;