sim: m32r: fixup some of the int<->pointer casts
The m32r trap code was written for a 32-bit Linux host (and really, one whose Linux ABI matched pretty exactly). This has lead to conversions between integers and pointers which breaks down hard on 64-bit hosts. Clean up some of the functions where possible to avoid unnecessary conversions, use uintptr_t to cast 32-bit target pointers to host pointers in some places, and just stub out a few functions that can't easily be salvaged currently when sizeof(void*) is not 32-bits. This is a bit ugly, but lets us enable warnings for the whole file.
This commit is contained in:
parent
dbd4aebe5b
commit
08a7937f3a
@ -489,6 +489,9 @@
|
|||||||
/* The size of `long long', as computed by sizeof. */
|
/* The size of `long long', as computed by sizeof. */
|
||||||
#undef SIZEOF_LONG_LONG
|
#undef SIZEOF_LONG_LONG
|
||||||
|
|
||||||
|
/* The size of `void *', as computed by sizeof. */
|
||||||
|
#undef SIZEOF_VOID_P
|
||||||
|
|
||||||
/* Define to 1 if you have the ANSI C header files. */
|
/* Define to 1 if you have the ANSI C header files. */
|
||||||
#undef STDC_HEADERS
|
#undef STDC_HEADERS
|
||||||
|
|
||||||
|
39
sim/configure
vendored
39
sim/configure
vendored
@ -8882,6 +8882,40 @@ _ACEOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# The cast to long int works around a bug in the HP C Compiler
|
||||||
|
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
||||||
|
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
|
||||||
|
# This bug is HP SR number 8606223364.
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of void *" >&5
|
||||||
|
$as_echo_n "checking size of void *... " >&6; }
|
||||||
|
if ${ac_cv_sizeof_void_p+:} false; then :
|
||||||
|
$as_echo_n "(cached) " >&6
|
||||||
|
else
|
||||||
|
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (void *))" "ac_cv_sizeof_void_p" "$ac_includes_default"; then :
|
||||||
|
|
||||||
|
else
|
||||||
|
if test "$ac_cv_type_void_p" = yes; then
|
||||||
|
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
|
||||||
|
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
|
||||||
|
as_fn_error 77 "cannot compute sizeof (void *)
|
||||||
|
See \`config.log' for more details" "$LINENO" 5; }
|
||||||
|
else
|
||||||
|
ac_cv_sizeof_void_p=0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_void_p" >&5
|
||||||
|
$as_echo "$ac_cv_sizeof_void_p" >&6; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cat >>confdefs.h <<_ACEOF
|
||||||
|
#define SIZEOF_VOID_P $ac_cv_sizeof_void_p
|
||||||
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct statfs" >&5
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct statfs" >&5
|
||||||
$as_echo_n "checking for struct statfs... " >&6; }
|
$as_echo_n "checking for struct statfs... " >&6; }
|
||||||
if ${sim_cv_struct_statfs+:} false; then :
|
if ${sim_cv_struct_statfs+:} false; then :
|
||||||
@ -12858,7 +12892,7 @@ else
|
|||||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||||
lt_status=$lt_dlunknown
|
lt_status=$lt_dlunknown
|
||||||
cat > conftest.$ac_ext <<_LT_EOF
|
cat > conftest.$ac_ext <<_LT_EOF
|
||||||
#line 12861 "configure"
|
#line 12895 "configure"
|
||||||
#include "confdefs.h"
|
#include "confdefs.h"
|
||||||
|
|
||||||
#if HAVE_DLFCN_H
|
#if HAVE_DLFCN_H
|
||||||
@ -12964,7 +12998,7 @@ else
|
|||||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||||
lt_status=$lt_dlunknown
|
lt_status=$lt_dlunknown
|
||||||
cat > conftest.$ac_ext <<_LT_EOF
|
cat > conftest.$ac_ext <<_LT_EOF
|
||||||
#line 12967 "configure"
|
#line 13001 "configure"
|
||||||
#include "confdefs.h"
|
#include "confdefs.h"
|
||||||
|
|
||||||
#if HAVE_DLFCN_H
|
#if HAVE_DLFCN_H
|
||||||
@ -13961,7 +13995,6 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ac_fn_c_check_decl "$LINENO" "ffs" "ac_cv_have_decl_ffs" "$ac_includes_default"
|
ac_fn_c_check_decl "$LINENO" "ffs" "ac_cv_have_decl_ffs" "$ac_includes_default"
|
||||||
if test "x$ac_cv_have_decl_ffs" = xyes; then :
|
if test "x$ac_cv_have_decl_ffs" = xyes; then :
|
||||||
ac_have_decl=1
|
ac_have_decl=1
|
||||||
|
@ -436,7 +436,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_LINUX_SYS_brk:
|
case TARGET_LINUX_SYS_brk:
|
||||||
result = brk ((void *) arg1);
|
result = brk ((void *) (uintptr_t) arg1);
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
//result = arg1;
|
//result = arg1;
|
||||||
break;
|
break;
|
||||||
@ -582,51 +582,51 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
fd_set *treadfdsp;
|
unsigned int treadfdsp;
|
||||||
fd_set *hreadfdsp;
|
fd_set *hreadfdsp;
|
||||||
fd_set writefds;
|
fd_set writefds;
|
||||||
fd_set *twritefdsp;
|
unsigned int twritefdsp;
|
||||||
fd_set *hwritefdsp;
|
fd_set *hwritefdsp;
|
||||||
fd_set exceptfds;
|
fd_set exceptfds;
|
||||||
fd_set *texceptfdsp;
|
unsigned int texceptfdsp;
|
||||||
fd_set *hexceptfdsp;
|
fd_set *hexceptfdsp;
|
||||||
struct timeval *ttimeoutp;
|
unsigned int ttimeoutp;
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
|
|
||||||
n = arg1;
|
n = arg1;
|
||||||
|
|
||||||
treadfdsp = (fd_set *) arg2;
|
treadfdsp = arg2;
|
||||||
if (treadfdsp != NULL)
|
if (treadfdsp !=0)
|
||||||
{
|
{
|
||||||
readfds = *((fd_set *) t2h_addr (cb, &s, (unsigned int) treadfdsp));
|
readfds = *((fd_set *) t2h_addr (cb, &s, treadfdsp));
|
||||||
translate_endian_t2h (&readfds, sizeof(readfds));
|
translate_endian_t2h (&readfds, sizeof(readfds));
|
||||||
hreadfdsp = &readfds;
|
hreadfdsp = &readfds;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hreadfdsp = NULL;
|
hreadfdsp = NULL;
|
||||||
|
|
||||||
twritefdsp = (fd_set *) arg3;
|
twritefdsp = arg3;
|
||||||
if (twritefdsp != NULL)
|
if (twritefdsp != 0)
|
||||||
{
|
{
|
||||||
writefds = *((fd_set *) t2h_addr (cb, &s, (unsigned int) twritefdsp));
|
writefds = *((fd_set *) t2h_addr (cb, &s, twritefdsp));
|
||||||
translate_endian_t2h (&writefds, sizeof(writefds));
|
translate_endian_t2h (&writefds, sizeof(writefds));
|
||||||
hwritefdsp = &writefds;
|
hwritefdsp = &writefds;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hwritefdsp = NULL;
|
hwritefdsp = NULL;
|
||||||
|
|
||||||
texceptfdsp = (fd_set *) arg4;
|
texceptfdsp = arg4;
|
||||||
if (texceptfdsp != NULL)
|
if (texceptfdsp != 0)
|
||||||
{
|
{
|
||||||
exceptfds = *((fd_set *) t2h_addr (cb, &s, (unsigned int) texceptfdsp));
|
exceptfds = *((fd_set *) t2h_addr (cb, &s, texceptfdsp));
|
||||||
translate_endian_t2h (&exceptfds, sizeof(exceptfds));
|
translate_endian_t2h (&exceptfds, sizeof(exceptfds));
|
||||||
hexceptfdsp = &exceptfds;
|
hexceptfdsp = &exceptfds;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hexceptfdsp = NULL;
|
hexceptfdsp = NULL;
|
||||||
|
|
||||||
ttimeoutp = (struct timeval *) arg5;
|
ttimeoutp = arg5;
|
||||||
timeout = *((struct timeval *) t2h_addr (cb, &s, (unsigned int) ttimeoutp));
|
timeout = *((struct timeval *) t2h_addr (cb, &s, ttimeoutp));
|
||||||
translate_endian_t2h (&timeout, sizeof(timeout));
|
translate_endian_t2h (&timeout, sizeof(timeout));
|
||||||
|
|
||||||
result = select (n, hreadfdsp, hwritefdsp, hexceptfdsp, &timeout);
|
result = select (n, hreadfdsp, hwritefdsp, hexceptfdsp, &timeout);
|
||||||
@ -635,10 +635,10 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
if (result != 0)
|
if (result != 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (treadfdsp != NULL)
|
if (treadfdsp != 0)
|
||||||
{
|
{
|
||||||
translate_endian_h2t (&readfds, sizeof(readfds));
|
translate_endian_h2t (&readfds, sizeof(readfds));
|
||||||
if ((s.write_mem) (cb, &s, (unsigned long) treadfdsp,
|
if ((s.write_mem) (cb, &s, treadfdsp,
|
||||||
(char *) &readfds, sizeof(readfds)) != sizeof(readfds))
|
(char *) &readfds, sizeof(readfds)) != sizeof(readfds))
|
||||||
{
|
{
|
||||||
result = -1;
|
result = -1;
|
||||||
@ -646,10 +646,10 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (twritefdsp != NULL)
|
if (twritefdsp != 0)
|
||||||
{
|
{
|
||||||
translate_endian_h2t (&writefds, sizeof(writefds));
|
translate_endian_h2t (&writefds, sizeof(writefds));
|
||||||
if ((s.write_mem) (cb, &s, (unsigned long) twritefdsp,
|
if ((s.write_mem) (cb, &s, twritefdsp,
|
||||||
(char *) &writefds, sizeof(writefds)) != sizeof(writefds))
|
(char *) &writefds, sizeof(writefds)) != sizeof(writefds))
|
||||||
{
|
{
|
||||||
result = -1;
|
result = -1;
|
||||||
@ -657,10 +657,10 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texceptfdsp != NULL)
|
if (texceptfdsp != 0)
|
||||||
{
|
{
|
||||||
translate_endian_h2t (&exceptfds, sizeof(exceptfds));
|
translate_endian_h2t (&exceptfds, sizeof(exceptfds));
|
||||||
if ((s.write_mem) (cb, &s, (unsigned long) texceptfdsp,
|
if ((s.write_mem) (cb, &s, texceptfdsp,
|
||||||
(char *) &exceptfds, sizeof(exceptfds)) != sizeof(exceptfds))
|
(char *) &exceptfds, sizeof(exceptfds)) != sizeof(exceptfds))
|
||||||
{
|
{
|
||||||
result = -1;
|
result = -1;
|
||||||
@ -669,7 +669,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
translate_endian_h2t (&timeout, sizeof(timeout));
|
translate_endian_h2t (&timeout, sizeof(timeout));
|
||||||
if ((s.write_mem) (cb, &s, (unsigned long) ttimeoutp,
|
if ((s.write_mem) (cb, &s, ttimeoutp,
|
||||||
(char *) &timeout, sizeof(timeout)) != sizeof(timeout))
|
(char *) &timeout, sizeof(timeout)) != sizeof(timeout))
|
||||||
{
|
{
|
||||||
result = -1;
|
result = -1;
|
||||||
@ -692,8 +692,13 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_LINUX_SYS_readdir:
|
case TARGET_LINUX_SYS_readdir:
|
||||||
|
#if SIZEOF_VOID_P == 4
|
||||||
result = (int) readdir ((DIR *) t2h_addr (cb, &s, arg1));
|
result = (int) readdir ((DIR *) t2h_addr (cb, &s, arg1));
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
|
#else
|
||||||
|
result = 0;
|
||||||
|
errcode = ENOSYS;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -714,6 +719,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
#endif
|
#endif
|
||||||
case TARGET_LINUX_SYS_mmap2:
|
case TARGET_LINUX_SYS_mmap2:
|
||||||
{
|
{
|
||||||
|
#if SIZEOF_VOID_P == 4 /* Code assumes m32r pointer size matches host. */
|
||||||
void *addr;
|
void *addr;
|
||||||
size_t len;
|
size_t len;
|
||||||
int prot, flags, fildes;
|
int prot, flags, fildes;
|
||||||
@ -736,11 +742,16 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
0, access_read_write_exec, 0,
|
0, access_read_write_exec, 0,
|
||||||
result, len, 0, NULL, NULL);
|
result, len, 0, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
result = 0;
|
||||||
|
errcode = ENOSYS;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_LINUX_SYS_mmap:
|
case TARGET_LINUX_SYS_mmap:
|
||||||
{
|
{
|
||||||
|
#if SIZEOF_VOID_P == 4 /* Code assumes m32r pointer size matches host. */
|
||||||
void *addr;
|
void *addr;
|
||||||
size_t len;
|
size_t len;
|
||||||
int prot, flags, fildes;
|
int prot, flags, fildes;
|
||||||
@ -773,11 +784,15 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
0, access_read_write_exec, 0,
|
0, access_read_write_exec, 0,
|
||||||
result, len, 0, NULL, NULL);
|
result, len, 0, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
result = 0;
|
||||||
|
errcode = ENOSYS;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_LINUX_SYS_munmap:
|
case TARGET_LINUX_SYS_munmap:
|
||||||
result = munmap ((void *)arg1, arg2);
|
result = munmap ((void *) (uintptr_t) arg1, arg2);
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
if (result != -1)
|
if (result != -1)
|
||||||
sim_core_detach (sd, NULL, 0, arg2, result);
|
sim_core_detach (sd, NULL, 0, arg2, result);
|
||||||
@ -1078,7 +1093,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_LINUX_SYS_mprotect:
|
case TARGET_LINUX_SYS_mprotect:
|
||||||
result = mprotect ((void *) arg1, arg2, arg3);
|
result = mprotect ((void *) (uintptr_t) arg1, arg2, arg3);
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1149,7 +1164,7 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_LINUX_SYS_msync:
|
case TARGET_LINUX_SYS_msync:
|
||||||
result = msync ((void *) arg1, arg2, arg3);
|
result = msync ((void *) (uintptr_t) arg1, arg2, arg3);
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1216,8 +1231,13 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_LINUX_SYS_mremap: /* FIXME */
|
case TARGET_LINUX_SYS_mremap: /* FIXME */
|
||||||
|
#if SIZEOF_VOID_P == 4 /* Code assumes m32r pointer size matches host. */
|
||||||
result = (int) mremap ((void *) t2h_addr (cb, &s, arg1), arg2, arg3, arg4);
|
result = (int) mremap ((void *) t2h_addr (cb, &s, arg1), arg2, arg3, arg4);
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
|
#else
|
||||||
|
result = -1;
|
||||||
|
errcode = ENOSYS;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_LINUX_SYS_getresuid32:
|
case TARGET_LINUX_SYS_getresuid32:
|
||||||
@ -1285,8 +1305,13 @@ m32r_trap (SIM_CPU *current_cpu, PCADDR pc, int num)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_LINUX_SYS_getcwd:
|
case TARGET_LINUX_SYS_getcwd:
|
||||||
result = (int) getcwd ((char *) t2h_addr (cb, &s, arg1), arg2);
|
{
|
||||||
|
void *ret;
|
||||||
|
|
||||||
|
ret = getcwd ((char *) t2h_addr (cb, &s, arg1), arg2);
|
||||||
|
result = ret == NULL ? 0 : arg1;
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TARGET_LINUX_SYS_sendfile:
|
case TARGET_LINUX_SYS_sendfile:
|
||||||
|
@ -133,6 +133,8 @@ AC_CHECK_TYPES(socklen_t, [], [],
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
])
|
])
|
||||||
|
|
||||||
|
AC_CHECK_SIZEOF([void *])
|
||||||
|
|
||||||
dnl Check for struct statfs.
|
dnl Check for struct statfs.
|
||||||
AC_CACHE_CHECK([for struct statfs],
|
AC_CACHE_CHECK([for struct statfs],
|
||||||
[sim_cv_struct_statfs],
|
[sim_cv_struct_statfs],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user