[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-stable] [PATCH 35/55] translate.c: Fix usermode big-endian AArch32
From: |
Michael Roth |
Subject: |
[Qemu-stable] [PATCH 35/55] translate.c: Fix usermode big-endian AArch32 LDREXD and STREXD |
Date: |
Wed, 6 Dec 2017 13:16:28 -0600 |
From: Peter Maydell <address@hidden>
For AArch32 LDREXD and STREXD, architecturally the 32-bit word at the
lowest address is always Rt and the one at addr+4 is Rt2, even if the
CPU is big-endian. Our implementation does these with a single
64-bit store, so if we're big-endian then we need to put the two
32-bit halves together in the opposite order to little-endian,
so that they end up in the right places. We were trying to do
this with the gen_aa32_frob64() function, but that is not correct
for the usermode emulator, because there there is a distinction
between "load a 64 bit value" (which does a BE 64-bit access
and doesn't need swapping) and "load two 32 bit values as one
64 bit access" (where we still need to do the swapping, like
system mode BE32).
Fixes: https://bugs.launchpad.net/qemu/+bug/1725267
Cc: address@hidden
Signed-off-by: Peter Maydell <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Message-id: address@hidden
(cherry picked from commit 3448d47b3172015006b79197eb5a69826c6a7b6d)
Signed-off-by: Michael Roth <address@hidden>
---
target/arm/translate.c | 39 ++++++++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 5 deletions(-)
diff --git a/target/arm/translate.c b/target/arm/translate.c
index d1a5f56998..ad758d333d 100644
--- a/target/arm/translate.c
+++ b/target/arm/translate.c
@@ -7858,9 +7858,27 @@ static void gen_load_exclusive(DisasContext *s, int rt,
int rt2,
TCGv_i32 tmp2 = tcg_temp_new_i32();
TCGv_i64 t64 = tcg_temp_new_i64();
- gen_aa32_ld_i64(s, t64, addr, get_mem_index(s), opc);
+ /* For AArch32, architecturally the 32-bit word at the lowest
+ * address is always Rt and the one at addr+4 is Rt2, even if
+ * the CPU is big-endian. That means we don't want to do a
+ * gen_aa32_ld_i64(), which invokes gen_aa32_frob64() as if
+ * for an architecturally 64-bit access, but instead do a
+ * 64-bit access using MO_BE if appropriate and then split
+ * the two halves.
+ * This only makes a difference for BE32 user-mode, where
+ * frob64() must not flip the two halves of the 64-bit data
+ * but this code must treat BE32 user-mode like BE32 system.
+ */
+ TCGv taddr = gen_aa32_addr(s, addr, opc);
+
+ tcg_gen_qemu_ld_i64(t64, taddr, get_mem_index(s), opc);
+ tcg_temp_free(taddr);
tcg_gen_mov_i64(cpu_exclusive_val, t64);
- tcg_gen_extr_i64_i32(tmp, tmp2, t64);
+ if (s->be_data == MO_BE) {
+ tcg_gen_extr_i64_i32(tmp2, tmp, t64);
+ } else {
+ tcg_gen_extr_i64_i32(tmp, tmp2, t64);
+ }
tcg_temp_free_i64(t64);
store_reg(s, rt2, tmp2);
@@ -7909,15 +7927,26 @@ static void gen_store_exclusive(DisasContext *s, int
rd, int rt, int rt2,
TCGv_i64 n64 = tcg_temp_new_i64();
t2 = load_reg(s, rt2);
- tcg_gen_concat_i32_i64(n64, t1, t2);
+ /* For AArch32, architecturally the 32-bit word at the lowest
+ * address is always Rt and the one at addr+4 is Rt2, even if
+ * the CPU is big-endian. Since we're going to treat this as a
+ * single 64-bit BE store, we need to put the two halves in the
+ * opposite order for BE to LE, so that they end up in the right
+ * places.
+ * We don't want gen_aa32_frob64() because that does the wrong
+ * thing for BE32 usermode.
+ */
+ if (s->be_data == MO_BE) {
+ tcg_gen_concat_i32_i64(n64, t2, t1);
+ } else {
+ tcg_gen_concat_i32_i64(n64, t1, t2);
+ }
tcg_temp_free_i32(t2);
- gen_aa32_frob64(s, n64);
tcg_gen_atomic_cmpxchg_i64(o64, taddr, cpu_exclusive_val, n64,
get_mem_index(s), opc);
tcg_temp_free_i64(n64);
- gen_aa32_frob64(s, o64);
tcg_gen_setcond_i64(TCG_COND_NE, o64, o64, cpu_exclusive_val);
tcg_gen_extrl_i64_i32(t0, o64);
--
2.11.0
- [Qemu-stable] [PATCH 28/55] hw/sd: fix out-of-bounds check for multi block reads, (continued)
- [Qemu-stable] [PATCH 28/55] hw/sd: fix out-of-bounds check for multi block reads, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 30/55] qcow2: Always execute preallocate() in a coroutine, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 27/55] memory: fix off-by-one error in memory_region_notify_one(), Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 29/55] qcow2: Fix unaligned preallocated truncation, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 24/55] memory: Share special empty FlatView, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 33/55] io: monitor encoutput buffer size from websocket GSource, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 02/55] hw/usb/bus: Remove bad object_unparent() from usb_try_create_simple(), Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 32/55] nios2: define tcg_env, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 36/55] hw/intc/arm_gicv3_its: Don't abort on table save failure, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 34/55] ppc: fix setting of compat mode, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 35/55] translate.c: Fix usermode big-endian AArch32 LDREXD and STREXD,
Michael Roth <=
- [Qemu-stable] [PATCH 37/55] net/socket: fix coverity issue, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 31/55] iotests: Add cluster_size=64k to 125, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 03/55] block/mirror: check backing in bdrv_mirror_top_flush, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 40/55] util/stats64: Fix min/max comparisons, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 42/55] vhost: restore avail index from vring used index on disconnection, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 44/55] spapr: reset DRCs after devices, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 38/55] net: fix check for number of parameters to -netdev socket, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 39/55] nbd/client: Use error_prepend() correctly, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 41/55] virtio: Add queue interface to restore avail index from vring used index, Michael Roth, 2017/12/06
- [Qemu-stable] [PATCH 43/55] hw/ppc: clear pending_events on machine reset, Michael Roth, 2017/12/06