• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisiónbe0e3d7a1e148180fe1b89c7f93720db0607614e (tree)
Tiempo2018-07-10 02:34:04
AutorRichard Henderson <richard.henderson@lina...>
CommiterRichard Henderson

Log Message

target/sh4: Fix translator.c assertion failure for gUSA

The translator loop does not allow the tb_start hook to set
dc->base.is_jmp; the only hook allowed to do that is translate_insn.

Split the work between init_disas_context where we validate
the gUSA parameters, and translate_insn where we emit code.

Tested-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Cambiar Resumen

Diferencia incremental

--- a/target/sh4/translate.c
+++ b/target/sh4/translate.c
@@ -1895,35 +1895,18 @@ static void decode_opc(DisasContext * ctx)
18951895 any sequence via cpu_exec_step_atomic, we can recognize the "normal"
18961896 sequences and transform them into atomic operations as seen by the host.
18971897 */
1898-static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns)
1898+static void decode_gusa(DisasContext *ctx, CPUSH4State *env)
18991899 {
19001900 uint16_t insns[5];
19011901 int ld_adr, ld_dst, ld_mop;
19021902 int op_dst, op_src, op_opc;
19031903 int mv_src, mt_dst, st_src, st_mop;
19041904 TCGv op_arg;
1905-
19061905 uint32_t pc = ctx->base.pc_next;
19071906 uint32_t pc_end = ctx->base.tb->cs_base;
1908- int backup = sextract32(ctx->tbflags, GUSA_SHIFT, 8);
19091907 int max_insns = (pc_end - pc) / 2;
19101908 int i;
19111909
1912- if (pc != pc_end + backup || max_insns < 2) {
1913- /* This is a malformed gUSA region. Don't do anything special,
1914- since the interpreter is likely to get confused. */
1915- ctx->envflags &= ~GUSA_MASK;
1916- return 0;
1917- }
1918-
1919- if (ctx->tbflags & GUSA_EXCLUSIVE) {
1920- /* Regardless of single-stepping or the end of the page,
1921- we must complete execution of the gUSA region while
1922- holding the exclusive lock. */
1923- *pmax_insns = max_insns;
1924- return 0;
1925- }
1926-
19271910 /* The state machine below will consume only a few insns.
19281911 If there are more than that in a region, fail now. */
19291912 if (max_insns > ARRAY_SIZE(insns)) {
@@ -2140,7 +2123,6 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns)
21402123 /*
21412124 * Emit the operation.
21422125 */
2143- tcg_gen_insn_start(pc, ctx->envflags);
21442126 switch (op_opc) {
21452127 case -1:
21462128 /* No operation found. Look for exchange pattern. */
@@ -2235,7 +2217,8 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns)
22352217 /* The entire region has been translated. */
22362218 ctx->envflags &= ~GUSA_MASK;
22372219 ctx->base.pc_next = pc_end;
2238- return max_insns;
2220+ ctx->base.num_insns += max_insns - 1;
2221+ return;
22392222
22402223 fail:
22412224 qemu_log_mask(LOG_UNIMP, "Unrecognized gUSA sequence %08x-%08x\n",
@@ -2243,7 +2226,6 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns)
22432226
22442227 /* Restart with the EXCLUSIVE bit set, within a TB run via
22452228 cpu_exec_step_atomic holding the exclusive lock. */
2246- tcg_gen_insn_start(pc, ctx->envflags);
22472229 ctx->envflags |= GUSA_EXCLUSIVE;
22482230 gen_save_cpu_state(ctx, false);
22492231 gen_helper_exclusive(cpu_env);
@@ -2254,7 +2236,7 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns)
22542236 entire region consumed via ctx->base.pc_next so that it's immediately
22552237 available in the disassembly dump. */
22562238 ctx->base.pc_next = pc_end;
2257- return 1;
2239+ ctx->base.num_insns += max_insns - 1;
22582240 }
22592241 #endif
22602242
@@ -2262,19 +2244,39 @@ static void sh4_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
22622244 {
22632245 DisasContext *ctx = container_of(dcbase, DisasContext, base);
22642246 CPUSH4State *env = cs->env_ptr;
2247+ uint32_t tbflags;
22652248 int bound;
22662249
2267- ctx->tbflags = (uint32_t)ctx->base.tb->flags;
2268- ctx->envflags = ctx->base.tb->flags & TB_FLAG_ENVFLAGS_MASK;
2269- ctx->memidx = (ctx->tbflags & (1u << SR_MD)) == 0 ? 1 : 0;
2250+ ctx->tbflags = tbflags = ctx->base.tb->flags;
2251+ ctx->envflags = tbflags & TB_FLAG_ENVFLAGS_MASK;
2252+ ctx->memidx = (tbflags & (1u << SR_MD)) == 0 ? 1 : 0;
22702253 /* We don't know if the delayed pc came from a dynamic or static branch,
22712254 so assume it is a dynamic branch. */
22722255 ctx->delayed_pc = -1; /* use delayed pc from env pointer */
22732256 ctx->features = env->features;
2274- ctx->has_movcal = (ctx->tbflags & TB_FLAG_PENDING_MOVCA);
2275- ctx->gbank = ((ctx->tbflags & (1 << SR_MD)) &&
2276- (ctx->tbflags & (1 << SR_RB))) * 0x10;
2277- ctx->fbank = ctx->tbflags & FPSCR_FR ? 0x10 : 0;
2257+ ctx->has_movcal = (tbflags & TB_FLAG_PENDING_MOVCA);
2258+ ctx->gbank = ((tbflags & (1 << SR_MD)) &&
2259+ (tbflags & (1 << SR_RB))) * 0x10;
2260+ ctx->fbank = tbflags & FPSCR_FR ? 0x10 : 0;
2261+
2262+ if (tbflags & GUSA_MASK) {
2263+ uint32_t pc = ctx->base.pc_next;
2264+ uint32_t pc_end = ctx->base.tb->cs_base;
2265+ int backup = sextract32(ctx->tbflags, GUSA_SHIFT, 8);
2266+ int max_insns = (pc_end - pc) / 2;
2267+
2268+ if (pc != pc_end + backup || max_insns < 2) {
2269+ /* This is a malformed gUSA region. Don't do anything special,
2270+ since the interpreter is likely to get confused. */
2271+ ctx->envflags &= ~GUSA_MASK;
2272+ } else if (tbflags & GUSA_EXCLUSIVE) {
2273+ /* Regardless of single-stepping or the end of the page,
2274+ we must complete execution of the gUSA region while
2275+ holding the exclusive lock. */
2276+ ctx->base.max_insns = max_insns;
2277+ return;
2278+ }
2279+ }
22782280
22792281 /* Since the ISA is fixed-width, we can bound by the number
22802282 of instructions remaining on the page. */
@@ -2284,14 +2286,6 @@ static void sh4_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
22842286
22852287 static void sh4_tr_tb_start(DisasContextBase *dcbase, CPUState *cs)
22862288 {
2287-#ifdef CONFIG_USER_ONLY
2288- DisasContext *ctx = container_of(dcbase, DisasContext, base);
2289- CPUSH4State *env = cs->env_ptr;
2290-
2291- if (ctx->tbflags & GUSA_MASK) {
2292- ctx->base.num_insns = decode_gusa(ctx, env, &ctx->base.max_insns);
2293- }
2294-#endif
22952289 }
22962290
22972291 static void sh4_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
@@ -2323,6 +2317,19 @@ static void sh4_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
23232317 CPUSH4State *env = cs->env_ptr;
23242318 DisasContext *ctx = container_of(dcbase, DisasContext, base);
23252319
2320+#ifdef CONFIG_USER_ONLY
2321+ if (unlikely(ctx->envflags & GUSA_MASK)
2322+ && !(ctx->envflags & GUSA_EXCLUSIVE)) {
2323+ /* We're in an gUSA region, and we have not already fallen
2324+ back on using an exclusive region. Attempt to parse the
2325+ region into a single supported atomic operation. Failure
2326+ is handled within the parser by raising an exception to
2327+ retry using an exclusive region. */
2328+ decode_gusa(ctx, env);
2329+ return;
2330+ }
2331+#endif
2332+
23262333 ctx->opcode = cpu_lduw_code(env, ctx->base.pc_next);
23272334 decode_opc(ctx);
23282335 ctx->base.pc_next += 2;