master
h 106 lines 3.71 KB
Raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #ifndef MONITOR_HMP_INTERNAL_H
4 #define MONITOR_HMP_INTERNAL_H
5
6 #ifdef CONFIG_HMP
7 #include "monitor/hmp.h"
8 /*
9 * Supported types:
10 *
11 * 'F' filename
12 * 'B' block device name
13 * 's' string (accept optional quote)
14 * 'S' it just appends the rest of the string (accept optional quote)
15 * 'O' option string of the form NAME=VALUE,...
16 * parsed according to QemuOptsList given by its name
17 * Example: 'device:O' uses qemu_device_opts.
18 * Restriction: only lists with empty desc are supported
19 * TODO lift the restriction
20 * 'i' 32 bit integer
21 * 'l' target long (32 or 64 bit)
22 * 'M' Non-negative target long (32 or 64 bit), in user mode the
23 * value is multiplied by 2^20 (think Mebibyte)
24 * 'o' octets (aka bytes)
25 * user mode accepts an optional E, e, P, p, T, t, G, g, M, m,
26 * K, k suffix, which multiplies the value by 2^60 for suffixes E
27 * and e, 2^50 for suffixes P and p, 2^40 for suffixes T and t,
28 * 2^30 for suffixes G and g, 2^20 for M and m, 2^10 for K and k
29 * 'T' double
30 * user mode accepts an optional ms, us, ns suffix,
31 * which divides the value by 1e3, 1e6, 1e9, respectively
32 * '/' optional gdb-like print format (like "/10x")
33 *
34 * '?' optional type (for all types, except '/')
35 * '.' other form of optional type (for 'i' and 'l')
36 * 'b' boolean
37 * user mode accepts "on" or "off"
38 * '-' optional parameter (eg. '-f'); if followed by a 's', it
39 * specifies an optional string param (e.g. '-fs' allows '-f foo')
40 *
41 */
42
43 typedef struct HMPCommand {
44 const char *name;
45 const char *args_type;
46 const char *params;
47 const char *help;
48 const char *flags; /* p=preconfig */
49 void (*cmd)(MonitorHMP *hmp, const QDict *qdict);
50 /*
51 * If implementing a command that takes no arguments and simply
52 * prints formatted data, then leave @cmd NULL, and then set
53 * @cmd_info_hrt to the corresponding QMP handler that returns
54 * the formatted text.
55 */
56 HumanReadableText *(*cmd_info_hrt)(Error **errp);
57 /*
58 * @sub_table is a list of 2nd level of commands. If it does not exist,
59 * cmd should be used. If it exists, sub_table[?].cmd should be
60 * used, and cmd of 1st level plays the role of help function.
61 */
62 struct HMPCommand *sub_table;
63 void (*command_completion)(ReadLineState *rs, int nb_args, const char *str);
64
65 /* Keep non-pointer data at the end to minimize holes. */
66
67 /**
68 * @arch_bitmask: bitmask of QEMU_ARCH_* constants
69 * Allow to restrict the command for a particular set of
70 * target architectures.
71 */
72 uint32_t arch_bitmask;
73 bool coroutine;
74 } HMPCommand;
75
76 struct MonitorHMPClass {
77 MonitorClass parent_class;
78 };
79
80 struct MonitorHMP {
81 Monitor parent_obj;
82 bool use_readline;
83 /*
84 * State used only in the thread "owning" the monitor.
85 * This is currently always the main thread, since
86 * HMP does not allow use of the I/O thread at this time.
87 * These members can be safely accessed without locks.
88 */
89 ReadLineState *rs;
90 char *mon_cpu_path;
91 int reset_seen;
92 };
93
94 int monitor_hmp_set_cpu(MonitorHMP *hmp, int cpu_index);
95 void handle_hmp_command(MonitorHMP *hmp, const char *cmdline);
96 int hmp_compare_cmd(const char *name, const char *list);
97
98 /*
99 * hmp_cmds_for_target: Return array of HMPCommand entries
100 *
101 * If @info_command is true, return the particular 'info foo' commands array.
102 */
103 HMPCommand *hmp_cmds_for_target(bool info_command);
104
105 #endif /* CONFIG_HMP */
106 #endif