Skip to contentSkip to conversation

Target ARM specific code

RFC PATCH In review Pavel Dovgaluk 1 participant 1 message Jul 1, 2014

lore
Share & tools
lore
#0 lore raw

RFC PATCH 21/22 Target ARM specific code

Platform-specific chanches to i386 simulation for deterministic replay and reverse debugging.

We insert instruction-counting code before executing every instruction. In replay mode this code also breaks execution of TB, when any of the events are found in the replay log.

---

target-arm/helper.h +4 -0
index facfcd2..3f7a4f5
@@ -1,3 +1,4 @@
+DEF_HELPER_1(assert_cpu, void, env)
 DEF_HELPER_FLAGS_1(clz, TCG_CALL_NO_RWG_SE, i32, i32)
 DEF_HELPER_FLAGS_1(sxtb16, TCG_CALL_NO_RWG_SE, i32, i32)
 DEF_HELPER_FLAGS_1(uxtb16, TCG_CALL_NO_RWG_SE, i32, i32)
@@ -506,6 +507,9 @@ DEF_HELPER_3(neon_zip16, void, env, i32, i32)
 DEF_HELPER_3(neon_qzip8, void, env, i32, i32)
 DEF_HELPER_3(neon_qzip16, void, env, i32, i32)
 DEF_HELPER_3(neon_qzip32, void, env, i32, i32)
+DEF_HELPER_1(replay_instruction, i32, env)
+DEF_HELPER_0(instruction_changed, void)
+DEF_HELPER_0(reverse_breakpoint, void)
 
 DEF_HELPER_4(crypto_aese, void, env, i32, i32, i32)
 DEF_HELPER_4(crypto_aesmc, void, env, i32, i32, i32)
target-arm/machine.c +4 -0
index 3bcc7cc..18b4dd5 100644
@@ -259,6 +259,10 @@ const VMStateDescription vmstate_arm_cpu = {
         VMSTATE_UINT64(env.exception.vaddress, ARMCPU),
         VMSTATE_TIMER(gt_timer[GTIMER_PHYS], ARMCPU),
         VMSTATE_TIMER(gt_timer[GTIMER_VIRT], ARMCPU),
+        /* Fields required by replay */
+        VMSTATE_UINT32(parent_obj.interrupt_request, ARMCPU),
+        VMSTATE_INT32(parent_obj.exit_request, ARMCPU),
+        VMSTATE_INT32(parent_obj.exception_index, ARMCPU),
         VMSTATE_END_OF_LIST()
     },
     .subsections = (VMStateSubsection[]) {
target-arm/op_helper.c +55 -0

58 lines not on this page · raw message

target-arm/translate.c +41 -2

75 lines not on this page · raw message

the block.
+ This is needed, when replaying has changed the bounds of translation blocks.
+ */
+ if ((dc->pc == pc_start || replay_mode == REPLAY_PLAY)
+ && replay_get_play_submode() != REPLAY_PLAY_CHANGED) {
+ gen_instr_replay(dc, dc->pc);
+ } else {
+ gen_instructions_count();
+ }
+ }
+
+ /* icount mode support */
+ if (replay_mode != REPLAY_NONE) {
+ gen_icount_step(dc, dc->pc);
+ }
+

         if (dc->thumb) {
             disas_thumb_insn(env, dc);
@@ -11054,7 +11108,8 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
     } while (!dc->is_jmp && tcg_ctx.gen_opc_ptr < gen_opc_end &&
              !cs->singlestep_enabled &&
              !singlestep &&
-             dc->pc < next_page_start &&
+             /* +3 is for unaligned Thumb2 instructions */
+             dc->pc + 3 < next_page_start &&
              num_insns < max_insns);
 
     if (tb->cflags & CF_LAST_IO) {
@@ -11134,7 +11189,11 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
     }

done_generating:
- gen_tb_end(tb, num_insns);
+ if (replay_mode == REPLAY_NONE) {
+ if (tb->cflags & CF_LAST_IO)
+ gen_io_end();
+ gen_tb_end(tb, num_insns);
+ }

     *tcg_ctx.gen_opc_ptr = INDEX_op_end;

#ifdef DEBUG_DISAS
@@ -11155,6 +11214,10 @@ done_generating:

         tb->size = dc->pc - pc_start;
         tb->icount = num_insns;
     }

+ if (tcg_ctx.gen_opc_ptr > tcg_ctx.gen_opc_buf + OPC_BUF_SIZE) {
+ fprintf(stderr, "TCG buffer overflow\n");
+ exit(1);
+ }
}

void gen_intermediate_code(CPUARMState *env, TranslationBlock *tb)
@@ -11231,3 +11294,41 @@ void restore_state_to_opc(CPUARMState *env, TranslationBlock *tb, int pc_pos)

         env->condexec_bits = gen_opc_condexec_bits[pc_pos];
     }

}
+
+static void gen_instr_exit(DisasContext *s, target_ulong pc_ptr, long tb) +{

+    gen_set_condexec(s);
+    gen_set_pc_im(s, pc_ptr);
+    tcg_gen_exit_tb(tb);

+}
+
+static void gen_instr_replay(DisasContext *s, target_ulong pc_ptr) +{
+ int l1 = gen_new_label();
+ TCGv_i32 cpu_tmp2_i32 = tcg_temp_new();
+
+ gen_helper_replay_instruction(cpu_tmp2_i32, cpu_env);
+ tcg_gen_brcondi_i32(TCG_COND_EQ, cpu_tmp2_i32, 0, l1);
+

+    gen_instr_exit(s, pc_ptr, 0);
+    gen_set_label(l1);
+    tcg_temp_free(cpu_tmp2_i32);

+}
+
+static void gen_icount_step(DisasContext *s, target_ulong pc_ptr) +{
+ if (!use_icount)
+ return;
+

+    int l1 = gen_new_label();
+    TCGv_i32 cpu_tmp2_i32 = tcg_temp_new();
+    tcg_gen_ld_i32(cpu_tmp2_i32, cpu_env, offsetof(CPUState, icount_decr.u32) - ENV_OFFSET);
+    tcg_gen_brcondi_i32(TCG_COND_NE, cpu_tmp2_i32, 0, l1);
+
+    gen_instr_exit(s, pc_ptr, 2);
+
+    gen_set_label(l1);
+    tcg_gen_subi_i32(cpu_tmp2_i32, cpu_tmp2_i32, 1);
+    tcg_gen_st16_i32(cpu_tmp2_i32, cpu_env, offsetof(CPUState, icount_decr.u16.low) - ENV_OFFSET);
+    tcg_temp_free(cpu_tmp2_i32);

+}