1 /* m32r exception, interrupt, and trap (EIT) support
2 Copyright (C) 1998-2021 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"
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_LINUX_SYSCALL 2
54 #define TRAP_FLUSH_CACHE 12
55 /* The semantic code invokes this for invalid (unrecognized) instructions. */
58 sim_engine_invalid_insn (SIM_CPU
*current_cpu
, IADDR cia
, SEM_PC pc
)
60 SIM_DESC sd
= CPU_STATE (current_cpu
);
63 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
65 h_bsm_set (current_cpu
, h_sm_get (current_cpu
));
66 h_bie_set (current_cpu
, h_ie_get (current_cpu
));
67 h_bcond_set (current_cpu
, h_cond_get (current_cpu
));
69 h_ie_set (current_cpu
, 0);
70 h_cond_set (current_cpu
, 0);
72 h_bpc_set (current_cpu
, cia
);
74 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
79 sim_engine_halt (sd
, current_cpu
, NULL
, cia
, sim_stopped
, SIM_SIGILL
);
84 /* Process an address exception. */
87 m32r_core_signal (SIM_DESC sd
, SIM_CPU
*current_cpu
, sim_cia cia
,
88 unsigned int map
, int nr_bytes
, address_word addr
,
89 transfer_type transfer
, sim_core_signals sig
)
91 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
93 m32rbf_h_cr_set (current_cpu
, H_CR_BBPC
,
94 m32rbf_h_cr_get (current_cpu
, H_CR_BPC
));
95 switch (MACH_NUM (CPU_MACH (current_cpu
)))
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);
103 m32rxf_h_bpsw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
));
104 /* sm not changed. */
105 m32rxf_h_psw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
) & 0x80);
108 m32r2f_h_bpsw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
));
109 /* sm not changed. */
110 m32r2f_h_psw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
) & 0x80);
116 m32rbf_h_cr_set (current_cpu
, H_CR_BPC
, cia
);
118 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
122 sim_core_signal (sd
, current_cpu
, cia
, map
, nr_bytes
, addr
,
126 /* Translate target's address to host's address. */
129 t2h_addr (host_callback
*cb
, struct cb_syscall
*sc
,
133 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
134 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
139 return sim_core_trans_addr (sd
, cpu
, read_map
, taddr
);
142 /* TODO: These functions are a big hack and assume that the host runtime has
143 type sizes and struct layouts that match the target. So the Linux emulation
144 probaly only really works in 32-bit runtimes. */
147 translate_endian_h2t (void *addr
, size_t size
)
149 unsigned int *p
= (unsigned int *) addr
;
152 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
156 *((unsigned short *) p
) = H2T_2 (*((unsigned short *) p
));
160 translate_endian_t2h (void *addr
, size_t size
)
162 unsigned int *p
= (unsigned int *) addr
;
165 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
169 *((unsigned short *) p
) = T2H_2 (*((unsigned short *) p
));
173 The result is the pc address to continue at.
174 Preprocessing like saving the various registers has already been done. */
177 m32r_trap (SIM_CPU
*current_cpu
, PCADDR pc
, int num
)
179 SIM_DESC sd
= CPU_STATE (current_cpu
);
180 host_callback
*cb
= STATE_CALLBACK (sd
);
182 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
189 long result
, result2
;
192 sim_syscall_multi (current_cpu
,
193 m32rbf_h_gr_get (current_cpu
, 0),
194 m32rbf_h_gr_get (current_cpu
, 1),
195 m32rbf_h_gr_get (current_cpu
, 2),
196 m32rbf_h_gr_get (current_cpu
, 3),
197 m32rbf_h_gr_get (current_cpu
, 4),
198 &result
, &result2
, &errcode
);
200 m32rbf_h_gr_set (current_cpu
, 2, errcode
);
201 m32rbf_h_gr_set (current_cpu
, 0, result
);
202 m32rbf_h_gr_set (current_cpu
, 1, result2
);
206 case TRAP_LINUX_SYSCALL
:
209 unsigned int func
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
;
210 int result
, result2
, errcode
;
212 if (STATE_ENVIRONMENT (sd
) != USER_ENVIRONMENT
)
215 func
= m32rbf_h_gr_get (current_cpu
, 7);
216 arg1
= m32rbf_h_gr_get (current_cpu
, 0);
217 arg2
= m32rbf_h_gr_get (current_cpu
, 1);
218 arg3
= m32rbf_h_gr_get (current_cpu
, 2);
219 arg4
= m32rbf_h_gr_get (current_cpu
, 3);
220 arg5
= m32rbf_h_gr_get (current_cpu
, 4);
221 arg6
= m32rbf_h_gr_get (current_cpu
, 5);
222 arg7
= m32rbf_h_gr_get (current_cpu
, 6);
224 CB_SYSCALL_INIT (&s
);
235 s
.p2
= (PTR
) current_cpu
;
236 s
.read_mem
= sim_syscall_read_mem
;
237 s
.write_mem
= sim_syscall_write_mem
;
245 case TARGET_LINUX_SYS_exit
:
246 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, arg1
);
249 case TARGET_LINUX_SYS_read
:
250 result
= read(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
254 case TARGET_LINUX_SYS_write
:
255 result
= write(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
259 case TARGET_LINUX_SYS_open
:
260 result
= open((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
264 case TARGET_LINUX_SYS_close
:
265 result
= close(arg1
);
269 case TARGET_LINUX_SYS_creat
:
270 result
= creat((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
274 case TARGET_LINUX_SYS_link
:
275 result
= link((char *) t2h_addr(cb
, &s
, arg1
),
276 (char *) t2h_addr(cb
, &s
, arg2
));
280 case TARGET_LINUX_SYS_unlink
:
281 result
= unlink((char *) t2h_addr(cb
, &s
, arg1
));
285 case TARGET_LINUX_SYS_chdir
:
286 result
= chdir((char *) t2h_addr(cb
, &s
, arg1
));
290 case TARGET_LINUX_SYS_time
:
296 result
= (int) time(NULL
);
301 result
= (int) time(&t
);
308 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
)) != sizeof(t
))
317 case TARGET_LINUX_SYS_mknod
:
318 result
= mknod((char *) t2h_addr(cb
, &s
, arg1
),
319 (mode_t
) arg2
, (dev_t
) arg3
);
323 case TARGET_LINUX_SYS_chmod
:
324 result
= chmod((char *) t2h_addr(cb
, &s
, arg1
), (mode_t
) arg2
);
328 case TARGET_LINUX_SYS_lchown32
:
329 case TARGET_LINUX_SYS_lchown
:
330 result
= lchown((char *) t2h_addr(cb
, &s
, arg1
),
331 (uid_t
) arg2
, (gid_t
) arg3
);
335 case TARGET_LINUX_SYS_lseek
:
336 result
= (int) lseek(arg1
, (off_t
) arg2
, arg3
);
340 case TARGET_LINUX_SYS_getpid
:
345 case TARGET_LINUX_SYS_getuid32
:
346 case TARGET_LINUX_SYS_getuid
:
351 case TARGET_LINUX_SYS_utime
:
357 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), NULL
);
362 buf
= *((struct utimbuf
*) t2h_addr(cb
, &s
, arg2
));
363 translate_endian_t2h (&buf
, sizeof(buf
));
364 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), &buf
);
370 case TARGET_LINUX_SYS_access
:
371 result
= access((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
375 case TARGET_LINUX_SYS_ftime
:
385 t
.time
= H2T_4 (t
.time
);
386 t
.millitm
= H2T_2 (t
.millitm
);
387 t
.timezone
= H2T_2 (t
.timezone
);
388 t
.dstflag
= H2T_2 (t
.dstflag
);
389 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
))
397 case TARGET_LINUX_SYS_sync
:
402 case TARGET_LINUX_SYS_rename
:
403 result
= rename((char *) t2h_addr(cb
, &s
, arg1
),
404 (char *) t2h_addr(cb
, &s
, arg2
));
408 case TARGET_LINUX_SYS_mkdir
:
409 result
= mkdir((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
413 case TARGET_LINUX_SYS_rmdir
:
414 result
= rmdir((char *) t2h_addr(cb
, &s
, arg1
));
418 case TARGET_LINUX_SYS_dup
:
423 case TARGET_LINUX_SYS_brk
:
424 result
= brk((void *) arg1
);
429 case TARGET_LINUX_SYS_getgid32
:
430 case TARGET_LINUX_SYS_getgid
:
435 case TARGET_LINUX_SYS_geteuid32
:
436 case TARGET_LINUX_SYS_geteuid
:
441 case TARGET_LINUX_SYS_getegid32
:
442 case TARGET_LINUX_SYS_getegid
:
447 case TARGET_LINUX_SYS_ioctl
:
448 result
= ioctl(arg1
, arg2
, arg3
);
452 case TARGET_LINUX_SYS_fcntl
:
453 result
= fcntl(arg1
, arg2
, arg3
);
457 case TARGET_LINUX_SYS_dup2
:
458 result
= dup2(arg1
, arg2
);
462 case TARGET_LINUX_SYS_getppid
:
467 case TARGET_LINUX_SYS_getpgrp
:
472 case TARGET_LINUX_SYS_getrlimit
:
476 result
= getrlimit(arg1
, &rlim
);
482 translate_endian_h2t (&rlim
, sizeof(rlim
));
483 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rlim
, sizeof(rlim
))
492 case TARGET_LINUX_SYS_getrusage
:
496 result
= getrusage(arg1
, &usage
);
502 translate_endian_h2t (&usage
, sizeof(usage
));
503 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &usage
, sizeof(usage
))
512 case TARGET_LINUX_SYS_gettimeofday
:
517 result
= gettimeofday(&tv
, &tz
);
523 translate_endian_h2t (&tv
, sizeof(tv
));
524 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &tv
, sizeof(tv
))
531 translate_endian_h2t (&tz
, sizeof(tz
));
532 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &tz
, sizeof(tz
))
541 case TARGET_LINUX_SYS_getgroups32
:
542 case TARGET_LINUX_SYS_getgroups
:
547 list
= (gid_t
*) malloc(arg1
* sizeof(gid_t
));
549 result
= getgroups(arg1
, list
);
555 translate_endian_h2t (list
, arg1
* sizeof(gid_t
));
557 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) list
, arg1
* sizeof(gid_t
))
558 != arg1
* sizeof(gid_t
))
566 case TARGET_LINUX_SYS_select
:
578 struct timeval
*ttimeoutp
;
579 struct timeval timeout
;
583 treadfdsp
= (fd_set
*) arg2
;
584 if (treadfdsp
!= NULL
)
586 readfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) treadfdsp
));
587 translate_endian_t2h (&readfds
, sizeof(readfds
));
588 hreadfdsp
= &readfds
;
593 twritefdsp
= (fd_set
*) arg3
;
594 if (twritefdsp
!= NULL
)
596 writefds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) twritefdsp
));
597 translate_endian_t2h (&writefds
, sizeof(writefds
));
598 hwritefdsp
= &writefds
;
603 texceptfdsp
= (fd_set
*) arg4
;
604 if (texceptfdsp
!= NULL
)
606 exceptfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) texceptfdsp
));
607 translate_endian_t2h (&exceptfds
, sizeof(exceptfds
));
608 hexceptfdsp
= &exceptfds
;
613 ttimeoutp
= (struct timeval
*) arg5
;
614 timeout
= *((struct timeval
*) t2h_addr(cb
, &s
, (unsigned int) ttimeoutp
));
615 translate_endian_t2h (&timeout
, sizeof(timeout
));
617 result
= select(n
, hreadfdsp
, hwritefdsp
, hexceptfdsp
, &timeout
);
623 if (treadfdsp
!= NULL
)
625 translate_endian_h2t (&readfds
, sizeof(readfds
));
626 if ((s
.write_mem
) (cb
, &s
, (unsigned long) treadfdsp
,
627 (char *) &readfds
, sizeof(readfds
)) != sizeof(readfds
))
634 if (twritefdsp
!= NULL
)
636 translate_endian_h2t (&writefds
, sizeof(writefds
));
637 if ((s
.write_mem
) (cb
, &s
, (unsigned long) twritefdsp
,
638 (char *) &writefds
, sizeof(writefds
)) != sizeof(writefds
))
645 if (texceptfdsp
!= NULL
)
647 translate_endian_h2t (&exceptfds
, sizeof(exceptfds
));
648 if ((s
.write_mem
) (cb
, &s
, (unsigned long) texceptfdsp
,
649 (char *) &exceptfds
, sizeof(exceptfds
)) != sizeof(exceptfds
))
656 translate_endian_h2t (&timeout
, sizeof(timeout
));
657 if ((s
.write_mem
) (cb
, &s
, (unsigned long) ttimeoutp
,
658 (char *) &timeout
, sizeof(timeout
)) != sizeof(timeout
))
666 case TARGET_LINUX_SYS_symlink
:
667 result
= symlink((char *) t2h_addr(cb
, &s
, arg1
),
668 (char *) t2h_addr(cb
, &s
, arg2
));
672 case TARGET_LINUX_SYS_readlink
:
673 result
= readlink((char *) t2h_addr(cb
, &s
, arg1
),
674 (char *) t2h_addr(cb
, &s
, arg2
),
679 case TARGET_LINUX_SYS_readdir
:
680 result
= (int) readdir((DIR *) t2h_addr(cb
, &s
, arg1
));
685 case TARGET_LINUX_SYS_mmap
:
687 result
= (int) mmap((void *) t2h_addr(cb
, &s
, arg1
),
688 arg2
, arg3
, arg4
, arg5
, arg6
);
693 sim_core_attach (sd
, NULL
,
694 0, access_read_write_exec
, 0,
695 result
, arg2
, 0, NULL
, NULL
);
700 case TARGET_LINUX_SYS_mmap2
:
704 int prot
, flags
, fildes
;
707 addr
= (void *) t2h_addr(cb
, &s
, arg1
);
714 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
719 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
720 sim_core_attach (sd
, NULL
,
721 0, access_read_write_exec
, 0,
722 result
, len
, 0, NULL
, NULL
);
727 case TARGET_LINUX_SYS_mmap
:
731 int prot
, flags
, fildes
;
734 addr
= *((void **) t2h_addr(cb
, &s
, arg1
));
735 len
= *((size_t *) t2h_addr(cb
, &s
, arg1
+ 4));
736 prot
= *((int *) t2h_addr(cb
, &s
, arg1
+ 8));
737 flags
= *((int *) t2h_addr(cb
, &s
, arg1
+ 12));
738 fildes
= *((int *) t2h_addr(cb
, &s
, arg1
+ 16));
739 off
= *((off_t
*) t2h_addr(cb
, &s
, arg1
+ 20));
741 addr
= (void *) T2H_4 ((unsigned int) addr
);
744 flags
= T2H_4 (flags
);
745 fildes
= T2H_4 (fildes
);
748 //addr = (void *) t2h_addr(cb, &s, (unsigned int) addr);
749 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
756 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
757 sim_core_attach (sd
, NULL
,
758 0, access_read_write_exec
, 0,
759 result
, len
, 0, NULL
, NULL
);
764 case TARGET_LINUX_SYS_munmap
:
766 result
= munmap((void *)arg1
, arg2
);
770 sim_core_detach (sd
, NULL
, 0, arg2
, result
);
775 case TARGET_LINUX_SYS_truncate
:
776 result
= truncate((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
780 case TARGET_LINUX_SYS_ftruncate
:
781 result
= ftruncate(arg1
, arg2
);
785 case TARGET_LINUX_SYS_fchmod
:
786 result
= fchmod(arg1
, arg2
);
790 case TARGET_LINUX_SYS_fchown32
:
791 case TARGET_LINUX_SYS_fchown
:
792 result
= fchown(arg1
, arg2
, arg3
);
796 case TARGET_LINUX_SYS_statfs
:
798 struct statfs statbuf
;
800 result
= statfs((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
806 translate_endian_h2t (&statbuf
, sizeof(statbuf
));
807 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
816 case TARGET_LINUX_SYS_fstatfs
:
818 struct statfs statbuf
;
820 result
= fstatfs(arg1
, &statbuf
);
826 translate_endian_h2t (&statbuf
, sizeof(statbuf
));
827 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
836 case TARGET_LINUX_SYS_syslog
:
837 result
= syslog(arg1
, (char *) t2h_addr(cb
, &s
, arg2
));
841 case TARGET_LINUX_SYS_setitimer
:
843 struct itimerval value
, ovalue
;
845 value
= *((struct itimerval
*) t2h_addr(cb
, &s
, arg2
));
846 translate_endian_t2h (&value
, sizeof(value
));
850 result
= setitimer(arg1
, &value
, NULL
);
855 result
= setitimer(arg1
, &value
, &ovalue
);
861 translate_endian_h2t (&ovalue
, sizeof(ovalue
));
862 if ((s
.write_mem
) (cb
, &s
, arg3
, (char *) &ovalue
, sizeof(ovalue
))
872 case TARGET_LINUX_SYS_getitimer
:
874 struct itimerval value
;
876 result
= getitimer(arg1
, &value
);
882 translate_endian_h2t (&value
, sizeof(value
));
883 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &value
, sizeof(value
))
892 case TARGET_LINUX_SYS_stat
:
898 result
= stat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
903 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
904 buf
= xmalloc (buflen
);
905 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
907 /* The translation failed. This is due to an internal
908 host program error, not the target's fault. */
914 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
925 case TARGET_LINUX_SYS_lstat
:
931 result
= lstat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
936 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
937 buf
= xmalloc (buflen
);
938 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
940 /* The translation failed. This is due to an internal
941 host program error, not the target's fault. */
947 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
958 case TARGET_LINUX_SYS_fstat
:
964 result
= fstat(arg1
, &statbuf
);
969 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
970 buf
= xmalloc (buflen
);
971 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
973 /* The translation failed. This is due to an internal
974 host program error, not the target's fault. */
980 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
991 case TARGET_LINUX_SYS_sysinfo
:
995 result
= sysinfo(&info
);
1001 info
.uptime
= H2T_4 (info
.uptime
);
1002 info
.loads
[0] = H2T_4 (info
.loads
[0]);
1003 info
.loads
[1] = H2T_4 (info
.loads
[1]);
1004 info
.loads
[2] = H2T_4 (info
.loads
[2]);
1005 info
.totalram
= H2T_4 (info
.totalram
);
1006 info
.freeram
= H2T_4 (info
.freeram
);
1007 info
.sharedram
= H2T_4 (info
.sharedram
);
1008 info
.bufferram
= H2T_4 (info
.bufferram
);
1009 info
.totalswap
= H2T_4 (info
.totalswap
);
1010 info
.freeswap
= H2T_4 (info
.freeswap
);
1011 info
.procs
= H2T_2 (info
.procs
);
1012 #if LINUX_VERSION_CODE >= 0x20400
1013 info
.totalhigh
= H2T_4 (info
.totalhigh
);
1014 info
.freehigh
= H2T_4 (info
.freehigh
);
1015 info
.mem_unit
= H2T_4 (info
.mem_unit
);
1017 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &info
, sizeof(info
))
1027 case TARGET_LINUX_SYS_ipc
:
1029 result
= ipc(arg1
, arg2
, arg3
, arg4
,
1030 (void *) t2h_addr(cb
, &s
, arg5
), arg6
);
1036 case TARGET_LINUX_SYS_fsync
:
1037 result
= fsync(arg1
);
1041 case TARGET_LINUX_SYS_uname
:
1042 /* utsname contains only arrays of char, so it is not necessary
1043 to translate endian. */
1044 result
= uname((struct utsname
*) t2h_addr(cb
, &s
, arg1
));
1048 case TARGET_LINUX_SYS_adjtimex
:
1052 result
= adjtimex(&buf
);
1058 translate_endian_h2t (&buf
, sizeof(buf
));
1059 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &buf
, sizeof(buf
))
1068 case TARGET_LINUX_SYS_mprotect
:
1069 result
= mprotect((void *) arg1
, arg2
, arg3
);
1073 case TARGET_LINUX_SYS_fchdir
:
1074 result
= fchdir(arg1
);
1078 case TARGET_LINUX_SYS_setfsuid32
:
1079 case TARGET_LINUX_SYS_setfsuid
:
1080 result
= setfsuid(arg1
);
1084 case TARGET_LINUX_SYS_setfsgid32
:
1085 case TARGET_LINUX_SYS_setfsgid
:
1086 result
= setfsgid(arg1
);
1091 case TARGET_LINUX_SYS__llseek
:
1095 result
= _llseek(arg1
, arg2
, arg3
, &buf
, arg5
);
1101 translate_endian_h2t (&buf
, sizeof(buf
));
1102 if ((s
.write_mem
) (cb
, &s
, t2h_addr(cb
, &s
, arg4
),
1103 (char *) &buf
, sizeof(buf
)) != sizeof(buf
))
1111 case TARGET_LINUX_SYS_getdents
:
1115 result
= getdents(arg1
, &dir
, arg3
);
1121 dir
.d_ino
= H2T_4 (dir
.d_ino
);
1122 dir
.d_off
= H2T_4 (dir
.d_off
);
1123 dir
.d_reclen
= H2T_2 (dir
.d_reclen
);
1124 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &dir
, sizeof(dir
))
1134 case TARGET_LINUX_SYS_flock
:
1135 result
= flock(arg1
, arg2
);
1139 case TARGET_LINUX_SYS_msync
:
1140 result
= msync((void *) arg1
, arg2
, arg3
);
1144 case TARGET_LINUX_SYS_readv
:
1146 struct iovec vector
;
1148 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1149 translate_endian_t2h (&vector
, sizeof(vector
));
1151 result
= readv(arg1
, &vector
, arg3
);
1156 case TARGET_LINUX_SYS_writev
:
1158 struct iovec vector
;
1160 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1161 translate_endian_t2h (&vector
, sizeof(vector
));
1163 result
= writev(arg1
, &vector
, arg3
);
1168 case TARGET_LINUX_SYS_fdatasync
:
1169 result
= fdatasync(arg1
);
1173 case TARGET_LINUX_SYS_mlock
:
1174 result
= mlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1178 case TARGET_LINUX_SYS_munlock
:
1179 result
= munlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1183 case TARGET_LINUX_SYS_nanosleep
:
1185 struct timespec req
, rem
;
1187 req
= *((struct timespec
*) t2h_addr(cb
, &s
, arg2
));
1188 translate_endian_t2h (&req
, sizeof(req
));
1190 result
= nanosleep(&req
, &rem
);
1196 translate_endian_h2t (&rem
, sizeof(rem
));
1197 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rem
, sizeof(rem
))
1206 case TARGET_LINUX_SYS_mremap
: /* FIXME */
1207 result
= (int) mremap((void *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
, arg4
);
1211 case TARGET_LINUX_SYS_getresuid32
:
1212 case TARGET_LINUX_SYS_getresuid
:
1214 uid_t ruid
, euid
, suid
;
1216 result
= getresuid(&ruid
, &euid
, &suid
);
1222 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = H2T_4 (ruid
);
1223 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = H2T_4 (euid
);
1224 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = H2T_4 (suid
);
1228 case TARGET_LINUX_SYS_poll
:
1232 ufds
= *((struct pollfd
*) t2h_addr(cb
, &s
, arg1
));
1233 ufds
.fd
= T2H_4 (ufds
.fd
);
1234 ufds
.events
= T2H_2 (ufds
.events
);
1235 ufds
.revents
= T2H_2 (ufds
.revents
);
1237 result
= poll(&ufds
, arg2
, arg3
);
1242 case TARGET_LINUX_SYS_getresgid32
:
1243 case TARGET_LINUX_SYS_getresgid
:
1245 uid_t rgid
, egid
, sgid
;
1247 result
= getresgid(&rgid
, &egid
, &sgid
);
1253 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = H2T_4 (rgid
);
1254 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = H2T_4 (egid
);
1255 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = H2T_4 (sgid
);
1259 case TARGET_LINUX_SYS_pread
:
1260 result
= pread(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1264 case TARGET_LINUX_SYS_pwrite
:
1265 result
= pwrite(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1269 case TARGET_LINUX_SYS_chown32
:
1270 case TARGET_LINUX_SYS_chown
:
1271 result
= chown((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
1275 case TARGET_LINUX_SYS_getcwd
:
1276 result
= (int) getcwd((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
1280 case TARGET_LINUX_SYS_sendfile
:
1284 offset
= *((off_t
*) t2h_addr(cb
, &s
, arg3
));
1285 offset
= T2H_4 (offset
);
1287 result
= sendfile(arg1
, arg2
, &offset
, arg3
);
1293 *((off_t
*) t2h_addr(cb
, &s
, arg3
)) = H2T_4 (offset
);
1304 m32rbf_h_gr_set (current_cpu
, 0, -errcode
);
1306 m32rbf_h_gr_set (current_cpu
, 0, result
);
1310 case TRAP_BREAKPOINT
:
1311 sim_engine_halt (sd
, current_cpu
, NULL
, pc
,
1312 sim_stopped
, SIM_SIGTRAP
);
1315 case TRAP_FLUSH_CACHE
:
1322 /* The new pc is the trap vector entry.
1323 We assume there's a branch there to some handler.
1324 Use cr5 as EVB (EIT Vector Base) register. */
1325 /* USI new_pc = EIT_TRAP_BASE_ADDR + num * 4; */
1326 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
1331 /* Fake an "rte" insn. */
1332 /* FIXME: Should duplicate all of rte processing. */
1333 return (pc
& -4) + 4;