qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] tci: Detect function argument alignment
@ 2013-09-12 19:45 Stefan Weil
  2013-09-12 20:29 ` Richard Henderson
  2013-09-12 20:35 ` Peter Maydell
  0 siblings, 2 replies; 8+ messages in thread
From: Stefan Weil @ 2013-09-12 19:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Stefan Weil, Richard Henderson

This fixes TCI on ARM hosts (tested with Debian's busybox-static
running in linux-user emulation).

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 configure            |   63 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tcg/tci/tcg-target.h |    6 ++++-
 2 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 2b83936..93c3a32 100755
--- a/configure
+++ b/configure
@@ -185,6 +185,7 @@ debug_tcg="no"
 debug="no"
 strip_opt="yes"
 tcg_interpreter="no"
+call_align_args=""
 bigendian="no"
 mingw32="no"
 gcov="no"
@@ -808,6 +809,10 @@ for opt do
   ;;
   --enable-tcg-interpreter) tcg_interpreter="yes"
   ;;
+  --disable-call-align-args) call_align_args="no"
+  ;;
+  --enable-call-align-args) call_align_args="yes"
+  ;;
   --disable-cap-ng)  cap_ng="no"
   ;;
   --enable-cap-ng) cap_ng="yes"
@@ -1461,6 +1466,58 @@ esac
 fi
 
 ##########################################
+# Alignment probe for 64 bit function arguments (only needed for TCG interpreter)
+
+if test "$tcg_interpreter" = "yes" -a -z "$call_align_args"; then
+
+if test -z "$cross_prefix"; then
+
+cat > $TMPC << EOF
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <inttypes.h>
+static bool call_align_args(uint32_t arg1, uint64_t arg2) {
+  if (arg2 == 0x000000030000004ULL || arg2 == 0x0000000400000003ULL) {
+    return true;
+  } else if (arg2 == 2) {
+    /* 64 bit host, 64 bit function arguments are not aligned. */
+  } else if (arg2 == 0x0000000200000003 || arg2 == 0x0000000300000002ULL) {
+    /* 64 bit function arguments are not aligned. */
+  } else {
+    fprintf(stderr, "unexpected 64 bit function argument 0x%016" PRIx64 "\n", arg2);
+  }
+  return false;
+}
+
+typedef bool (*fptr)(uint32_t, uint32_t, uint32_t, uint32_t);
+
+int main(void) {
+  fptr f = (fptr)call_align_args;
+  return f(1, 2, 3, 4) ? 0 : 1;
+}
+EOF
+
+if compile_prog "" ""; then
+  call_align_args="no"
+  $TMPE && call_align_args="yes"
+else
+  error_exit "Function argument alignment test failed"
+fi
+
+else
+
+  # Cross compilation, so we cannot launch a program. Require configure argument.
+  error_exit "Unknown function argument alignment" \
+             "The TCG interpreter must know the alignment of function arguments." \
+             "Configure cannot determine the alignment because this is a cross build," \
+             "so please add --enable-call-align-args or --disable-call-align-args."
+
+fi
+
+fi # "$tcg_interpreter" = "yes"
+
+##########################################
 # pkg-config probe
 
 if ! has "$pkg_config_exe"; then
@@ -3709,6 +3766,9 @@ echo "Install blobs     $blobs"
 echo "KVM support       $kvm"
 echo "RDMA support      $rdma"
 echo "TCG interpreter   $tcg_interpreter"
+if test "$tcg_interpreter" = "yes"; then
+echo "call align args   $call_align_args"
+fi
 echo "fdt support       $fdt"
 echo "preadv support    $preadv"
 echo "fdatasync         $fdatasync"
@@ -4029,6 +4089,9 @@ if test "$signalfd" = "yes" ; then
 fi
 if test "$tcg_interpreter" = "yes" ; then
   echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
+  if test "$call_align_args" = "yes"; then
+    echo "CONFIG_CALL_ALIGN_ARGS=y" >> $config_host_mak
+  fi
 fi
 if test "$fdatasync" = "yes" ; then
   echo "CONFIG_FDATASYNC=y" >> $config_host_mak
diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h
index c2ecfbe..0420e96 100644
--- a/tcg/tci/tcg-target.h
+++ b/tcg/tci/tcg-target.h
@@ -1,7 +1,7 @@
 /*
  * Tiny Code Generator for QEMU
  *
- * Copyright (c) 2009, 2011 Stefan Weil
+ * Copyright (c) 2009, 2013 Stefan Weil
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -63,6 +63,10 @@
 #endif
 #endif
 
+#if defined(CONFIG_CALL_ALIGN_ARGS)
+# define TCG_TARGET_CALL_ALIGN_ARGS     1
+#endif
+
 /* Optional instructions. */
 
 #define TCG_TARGET_HAS_bswap16_i32      1
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-09-14 20:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-12 19:45 [Qemu-devel] [PATCH] tci: Detect function argument alignment Stefan Weil
2013-09-12 20:29 ` Richard Henderson
2013-09-12 20:40   ` Stefan Weil
2013-09-12 21:04     ` Richard Henderson
2013-09-12 20:35 ` Peter Maydell
2013-09-14  7:18   ` Stefan Weil
2013-09-14  9:51     ` Peter Maydell
2013-09-14 20:34       ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).