Improve xscale command argument parsing.
[openocd.git] / src / target / arm_simulator.c
index 5af2c129bea5e7969e72028cd7ff79fce4adb1cf..27957b2f6ca46bd30b196346f7a0615258565873 100644 (file)
@@ -317,8 +317,8 @@ int arm_simulate_step_core(target_t *target, uint32_t *dry_run_pc, struct arm_si
                        return retval;
                instruction_size = 2;
 
-               /* check condition code (only for branch instructions) */
-               if (instruction.type == ARM_B &&
+               /* check condition code (only for branch (1) instructions) */
+               if ((opcode & 0xf000) == 0xd000 &&
                    !thumb_pass_branch_condition(sim->get_cpsr(sim, 0, 32), opcode))
                {
                        if (dry_run_pc)
@@ -380,7 +380,8 @@ int arm_simulate_step_core(target_t *target, uint32_t *dry_run_pc, struct arm_si
                        else if (instruction.type == ARM_BL)
                        {
                                uint32_t old_pc = sim->get_reg(sim, 15);
-                               sim->set_reg_mode(sim, 14, old_pc + 4);
+                               int T = (sim->get_state(sim) == ARMV4_5_STATE_THUMB);
+                               sim->set_reg_mode(sim, 14, old_pc + 4 + T);
                                sim->set_reg(sim, 15, target);
                        }
                        else if (instruction.type == ARM_BX)
@@ -398,7 +399,8 @@ int arm_simulate_step_core(target_t *target, uint32_t *dry_run_pc, struct arm_si
                        else if (instruction.type == ARM_BLX)
                        {
                                uint32_t old_pc = sim->get_reg(sim, 15);
-                               sim->set_reg_mode(sim, 14, old_pc + 4);
+                               int T = (sim->get_state(sim) == ARMV4_5_STATE_THUMB);
+                               sim->set_reg_mode(sim, 14, old_pc + 4 + T);
 
                                if (target & 0x1)
                                {
@@ -465,24 +467,24 @@ int arm_simulate_step_core(target_t *target, uint32_t *dry_run_pc, struct arm_si
                if (dry_run_pc)
                {
                        if (instruction.info.data_proc.Rd == 15)
-                       {
-                               *dry_run_pc = Rd;
-                               return ERROR_OK;
-                       }
+                               *dry_run_pc = Rd & ~1;
                        else
-                       {
                                *dry_run_pc = current_pc + instruction_size;
-                       }
 
                        return ERROR_OK;
                }
                else
                {
+                       if (instruction.info.data_proc.Rd == 15) {
+                               sim->set_reg_mode(sim, 15, Rd & ~1);
+                               if (Rd & 1)
+                                       sim->set_state(sim, ARMV4_5_STATE_THUMB);
+                               else
+                                       sim->set_state(sim, ARMV4_5_STATE_ARM);
+                               return ERROR_OK;
+                       }
                        sim->set_reg_mode(sim, instruction.info.data_proc.Rd, Rd);
                        LOG_WARNING("no updating of flags yet");
-
-                       if (instruction.info.data_proc.Rd == 15)
-                               return ERROR_OK;
                }
        }
        /* compare instructions (CMP, CMN, TST, TEQ) */
@@ -566,15 +568,9 @@ int arm_simulate_step_core(target_t *target, uint32_t *dry_run_pc, struct arm_si
                if (dry_run_pc)
                {
                        if (instruction.info.load_store.Rd == 15)
-                       {
-                               *dry_run_pc = load_value;
-                               return ERROR_OK;
-                       }
+                               *dry_run_pc = load_value & ~1;
                        else
-                       {
                                *dry_run_pc = current_pc + instruction_size;
-                       }
-
                        return ERROR_OK;
                }
                else
@@ -584,10 +580,16 @@ int arm_simulate_step_core(target_t *target, uint32_t *dry_run_pc, struct arm_si
                        {
                                sim->set_reg_mode(sim, instruction.info.load_store.Rn, modified_address);
                        }
-                       sim->set_reg_mode(sim, instruction.info.load_store.Rd, load_value);
 
-                       if (instruction.info.load_store.Rd == 15)
+                       if (instruction.info.load_store.Rd == 15) {
+                               sim->set_reg_mode(sim, 15, load_value & ~1);
+                               if (load_value & 1)
+                                       sim->set_state(sim, ARMV4_5_STATE_THUMB);
+                               else
+                                       sim->set_state(sim, ARMV4_5_STATE_ARM);
                                return ERROR_OK;
+                       }
+                       sim->set_reg_mode(sim, instruction.info.load_store.Rd, load_value);
                }
        }
        /* load multiple instruction */
@@ -636,7 +638,7 @@ int arm_simulate_step_core(target_t *target, uint32_t *dry_run_pc, struct arm_si
                {
                        if (instruction.info.load_store_multiple.register_list & 0x8000)
                        {
-                               *dry_run_pc = load_values[15];
+                               *dry_run_pc = load_values[15] & ~1;
                                return ERROR_OK;
                        }
                }
@@ -657,7 +659,16 @@ int arm_simulate_step_core(target_t *target, uint32_t *dry_run_pc, struct arm_si
                        {
                                if (instruction.info.load_store_multiple.register_list & (1 << i))
                                {
-                                       sim->set_reg_mode(sim, i, load_values[i]);
+                                       if (i == 15) {
+                                               uint32_t val = load_values[i];
+                                       sim->set_reg_mode(sim, i, val & ~1);
+                                       if (val & 1)
+                                               sim->set_state(sim, ARMV4_5_STATE_THUMB);
+                                       else
+                                               sim->set_state(sim, ARMV4_5_STATE_ARM);
+                                       } else {
+                                               sim->set_reg_mode(sim, i, load_values[i]);
+                                       }
                                }
                        }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)