2 * QEMU PPC (monitor definitions)
4 * Copyright (c) 2003-2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
27 #include "monitor/monitor.h"
28 #include "qemu/ctype.h"
29 #include "monitor/hmp-target.h"
30 #include "monitor/hmp.h"
31 #include "qapi/qapi-commands-machine-target.h"
32 #include "cpu-models.h"
35 static target_long monitor_get_ccr(Monitor *mon, const struct MonitorDef *md,
38 CPUArchState *env = mon_get_cpu_env(mon);
46 static target_long monitor_get_xer(Monitor *mon, const struct MonitorDef *md,
49 CPUArchState *env = mon_get_cpu_env(mon);
50 return cpu_read_xer(env);
53 static target_long monitor_get_decr(Monitor *mon, const struct MonitorDef *md,
56 CPUArchState *env = mon_get_cpu_env(mon);
60 return cpu_ppc_load_decr(env);
63 static target_long monitor_get_tbu(Monitor *mon, const struct MonitorDef *md,
66 CPUArchState *env = mon_get_cpu_env(mon);
70 return cpu_ppc_load_tbu(env);
73 static target_long monitor_get_tbl(Monitor *mon, const struct MonitorDef *md,
76 CPUArchState *env = mon_get_cpu_env(mon);
80 return cpu_ppc_load_tbl(env);
83 void hmp_info_tlb(Monitor *mon, const QDict *qdict)
85 CPUArchState *env1 = mon_get_cpu_env(mon);
88 monitor_printf(mon, "No CPU available\n");
94 const MonitorDef monitor_defs[] = {
95 { "fpscr", offsetof(CPUPPCState, fpscr) },
96 /* Next instruction pointer */
97 { "nip|pc", offsetof(CPUPPCState, nip) },
98 { "lr", offsetof(CPUPPCState, lr) },
99 { "ctr", offsetof(CPUPPCState, ctr) },
100 { "decr", 0, &monitor_get_decr, },
101 { "ccr|cr", 0, &monitor_get_ccr, },
102 /* Machine state register */
103 { "xer", 0, &monitor_get_xer },
104 { "msr", offsetof(CPUPPCState, msr) },
105 { "tbu", 0, &monitor_get_tbu, },
106 { "tbl", 0, &monitor_get_tbl, },
110 const MonitorDef *target_monitor_defs(void)
115 static int ppc_cpu_get_reg_num(const char *numstr, int maxnum, int *pregnum)
124 regnum = strtoul(numstr, &endptr, 10);
125 if (*endptr || (regnum >= maxnum)) {
133 int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
136 PowerPCCPU *cpu = POWERPC_CPU(cs);
137 CPUPPCState *env = &cpu->env;
139 /* General purpose registers */
140 if ((qemu_tolower(name[0]) == 'r') &&
141 ppc_cpu_get_reg_num(name + 1, ARRAY_SIZE(env->gpr), ®num)) {
142 *pval = env->gpr[regnum];
146 /* Floating point registers */
147 if ((qemu_tolower(name[0]) == 'f') &&
148 ppc_cpu_get_reg_num(name + 1, 32, ®num)) {
149 *pval = *cpu_fpr_ptr(env, regnum);
153 /* Special purpose registers */
154 for (i = 0; i < ARRAY_SIZE(env->spr_cb); ++i) {
155 ppc_spr_t *spr = &env->spr_cb[i];
157 if (spr->name && (strcasecmp(name, spr->name) == 0)) {
163 /* Segment registers */
164 #if !defined(CONFIG_USER_ONLY)
165 if ((strncasecmp(name, "sr", 2) == 0) &&
166 ppc_cpu_get_reg_num(name + 2, ARRAY_SIZE(env->sr), ®num)) {
167 *pval = env->sr[regnum];
175 static void ppc_cpu_defs_entry(gpointer data, gpointer user_data)
177 ObjectClass *oc = data;
178 CpuDefinitionInfoList **first = user_data;
179 const char *typename;
180 CpuDefinitionInfo *info;
182 typename = object_class_get_name(oc);
183 info = g_malloc0(sizeof(*info));
184 info->name = g_strndup(typename,
185 strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX));
187 QAPI_LIST_PREPEND(*first, info);
190 CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
192 CpuDefinitionInfoList *cpu_list = NULL;
196 list = object_class_get_list(TYPE_POWERPC_CPU, false);
197 g_slist_foreach(list, ppc_cpu_defs_entry, &cpu_list);
200 for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
201 PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];
203 CpuDefinitionInfo *info;
205 oc = ppc_cpu_class_by_name(alias->model);
210 info = g_malloc0(sizeof(*info));
211 info->name = g_strdup(alias->alias);
212 info->q_typename = g_strdup(object_class_get_name(oc));
214 QAPI_LIST_PREPEND(cpu_list, info);