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 },
71 struct command_function *
72 command_string_to_function(struct command_function *functions, char *name)
75 for (i = 0; functions[i].name; i++)
76 if (!strcmp(name, functions[i].name) ||
77 !strcmp(name, functions[i].alias))
83 command_function_help(struct command_function *functions, int argc, char **argv)
86 struct command_function *func;
89 for (i = 0; functions[i].name; i++)
90 s51_printf("%-10s%s\n", functions[i].name,
93 for (i = 1; i < argc; i++) {
94 func = command_string_to_function(functions, argv[i]);
96 s51_printf("%-10s unknown command\n", argv[i]);
97 return command_syntax;
99 s51_printf("%-10s %s\n%s", func->name,
100 func->usage, func->help);
103 return command_debug;
107 command_split_into_words(char *line, char **argv)
114 while (isspace(*line))
122 while (*line && *line != quotechar)
129 while (*line && !isspace(*line))
140 command_help(int argc, char **argv)
142 return command_function_help(functions, argc, argv);
146 command_syntax_error(int argc, char **argv)
148 s51_printf("Syntax error in:");
150 s51_printf(" %s", *argv++);
160 enum command_result result;
161 struct command_function *func;
165 s51_device = getenv("AO_DBG_DEVICE");
166 s51_tty = cc_usbdevs_find_by_arg(s51_device, "TeleDongle");
168 s51_dbg = ccdbg_open (s51_tty);
171 ccdbg_debug_mode(s51_dbg);
173 s51_printf("Welcome to the non-simulated processor\n");
175 if (s51_read_line (line, sizeof line) == 0)
178 argc = command_split_into_words(line, argv);
180 func = command_string_to_function(functions, argv[0]);
182 command_syntax_error(argc, argv);
185 result = (*func->func)(argc, argv);
187 result = command_interrupt;
190 command_syntax_error(argc, argv);
193 s51_printf("Error\n");
195 case command_success:
197 case command_interrupt:
199 s51_printf("Interrupted\n");
207 ccdbg_close(s51_dbg);