target/aarch64: Call aarch64_init_debug_access() earlier in aarch64_deassert_reset()
[openocd.git] / src / hello.c
blob25938bcf88d75e5a45c2f07e5237a32823519e78
1 /***************************************************************************
2 * Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net> *
3 * *
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. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16 ***************************************************************************/
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21 #include <helper/log.h>
23 COMMAND_HANDLER(handle_foo_command)
25 if (CMD_ARGC < 1 || CMD_ARGC > 2)
26 return ERROR_COMMAND_SYNTAX_ERROR;
28 uint32_t address;
29 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
31 const char *msg = "<unchanged>";
32 if (CMD_ARGC == 2) {
33 bool enable;
34 COMMAND_PARSE_ENABLE(CMD_ARGV[1], enable);
35 msg = enable ? "enable" : "disable";
38 LOG_INFO("%s: address=0x%8.8" PRIx32 " enabled=%s", CMD_NAME, address, msg);
39 return ERROR_OK;
42 static bool foo_flag;
44 COMMAND_HANDLER(handle_flag_command)
46 return CALL_COMMAND_HANDLER(handle_command_parse_bool,
47 &foo_flag, "foo flag");
50 static const struct command_registration foo_command_handlers[] = {
52 .name = "bar",
53 .handler = &handle_foo_command,
54 .mode = COMMAND_ANY,
55 .usage = "address ['enable'|'disable']",
56 .help = "an example command",
59 .name = "baz",
60 .handler = &handle_foo_command,
61 .mode = COMMAND_ANY,
62 .usage = "address ['enable'|'disable']",
63 .help = "a sample command",
66 .name = "flag",
67 .handler = &handle_flag_command,
68 .mode = COMMAND_ANY,
69 .usage = "[on|off]",
70 .help = "set a flag",
72 COMMAND_REGISTRATION_DONE
75 static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name)
77 if (CMD_ARGC > 1)
78 return ERROR_COMMAND_SYNTAX_ERROR;
79 if (1 == CMD_ARGC) {
80 *sep = " ";
81 *name = CMD_ARGV[0];
82 } else
83 *sep = *name = "";
85 return ERROR_OK;
87 COMMAND_HANDLER(handle_hello_command)
89 const char *sep, *name;
90 int retval = CALL_COMMAND_HANDLER(handle_hello_args, &sep, &name);
91 if (ERROR_OK == retval)
92 command_print(CMD_CTX, "Greetings%s%s!", sep, name);
93 return retval;
96 const struct command_registration hello_command_handlers[] = {
98 .name = "hello",
99 .handler = handle_hello_command,
100 .mode = COMMAND_ANY,
101 .help = "prints a warm welcome",
102 .usage = "[name]",
105 .name = "foo",
106 .mode = COMMAND_ANY,
107 .help = "example command handler skeleton",
109 .chain = foo_command_handlers,
111 COMMAND_REGISTRATION_DONE