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
:
765 result
= munmap ((void *)arg1
, arg2
);
768 sim_core_detach (sd
, NULL
, 0, arg2
, result
);
771 case TARGET_LINUX_SYS_truncate
:
772 result
= truncate ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
776 case TARGET_LINUX_SYS_ftruncate
:
777 result
= ftruncate (arg1
, arg2
);
781 case TARGET_LINUX_SYS_fchmod
:
782 result
= fchmod (arg1
, arg2
);
786 case TARGET_LINUX_SYS_fchown32
:
787 case TARGET_LINUX_SYS_fchown
:
788 result
= fchown (arg1
, arg2
, arg3
);
792 case TARGET_LINUX_SYS_statfs
:
794 struct statfs statbuf
;
796 result
= statfs ((char *) t2h_addr (cb
, &s
, arg1
), &statbuf
);
802 translate_endian_h2t (&statbuf
, sizeof(statbuf
));
803 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
812 case TARGET_LINUX_SYS_fstatfs
:
814 struct statfs statbuf
;
816 result
= fstatfs (arg1
, &statbuf
);
822 translate_endian_h2t (&statbuf
, sizeof(statbuf
));
823 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
832 case TARGET_LINUX_SYS_syslog
:
833 result
= syslog (arg1
, (char *) t2h_addr (cb
, &s
, arg2
));
837 case TARGET_LINUX_SYS_setitimer
:
839 struct itimerval value
, ovalue
;
841 value
= *((struct itimerval
*) t2h_addr (cb
, &s
, arg2
));
842 translate_endian_t2h (&value
, sizeof(value
));
846 result
= setitimer (arg1
, &value
, NULL
);
851 result
= setitimer (arg1
, &value
, &ovalue
);
857 translate_endian_h2t (&ovalue
, sizeof(ovalue
));
858 if ((s
.write_mem
) (cb
, &s
, arg3
, (char *) &ovalue
, sizeof(ovalue
))
868 case TARGET_LINUX_SYS_getitimer
:
870 struct itimerval value
;
872 result
= getitimer (arg1
, &value
);
878 translate_endian_h2t (&value
, sizeof(value
));
879 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &value
, sizeof(value
))
888 case TARGET_LINUX_SYS_stat
:
894 result
= stat ((char *) t2h_addr (cb
, &s
, arg1
), &statbuf
);
899 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
900 buf
= xmalloc (buflen
);
901 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
903 /* The translation failed. This is due to an internal
904 host program error, not the target's fault. */
910 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
921 case TARGET_LINUX_SYS_lstat
:
927 result
= lstat ((char *) t2h_addr (cb
, &s
, arg1
), &statbuf
);
932 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
933 buf
= xmalloc (buflen
);
934 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
936 /* The translation failed. This is due to an internal
937 host program error, not the target's fault. */
943 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
954 case TARGET_LINUX_SYS_fstat
:
960 result
= fstat (arg1
, &statbuf
);
965 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
966 buf
= xmalloc (buflen
);
967 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
969 /* The translation failed. This is due to an internal
970 host program error, not the target's fault. */
976 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
987 case TARGET_LINUX_SYS_sysinfo
:
991 result
= sysinfo (&info
);
997 info
.uptime
= H2T_4 (info
.uptime
);
998 info
.loads
[0] = H2T_4 (info
.loads
[0]);
999 info
.loads
[1] = H2T_4 (info
.loads
[1]);
1000 info
.loads
[2] = H2T_4 (info
.loads
[2]);
1001 info
.totalram
= H2T_4 (info
.totalram
);
1002 info
.freeram
= H2T_4 (info
.freeram
);
1003 info
.sharedram
= H2T_4 (info
.sharedram
);
1004 info
.bufferram
= H2T_4 (info
.bufferram
);
1005 info
.totalswap
= H2T_4 (info
.totalswap
);
1006 info
.freeswap
= H2T_4 (info
.freeswap
);
1007 info
.procs
= H2T_2 (info
.procs
);
1008 #if LINUX_VERSION_CODE >= 0x20400
1009 info
.totalhigh
= H2T_4 (info
.totalhigh
);
1010 info
.freehigh
= H2T_4 (info
.freehigh
);
1011 info
.mem_unit
= H2T_4 (info
.mem_unit
);
1013 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &info
, sizeof(info
))
1023 case TARGET_LINUX_SYS_ipc
:
1025 result
= ipc (arg1
, arg2
, arg3
, arg4
,
1026 (void *) t2h_addr (cb
, &s
, arg5
), arg6
);
1032 case TARGET_LINUX_SYS_fsync
:
1033 result
= fsync (arg1
);
1037 case TARGET_LINUX_SYS_uname
:
1038 /* utsname contains only arrays of char, so it is not necessary
1039 to translate endian. */
1040 result
= uname ((struct utsname
*) t2h_addr (cb
, &s
, arg1
));
1044 case TARGET_LINUX_SYS_adjtimex
:
1048 result
= adjtimex (&buf
);
1054 translate_endian_h2t (&buf
, sizeof(buf
));
1055 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &buf
, sizeof(buf
))
1064 case TARGET_LINUX_SYS_mprotect
:
1065 result
= mprotect ((void *) arg1
, arg2
, arg3
);
1069 case TARGET_LINUX_SYS_fchdir
:
1070 result
= fchdir (arg1
);
1074 case TARGET_LINUX_SYS_setfsuid32
:
1075 case TARGET_LINUX_SYS_setfsuid
:
1076 result
= setfsuid (arg1
);
1080 case TARGET_LINUX_SYS_setfsgid32
:
1081 case TARGET_LINUX_SYS_setfsgid
:
1082 result
= setfsgid (arg1
);
1087 case TARGET_LINUX_SYS__llseek
:
1091 result
= _llseek (arg1
, arg2
, arg3
, &buf
, arg5
);
1097 translate_endian_h2t (&buf
, sizeof(buf
));
1098 if ((s
.write_mem
) (cb
, &s
, t2h_addr (cb
, &s
, arg4
),
1099 (char *) &buf
, sizeof(buf
)) != sizeof(buf
))
1107 case TARGET_LINUX_SYS_getdents
:
1111 result
= getdents (arg1
, &dir
, arg3
);
1117 dir
.d_ino
= H2T_4 (dir
.d_ino
);
1118 dir
.d_off
= H2T_4 (dir
.d_off
);
1119 dir
.d_reclen
= H2T_2 (dir
.d_reclen
);
1120 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &dir
, sizeof(dir
))
1130 case TARGET_LINUX_SYS_flock
:
1131 result
= flock (arg1
, arg2
);
1135 case TARGET_LINUX_SYS_msync
:
1136 result
= msync ((void *) arg1
, arg2
, arg3
);
1140 case TARGET_LINUX_SYS_readv
:
1142 struct iovec vector
;
1144 vector
= *((struct iovec
*) t2h_addr (cb
, &s
, arg2
));
1145 translate_endian_t2h (&vector
, sizeof(vector
));
1147 result
= readv (arg1
, &vector
, arg3
);
1152 case TARGET_LINUX_SYS_writev
:
1154 struct iovec vector
;
1156 vector
= *((struct iovec
*) t2h_addr (cb
, &s
, arg2
));
1157 translate_endian_t2h (&vector
, sizeof(vector
));
1159 result
= writev (arg1
, &vector
, arg3
);
1164 case TARGET_LINUX_SYS_fdatasync
:
1165 result
= fdatasync (arg1
);
1169 case TARGET_LINUX_SYS_mlock
:
1170 result
= mlock ((void *) t2h_addr (cb
, &s
, arg1
), arg2
);
1174 case TARGET_LINUX_SYS_munlock
:
1175 result
= munlock ((void *) t2h_addr (cb
, &s
, arg1
), arg2
);
1179 case TARGET_LINUX_SYS_nanosleep
:
1181 struct timespec req
, rem
;
1183 req
= *((struct timespec
*) t2h_addr (cb
, &s
, arg2
));
1184 translate_endian_t2h (&req
, sizeof(req
));
1186 result
= nanosleep (&req
, &rem
);
1192 translate_endian_h2t (&rem
, sizeof(rem
));
1193 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rem
, sizeof(rem
))
1202 case TARGET_LINUX_SYS_mremap
: /* FIXME */
1203 result
= (int) mremap ((void *) t2h_addr (cb
, &s
, arg1
), arg2
, arg3
, arg4
);
1207 case TARGET_LINUX_SYS_getresuid32
:
1208 case TARGET_LINUX_SYS_getresuid
:
1210 uid_t ruid
, euid
, suid
;
1212 result
= getresuid (&ruid
, &euid
, &suid
);
1218 *((uid_t
*) t2h_addr (cb
, &s
, arg1
)) = H2T_4 (ruid
);
1219 *((uid_t
*) t2h_addr (cb
, &s
, arg2
)) = H2T_4 (euid
);
1220 *((uid_t
*) t2h_addr (cb
, &s
, arg3
)) = H2T_4 (suid
);
1224 case TARGET_LINUX_SYS_poll
:
1228 ufds
= *((struct pollfd
*) t2h_addr (cb
, &s
, arg1
));
1229 ufds
.fd
= T2H_4 (ufds
.fd
);
1230 ufds
.events
= T2H_2 (ufds
.events
);
1231 ufds
.revents
= T2H_2 (ufds
.revents
);
1233 result
= poll (&ufds
, arg2
, arg3
);
1238 case TARGET_LINUX_SYS_getresgid32
:
1239 case TARGET_LINUX_SYS_getresgid
:
1241 uid_t rgid
, egid
, sgid
;
1243 result
= getresgid (&rgid
, &egid
, &sgid
);
1249 *((uid_t
*) t2h_addr (cb
, &s
, arg1
)) = H2T_4 (rgid
);
1250 *((uid_t
*) t2h_addr (cb
, &s
, arg2
)) = H2T_4 (egid
);
1251 *((uid_t
*) t2h_addr (cb
, &s
, arg3
)) = H2T_4 (sgid
);
1255 case TARGET_LINUX_SYS_pread
:
1256 result
= pread (arg1
, (void *) t2h_addr (cb
, &s
, arg2
), arg3
, arg4
);
1260 case TARGET_LINUX_SYS_pwrite
:
1261 result
= pwrite (arg1
, (void *) t2h_addr (cb
, &s
, arg2
), arg3
, arg4
);
1265 case TARGET_LINUX_SYS_chown32
:
1266 case TARGET_LINUX_SYS_chown
:
1267 result
= chown ((char *) t2h_addr (cb
, &s
, arg1
), arg2
, arg3
);
1271 case TARGET_LINUX_SYS_getcwd
:
1272 result
= (int) getcwd ((char *) t2h_addr (cb
, &s
, arg1
), arg2
);
1276 case TARGET_LINUX_SYS_sendfile
:
1280 offset
= *((off_t
*) t2h_addr (cb
, &s
, arg3
));
1281 offset
= T2H_4 (offset
);
1283 result
= sendfile (arg1
, arg2
, &offset
, arg3
);
1289 *((off_t
*) t2h_addr (cb
, &s
, arg3
)) = H2T_4 (offset
);
1300 m32rbf_h_gr_set (current_cpu
, 0, -errcode
);
1302 m32rbf_h_gr_set (current_cpu
, 0, result
);
1306 case TRAP_BREAKPOINT
:
1307 sim_engine_halt (sd
, current_cpu
, NULL
, pc
,
1308 sim_stopped
, SIM_SIGTRAP
);
1311 case TRAP_FLUSH_CACHE
:
1318 /* The new pc is the trap vector entry.
1319 We assume there's a branch there to some handler.
1320 Use cr5 as EVB (EIT Vector Base) register. */
1321 /* USI new_pc = EIT_TRAP_BASE_ADDR + num * 4; */
1322 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
1327 /* Fake an "rte" insn. */
1328 /* FIXME: Should duplicate all of rte processing. */
1329 return (pc
& -4) + 4;