summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/helper/command.c8
-rw-r--r--src/helper/command.h4
-rw-r--r--src/jtag/tcl.c4
-rw-r--r--src/target/armv4_5.c8
-rw-r--r--src/target/target.c29
5 files changed, 30 insertions, 23 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 3625508f..be262f2e 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -167,14 +167,18 @@ static const char **script_command_args_alloc(
return words;
}
-static struct command_context *current_command_context(Jim_Interp *interp)
+struct command_context *current_command_context(Jim_Interp *interp)
{
/* grab the command context from the associated data */
struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
if (NULL == cmd_ctx)
{
/* Tcl can invoke commands directly instead of via command_run_line(). This would
- * happen when the Jim Tcl interpreter is provided by eCos.
+ * happen when the Jim Tcl interpreter is provided by eCos or if we are running
+ * commands in a startup script.
+ *
+ * A telnet or gdb server would provide a non-default command context to
+ * handle piping of error output, have a separate current target, etc.
*/
cmd_ctx = global_cmd_ctx;
}
diff --git a/src/helper/command.h b/src/helper/command.h
index 8a418d36..2c192416 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -311,6 +311,10 @@ void command_set_output_handler(struct command_context* context,
int command_context_mode(struct command_context *context, enum command_mode mode);
+/* Return the current command context associated with the Jim interpreter or
+ * alternatively the global default command interpreter
+ */
+struct command_context *current_command_context(Jim_Interp *interp);
/**
* Creates a new command context using the startup TCL provided and
* the existing Jim interpreter, if any. If interp == NULL, then command_init
diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c
index 579ca9e5..ea6d07e3 100644
--- a/src/jtag/tcl.c
+++ b/src/jtag/tcl.c
@@ -684,7 +684,7 @@ static int jim_jtag_arp_init(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
return JIM_ERR;
}
- struct command_context *context = Jim_GetAssocData(interp, "context");
+ struct command_context *context = current_command_context(interp);
int e = jtag_init_inner(context);
if (e != ERROR_OK) {
Jim_SetResult_sprintf(goi.interp, "error: %d", e);
@@ -701,7 +701,7 @@ static int jim_jtag_arp_init_reset(Jim_Interp *interp, int argc, Jim_Obj *const
Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
return JIM_ERR;
}
- struct command_context *context = Jim_GetAssocData(interp, "context");
+ struct command_context *context = current_command_context(interp);
int e = jtag_init_reset(context);
if (e != ERROR_OK) {
Jim_SetResult_sprintf(goi.interp, "error: %d", e);
diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c
index eeb6694c..1a84a5f4 100644
--- a/src/target/armv4_5.c
+++ b/src/target/armv4_5.c
@@ -820,11 +820,9 @@ static int jim_mcrmrc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
struct arm *arm;
int retval;
- context = Jim_GetAssocData(interp, "context");
- if (context == NULL) {
- LOG_ERROR("%s: no command context", __func__);
- return JIM_ERR;
- }
+ context = current_command_context(interp);
+ assert( context != NULL);
+
target = get_current_target(context);
if (target == NULL) {
LOG_ERROR("%s: no current target", __func__);
diff --git a/src/target/target.c b/src/target/target.c
index a3a1b0ad..d17bb744 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -3236,12 +3236,9 @@ static int jim_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
struct command_context *context;
struct target *target;
- context = Jim_GetAssocData(interp, "context");
- if (context == NULL)
- {
- LOG_ERROR("mem2array: no command context");
- return JIM_ERR;
- }
+ context = current_command_context(interp);
+ assert (context != NULL);
+
target = get_current_target(context);
if (target == NULL)
{
@@ -3432,11 +3429,9 @@ static int jim_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
struct command_context *context;
struct target *target;
- context = Jim_GetAssocData(interp, "context");
- if (context == NULL) {
- LOG_ERROR("array2mem: no command context");
- return JIM_ERR;
- }
+ context = current_command_context(interp);
+ assert (context != NULL);
+
target = get_current_target(context);
if (target == NULL) {
LOG_ERROR("array2mem: no current target");
@@ -4318,7 +4313,9 @@ static int jim_target_wait_state(Jim_Interp *interp, int argc, Jim_Obj *const *a
*/
static int jim_target_event_list(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
- struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
+ struct command_context *cmd_ctx = current_command_context(interp);
+ assert (cmd_ctx != NULL);
+
struct target *target = Jim_CmdPrivData(interp);
struct target_event_action *teap = target->event_action;
command_print(cmd_ctx, "Event actions for target (%d) %s\n",
@@ -4512,7 +4509,9 @@ static int target_create(Jim_GetOptInfo *goi)
struct target *target;
struct command_context *cmd_ctx;
- cmd_ctx = Jim_GetAssocData(goi->interp, "context");
+ cmd_ctx = current_command_context(goi->interp);
+ assert (cmd_ctx != NULL);
+
if (goi->argc < 3) {
Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ?type? ..options...");
return JIM_ERR;
@@ -4686,7 +4685,9 @@ static int jim_target_current(Jim_Interp *interp, int argc, Jim_Obj *const *argv
Jim_WrongNumArgs(interp, 1, argv, "Too many parameters");
return JIM_ERR;
}
- struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
+ struct command_context *cmd_ctx = current_command_context(interp);
+ assert (cmd_ctx != NULL);
+
Jim_SetResultString(interp, get_current_target(cmd_ctx)->cmd_name, -1);
return JIM_OK;
}