From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
Laurent Vivier <laurent@vivier.eu>
Subject: [PULL 10/27] target/alpha: Implement prctl_unalign_sigbus
Date: Thu, 6 Jan 2022 11:41:20 +0100 [thread overview]
Message-ID: <20220106104137.732883-11-laurent@vivier.eu> (raw)
In-Reply-To: <20220106104137.732883-1-laurent@vivier.eu>
From: Richard Henderson <richard.henderson@linaro.org>
Leave TARGET_ALIGNED_ONLY set, but use the new CPUState
flag to set MO_UNALN for the instructions that the kernel
handles in the unaligned trap.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20211227150127.2659293-5-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/alpha/target_prctl.h | 2 +-
target/alpha/cpu.h | 5 +++++
target/alpha/translate.c | 31 ++++++++++++++++++++++---------
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/linux-user/alpha/target_prctl.h b/linux-user/alpha/target_prctl.h
index eb53b31ad554..5629ddbf39cd 100644
--- a/linux-user/alpha/target_prctl.h
+++ b/linux-user/alpha/target_prctl.h
@@ -1 +1 @@
-/* No special prctl support required. */
+#include "../generic/target_prctl_unalign.h"
diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h
index afd975c87801..e81921150392 100644
--- a/target/alpha/cpu.h
+++ b/target/alpha/cpu.h
@@ -383,6 +383,8 @@ enum {
#define ENV_FLAG_TB_MASK \
(ENV_FLAG_PAL_MODE | ENV_FLAG_PS_USER | ENV_FLAG_FEN)
+#define TB_FLAG_UNALIGN (1u << 1)
+
static inline int cpu_mmu_index(CPUAlphaState *env, bool ifetch)
{
int ret = env->flags & ENV_FLAG_PS_USER ? MMU_USER_IDX : MMU_KERNEL_IDX;
@@ -470,6 +472,9 @@ static inline void cpu_get_tb_cpu_state(CPUAlphaState *env, target_ulong *pc,
*pc = env->pc;
*cs_base = 0;
*pflags = env->flags & ENV_FLAG_TB_MASK;
+#ifdef CONFIG_USER_ONLY
+ *pflags |= TB_FLAG_UNALIGN * !env_cpu(env)->prctl_unalign_sigbus;
+#endif
}
#ifdef CONFIG_USER_ONLY
diff --git a/target/alpha/translate.c b/target/alpha/translate.c
index a4c3f43e720a..208ae5fbd50d 100644
--- a/target/alpha/translate.c
+++ b/target/alpha/translate.c
@@ -45,7 +45,9 @@ typedef struct DisasContext DisasContext;
struct DisasContext {
DisasContextBase base;
-#ifndef CONFIG_USER_ONLY
+#ifdef CONFIG_USER_ONLY
+ MemOp unalign;
+#else
uint64_t palbr;
#endif
uint32_t tbflags;
@@ -68,6 +70,12 @@ struct DisasContext {
TCGv sink;
};
+#ifdef CONFIG_USER_ONLY
+#define UNALIGN(C) (C)->unalign
+#else
+#define UNALIGN(C) 0
+#endif
+
/* Target-specific return values from translate_one, indicating the
state of the TB. Note that DISAS_NEXT indicates that we are not
exiting the TB. */
@@ -270,7 +278,7 @@ static inline DisasJumpType gen_invalid(DisasContext *ctx)
static void gen_ldf(DisasContext *ctx, TCGv dest, TCGv addr)
{
TCGv_i32 tmp32 = tcg_temp_new_i32();
- tcg_gen_qemu_ld_i32(tmp32, addr, ctx->mem_idx, MO_LEUL);
+ tcg_gen_qemu_ld_i32(tmp32, addr, ctx->mem_idx, MO_LEUL | UNALIGN(ctx));
gen_helper_memory_to_f(dest, tmp32);
tcg_temp_free_i32(tmp32);
}
@@ -278,7 +286,7 @@ static void gen_ldf(DisasContext *ctx, TCGv dest, TCGv addr)
static void gen_ldg(DisasContext *ctx, TCGv dest, TCGv addr)
{
TCGv tmp = tcg_temp_new();
- tcg_gen_qemu_ld_i64(tmp, addr, ctx->mem_idx, MO_LEQ);
+ tcg_gen_qemu_ld_i64(tmp, addr, ctx->mem_idx, MO_LEQ | UNALIGN(ctx));
gen_helper_memory_to_g(dest, tmp);
tcg_temp_free(tmp);
}
@@ -286,14 +294,14 @@ static void gen_ldg(DisasContext *ctx, TCGv dest, TCGv addr)
static void gen_lds(DisasContext *ctx, TCGv dest, TCGv addr)
{
TCGv_i32 tmp32 = tcg_temp_new_i32();
- tcg_gen_qemu_ld_i32(tmp32, addr, ctx->mem_idx, MO_LEUL);
+ tcg_gen_qemu_ld_i32(tmp32, addr, ctx->mem_idx, MO_LEUL | UNALIGN(ctx));
gen_helper_memory_to_s(dest, tmp32);
tcg_temp_free_i32(tmp32);
}
static void gen_ldt(DisasContext *ctx, TCGv dest, TCGv addr)
{
- tcg_gen_qemu_ld_i64(dest, addr, ctx->mem_idx, MO_LEQ);
+ tcg_gen_qemu_ld_i64(dest, addr, ctx->mem_idx, MO_LEQ | UNALIGN(ctx));
}
static void gen_load_fp(DisasContext *ctx, int ra, int rb, int32_t disp16,
@@ -324,6 +332,8 @@ static void gen_load_int(DisasContext *ctx, int ra, int rb, int32_t disp16,
tcg_gen_addi_i64(addr, load_gpr(ctx, rb), disp16);
if (clear) {
tcg_gen_andi_i64(addr, addr, ~0x7);
+ } else if (!locked) {
+ op |= UNALIGN(ctx);
}
dest = ctx->ir[ra];
@@ -340,7 +350,7 @@ static void gen_stf(DisasContext *ctx, TCGv src, TCGv addr)
{
TCGv_i32 tmp32 = tcg_temp_new_i32();
gen_helper_f_to_memory(tmp32, addr);
- tcg_gen_qemu_st_i32(tmp32, addr, ctx->mem_idx, MO_LEUL);
+ tcg_gen_qemu_st_i32(tmp32, addr, ctx->mem_idx, MO_LEUL | UNALIGN(ctx));
tcg_temp_free_i32(tmp32);
}
@@ -348,7 +358,7 @@ static void gen_stg(DisasContext *ctx, TCGv src, TCGv addr)
{
TCGv tmp = tcg_temp_new();
gen_helper_g_to_memory(tmp, src);
- tcg_gen_qemu_st_i64(tmp, addr, ctx->mem_idx, MO_LEQ);
+ tcg_gen_qemu_st_i64(tmp, addr, ctx->mem_idx, MO_LEQ | UNALIGN(ctx));
tcg_temp_free(tmp);
}
@@ -356,13 +366,13 @@ static void gen_sts(DisasContext *ctx, TCGv src, TCGv addr)
{
TCGv_i32 tmp32 = tcg_temp_new_i32();
gen_helper_s_to_memory(tmp32, src);
- tcg_gen_qemu_st_i32(tmp32, addr, ctx->mem_idx, MO_LEUL);
+ tcg_gen_qemu_st_i32(tmp32, addr, ctx->mem_idx, MO_LEUL | UNALIGN(ctx));
tcg_temp_free_i32(tmp32);
}
static void gen_stt(DisasContext *ctx, TCGv src, TCGv addr)
{
- tcg_gen_qemu_st_i64(src, addr, ctx->mem_idx, MO_LEQ);
+ tcg_gen_qemu_st_i64(src, addr, ctx->mem_idx, MO_LEQ | UNALIGN(ctx));
}
static void gen_store_fp(DisasContext *ctx, int ra, int rb, int32_t disp16,
@@ -383,6 +393,8 @@ static void gen_store_int(DisasContext *ctx, int ra, int rb, int32_t disp16,
tcg_gen_addi_i64(addr, load_gpr(ctx, rb), disp16);
if (clear) {
tcg_gen_andi_i64(addr, addr, ~0x7);
+ } else {
+ op |= UNALIGN(ctx);
}
src = load_gpr(ctx, ra);
@@ -2942,6 +2954,7 @@ static void alpha_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu)
#ifdef CONFIG_USER_ONLY
ctx->ir = cpu_std_ir;
+ ctx->unalign = (ctx->tbflags & TB_FLAG_UNALIGN ? MO_UNALN : MO_ALIGN);
#else
ctx->palbr = env->palbr;
ctx->ir = (ctx->tbflags & ENV_FLAG_PAL_MODE ? cpu_pal_ir : cpu_std_ir);
--
2.33.1
next prev parent reply other threads:[~2022-01-06 10:50 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-06 10:41 [PULL 00/27] Linux user for 7.0 patches Laurent Vivier
2022-01-06 10:41 ` [PULL 01/27] qemu-binfmt-conf.sh: fix -F option Laurent Vivier
2022-01-06 10:41 ` [PULL 02/27] linux-user/hexagon: Use generic target_stat64 structure Laurent Vivier
2022-01-06 10:41 ` [PULL 03/27] linux-user: Mark cpu_loop() with noreturn attribute Laurent Vivier
2022-01-06 10:41 ` [PULL 04/27] linux-user: Move target_signal.h generic definitions to generic/signal.h Laurent Vivier
2022-01-06 10:41 ` [PULL 05/27] linux-user: target_syscall.h remove definition TARGET_MINSIGSTKSZ Laurent Vivier
2022-01-06 10:41 ` [PULL 06/27] linux-user: Remove TARGET_SIGSTKSZ Laurent Vivier
2022-01-06 10:41 ` [PULL 07/27] linux-user: Split out do_prctl and subroutines Laurent Vivier
2022-01-06 10:41 ` [PULL 08/27] linux-user: Disable more prctl subcodes Laurent Vivier
2022-01-06 10:41 ` [PULL 09/27] linux-user: Add code for PR_GET/SET_UNALIGN Laurent Vivier
2022-01-06 10:41 ` Laurent Vivier [this message]
2022-01-06 10:41 ` [PULL 11/27] target/hppa: Implement prctl_unalign_sigbus Laurent Vivier
2022-01-06 10:41 ` [PULL 12/27] target/sh4: " Laurent Vivier
2022-01-06 10:41 ` [PULL 13/27] linux-user/signal: Map exit signals in SIGCHLD siginfo_t Laurent Vivier
2022-01-06 10:41 ` [PULL 14/27] linux-user: add sched_getattr support Laurent Vivier
2022-01-06 10:41 ` [PULL 15/27] linux-user: call set/getscheduler set/getparam directly Laurent Vivier
2022-01-06 10:41 ` [PULL 16/27] linux-user/syscall.c: fix missed flag for shared memory in open_self_maps Laurent Vivier
2022-01-06 10:41 ` [PULL 17/27] linux-user/nios2: Properly emulate EXCP_TRAP Laurent Vivier
2022-01-06 10:41 ` [PULL 18/27] linux-user/nios2: Fixes for signal frame setup Laurent Vivier
2022-01-06 10:41 ` [PULL 19/27] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE Laurent Vivier
2022-01-06 10:41 ` [PULL 20/27] linux-user/nios2: Map a real kuser page Laurent Vivier
2022-01-10 13:22 ` Peter Maydell
2022-01-06 10:41 ` [PULL 21/27] linux-user/nios2: Fix EA vs PC confusion Laurent Vivier
2022-01-06 10:41 ` [PULL 22/27] linux-user/nios2: Fix sigmask in setup_rt_frame Laurent Vivier
2022-01-06 10:41 ` [PULL 23/27] linux-user/nios2: Use set_sigmask in do_rt_sigreturn Laurent Vivier
2022-01-06 10:41 ` [PULL 24/27] linux-user/syscall.c: malloc to g_try_malloc Laurent Vivier
2022-01-06 10:41 ` [PULL 25/27] linux-user: netlink: update IFLA entries Laurent Vivier
2022-01-06 10:41 ` [PULL 26/27] linux-user: netlink: Add IFLA_VFINFO_LIST Laurent Vivier
2022-01-06 10:41 ` [PULL 27/27] linux-user: netlink: update IFLA_BRPORT entries Laurent Vivier
2022-01-06 21:15 ` [PULL 00/27] Linux user for 7.0 patches Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220106104137.732883-11-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).