tcg-mips: Adjust qemu_ld/st for mips64
In Richard's v2 patch (shown as below), the compilation on mips64 host is disabled.
-#define LO_OFF (MIPS_BE * 4)
-#define HI_OFF (4 - LO_OFF)
+#if TCG_TARGET_REG_BITS == 32
+# define LO_OFF (MIPS_BE * 4)
+# define HI_OFF (4 - LO_OFF)
+#else
+extern int link_error(void);
+# define LO_OFF link_error()
+# define HI_OFF link_error()
+#endif
When I compiled this patch on Loongson as mips64el, a link error occured:
LINK i386-softmmu/qemu-system-i386tcg/tcg.o: In function `tcg_out_tlb_load':
tcg-target.inc.c:1252: undefined reference to `link_error'
To pass the compilation, I removed the link_error() and redefined LO_OFF/HI_OFF. It works OK on little-endian mips o32/n64 host. I have no big-endian mips machine, so the bug on big-endian is not discovered.
Frankly speaking, I didn't take n32 into consideration until you pointed out that. I feel that n32 is rarely used in current and future market. I can not even find an n32 debian distribution in Aurelien's qemu image collection.
How about leave n32 as a TODO feature?
Jin Guojie
------------------ Original ------------------
From: "Richard Henderson";<[email protected]>; Date: Nov 25, 2016 To: "Jin Guojie"<[email protected]>; "qemu-devel"<[email protected]>;
Cc: "Aurelien Jarno"<[email protected]>; "James Hogan"<[email protected]>;
Subject: Re: [PATCH v3 10/11] tcg-mips: Adjust qemu_ld/st for mips64
Review
Quoted 4 lines · Jin Guojie
(quoted diff) +2
-2-#define LO_OFF (MIPS_BE * 4) -#define HI_OFF (4 - LO_OFF) +# define LO_OFF (MIPS_BE * sizeof(long)) +# define HI_OFF (sizeof(long) - LO_OFF)
For n32, sizeof(long) == 4, and for n64, sizeof(long) == 8. So in the end this change must be wrong for big-endian.
Surely using link_error, as my patch did, to assert at compile-time that these values were never used for TCG_TARGET_REGS == 64 is better.
r~
Quoted 13 lines · Jin Guojie
In Richard's v2 patch (shown as below), the compilation on mips64 host is disabled.
(quoted diff) +8
-2-#define LO_OFF (MIPS_BE * 4) -#define HI_OFF (4 - LO_OFF) +#if TCG_TARGET_REG_BITS == 32 +# define LO_OFF (MIPS_BE * 4) +# define HI_OFF (4 - LO_OFF) +#else +extern int link_error(void); +# define LO_OFF link_error() +# define HI_OFF link_error() +#endif
Quoted 5 lines
When I compiled this patch on Loongson as mips64el, a link error occured:
LINK i386-softmmu/qemu-system-i386
tcg/tcg.o: In function `tcg_out_tlb_load':
tcg-target.inc.c:1252: undefined reference to `link_error'
The intent of the link_error is to ensure that all paths that lead to the use of the symbol are eliminated by the compiler. Therefore all uses must be protected by some trivially eliminated condition like
TCG_TARGET_REG_BITS < TARGET_LONG_BITS
which can only be true for 32-bit host and 64-bit guest.
Within the code that I have here, I only see two uses of LO/HI_OFF within tcg_out_tlb_load, both of which are protected by this condition.
/* Load the (low half) tlb comparator. Mask the page bits, keeping the
alignment bits to compare against. */
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
tcg_out_ld(s, TCG_TYPE_I32, TCG_TMP0, TCG_REG_A0, cmp_off + LO_OFF);
tcg_out_movi(s, TCG_TYPE_I32, TCG_TMP1, mask);
...
/* Load and test the high half tlb comparator. */
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
/* delay slot */
tcg_out_ld(s, TCG_TYPE_I32, TCG_TMP0, TCG_REG_A0, cmp_off + HI_OFF);The line numbers don't match up with what you quote, so I'm curious exactly which use is generating the error.
Quoted 4 lines
Frankly speaking, I didn't take n32 into consideration until you pointed out that. I feel that n32 is rarely used in current and future market. I can not even find an n32 debian distribution in Aurelien's qemu image collection.
How about leave n32 as a TODO feature?
You're probably right. Especially in the case of qemu, we really want the host to have a 64-bit virtual address space within which we can store the guest memory. The 2G available to N32 is only good for really small guests.
In this case, however, it seems just as easy to get it right, since we can test this code with N64.
r~