aboutsummaryrefslogtreecommitdiff
path: root/src/target
diff options
context:
space:
mode:
authorØyvind Harboe <oyvind.harboe@zylin.com>2009-11-22 18:58:42 +0100
committerØyvind Harboe <oyvind.harboe@zylin.com>2009-11-22 18:58:42 +0100
commitaacc5b583c6415fe8d3e6fc99066d6ef819fa22c (patch)
tree7618d82f150b93c7f6eb7bd33a6e298848ff314e /src/target
parent7daec5a0ce109c04b117d42374a99b849fd8a89a (diff)
downloadriscv-openocd-aacc5b583c6415fe8d3e6fc99066d6ef819fa22c.zip
riscv-openocd-aacc5b583c6415fe8d3e6fc99066d6ef819fa22c.tar.gz
riscv-openocd-aacc5b583c6415fe8d3e6fc99066d6ef819fa22c.tar.bz2
target: reduce stack usage
4096 byte buffer allocated dynamically. Better for embedded OS's. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Diffstat (limited to 'src/target')
-rw-r--r--src/target/target.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/target/target.c b/src/target/target.c
index 70fd8f2..55adcce 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -3145,7 +3145,6 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc,
uint32_t count;
uint32_t v;
const char *varname;
- uint8_t buffer[4096];
int n, e, retval;
uint32_t i;
@@ -3227,14 +3226,20 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc,
/* index counter */
n = 0;
+
+ size_t buffersize = 4096;
+ uint8_t *buffer = malloc(buffersize);
+ if (buffer == NULL)
+ return JIM_ERR;
+
/* assume ok */
e = JIM_OK;
while (len) {
/* Slurp... in buffer size chunks */
count = len; /* in objects.. */
- if (count > (sizeof(buffer)/width)) {
- count = (sizeof(buffer)/width);
+ if (count > (buffersize/width)) {
+ count = (buffersize/width);
}
retval = target_read_memory(target, addr, width, count, buffer);
@@ -3268,6 +3273,8 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc,
}
}
+ free(buffer);
+
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
return JIM_OK;
@@ -3331,7 +3338,6 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc,
uint32_t count;
uint32_t v;
const char *varname;
- uint8_t buffer[4096];
int n, e, retval;
uint32_t i;
@@ -3415,12 +3421,18 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc,
n = 0;
/* assume ok */
e = JIM_OK;
+
+ size_t buffersize = 4096;
+ uint8_t *buffer = malloc(buffersize);
+ if (buffer == NULL)
+ return JIM_ERR;
+
while (len) {
/* Slurp... in buffer size chunks */
count = len; /* in objects.. */
- if (count > (sizeof(buffer)/width)) {
- count = (sizeof(buffer)/width);
+ if (count > (buffersize/width)) {
+ count = (buffersize/width);
}
v = 0; /* shut up gcc */
@@ -3454,6 +3466,8 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc,
}
}
+ free(buffer);
+
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
return JIM_OK;