split jim_jtag_command into multiple handlers
[openocd.git] / src / target / mips32_pracc.c
index 4f597a5e56090ef76ba710864f1bb6c655b9f9b3..604d34edbf2524d9183b69740fa6d85f00f1438e 100644 (file)
@@ -77,17 +77,18 @@ Nico Coesel
 #include "mips32.h"
 #include "mips32_pracc.h"
 
-typedef struct {
+struct mips32_pracc_context
+{
        uint32_t *local_iparam;
        int num_iparam;
        uint32_t *local_oparam;
        int num_oparam;
-       uint32_t *code;
+       const uint32_t *code;
        int code_len;
        uint32_t stack[32];
        int stack_offset;
        struct mips_ejtag *ejtag_info;
-} mips32_pracc_context;
+};
 
 static int wait_for_pracc_rw(struct mips_ejtag *ejtag_info, uint32_t *ctrl)
 {
@@ -108,7 +109,7 @@ static int wait_for_pracc_rw(struct mips_ejtag *ejtag_info, uint32_t *ctrl)
        return ERROR_OK;
 }
 
-static int mips32_pracc_exec_read(mips32_pracc_context *ctx, uint32_t address)
+static int mips32_pracc_exec_read(struct mips32_pracc_context *ctx, uint32_t address)
 {
        struct mips_ejtag *ejtag_info = ctx->ejtag_info;
        int offset;
@@ -164,7 +165,7 @@ static int mips32_pracc_exec_read(mips32_pracc_context *ctx, uint32_t address)
        return ERROR_OK;
 }
 
-static int mips32_pracc_exec_write(mips32_pracc_context *ctx, uint32_t address)
+static int mips32_pracc_exec_write(struct mips32_pracc_context *ctx, uint32_t address)
 {
        uint32_t ejtag_ctrl,data;
        int offset;
@@ -207,11 +208,11 @@ static int mips32_pracc_exec_write(mips32_pracc_context *ctx, uint32_t address)
        return ERROR_OK;
 }
 
-int mips32_pracc_exec(struct mips_ejtag *ejtag_info, int code_len, uint32_t *code, int num_param_in, uint32_t *param_in, int num_param_out, uint32_t *param_out, int cycle)
+int mips32_pracc_exec(struct mips_ejtag *ejtag_info, int code_len, const uint32_t *code, int num_param_in, uint32_t *param_in, int num_param_out, uint32_t *param_out, int cycle)
 {
        uint32_t ejtag_ctrl;
        uint32_t address, data;
-       mips32_pracc_context ctx;
+       struct mips32_pracc_context ctx;
        int retval;
        int pass = 0;
 
@@ -289,7 +290,7 @@ int mips32_pracc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size
 
 int mips32_pracc_read_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint32_t *buf)
 {
-       uint32_t code[] = {
+       static const uint32_t code[] = {
                                                                                                                        /* start: */
                MIPS32_MTC0(15,31,0),                                                           /* move $15 to COP0 DeSave */
                MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)),             /* $15 = MIPS32_PRACC_STACK */
@@ -347,8 +348,8 @@ int mips32_pracc_read_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int co
                param_in[0] = addr;
                param_in[1] = blocksize;
 
-               if ((retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code,
-                       sizeof(param_in)/sizeof(param_in[0]), param_in, blocksize, &buf[bytesread], 1)) != ERROR_OK)
+               if ((retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code,
+                       ARRAY_SIZE(param_in), param_in, blocksize, &buf[bytesread], 1)) != ERROR_OK)
                {
                        return retval;
                }
@@ -363,7 +364,7 @@ int mips32_pracc_read_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int co
 
 int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t *buf)
 {
-       uint32_t code[] = {
+       static const uint32_t code[] = {
                                                                                                                        /* start: */
                MIPS32_MTC0(15,31,0),                                                           /* move $15 to COP0 DeSave */
                MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)),             /* $15 = MIPS32_PRACC_STACK */
@@ -386,8 +387,8 @@ int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t
 
        param_in[0] = addr;
 
-       if ((retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code,
-               sizeof(param_in)/sizeof(param_in[0]), param_in, sizeof(uint32_t), buf, 1)) != ERROR_OK)
+       if ((retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code,
+               ARRAY_SIZE(param_in), param_in, sizeof(uint32_t), buf, 1)) != ERROR_OK)
        {
                return retval;
        }
