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 struct command_function {
24 enum command_result (*func)(int argc, char **argv);
29 static struct command_function functions[] = {
30 { "help", "?", command_help, "help", "Print this list\n" },
31 { "quit", "q", command_quit, "[q]uit", "Quit\n" },
32 { "di", "di", command_di, "di <start> <end>",
34 { "ds", "ds", command_ds, "ds <start> <end>",
36 { "dx", "dx", command_dx, "dx <start> <end>",
38 { "set", "t", command_set, "se[t] mem <prefix> <start> <end>",
39 "Set mem {xram|rom|iram|sfr} <start> <end>\n"
41 { "dump", "d", command_dump, "[d]ump <prefix> <start> <end>",
42 "Dump {xram|rom|iram|sfr} <start> <end>\n" },
43 { "file", "file", command_file, "file <filename>",
44 "Pretend to load executable from <filename>\n" },
45 { "pc", "p", command_pc, "[p]c [addr]",
46 "Get or set pc value\n" },
47 { "break", "b", command_break,"[b]reak <addr>",
48 "Set break point\n" },
49 { "clear", "c", command_clear,"[c]lear <addr>",
50 "Clear break point\n" },
51 { "run", "r", command_run, "[r]un [start] [stop]",
52 "Run with optional start and temp breakpoint addresses\n" },
53 { "next", "n", command_next, "[n]ext",
54 "Step over one instruction, past any call\n" },
55 { "step", "s", command_step, "[s]tep",
57 { "load", "l", command_load, "[l]oad <file>",
58 "Load a hex file into memory or flash" },
59 { "halt", "h", command_halt, "[h]alt",
60 "Halt the processor\n" },
61 { "reset","res",command_reset, "[res]et",
63 { "status","status",command_status, "status",
64 "Display CC1111 debug status\n" },
67 #define NUM_FUNCTIONS (sizeof functions / sizeof functions[0])
75 string_to_int(char *s, int *v)
79 if (isdigit(s[0]) || s[0] == '-' || s[0] == '+') {
80 *v = strtol(s, &endptr, 0);
83 } else if (*s == '\'') {
109 static struct command_function *
110 command_string_to_function(char *name)
113 for (i = 0; i < NUM_FUNCTIONS; i++)
114 if (!strcmp(name, functions[i].name) ||
115 !strcmp(name, functions[i].alias))
116 return &functions[i];
121 command_split_into_words(char *line, char **argv)
128 while (isspace(*line))
136 while (*line && *line != quotechar)
143 while (*line && !isspace(*line))
154 command_help(int argc, char **argv)
157 struct command_function *func;
160 for (i = 0; i < NUM_FUNCTIONS; i++)
161 s51_printf("%-10s%s\n", functions[i].name,
164 for (i = 1; i < argc; i++) {
165 func = command_string_to_function(argv[i]);
167 s51_printf("%-10s unknown command\n", argv[i]);
168 return command_syntax;
170 s51_printf("%-10s %s\n%s", func->name,
171 func->usage, func->help);
174 return command_debug;
178 command_syntax_error(int argc, char **argv)
180 s51_printf("Syntax error in:");
182 s51_printf(" %s", *argv++);
192 enum command_result result;
193 struct command_function *func;
195 s51_dbg = ccdbg_open ();
197 perror("ccdbg_open");
200 ccdbg_debug_mode(s51_dbg);
202 s51_printf("Welcome to the non-simulated processor\n");
204 if (s51_read_line (line, sizeof line) == 0)
207 argc = command_split_into_words(line, argv);
209 func = command_string_to_function(argv[0]);
211 command_syntax_error(argc, argv);
214 result = (*func->func)(argc, argv);
216 result = command_interrupt;
219 command_syntax_error(argc, argv);
222 s51_printf("Error\n");
224 case command_success:
226 case command_interrupt:
228 s51_printf("Interrupted\n");
236 ccdbg_close(s51_dbg);