Revisión | be0e3d7a1e148180fe1b89c7f93720db0607614e (tree) |
---|---|
Tiempo | 2018-07-10 02:34:04 |
Autor | Richard Henderson <richard.henderson@lina...> |
Commiter | Richard Henderson |
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>
@@ -1895,35 +1895,18 @@ static void decode_opc(DisasContext * ctx) | ||
1895 | 1895 | any sequence via cpu_exec_step_atomic, we can recognize the "normal" |
1896 | 1896 | sequences and transform them into atomic operations as seen by the host. |
1897 | 1897 | */ |
1898 | -static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns) | |
1898 | +static void decode_gusa(DisasContext *ctx, CPUSH4State *env) | |
1899 | 1899 | { |
1900 | 1900 | uint16_t insns[5]; |
1901 | 1901 | int ld_adr, ld_dst, ld_mop; |
1902 | 1902 | int op_dst, op_src, op_opc; |
1903 | 1903 | int mv_src, mt_dst, st_src, st_mop; |
1904 | 1904 | TCGv op_arg; |
1905 | - | |
1906 | 1905 | uint32_t pc = ctx->base.pc_next; |
1907 | 1906 | uint32_t pc_end = ctx->base.tb->cs_base; |
1908 | - int backup = sextract32(ctx->tbflags, GUSA_SHIFT, 8); | |
1909 | 1907 | int max_insns = (pc_end - pc) / 2; |
1910 | 1908 | int i; |
1911 | 1909 | |
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 | - | |
1927 | 1910 | /* The state machine below will consume only a few insns. |
1928 | 1911 | If there are more than that in a region, fail now. */ |
1929 | 1912 | if (max_insns > ARRAY_SIZE(insns)) { |
@@ -2140,7 +2123,6 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns) | ||
2140 | 2123 | /* |
2141 | 2124 | * Emit the operation. |
2142 | 2125 | */ |
2143 | - tcg_gen_insn_start(pc, ctx->envflags); | |
2144 | 2126 | switch (op_opc) { |
2145 | 2127 | case -1: |
2146 | 2128 | /* No operation found. Look for exchange pattern. */ |
@@ -2235,7 +2217,8 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns) | ||
2235 | 2217 | /* The entire region has been translated. */ |
2236 | 2218 | ctx->envflags &= ~GUSA_MASK; |
2237 | 2219 | ctx->base.pc_next = pc_end; |
2238 | - return max_insns; | |
2220 | + ctx->base.num_insns += max_insns - 1; | |
2221 | + return; | |
2239 | 2222 | |
2240 | 2223 | fail: |
2241 | 2224 | 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) | ||
2243 | 2226 | |
2244 | 2227 | /* Restart with the EXCLUSIVE bit set, within a TB run via |
2245 | 2228 | cpu_exec_step_atomic holding the exclusive lock. */ |
2246 | - tcg_gen_insn_start(pc, ctx->envflags); | |
2247 | 2229 | ctx->envflags |= GUSA_EXCLUSIVE; |
2248 | 2230 | gen_save_cpu_state(ctx, false); |
2249 | 2231 | gen_helper_exclusive(cpu_env); |
@@ -2254,7 +2236,7 @@ static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns) | ||
2254 | 2236 | entire region consumed via ctx->base.pc_next so that it's immediately |
2255 | 2237 | available in the disassembly dump. */ |
2256 | 2238 | ctx->base.pc_next = pc_end; |
2257 | - return 1; | |
2239 | + ctx->base.num_insns += max_insns - 1; | |
2258 | 2240 | } |
2259 | 2241 | #endif |
2260 | 2242 |
@@ -2262,19 +2244,39 @@ static void sh4_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
2262 | 2244 | { |
2263 | 2245 | DisasContext *ctx = container_of(dcbase, DisasContext, base); |
2264 | 2246 | CPUSH4State *env = cs->env_ptr; |
2247 | + uint32_t tbflags; | |
2265 | 2248 | int bound; |
2266 | 2249 | |
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; | |
2270 | 2253 | /* We don't know if the delayed pc came from a dynamic or static branch, |
2271 | 2254 | so assume it is a dynamic branch. */ |
2272 | 2255 | ctx->delayed_pc = -1; /* use delayed pc from env pointer */ |
2273 | 2256 | 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 | + } | |
2278 | 2280 | |
2279 | 2281 | /* Since the ISA is fixed-width, we can bound by the number |
2280 | 2282 | of instructions remaining on the page. */ |
@@ -2284,14 +2286,6 @@ static void sh4_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
2284 | 2286 | |
2285 | 2287 | static void sh4_tr_tb_start(DisasContextBase *dcbase, CPUState *cs) |
2286 | 2288 | { |
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 | |
2295 | 2289 | } |
2296 | 2290 | |
2297 | 2291 | static void sh4_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) |
@@ -2323,6 +2317,19 @@ static void sh4_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) | ||
2323 | 2317 | CPUSH4State *env = cs->env_ptr; |
2324 | 2318 | DisasContext *ctx = container_of(dcbase, DisasContext, base); |
2325 | 2319 | |
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 | + | |
2326 | 2333 | ctx->opcode = cpu_lduw_code(env, ctx->base.pc_next); |
2327 | 2334 | decode_opc(ctx); |
2328 | 2335 | ctx->base.pc_next += 2; |