1 /* m32r exception, interrupt, and trap (EIT) support
2 Copyright (C) 1998-2021 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/>. */
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_ELF_SYSCALL 0
54 #define TRAP_LINUX_SYSCALL 2
55 #define TRAP_FLUSH_CACHE 12
57 /* The semantic code invokes this for invalid (unrecognized) instructions. */
60 sim_engine_invalid_insn (SIM_CPU
*current_cpu
, IADDR cia
, SEM_PC vpc
)
62 SIM_DESC sd
= CPU_STATE (current_cpu
);
65 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
67 h_bsm_set (current_cpu
, h_sm_get (current_cpu
));
68 h_bie_set (current_cpu
, h_ie_get (current_cpu
));
69 h_bcond_set (current_cpu
, h_cond_get (current_cpu
));
71 h_ie_set (current_cpu
, 0);
72 h_cond_set (current_cpu
, 0);
74 h_bpc_set (current_cpu
, cia
);
76 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
81 sim_engine_halt (sd
, current_cpu
, NULL
, cia
, sim_stopped
, SIM_SIGILL
);
85 /* Process an address exception. */
88 m32r_core_signal (SIM_DESC sd
, SIM_CPU
*current_cpu
, sim_cia cia
,
89 unsigned int map
, int nr_bytes
, address_word addr
,
90 transfer_type transfer
, sim_core_signals sig
)
92 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
94 m32rbf_h_cr_set (current_cpu
, H_CR_BBPC
,
95 m32rbf_h_cr_get (current_cpu
, H_CR_BPC
));
96 if (MACH_NUM (CPU_MACH (current_cpu
)) == MACH_M32R
)
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);
102 else if (MACH_NUM (CPU_MACH (current_cpu
)) == MACH_M32RX
)
104 m32rxf_h_bpsw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
));
106 m32rxf_h_psw_set (current_cpu
, m32rxf_h_psw_get (current_cpu
) & 0x80);
110 m32r2f_h_bpsw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
));
112 m32r2f_h_psw_set (current_cpu
, m32r2f_h_psw_get (current_cpu
) & 0x80);
114 m32rbf_h_cr_set (current_cpu
, H_CR_BPC
, cia
);
116 sim_engine_restart (CPU_STATE (current_cpu
), current_cpu
, NULL
,
120 sim_core_signal (sd
, current_cpu
, cia
, map
, nr_bytes
, addr
,
124 /* Translate target's address to host's address. */
127 t2h_addr (host_callback
*cb
, struct cb_syscall
*sc
,
131 SIM_DESC sd
= (SIM_DESC
) sc
->p1
;
132 SIM_CPU
*cpu
= (SIM_CPU
*) sc
->p2
;
137 return sim_core_trans_addr (sd
, cpu
, read_map
, taddr
);
141 conv_endian (unsigned int tvalue
)
144 unsigned int t1
, t2
, t3
, t4
;
146 if (HOST_BYTE_ORDER
== BFD_ENDIAN_LITTLE
)
148 t1
= tvalue
& 0xff000000;
149 t2
= tvalue
& 0x00ff0000;
150 t3
= tvalue
& 0x0000ff00;
151 t4
= tvalue
& 0x000000ff;
164 static unsigned short
165 conv_endian16 (unsigned short tvalue
)
167 unsigned short hvalue
;
168 unsigned short t1
, t2
;
170 if (HOST_BYTE_ORDER
== BFD_ENDIAN_LITTLE
)
172 t1
= tvalue
& 0xff00;
173 t2
= tvalue
& 0x00ff;
185 translate_endian(void *addr
, size_t size
)
187 unsigned int *p
= (unsigned int *) addr
;
190 for (i
= 0; i
<= size
- 4; i
+= 4,p
++)
191 *p
= conv_endian(*p
);
194 *((unsigned short *) p
) = conv_endian16(*((unsigned short *) p
));
198 The result is the pc address to continue at.
199 Preprocessing like saving the various registers has already been done. */
202 m32r_trap (SIM_CPU
*current_cpu
, PCADDR pc
, int num
)
204 SIM_DESC sd
= CPU_STATE (current_cpu
);
205 host_callback
*cb
= STATE_CALLBACK (sd
);
209 case TRAP_ELF_SYSCALL
:
211 long result
, result2
;
214 sim_syscall_multi (current_cpu
,
215 m32rbf_h_gr_get (current_cpu
, 0),
216 m32rbf_h_gr_get (current_cpu
, 1),
217 m32rbf_h_gr_get (current_cpu
, 2),
218 m32rbf_h_gr_get (current_cpu
, 3),
219 m32rbf_h_gr_get (current_cpu
, 4),
220 &result
, &result2
, &errcode
);
222 m32rbf_h_gr_set (current_cpu
, 2, errcode
);
223 m32rbf_h_gr_set (current_cpu
, 0, result
);
224 m32rbf_h_gr_set (current_cpu
, 1, result2
);
228 case TRAP_LINUX_SYSCALL
:
231 unsigned int func
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
;
232 int result
, result2
, errcode
;
234 if (STATE_ENVIRONMENT (sd
) == OPERATING_ENVIRONMENT
)
236 /* The new pc is the trap vector entry.
237 We assume there's a branch there to some handler.
238 Use cr5 as EVB (EIT Vector Base) register. */
239 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
243 func
= m32rbf_h_gr_get (current_cpu
, 7);
244 arg1
= m32rbf_h_gr_get (current_cpu
, 0);
245 arg2
= m32rbf_h_gr_get (current_cpu
, 1);
246 arg3
= m32rbf_h_gr_get (current_cpu
, 2);
247 arg4
= m32rbf_h_gr_get (current_cpu
, 3);
248 arg5
= m32rbf_h_gr_get (current_cpu
, 4);
249 arg6
= m32rbf_h_gr_get (current_cpu
, 5);
250 arg7
= m32rbf_h_gr_get (current_cpu
, 6);
252 CB_SYSCALL_INIT (&s
);
263 s
.p2
= (PTR
) current_cpu
;
264 s
.read_mem
= sim_syscall_read_mem
;
265 s
.write_mem
= sim_syscall_write_mem
;
273 case TARGET_LINUX_SYS_exit
:
274 sim_engine_halt (sd
, current_cpu
, NULL
, pc
, sim_exited
, arg1
);
277 case TARGET_LINUX_SYS_read
:
278 result
= read(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
282 case TARGET_LINUX_SYS_write
:
283 result
= write(arg1
, t2h_addr(cb
, &s
, arg2
), arg3
);
287 case TARGET_LINUX_SYS_open
:
288 result
= open((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
292 case TARGET_LINUX_SYS_close
:
293 result
= close(arg1
);
297 case TARGET_LINUX_SYS_creat
:
298 result
= creat((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
302 case TARGET_LINUX_SYS_link
:
303 result
= link((char *) t2h_addr(cb
, &s
, arg1
),
304 (char *) t2h_addr(cb
, &s
, arg2
));
308 case TARGET_LINUX_SYS_unlink
:
309 result
= unlink((char *) t2h_addr(cb
, &s
, arg1
));
313 case TARGET_LINUX_SYS_chdir
:
314 result
= chdir((char *) t2h_addr(cb
, &s
, arg1
));
318 case TARGET_LINUX_SYS_time
:
324 result
= (int) time(NULL
);
329 result
= (int) time(&t
);
335 translate_endian((void *) &t
, sizeof(t
));
336 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
)) != sizeof(t
))
345 case TARGET_LINUX_SYS_mknod
:
346 result
= mknod((char *) t2h_addr(cb
, &s
, arg1
),
347 (mode_t
) arg2
, (dev_t
) arg3
);
351 case TARGET_LINUX_SYS_chmod
:
352 result
= chmod((char *) t2h_addr(cb
, &s
, arg1
), (mode_t
) arg2
);
356 case TARGET_LINUX_SYS_lchown32
:
357 case TARGET_LINUX_SYS_lchown
:
358 result
= lchown((char *) t2h_addr(cb
, &s
, arg1
),
359 (uid_t
) arg2
, (gid_t
) arg3
);
363 case TARGET_LINUX_SYS_lseek
:
364 result
= (int) lseek(arg1
, (off_t
) arg2
, arg3
);
368 case TARGET_LINUX_SYS_getpid
:
373 case TARGET_LINUX_SYS_getuid32
:
374 case TARGET_LINUX_SYS_getuid
:
379 case TARGET_LINUX_SYS_utime
:
385 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), NULL
);
390 buf
= *((struct utimbuf
*) t2h_addr(cb
, &s
, arg2
));
391 translate_endian((void *) &buf
, sizeof(buf
));
392 result
= utime((char *) t2h_addr(cb
, &s
, arg1
), &buf
);
398 case TARGET_LINUX_SYS_access
:
399 result
= access((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
403 case TARGET_LINUX_SYS_ftime
:
413 t
.time
= conv_endian(t
.time
);
414 t
.millitm
= conv_endian16(t
.millitm
);
415 t
.timezone
= conv_endian16(t
.timezone
);
416 t
.dstflag
= conv_endian16(t
.dstflag
);
417 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &t
, sizeof(t
))
425 case TARGET_LINUX_SYS_sync
:
430 case TARGET_LINUX_SYS_rename
:
431 result
= rename((char *) t2h_addr(cb
, &s
, arg1
),
432 (char *) t2h_addr(cb
, &s
, arg2
));
436 case TARGET_LINUX_SYS_mkdir
:
437 result
= mkdir((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
441 case TARGET_LINUX_SYS_rmdir
:
442 result
= rmdir((char *) t2h_addr(cb
, &s
, arg1
));
446 case TARGET_LINUX_SYS_dup
:
451 case TARGET_LINUX_SYS_brk
:
452 result
= brk((void *) arg1
);
457 case TARGET_LINUX_SYS_getgid32
:
458 case TARGET_LINUX_SYS_getgid
:
463 case TARGET_LINUX_SYS_geteuid32
:
464 case TARGET_LINUX_SYS_geteuid
:
469 case TARGET_LINUX_SYS_getegid32
:
470 case TARGET_LINUX_SYS_getegid
:
475 case TARGET_LINUX_SYS_ioctl
:
476 result
= ioctl(arg1
, arg2
, arg3
);
480 case TARGET_LINUX_SYS_fcntl
:
481 result
= fcntl(arg1
, arg2
, arg3
);
485 case TARGET_LINUX_SYS_dup2
:
486 result
= dup2(arg1
, arg2
);
490 case TARGET_LINUX_SYS_getppid
:
495 case TARGET_LINUX_SYS_getpgrp
:
500 case TARGET_LINUX_SYS_getrlimit
:
504 result
= getrlimit(arg1
, &rlim
);
510 translate_endian((void *) &rlim
, sizeof(rlim
));
511 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rlim
, sizeof(rlim
))
520 case TARGET_LINUX_SYS_getrusage
:
524 result
= getrusage(arg1
, &usage
);
530 translate_endian((void *) &usage
, sizeof(usage
));
531 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &usage
, sizeof(usage
))
540 case TARGET_LINUX_SYS_gettimeofday
:
545 result
= gettimeofday(&tv
, &tz
);
551 translate_endian((void *) &tv
, sizeof(tv
));
552 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &tv
, sizeof(tv
))
559 translate_endian((void *) &tz
, sizeof(tz
));
560 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &tz
, sizeof(tz
))
569 case TARGET_LINUX_SYS_getgroups32
:
570 case TARGET_LINUX_SYS_getgroups
:
575 list
= (gid_t
*) malloc(arg1
* sizeof(gid_t
));
577 result
= getgroups(arg1
, list
);
583 translate_endian((void *) list
, arg1
* sizeof(gid_t
));
585 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) list
, arg1
* sizeof(gid_t
))
586 != arg1
* sizeof(gid_t
))
594 case TARGET_LINUX_SYS_select
:
606 struct timeval
*ttimeoutp
;
607 struct timeval timeout
;
611 treadfdsp
= (fd_set
*) arg2
;
612 if (treadfdsp
!= NULL
)
614 readfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) treadfdsp
));
615 translate_endian((void *) &readfds
, sizeof(readfds
));
616 hreadfdsp
= &readfds
;
621 twritefdsp
= (fd_set
*) arg3
;
622 if (twritefdsp
!= NULL
)
624 writefds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) twritefdsp
));
625 translate_endian((void *) &writefds
, sizeof(writefds
));
626 hwritefdsp
= &writefds
;
631 texceptfdsp
= (fd_set
*) arg4
;
632 if (texceptfdsp
!= NULL
)
634 exceptfds
= *((fd_set
*) t2h_addr(cb
, &s
, (unsigned int) texceptfdsp
));
635 translate_endian((void *) &exceptfds
, sizeof(exceptfds
));
636 hexceptfdsp
= &exceptfds
;
641 ttimeoutp
= (struct timeval
*) arg5
;
642 timeout
= *((struct timeval
*) t2h_addr(cb
, &s
, (unsigned int) ttimeoutp
));
643 translate_endian((void *) &timeout
, sizeof(timeout
));
645 result
= select(n
, hreadfdsp
, hwritefdsp
, hexceptfdsp
, &timeout
);
651 if (treadfdsp
!= NULL
)
653 translate_endian((void *) &readfds
, sizeof(readfds
));
654 if ((s
.write_mem
) (cb
, &s
, (unsigned long) treadfdsp
,
655 (char *) &readfds
, sizeof(readfds
)) != sizeof(readfds
))
662 if (twritefdsp
!= NULL
)
664 translate_endian((void *) &writefds
, sizeof(writefds
));
665 if ((s
.write_mem
) (cb
, &s
, (unsigned long) twritefdsp
,
666 (char *) &writefds
, sizeof(writefds
)) != sizeof(writefds
))
673 if (texceptfdsp
!= NULL
)
675 translate_endian((void *) &exceptfds
, sizeof(exceptfds
));
676 if ((s
.write_mem
) (cb
, &s
, (unsigned long) texceptfdsp
,
677 (char *) &exceptfds
, sizeof(exceptfds
)) != sizeof(exceptfds
))
684 translate_endian((void *) &timeout
, sizeof(timeout
));
685 if ((s
.write_mem
) (cb
, &s
, (unsigned long) ttimeoutp
,
686 (char *) &timeout
, sizeof(timeout
)) != sizeof(timeout
))
694 case TARGET_LINUX_SYS_symlink
:
695 result
= symlink((char *) t2h_addr(cb
, &s
, arg1
),
696 (char *) t2h_addr(cb
, &s
, arg2
));
700 case TARGET_LINUX_SYS_readlink
:
701 result
= readlink((char *) t2h_addr(cb
, &s
, arg1
),
702 (char *) t2h_addr(cb
, &s
, arg2
),
707 case TARGET_LINUX_SYS_readdir
:
708 result
= (int) readdir((DIR *) t2h_addr(cb
, &s
, arg1
));
713 case TARGET_LINUX_SYS_mmap
:
715 result
= (int) mmap((void *) t2h_addr(cb
, &s
, arg1
),
716 arg2
, arg3
, arg4
, arg5
, arg6
);
721 sim_core_attach (sd
, NULL
,
722 0, access_read_write_exec
, 0,
723 result
, arg2
, 0, NULL
, NULL
);
728 case TARGET_LINUX_SYS_mmap2
:
732 int prot
, flags
, fildes
;
735 addr
= (void *) t2h_addr(cb
, &s
, arg1
);
742 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
747 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
748 sim_core_attach (sd
, NULL
,
749 0, access_read_write_exec
, 0,
750 result
, len
, 0, NULL
, NULL
);
755 case TARGET_LINUX_SYS_mmap
:
759 int prot
, flags
, fildes
;
762 addr
= *((void **) t2h_addr(cb
, &s
, arg1
));
763 len
= *((size_t *) t2h_addr(cb
, &s
, arg1
+ 4));
764 prot
= *((int *) t2h_addr(cb
, &s
, arg1
+ 8));
765 flags
= *((int *) t2h_addr(cb
, &s
, arg1
+ 12));
766 fildes
= *((int *) t2h_addr(cb
, &s
, arg1
+ 16));
767 off
= *((off_t
*) t2h_addr(cb
, &s
, arg1
+ 20));
769 addr
= (void *) conv_endian((unsigned int) addr
);
770 len
= conv_endian(len
);
771 prot
= conv_endian(prot
);
772 flags
= conv_endian(flags
);
773 fildes
= conv_endian(fildes
);
774 off
= conv_endian(off
);
776 //addr = (void *) t2h_addr(cb, &s, (unsigned int) addr);
777 result
= (int) mmap(addr
, len
, prot
, flags
, fildes
, off
);
784 if (sim_core_read_buffer (sd
, NULL
, read_map
, &c
, result
, 1) == 0)
785 sim_core_attach (sd
, NULL
,
786 0, access_read_write_exec
, 0,
787 result
, len
, 0, NULL
, NULL
);
792 case TARGET_LINUX_SYS_munmap
:
794 result
= munmap((void *)arg1
, arg2
);
798 sim_core_detach (sd
, NULL
, 0, arg2
, result
);
803 case TARGET_LINUX_SYS_truncate
:
804 result
= truncate((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
808 case TARGET_LINUX_SYS_ftruncate
:
809 result
= ftruncate(arg1
, arg2
);
813 case TARGET_LINUX_SYS_fchmod
:
814 result
= fchmod(arg1
, arg2
);
818 case TARGET_LINUX_SYS_fchown32
:
819 case TARGET_LINUX_SYS_fchown
:
820 result
= fchown(arg1
, arg2
, arg3
);
824 case TARGET_LINUX_SYS_statfs
:
826 struct statfs statbuf
;
828 result
= statfs((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
834 translate_endian((void *) &statbuf
, sizeof(statbuf
));
835 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
844 case TARGET_LINUX_SYS_fstatfs
:
846 struct statfs statbuf
;
848 result
= fstatfs(arg1
, &statbuf
);
854 translate_endian((void *) &statbuf
, sizeof(statbuf
));
855 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &statbuf
, sizeof(statbuf
))
864 case TARGET_LINUX_SYS_syslog
:
865 result
= syslog(arg1
, (char *) t2h_addr(cb
, &s
, arg2
));
869 case TARGET_LINUX_SYS_setitimer
:
871 struct itimerval value
, ovalue
;
873 value
= *((struct itimerval
*) t2h_addr(cb
, &s
, arg2
));
874 translate_endian((void *) &value
, sizeof(value
));
878 result
= setitimer(arg1
, &value
, NULL
);
883 result
= setitimer(arg1
, &value
, &ovalue
);
889 translate_endian((void *) &ovalue
, sizeof(ovalue
));
890 if ((s
.write_mem
) (cb
, &s
, arg3
, (char *) &ovalue
, sizeof(ovalue
))
900 case TARGET_LINUX_SYS_getitimer
:
902 struct itimerval value
;
904 result
= getitimer(arg1
, &value
);
910 translate_endian((void *) &value
, sizeof(value
));
911 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &value
, sizeof(value
))
920 case TARGET_LINUX_SYS_stat
:
926 result
= stat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
931 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
932 buf
= xmalloc (buflen
);
933 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
935 /* The translation failed. This is due to an internal
936 host program error, not the target's fault. */
942 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
953 case TARGET_LINUX_SYS_lstat
:
959 result
= lstat((char *) t2h_addr(cb
, &s
, arg1
), &statbuf
);
964 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
965 buf
= xmalloc (buflen
);
966 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
968 /* The translation failed. This is due to an internal
969 host program error, not the target's fault. */
975 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
986 case TARGET_LINUX_SYS_fstat
:
992 result
= fstat(arg1
, &statbuf
);
997 buflen
= cb_host_to_target_stat (cb
, NULL
, NULL
);
998 buf
= xmalloc (buflen
);
999 if (cb_host_to_target_stat (cb
, &statbuf
, buf
) != buflen
)
1001 /* The translation failed. This is due to an internal
1002 host program error, not the target's fault. */
1008 if ((s
.write_mem
) (cb
, &s
, arg2
, buf
, buflen
) != buflen
)
1019 case TARGET_LINUX_SYS_sysinfo
:
1021 struct sysinfo info
;
1023 result
= sysinfo(&info
);
1029 info
.uptime
= conv_endian(info
.uptime
);
1030 info
.loads
[0] = conv_endian(info
.loads
[0]);
1031 info
.loads
[1] = conv_endian(info
.loads
[1]);
1032 info
.loads
[2] = conv_endian(info
.loads
[2]);
1033 info
.totalram
= conv_endian(info
.totalram
);
1034 info
.freeram
= conv_endian(info
.freeram
);
1035 info
.sharedram
= conv_endian(info
.sharedram
);
1036 info
.bufferram
= conv_endian(info
.bufferram
);
1037 info
.totalswap
= conv_endian(info
.totalswap
);
1038 info
.freeswap
= conv_endian(info
.freeswap
);
1039 info
.procs
= conv_endian16(info
.procs
);
1040 #if LINUX_VERSION_CODE >= 0x20400
1041 info
.totalhigh
= conv_endian(info
.totalhigh
);
1042 info
.freehigh
= conv_endian(info
.freehigh
);
1043 info
.mem_unit
= conv_endian(info
.mem_unit
);
1045 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &info
, sizeof(info
))
1055 case TARGET_LINUX_SYS_ipc
:
1057 result
= ipc(arg1
, arg2
, arg3
, arg4
,
1058 (void *) t2h_addr(cb
, &s
, arg5
), arg6
);
1064 case TARGET_LINUX_SYS_fsync
:
1065 result
= fsync(arg1
);
1069 case TARGET_LINUX_SYS_uname
:
1070 /* utsname contains only arrays of char, so it is not necessary
1071 to translate endian. */
1072 result
= uname((struct utsname
*) t2h_addr(cb
, &s
, arg1
));
1076 case TARGET_LINUX_SYS_adjtimex
:
1080 result
= adjtimex(&buf
);
1086 translate_endian((void *) &buf
, sizeof(buf
));
1087 if ((s
.write_mem
) (cb
, &s
, arg1
, (char *) &buf
, sizeof(buf
))
1096 case TARGET_LINUX_SYS_mprotect
:
1097 result
= mprotect((void *) arg1
, arg2
, arg3
);
1101 case TARGET_LINUX_SYS_fchdir
:
1102 result
= fchdir(arg1
);
1106 case TARGET_LINUX_SYS_setfsuid32
:
1107 case TARGET_LINUX_SYS_setfsuid
:
1108 result
= setfsuid(arg1
);
1112 case TARGET_LINUX_SYS_setfsgid32
:
1113 case TARGET_LINUX_SYS_setfsgid
:
1114 result
= setfsgid(arg1
);
1119 case TARGET_LINUX_SYS__llseek
:
1123 result
= _llseek(arg1
, arg2
, arg3
, &buf
, arg5
);
1129 translate_endian((void *) &buf
, sizeof(buf
));
1130 if ((s
.write_mem
) (cb
, &s
, t2h_addr(cb
, &s
, arg4
),
1131 (char *) &buf
, sizeof(buf
)) != sizeof(buf
))
1139 case TARGET_LINUX_SYS_getdents
:
1143 result
= getdents(arg1
, &dir
, arg3
);
1149 dir
.d_ino
= conv_endian(dir
.d_ino
);
1150 dir
.d_off
= conv_endian(dir
.d_off
);
1151 dir
.d_reclen
= conv_endian16(dir
.d_reclen
);
1152 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &dir
, sizeof(dir
))
1162 case TARGET_LINUX_SYS_flock
:
1163 result
= flock(arg1
, arg2
);
1167 case TARGET_LINUX_SYS_msync
:
1168 result
= msync((void *) arg1
, arg2
, arg3
);
1172 case TARGET_LINUX_SYS_readv
:
1174 struct iovec vector
;
1176 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1177 translate_endian((void *) &vector
, sizeof(vector
));
1179 result
= readv(arg1
, &vector
, arg3
);
1184 case TARGET_LINUX_SYS_writev
:
1186 struct iovec vector
;
1188 vector
= *((struct iovec
*) t2h_addr(cb
, &s
, arg2
));
1189 translate_endian((void *) &vector
, sizeof(vector
));
1191 result
= writev(arg1
, &vector
, arg3
);
1196 case TARGET_LINUX_SYS_fdatasync
:
1197 result
= fdatasync(arg1
);
1201 case TARGET_LINUX_SYS_mlock
:
1202 result
= mlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1206 case TARGET_LINUX_SYS_munlock
:
1207 result
= munlock((void *) t2h_addr(cb
, &s
, arg1
), arg2
);
1211 case TARGET_LINUX_SYS_nanosleep
:
1213 struct timespec req
, rem
;
1215 req
= *((struct timespec
*) t2h_addr(cb
, &s
, arg2
));
1216 translate_endian((void *) &req
, sizeof(req
));
1218 result
= nanosleep(&req
, &rem
);
1224 translate_endian((void *) &rem
, sizeof(rem
));
1225 if ((s
.write_mem
) (cb
, &s
, arg2
, (char *) &rem
, sizeof(rem
))
1234 case TARGET_LINUX_SYS_mremap
: /* FIXME */
1235 result
= (int) mremap((void *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
, arg4
);
1239 case TARGET_LINUX_SYS_getresuid32
:
1240 case TARGET_LINUX_SYS_getresuid
:
1242 uid_t ruid
, euid
, suid
;
1244 result
= getresuid(&ruid
, &euid
, &suid
);
1250 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = conv_endian(ruid
);
1251 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = conv_endian(euid
);
1252 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(suid
);
1256 case TARGET_LINUX_SYS_poll
:
1260 ufds
= *((struct pollfd
*) t2h_addr(cb
, &s
, arg1
));
1261 ufds
.fd
= conv_endian(ufds
.fd
);
1262 ufds
.events
= conv_endian16(ufds
.events
);
1263 ufds
.revents
= conv_endian16(ufds
.revents
);
1265 result
= poll(&ufds
, arg2
, arg3
);
1270 case TARGET_LINUX_SYS_getresgid32
:
1271 case TARGET_LINUX_SYS_getresgid
:
1273 uid_t rgid
, egid
, sgid
;
1275 result
= getresgid(&rgid
, &egid
, &sgid
);
1281 *((uid_t
*) t2h_addr(cb
, &s
, arg1
)) = conv_endian(rgid
);
1282 *((uid_t
*) t2h_addr(cb
, &s
, arg2
)) = conv_endian(egid
);
1283 *((uid_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(sgid
);
1287 case TARGET_LINUX_SYS_pread
:
1288 result
= pread(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1292 case TARGET_LINUX_SYS_pwrite
:
1293 result
= pwrite(arg1
, (void *) t2h_addr(cb
, &s
, arg2
), arg3
, arg4
);
1297 case TARGET_LINUX_SYS_chown32
:
1298 case TARGET_LINUX_SYS_chown
:
1299 result
= chown((char *) t2h_addr(cb
, &s
, arg1
), arg2
, arg3
);
1303 case TARGET_LINUX_SYS_getcwd
:
1304 result
= (int) getcwd((char *) t2h_addr(cb
, &s
, arg1
), arg2
);
1308 case TARGET_LINUX_SYS_sendfile
:
1312 offset
= *((off_t
*) t2h_addr(cb
, &s
, arg3
));
1313 offset
= conv_endian(offset
);
1315 result
= sendfile(arg1
, arg2
, &offset
, arg3
);
1321 *((off_t
*) t2h_addr(cb
, &s
, arg3
)) = conv_endian(offset
);
1332 m32rbf_h_gr_set (current_cpu
, 0, -errcode
);
1334 m32rbf_h_gr_set (current_cpu
, 0, result
);
1338 case TRAP_BREAKPOINT
:
1339 sim_engine_halt (sd
, current_cpu
, NULL
, pc
,
1340 sim_stopped
, SIM_SIGTRAP
);
1343 case TRAP_FLUSH_CACHE
:
1349 /* Use cr5 as EVB (EIT Vector Base) register. */
1350 USI new_pc
= m32rbf_h_cr_get (current_cpu
, 5) + 0x40 + num
* 4;
1355 /* Fake an "rte" insn. */
1356 /* FIXME: Should duplicate all of rte processing. */
1357 return (pc
& -4) + 4;