2 * Copyright © 2008 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 static struct command_function functions[] = {
22 { "help", "?", command_help, "help", "Print this list\n" },
23 { "quit", "q", command_quit, "[q]uit", "Quit\n" },
24 { "di", "di", command_di, "di <start> <end>",
26 { "ds", "ds", command_ds, "ds <start> <end>",
28 { "dx", "dx", command_dx, "dx <start> <end>",
30 { "set", "t", command_set, "se[t] mem <prefix> <address> <data> ...",
31 "Set mem {xram|rom|iram|sfr}\n"
33 { "dump", "d", command_dump, "[d]ump <prefix> <start> <end>",
34 "Dump {xram|rom|iram|sfr} <start> <end>\n" },
35 { "file", "file", command_file, "file <filename>",
36 "Pretend to load executable from <filename>\n" },
37 { "pc", "p", command_pc, "[p]c [addr]",
38 "Get or set pc value\n" },
39 { "break", "b", command_break,"[b]reak <addr>",
40 "Set break point\n" },
41 { "clear", "c", command_clear,"[c]lear <addr>",
42 "Clear break point\n" },
43 { "run", "r", command_run, "[r]un [start] [stop]",
44 "Run with optional start and temp breakpoint addresses\n" },
45 { "go", "g", command_run, "[g]o [start] [stop]",
46 "Run with optional start and temp breakpoint addresses\n" },
47 { "next", "n", command_next, "[n]ext",
48 "Step over one instruction, past any call\n" },
49 { "step", "s", command_step, "[s]tep",
51 { "load", "l", command_load, "[l]oad <file>",
52 "Load a hex file into memory or flash" },
53 { "halt", "h", command_halt, "[h]alt",
54 "Halt the processor\n" },
55 { "reset","res",command_reset, "[res]et",
57 { "status","status",command_status, "status",
58 "Display CC1111 debug status\n" },
59 { "info", "i", command_info, "[i]info",
60 "Get information\n" },
61 { "stop", "stop", command_stop, "stop",
63 { NULL, NULL, NULL, NULL, NULL },
72 string_to_int(char *s, int *v)
76 if (isdigit(s[0]) || s[0] == '-' || s[0] == '+') {
77 *v = strtol(s, &endptr, 0);
80 } else if (*s == '\'') {
106 struct command_function *
107 command_string_to_function(struct command_function *functions, char *name)
110 for (i = 0; functions[i].name; i++)
111 if (!strcmp(name, functions[i].name) ||
112 !strcmp(name, functions[i].alias))
113 return &functions[i];
118 command_function_help(struct command_function *functions, int argc, char **argv)
121 struct command_function *func;
124 for (i = 0; functions[i].name; i++)
125 s51_printf("%-10s%s\n", functions[i].name,
128 for (i = 1; i < argc; i++) {
129 func = command_string_to_function(functions, argv[i]);
131 s51_printf("%-10s unknown command\n", argv[i]);
132 return command_syntax;
134 s51_printf("%-10s %s\n%s", func->name,
135 func->usage, func->help);
138 return command_debug;
142 command_split_into_words(char *line, char **argv)
149 while (isspace(*line))
157 while (*line && *line != quotechar)
164 while (*line && !isspace(*line))
175 command_help(int argc, char **argv)
177 return command_function_help(functions, argc, argv);
181 command_syntax_error(int argc, char **argv)
183 s51_printf("Syntax error in:");
185 s51_printf(" %s", *argv++);
195 enum command_result result;
196 struct command_function *func;
200 s51_device = getenv("AO_DBG_DEVICE");
201 s51_tty = cc_usbdevs_find_by_arg(s51_device, "TeleDongle");
203 s51_dbg = ccdbg_open (s51_tty);
206 ccdbg_debug_mode(s51_dbg);
208 s51_printf("Welcome to the non-simulated processor\n");
210 if (s51_read_line (line, sizeof line) == 0)
213 argc = command_split_into_words(line, argv);
215 func = command_string_to_function(functions, argv[0]);
217 command_syntax_error(argc, argv);
220 result = (*func->func)(argc, argv);
222 result = command_interrupt;
225 command_syntax_error(argc, argv);
228 s51_printf("Error\n");
230 case command_success:
232 case command_interrupt:
234 s51_printf("Interrupted\n");
242 ccdbg_close(s51_dbg);