w64: Fix TCG helper functions with 5 arguments
authorStefan Weil <sw@weilnetz.de>
Thu, 13 Sep 2012 17:37:43 +0000 (19:37 +0200)
committerAurelien Jarno <aurelien@aurel32.net>
Sat, 22 Sep 2012 13:10:22 +0000 (15:10 +0200)
TCG uses 6 registers for function arguments on 64 bit Linux hosts,
but only 4 registers on W64 hosts.

Commit 2999a0b20074a7e4a58f56572bb1436749368f59 increased the number
of arguments for some important helper functions from 4 to 5
which triggered a bug for W64 hosts: QEMU aborts when executing
helper_lcall_real in the guest's BIOS because function
tcg_target_get_call_iarg_regs_count always returned 6.

As W64 has only 4 registers for arguments, the 5th argument must be
passed on the stack using a correct stack offset.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
tcg/i386/tcg-target.c
tcg/i386/tcg-target.h

index aa1fa9ff4c6f649b3792f6d34ffef93b5193367c..85c6b8159e2e32fb63007e317534a15953c83420 100644 (file)
@@ -118,7 +118,7 @@ static void patch_reloc(uint8_t *code_ptr, int type,
 static inline int tcg_target_get_call_iarg_regs_count(int flags)
 {
     if (TCG_TARGET_REG_BITS == 64) {
-        return 6;
+        return ARRAY_SIZE(tcg_target_call_iarg_regs);
     }
 
     return 0;
index b356d76312beb2a1b857e335c72db3ffb576abe9..ace63ba37b8be16c75c491aaf055b32d296be039 100644 (file)
@@ -67,7 +67,11 @@ typedef enum {
 /* used for function call generation */
 #define TCG_REG_CALL_STACK TCG_REG_ESP 
 #define TCG_TARGET_STACK_ALIGN 16
+#if defined(_WIN64)
+#define TCG_TARGET_CALL_STACK_OFFSET 32
+#else
 #define TCG_TARGET_CALL_STACK_OFFSET 0
+#endif
 
 /* optional instructions */
 #define TCG_TARGET_HAS_div2_i32         1