+ context->mode = COMMAND_EXEC;
+ context->commands = NULL;
+ context->current_target = 0;
+ context->output_handler = NULL;
+ context->output_handler_priv = NULL;
+
+#if !BUILD_ECOSBOARD
+ Jim_InitEmbedded();
+ /* Create an interpreter */
+ interp = Jim_CreateInterp();
+ /* Add all the Jim core commands */
+ Jim_RegisterCoreCommands(interp);
+#endif
+
+#if defined(_MSC_VER)
+ /* WinXX - is generic, the forward
+ * looking problem is this:
+ *
+ * "win32" or "win64"
+ *
+ * "winxx" is generic.
+ */
+ HostOs = "winxx";
+#elif defined(__linux__)
+ HostOs = "linux";
+#elif defined(__DARWIN__)
+ HostOs = "darwin";
+#elif defined(__CYGWIN__)
+ HostOs = "cygwin";
+#elif defined(__MINGW32__)
+ HostOs = "mingw32";
+#elif defined(__ECOS)
+ HostOs = "ecos";
+#else
+#warn unrecognized host OS...
+ HostOs = "other";
+#endif
+ Jim_SetGlobalVariableStr(interp, "ocd_HOSTOS",
+ Jim_NewStringObj(interp, HostOs , strlen(HostOs)));
+
+ Jim_CreateCommand(interp, "ocd_find", jim_find, NULL, NULL);
+ Jim_CreateCommand(interp, "echo", jim_echo, NULL, NULL);
+ Jim_CreateCommand(interp, "capture", jim_capture, NULL, NULL);
+
+ /* Set Jim's STDIO */
+ interp->cookie_stdin = interp;
+ interp->cookie_stdout = interp;
+ interp->cookie_stderr = interp;
+ interp->cb_fwrite = openocd_jim_fwrite;
+ interp->cb_fread = openocd_jim_fread ;
+ interp->cb_vfprintf = openocd_jim_vfprintf;
+ interp->cb_fflush = openocd_jim_fflush;
+ interp->cb_fgets = openocd_jim_fgets;
+
+#if !BUILD_ECOSBOARD
+ Jim_EventLoopOnLoad(interp);
+#endif
+ if (Jim_Eval_Named(interp, startup_tcl, "embedded:startup.tcl",1) == JIM_ERR)
+ {
+ LOG_ERROR("Failed to run startup.tcl (embedded into OpenOCD)");
+ Jim_PrintErrorMessage(interp);
+ exit(-1);
+ }
+
+ register_command(context, NULL, "sleep",
+ handle_sleep_command, COMMAND_ANY,
+ "<n> [busy] - sleep for n milliseconds. "
+ "\"busy\" means busy wait");
+ register_command(context, NULL, "fast",
+ handle_fast_command, COMMAND_ANY,
+ "fast <enable/disable> - place at beginning of "
+ "config files. Sets defaults to fast and dangerous.");
+
+ return context;
+}
+
+int command_context_mode(command_context_t *cmd_ctx, enum command_mode mode)
+{
+ if (!cmd_ctx)
+ return ERROR_INVALID_ARGUMENTS;
+
+ cmd_ctx->mode = mode;
+ return ERROR_OK;
+}
+
+void process_jim_events(void)
+{
+#if !BUILD_ECOSBOARD
+ static int recursion = 0;
+
+ if (!recursion)
+ {
+ recursion++;
+ Jim_ProcessEvents (interp, JIM_ALL_EVENTS | JIM_DONT_WAIT);
+ recursion--;
+ }
+#endif
+}
+
+void register_jim(struct command_context_s *cmd_ctx, const char *name, int (*cmd)(Jim_Interp *interp, int argc, Jim_Obj *const *argv), const char *help)
+{
+ Jim_CreateCommand(interp, name, cmd, NULL, NULL);
+
+ Jim_Obj *cmd_list = Jim_NewListObj(interp, NULL, 0);
+ Jim_ListAppendElement(interp, cmd_list,
+ Jim_NewStringObj(interp, name, -1));
+
+ command_helptext_add(cmd_list, help);