mips: change in restoring debug working register
[openocd.git] / src / target / mips32_pracc.c
index 787daefe5a76c4ebb2c75f4f7a563795c2ae2b32..2ccbfc7fc4891484e41beae4892554799591b085 100644 (file)
@@ -194,11 +194,7 @@ static int mips32_pracc_exec_write(struct mips32_pracc_context *ctx, uint32_t ad
        if (retval != ERROR_OK)
                return retval;
 
-       if ((address >= MIPS32_PRACC_PARAM_IN)
-               && (address < MIPS32_PRACC_PARAM_IN + ctx->num_iparam * 4)) {
-               offset = (address - MIPS32_PRACC_PARAM_IN) / 4;
-               ctx->local_iparam[offset] = data;
-       } else if ((address >= MIPS32_PRACC_PARAM_OUT)
+       if ((address >= MIPS32_PRACC_PARAM_OUT)
                && (address < MIPS32_PRACC_PARAM_OUT + ctx->num_oparam * 4)) {
                offset = (address - MIPS32_PRACC_PARAM_OUT) / 4;
                ctx->local_oparam[offset] = data;
@@ -280,13 +276,13 @@ static int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, u
                                                                                                                /* start: */
                MIPS32_MTC0(15, 31, 0),                                         /* move $15 to COP0 DeSave */
                MIPS32_LUI(15, PRACC_UPPER_BASE_ADDR),                          /* $15 = MIPS32_PRACC_BASE_ADDR */
-               MIPS32_SW(8, PRACC_STACK_OFFSET, 15),                           /* sw $8,PRACC_STACK_OFFSET($15) */
 
                MIPS32_LUI(8, UPPER16((addr + 0x8000))),                        /* load  $8 with modified upper address */
                MIPS32_LW(8, LOWER16(addr), 8),                                 /* lw $8, LOWER16(addr)($8) */
                MIPS32_SW(8, PRACC_OUT_OFFSET, 15),                             /* sw $8,PRACC_OUT_OFFSET($15) */
 
-               MIPS32_LW(8, PRACC_STACK_OFFSET, 15),                           /* lw $8,PRACC_STACK_OFFSET($15) */
+               MIPS32_LUI(8, UPPER16(ejtag_info->reg8)),                               /* restore upper 16 bits of reg 8 */
+               MIPS32_ORI(8, 8, LOWER16(ejtag_info->reg8)),                            /* restore lower 16 bits of reg 8 */
                MIPS32_B(NEG16(8)),                                                     /* b start */
                MIPS32_MFC0(15, 31, 0),                                         /* move COP0 DeSave to $15 */
        };
@@ -334,10 +330,8 @@ int mips32_pracc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size
 
                *code_p++ = MIPS32_MTC0(15, 31, 0);                                     /* save $15 in DeSave */
                *code_p++ = MIPS32_LUI(15, PRACC_UPPER_BASE_ADDR);                      /* $15 = MIPS32_PRACC_BASE_ADDR */
-               *code_p++ = MIPS32_SW(8, PRACC_STACK_OFFSET, 15);                       /* save $8 and $9 to pracc stack */
-               *code_p++ = MIPS32_SW(9, PRACC_STACK_OFFSET, 15);
                *code_p++ = MIPS32_LUI(9, last_upper_base_addr);                        /* load the upper memory address in $9*/
-               code_len = 5;
+               code_len = 3;
 
                for (i = 0; i != this_round_count; i++) {               /* Main code loop */
                        upper_base_addr = UPPER16((addr + 0x8000));
@@ -360,10 +354,12 @@ int mips32_pracc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size
                        addr += size;
                }
 
-               *code_p++ = MIPS32_LW(9, PRACC_STACK_OFFSET, 15);                       /* restore $8 and $9 from pracc stack */
-               *code_p++ = MIPS32_LW(8, PRACC_STACK_OFFSET, 15);
+               *code_p++ = MIPS32_LUI(8, UPPER16(ejtag_info->reg8));                   /* restore upper 16 bits of reg 8 */
+               *code_p++ = MIPS32_ORI(8, 8, LOWER16(ejtag_info->reg8));                /* restore lower 16 bits of reg 8 */
+               *code_p++ = MIPS32_LUI(9, UPPER16(ejtag_info->reg8));                   /* restore upper 16 bits of reg 9 */
+               *code_p++ = MIPS32_ORI(9, 9, LOWER16(ejtag_info->reg8));                /* restore lower 16 bits of reg 9 */
 
-               code_len += 4;
+               code_len += 6;
                *code_p++ = MIPS32_B(NEG16(code_len - 1));                                      /* jump to start */
                *code_p = MIPS32_MFC0(15, 31, 0);                                       /* restore $15 from DeSave */
 
@@ -399,18 +395,18 @@ int mips32_cp0_read(struct mips_ejtag *ejtag_info, uint32_t *val, uint32_t cp0_r
 {
        /**
         * Do not make this code static, but regenerate it every time,
-        * as 3th element has to be changed to add parameters
+        * as 2th element has to be changed to add parameters
         */
        uint32_t code[] = {
                                                                                                                /* start: */
                MIPS32_MTC0(15, 31, 0),                                                 /* move $15 to COP0 DeSave */
                MIPS32_LUI(15, PRACC_UPPER_BASE_ADDR),                                  /* $15 = MIPS32_PRACC_BASE_ADDR */
-               MIPS32_SW(8, PRACC_STACK_OFFSET, 15),                                   /* sw $8,PRACC_STACK_OFFSET($15) */
 
-               /* 3 */ MIPS32_MFC0(8, 0, 0),                                           /* move COP0 [cp0_reg select] to $8 */
+               /* 2 */ MIPS32_MFC0(8, 0, 0),                                           /* move COP0 [cp0_reg select] to $8 */
                MIPS32_SW(8, PRACC_OUT_OFFSET, 15),                                     /* sw $8,PRACC_OUT_OFFSET($15) */
 
-               MIPS32_LW(8, PRACC_STACK_OFFSET, 15),                                   /* lw $8,PRACC_STACK_OFFSET($15) */
+               MIPS32_LUI(8, UPPER16(ejtag_info->reg8)),                               /* restore upper 16 bits of reg 8 */
+               MIPS32_ORI(8, 8, LOWER16(ejtag_info->reg8)),                            /* restore lower 16 bits of reg 8 */
                MIPS32_B(NEG16(7)),                                                     /* b start */
                MIPS32_MFC0(15, 31, 0),                                                 /* move COP0 DeSave to $15 */
        };
@@ -429,7 +425,7 @@ int mips32_cp0_read(struct mips_ejtag *ejtag_info, uint32_t *val, uint32_t cp0_r
         * MIPS32_MTC0 is implemented via MIPS32_R_INST macro.
         * In order to insert our parameters, we must change rd and funct fields.
         */
-       code[3] |= (cp0_reg << 11) | cp0_sel;  /* change rd and funct of MIPS32_R_INST macro */
+       code[2] |= (cp0_reg << 11) | cp0_sel;  /* change rd and funct of MIPS32_R_INST macro */
 
        return mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, 0, NULL, 1, val, 1);
 }
@@ -633,10 +629,8 @@ static int mips32_pracc_write_mem_generic(struct mips_ejtag *ejtag_info, uint32_
                code_p = code;
 
                *code_p++ = MIPS32_MTC0(15, 31, 0);                                     /* save $15 in DeSave */
-               *code_p++ = MIPS32_LUI(15, PRACC_UPPER_BASE_ADDR);                      /* $15 = MIPS32_PRACC_BASE_ADDR */
-               *code_p++ = MIPS32_SW(8, PRACC_STACK_OFFSET, 15);                       /* save $8 to pracc stack */
-               *code_p++ = MIPS32_LUI(15, last_upper_base_addr);                       /* reuse $15 as memory base address */
-               code_len = 4;
+               *code_p++ = MIPS32_LUI(15, last_upper_base_addr);                       /* load $15 with memory base address */
+               code_len = 2;
 
                for (i = 0; i != this_round_count; i++) {
                        upper_base_addr = UPPER16((addr + 0x8000));
@@ -678,8 +672,8 @@ static int mips32_pracc_write_mem_generic(struct mips_ejtag *ejtag_info, uint32_
                        addr += size;
                }
 
-               *code_p++ = MIPS32_LUI(15, PRACC_UPPER_BASE_ADDR);                      /* $15 = MIPS32_PRACC_BASE_ADDR */
-               *code_p++ = MIPS32_LW(8, PRACC_STACK_OFFSET, 15);                       /* restore $8 from pracc stack */
+               *code_p++ = MIPS32_LUI(8, UPPER16(ejtag_info->reg8)),                   /* restore upper 16 bits of reg 8 */
+               *code_p++ = MIPS32_ORI(8, 8, LOWER16(ejtag_info->reg8)),                /* restore lower 16 bits of reg 8 */
 
                code_len += 4;
                *code_p++ = MIPS32_B(NEG16(code_len - 1));                                      /* jump to start */
@@ -814,6 +808,9 @@ int mips32_pracc_write_regs(struct mips_ejtag *ejtag_info, uint32_t *regs)
 
        int retval = mips32_pracc_exec(ejtag_info, code_len, code, 0, NULL, 0, NULL, 1);
        free(code);
+
+       ejtag_info->reg8 = regs[8];
+       ejtag_info->reg9 = regs[9];
        return retval;
 }
 
@@ -856,8 +853,10 @@ int mips32_pracc_read_regs(struct mips_ejtag *ejtag_info, uint32_t *regs)
        *code_p = MIPS32_MFC0(1, 31, 0);                                                /* move COP0 DeSave to $1 */
 
        int retval = mips32_pracc_exec(ejtag_info, 49, code, 0, NULL, MIPS32NUMCOREREGS, regs, 1);
-
        free(code);
+
+       ejtag_info->reg8 = regs[8];
+       ejtag_info->reg9 = regs[9];
        return retval;
 }
 
@@ -948,6 +947,7 @@ int mips32_pracc_fastdata_xfer(struct mips_ejtag *ejtag_info, struct working_are
                mips_ejtag_drscan_32_out(ejtag_info, ejtag_ctrl);
        }
 
+       /* wait PrAcc pending bit for FASTDATA write */
        retval = wait_for_pracc_rw(ejtag_info, &ejtag_ctrl);
        if (retval != ERROR_OK)
                return retval;
@@ -962,18 +962,18 @@ int mips32_pracc_fastdata_xfer(struct mips_ejtag *ejtag_info, struct working_are
        if (address != MIPS32_PRACC_FASTDATA_AREA)
                return ERROR_FAIL;
 
-       /* wait PrAcc pending bit for FASTDATA write */
-       retval = wait_for_pracc_rw(ejtag_info, &ejtag_ctrl);
-       if (retval != ERROR_OK)
-               return retval;
-
        /* Send the load start address */
        val = addr;
        mips_ejtag_set_instr(ejtag_info, EJTAG_INST_FASTDATA);
        mips_ejtag_fastdata_scan(ejtag_info, 1, &val);
 
+       retval = wait_for_pracc_rw(ejtag_info, &ejtag_ctrl);
+       if (retval != ERROR_OK)
+               return retval;
+
        /* Send the load end address */
        val = addr + (count - 1) * 4;
+       mips_ejtag_set_instr(ejtag_info, EJTAG_INST_FASTDATA);
        mips_ejtag_fastdata_scan(ejtag_info, 1, &val);
 
        for (i = 0; i < count; 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)