1 /*
2  * Copyright (c) 2008-2009 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include <stdbool.h>
11 #include <stddef.h>
12 #include <stdalign.h>
13 #include <sys/types.h>
14 #include <lk/compiler.h>
15 
16 __BEGIN_CDECLS
17 
18 /* Included from top level lk/console_cmd.h when lib/console is built.
19  * Provides definitions for how to register a command block to be picked up by
20  * the lib/console machinery.
21  *
22  * Do not include directly.
23  */
24 
25 /* an individual command */
26 typedef struct {
27     const char *cmd_str;
28     const char *help_str;
29     const console_cmd_func cmd_callback;
30     uint8_t availability_mask;
31 } console_cmd;
32 
33 /* a block of commands to register */
34 typedef struct _cmd_block {
35     const char *name;
36     size_t count;
37     const console_cmd *list;
38 } console_cmd_block;
39 
40 #define STATIC_COMMAND_START static const console_cmd _cmd_list[] = {
41 
42 #define STATIC_COMMAND_END(name) }; alignas(console_cmd_block) const console_cmd_block _cmd_block_##name \
43     __SECTION("commands") = \
44     { #name, sizeof(_cmd_list) / sizeof(_cmd_list[0]), _cmd_list }
45 
46 /* same as above but with a suffixed name to make the list unique within the file */
47 #define STATIC_COMMAND_START_NAMED(name) static const console_cmd _cmd_list_##name[] = {
48 
49 #define STATIC_COMMAND_END_NAMED(name) }; alignas(console_cmd_block) const console_cmd_block _cmd_block_##name \
50     __SECTION("commands") = \
51     { #name, sizeof(_cmd_list_##name) / sizeof(_cmd_list_##name[0]), _cmd_list_##name }
52 
53 #define STATIC_COMMAND(command_str, help_str, func) \
54     { command_str, help_str, func, CMD_AVAIL_NORMAL },
55 
56 #define STATIC_COMMAND_MASKED(command_str, help_str, func, availability_mask) \
57     { command_str, help_str, func, availability_mask },
58 
59 __END_CDECLS
60 
61