@@ -397,7 +398,7 @@ int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t
 
 int mips32_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint16_t *buf)
 {
-       uint32_t code[] = {
+       static const uint32_t code[] = {
                                                                                                                        /* start: */
                MIPS32_MTC0(15,31,0),                                                           /* move $15 to COP0 DeSave */
                MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)),             /* $15 = MIPS32_PRACC_STACK */
@@ -439,7 +440,7 @@ int mips32_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int co
        };
 
 //     /* TODO remove array */
-       uint32_t param_out[count];
+       uint32_t *param_out = malloc(count * sizeof(uint32_t));
        int i;
 
 //     int retval;
@@ -458,8 +459,8 @@ int mips32_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int co
                param_in[0] = addr;
                param_in[1] = blocksize;
 
-               mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
-                       sizeof(param_in)/sizeof(param_in[0]), param_in, count, param_out, 1);
+               mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
+                       ARRAY_SIZE(param_in), param_in, count, param_out, 1);
 
 //             count -= blocksize;
 //             addr += blocksize;
@@ -471,12 +472,14 @@ int mips32_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int co
                buf[i] = param_out[i];
        }
 
+       free(param_out);
+
        return ERROR_OK;
 }
 
 int mips32_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint8_t *buf)
 {
-       uint32_t code[] = {
+       static const uint32_t code[] = {
                                                                                                                        /* start: */
                MIPS32_MTC0(15,31,0),                                                           /* move $15 to COP0 DeSave */
                MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)),             /* $15 = MIPS32_PRACC_STACK */
@@ -518,7 +521,7 @@ int mips32_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int cou
        };
 
 //     /* TODO remove array */
-       uint32_t param_out[count];
+       uint32_t *param_out = malloc(count * sizeof(uint32_t));
        int i;
 
 //     int retval;
@@ -537,8 +540,8 @@ int mips32_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int cou
                param_in[0] = addr;
                param_in[1] = blocksize;
 
-               mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
-                       sizeof(param_in)/sizeof(param_in[0]), param_in, count, param_out, 1);
+               mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
+                       ARRAY_SIZE(param_in), param_in, count, param_out, 1);
 
 //             count -= blocksize;
 //             addr += blocksize;
@@ -550,6 +553,8 @@ int mips32_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int cou
                buf[i] = param_out[i];
        }
 
+       free(param_out);
+
        return ERROR_OK;
 }
 
@@ -575,7 +580,7 @@ int mips32_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int c
 {
 
 //NC: use destination pointer as loop counter (last address is in $10)
-       uint32_t code[] = {
+       static const uint32_t code[] = {
                                                                                                                        /* start: */
                MIPS32_MTC0(15,31,0),                                                           /* move $15 to COP0 DeSave */
                MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)),             /* $15 = MIPS32_PRACC_STACK */
@@ -608,21 +613,23 @@ int mips32_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint32_t addr, int c
        };
 
        /* TODO remove array */
-       uint32_t param_in[count + 2];
+       uint32_t *param_in = malloc((count + 2) * sizeof(uint32_t));
        param_in[0] = addr;
        param_in[1] = addr + count * sizeof(uint32_t);  //last address
 
        memcpy(&param_in[2], buf, count * sizeof(uint32_t));
 
