target: reduce stack usage
4096 byte buffer allocated dynamically. Better for embedded OS's. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
This commit is contained in:
parent
7daec5a0ce
commit
aacc5b583c
|
@ -3145,7 +3145,6 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc,
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
uint32_t v;
|
uint32_t v;
|
||||||
const char *varname;
|
const char *varname;
|
||||||
uint8_t buffer[4096];
|
|
||||||
int n, e, retval;
|
int n, e, retval;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
|
@ -3227,14 +3226,20 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc,
|
||||||
|
|
||||||
/* index counter */
|
/* index counter */
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
|
size_t buffersize = 4096;
|
||||||
|
uint8_t *buffer = malloc(buffersize);
|
||||||
|
if (buffer == NULL)
|
||||||
|
return JIM_ERR;
|
||||||
|
|
||||||
/* assume ok */
|
/* assume ok */
|
||||||
e = JIM_OK;
|
e = JIM_OK;
|
||||||
while (len) {
|
while (len) {
|
||||||
/* Slurp... in buffer size chunks */
|
/* Slurp... in buffer size chunks */
|
||||||
|
|
||||||
count = len; /* in objects.. */
|
count = len; /* in objects.. */
|
||||||
if (count > (sizeof(buffer)/width)) {
|
if (count > (buffersize/width)) {
|
||||||
count = (sizeof(buffer)/width);
|
count = (buffersize/width);
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = target_read_memory(target, addr, width, count, buffer);
|
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));
|
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
|
||||||
|
|
||||||
return JIM_OK;
|
return JIM_OK;
|
||||||
|
@ -3331,7 +3338,6 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc,
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
uint32_t v;
|
uint32_t v;
|
||||||
const char *varname;
|
const char *varname;
|
||||||
uint8_t buffer[4096];
|
|
||||||
int n, e, retval;
|
int n, e, retval;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
|
@ -3415,12 +3421,18 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc,
|
||||||
n = 0;
|
n = 0;
|
||||||
/* assume ok */
|
/* assume ok */
|
||||||
e = JIM_OK;
|
e = JIM_OK;
|
||||||
|
|
||||||
|
size_t buffersize = 4096;
|
||||||
|
uint8_t *buffer = malloc(buffersize);
|
||||||
|
if (buffer == NULL)
|
||||||
|
return JIM_ERR;
|
||||||
|
|
||||||
while (len) {
|
while (len) {
|
||||||
/* Slurp... in buffer size chunks */
|
/* Slurp... in buffer size chunks */
|
||||||
|
|
||||||
count = len; /* in objects.. */
|
count = len; /* in objects.. */
|
||||||
if (count > (sizeof(buffer)/width)) {
|
if (count > (buffersize/width)) {
|
||||||
count = (sizeof(buffer)/width);
|
count = (buffersize/width);
|
||||||
}
|
}
|
||||||
|
|
||||||
v = 0; /* shut up gcc */
|
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));
|
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
|
||||||
|
|
||||||
return JIM_OK;
|
return JIM_OK;
|
||||||
|
|
Loading…
Reference in New Issue