-       mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
-               sizeof(param_in)/sizeof(param_in[0]),param_in, 0, NULL, 1);
+       mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
+               count + 2, param_in, 0, NULL, 1);
+
+       free(param_in);
 
        return ERROR_OK;
 }
 
 int mips32_pracc_write_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t *buf)
 {
-       uint32_t code[] = {
+       static const uint32_t code[] = {
                                                                                                                        /* start: */
                MIPS32_MTC0(15,31,0),                                                           /* move $15 to COP0 DeSave */
                MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)),             /* $15 = MIPS32_PRACC_STACK */
@@ -647,15 +654,15 @@ int mips32_pracc_write_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_
        param_in[0] = addr;
        param_in[1] = *buf;
 
-       mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
-               sizeof(param_in)/sizeof(param_in[0]),param_in, 0, NULL, 1);
+       mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
+               ARRAY_SIZE(param_in),param_in, 0, NULL, 1);
 
        return ERROR_OK;
 }
 
 int mips32_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint16_t *buf)
 {
-       uint32_t code[] = {
+       static const uint32_t code[] = {
                                                                                                                        /* start: */
                MIPS32_MTC0(15,31,0),                                                           /* move $15 to COP0 DeSave */
                MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)),             /* $15 = MIPS32_PRACC_STACK */
@@ -697,7 +704,7 @@ int mips32_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int c
        };
 
        /* TODO remove array */
-       uint32_t param_in[count + 2];
+       uint32_t *param_in = malloc((count + 2) * sizeof(uint32_t));
        int i;
        param_in[0] = addr;
        param_in[1] = count;
@@ -707,15 +714,17 @@ int mips32_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint32_t addr, int c
                param_in[i + 2] = buf[i];
        }
 
-       mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
-               sizeof(param_in)/sizeof(param_in[0]), param_in, 0, NULL, 1);
+       mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
+               count + 2, param_in, 0, NULL, 1);
+
+       free(param_in);
 
        return ERROR_OK;
 }
 
 int mips32_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int count, uint8_t *buf)
 {
-       uint32_t code[] = {
+       static const uint32_t code[] = {
                                                                                                                        /* start: */
                MIPS32_MTC0(15,31,0),                                                           /* move $15 to COP0 DeSave */
                MIPS32_LUI(15,UPPER16(MIPS32_PRACC_STACK)),             /* $15 = MIPS32_PRACC_STACK */
@@ -757,7 +766,7 @@ int mips32_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int co
        };
 
        /* TODO remove array */
-       uint32_t param_in[count + 2];
+       uint32_t *param_in = malloc((count + 2) * sizeof(uint32_t));
        int retval;
        int i;
        param_in[0] = addr;
@@ -768,15 +777,17 @@ int mips32_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint32_t addr, int co
                param_in[i + 2] = buf[i];
        }
 
-       retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
-               sizeof(param_in)/sizeof(param_in[0]), param_in, 0, NULL, 1);
+       retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
+               count +2, param_in, 0, NULL, 1);
+
+       free(param_in);
 
        return retval;
 }
 
 int mips32_pracc_write_regs(struct mips_ejtag *ejtag_info, uint32_t *regs)
 {
-       uint32_t code[] = {
+       static const uint32_t code[] = {
                                                                                                                /* start: */
                MIPS32_LUI(2,UPPER16(MIPS32_PRACC_PARAM_IN)),   /* $2 = MIPS32_PRACC_PARAM_IN */
                MIPS32_ORI(2,2,LOWER16(MIPS32_PRACC_PARAM_IN)),
@@ -840,7 +851,7 @@ int mips32_pracc_write_regs(struct mips_ejtag *ejtag_info, uint32_t *regs)
 
        int retval;
 
-       retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
+       retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
                38, regs, 0, NULL, 1);
 
        return retval;
@@ -848,7 +859,7 @@ int mips32_pracc_write_regs(struct mips_ejtag *ejtag_info, uint32_t *regs)
 
 int mips32_pracc_read_regs(struct mips_ejtag *ejtag_info, uint32_t *regs)
 {
-       uint32_t code[] = {
+       static const uint32_t code[] = {
                                                                                                                /* start: */
                MIPS32_MTC0(2,31,0),                                                    /* move $2 to COP0 DeSave */
                MIPS32_LUI(2,UPPER16(MIPS32_PRACC_PARAM_OUT)),  /* $2 = MIPS32_PRACC_PARAM_OUT */
@@ -917,7 +928,7 @@ int mips32_pracc_read_regs(struct mips_ejtag *ejtag_info, uint32_t *regs)
 
        int retval;
 
-       retval = mips32_pracc_exec(ejtag_info, sizeof(code)/sizeof(code[0]), code, \
+       retval = mips32_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \
                0, NULL, 38, regs, 1);
 
        return retval;

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)