1bf957284SPavel Butsykin /*
20f3fea21SPhilippe Mathieu-Daudé * QEMU PPC (monitor definitions)
3bf957284SPavel Butsykin *
4bf957284SPavel Butsykin * Copyright (c) 2003-2004 Fabrice Bellard
5bf957284SPavel Butsykin *
6bf957284SPavel Butsykin * Permission is hereby granted, free of charge, to any person obtaining a copy
7bf957284SPavel Butsykin * of this software and associated documentation files (the "Software"), to deal
8bf957284SPavel Butsykin * in the Software without restriction, including without limitation the rights
9bf957284SPavel Butsykin * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10bf957284SPavel Butsykin * copies of the Software, and to permit persons to whom the Software is
11bf957284SPavel Butsykin * furnished to do so, subject to the following conditions:
12bf957284SPavel Butsykin *
13bf957284SPavel Butsykin * The above copyright notice and this permission notice shall be included in
14bf957284SPavel Butsykin * all copies or substantial portions of the Software.
15bf957284SPavel Butsykin *
16bf957284SPavel Butsykin * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf957284SPavel Butsykin * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf957284SPavel Butsykin * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19bf957284SPavel Butsykin * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20bf957284SPavel Butsykin * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21bf957284SPavel Butsykin * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22bf957284SPavel Butsykin * THE SOFTWARE.
23bf957284SPavel Butsykin */
24856dfd8aSMarkus Armbruster
250d75590dSPeter Maydell #include "qemu/osdep.h"
26bf957284SPavel Butsykin #include "cpu.h"
27bf957284SPavel Butsykin #include "monitor/monitor.h"
28856dfd8aSMarkus Armbruster #include "qemu/ctype.h"
29bf957284SPavel Butsykin #include "monitor/hmp-target.h"
30275307aaSMarkus Armbruster #include "monitor/hmp.h"
31*d6758495SDaniel P. Berrangé #include "qapi/error.h"
32*d6758495SDaniel P. Berrangé #include "qapi/qapi-commands-machine.h"
330f3fea21SPhilippe Mathieu-Daudé #include "cpu-models.h"
340f3fea21SPhilippe Mathieu-Daudé #include "cpu-qom.h"
35bf957284SPavel Butsykin
monitor_get_ccr(Monitor * mon,const struct MonitorDef * md,int val)3643cf067fSKevin Wolf static target_long monitor_get_ccr(Monitor *mon, const struct MonitorDef *md,
3743cf067fSKevin Wolf int val)
38bf957284SPavel Butsykin {
39e7cff9c6SKevin Wolf CPUArchState *env = mon_get_cpu_env(mon);
40bf957284SPavel Butsykin unsigned int u;
41bf957284SPavel Butsykin
422060436aSHarsh Prateek Bora u = ppc_get_cr(env);
43bf957284SPavel Butsykin
44bf957284SPavel Butsykin return u;
45bf957284SPavel Butsykin }
46bf957284SPavel Butsykin
monitor_get_xer(Monitor * mon,const struct MonitorDef * md,int val)473938cacdSMatheus Ferst static target_long monitor_get_xer(Monitor *mon, const struct MonitorDef *md,
483938cacdSMatheus Ferst int val)
493938cacdSMatheus Ferst {
503938cacdSMatheus Ferst CPUArchState *env = mon_get_cpu_env(mon);
513938cacdSMatheus Ferst return cpu_read_xer(env);
523938cacdSMatheus Ferst }
533938cacdSMatheus Ferst
monitor_get_decr(Monitor * mon,const struct MonitorDef * md,int val)5443cf067fSKevin Wolf static target_long monitor_get_decr(Monitor *mon, const struct MonitorDef *md,
5543cf067fSKevin Wolf int val)
56bf957284SPavel Butsykin {
57e7cff9c6SKevin Wolf CPUArchState *env = mon_get_cpu_env(mon);
583778aa97SMatheus Ferst if (!env->tb_env) {
593778aa97SMatheus Ferst return 0;
603778aa97SMatheus Ferst }
61bf957284SPavel Butsykin return cpu_ppc_load_decr(env);
62bf957284SPavel Butsykin }
63bf957284SPavel Butsykin
monitor_get_tbu(Monitor * mon,const struct MonitorDef * md,int val)6443cf067fSKevin Wolf static target_long monitor_get_tbu(Monitor *mon, const struct MonitorDef *md,
6543cf067fSKevin Wolf int val)
66bf957284SPavel Butsykin {
67e7cff9c6SKevin Wolf CPUArchState *env = mon_get_cpu_env(mon);
683778aa97SMatheus Ferst if (!env->tb_env) {
693778aa97SMatheus Ferst return 0;
703778aa97SMatheus Ferst }
71bf957284SPavel Butsykin return cpu_ppc_load_tbu(env);
72bf957284SPavel Butsykin }
73bf957284SPavel Butsykin
monitor_get_tbl(Monitor * mon,const struct MonitorDef * md,int val)7443cf067fSKevin Wolf static target_long monitor_get_tbl(Monitor *mon, const struct MonitorDef *md,
7543cf067fSKevin Wolf int val)
76bf957284SPavel Butsykin {
77e7cff9c6SKevin Wolf CPUArchState *env = mon_get_cpu_env(mon);
783778aa97SMatheus Ferst if (!env->tb_env) {
793778aa97SMatheus Ferst return 0;
803778aa97SMatheus Ferst }
81bf957284SPavel Butsykin return cpu_ppc_load_tbl(env);
82bf957284SPavel Butsykin }
83bf957284SPavel Butsykin
hmp_info_tlb(Monitor * mon,const QDict * qdict)84bf957284SPavel Butsykin void hmp_info_tlb(Monitor *mon, const QDict *qdict)
85bf957284SPavel Butsykin {
86e7cff9c6SKevin Wolf CPUArchState *env1 = mon_get_cpu_env(mon);
87bf957284SPavel Butsykin
88854e67feSThomas Huth if (!env1) {
89854e67feSThomas Huth monitor_printf(mon, "No CPU available\n");
90854e67feSThomas Huth return;
91854e67feSThomas Huth }
92fad866daSMarkus Armbruster dump_mmu(env1);
93bf957284SPavel Butsykin }
94bf957284SPavel Butsykin
95bf957284SPavel Butsykin const MonitorDef monitor_defs[] = {
96bf957284SPavel Butsykin { "fpscr", offsetof(CPUPPCState, fpscr) },
97bf957284SPavel Butsykin /* Next instruction pointer */
98bf957284SPavel Butsykin { "nip|pc", offsetof(CPUPPCState, nip) },
99bf957284SPavel Butsykin { "lr", offsetof(CPUPPCState, lr) },
100bf957284SPavel Butsykin { "ctr", offsetof(CPUPPCState, ctr) },
101bf957284SPavel Butsykin { "decr", 0, &monitor_get_decr, },
1020a9516c2SAlexey Kardashevskiy { "ccr|cr", 0, &monitor_get_ccr, },
103bf957284SPavel Butsykin /* Machine state register */
1043938cacdSMatheus Ferst { "xer", 0, &monitor_get_xer },
1050a9516c2SAlexey Kardashevskiy { "msr", offsetof(CPUPPCState, msr) },
106bf957284SPavel Butsykin { "tbu", 0, &monitor_get_tbu, },
10719e81ce5SNicholas Piggin #if defined(TARGET_PPC64)
10819e81ce5SNicholas Piggin { "tb", 0, &monitor_get_tbl, },
10919e81ce5SNicholas Piggin #else
110bf957284SPavel Butsykin { "tbl", 0, &monitor_get_tbl, },
11119e81ce5SNicholas Piggin #endif
112bf957284SPavel Butsykin { NULL },
113bf957284SPavel Butsykin };
114bf957284SPavel Butsykin
target_monitor_defs(void)115bf957284SPavel Butsykin const MonitorDef *target_monitor_defs(void)
116bf957284SPavel Butsykin {
117bf957284SPavel Butsykin return monitor_defs;
118bf957284SPavel Butsykin }
1190a9516c2SAlexey Kardashevskiy
ppc_cpu_get_reg_num(const char * numstr,int maxnum,int * pregnum)1200a9516c2SAlexey Kardashevskiy static int ppc_cpu_get_reg_num(const char *numstr, int maxnum, int *pregnum)
1210a9516c2SAlexey Kardashevskiy {
1220a9516c2SAlexey Kardashevskiy int regnum;
1230a9516c2SAlexey Kardashevskiy char *endptr = NULL;
1240a9516c2SAlexey Kardashevskiy
1250a9516c2SAlexey Kardashevskiy if (!*numstr) {
1260a9516c2SAlexey Kardashevskiy return false;
1270a9516c2SAlexey Kardashevskiy }
1280a9516c2SAlexey Kardashevskiy
1290a9516c2SAlexey Kardashevskiy regnum = strtoul(numstr, &endptr, 10);
1300a9516c2SAlexey Kardashevskiy if (*endptr || (regnum >= maxnum)) {
1310a9516c2SAlexey Kardashevskiy return false;
1320a9516c2SAlexey Kardashevskiy }
1330a9516c2SAlexey Kardashevskiy *pregnum = regnum;
1340a9516c2SAlexey Kardashevskiy
1350a9516c2SAlexey Kardashevskiy return true;
1360a9516c2SAlexey Kardashevskiy }
1370a9516c2SAlexey Kardashevskiy
target_get_monitor_def(CPUState * cs,const char * name,uint64_t * pval)1380a9516c2SAlexey Kardashevskiy int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
1390a9516c2SAlexey Kardashevskiy {
1400a9516c2SAlexey Kardashevskiy int i, regnum;
141794511bcSPhilippe Mathieu-Daudé CPUPPCState *env = cpu_env(cs);
1420a9516c2SAlexey Kardashevskiy
1430a9516c2SAlexey Kardashevskiy /* General purpose registers */
14495a5befcSPeter Maydell if ((qemu_tolower(name[0]) == 'r') &&
1450a9516c2SAlexey Kardashevskiy ppc_cpu_get_reg_num(name + 1, ARRAY_SIZE(env->gpr), ®num)) {
1460a9516c2SAlexey Kardashevskiy *pval = env->gpr[regnum];
1470a9516c2SAlexey Kardashevskiy return 0;
1480a9516c2SAlexey Kardashevskiy }
1490a9516c2SAlexey Kardashevskiy
1500a9516c2SAlexey Kardashevskiy /* Floating point registers */
15195a5befcSPeter Maydell if ((qemu_tolower(name[0]) == 'f') &&
152ef96e3aeSMark Cave-Ayland ppc_cpu_get_reg_num(name + 1, 32, ®num)) {
153ef96e3aeSMark Cave-Ayland *pval = *cpu_fpr_ptr(env, regnum);
1540a9516c2SAlexey Kardashevskiy return 0;
1550a9516c2SAlexey Kardashevskiy }
1560a9516c2SAlexey Kardashevskiy
1570a9516c2SAlexey Kardashevskiy /* Special purpose registers */
1580a9516c2SAlexey Kardashevskiy for (i = 0; i < ARRAY_SIZE(env->spr_cb); ++i) {
1590a9516c2SAlexey Kardashevskiy ppc_spr_t *spr = &env->spr_cb[i];
1600a9516c2SAlexey Kardashevskiy
1610a9516c2SAlexey Kardashevskiy if (spr->name && (strcasecmp(name, spr->name) == 0)) {
1620a9516c2SAlexey Kardashevskiy *pval = env->spr[i];
1630a9516c2SAlexey Kardashevskiy return 0;
1640a9516c2SAlexey Kardashevskiy }
1650a9516c2SAlexey Kardashevskiy }
1660a9516c2SAlexey Kardashevskiy
1670a9516c2SAlexey Kardashevskiy /* Segment registers */
1680a9516c2SAlexey Kardashevskiy #if !defined(CONFIG_USER_ONLY)
1690a9516c2SAlexey Kardashevskiy if ((strncasecmp(name, "sr", 2) == 0) &&
1700a9516c2SAlexey Kardashevskiy ppc_cpu_get_reg_num(name + 2, ARRAY_SIZE(env->sr), ®num)) {
1710a9516c2SAlexey Kardashevskiy *pval = env->sr[regnum];
1720a9516c2SAlexey Kardashevskiy return 0;
1730a9516c2SAlexey Kardashevskiy }
1740a9516c2SAlexey Kardashevskiy #endif
1750a9516c2SAlexey Kardashevskiy
1760a9516c2SAlexey Kardashevskiy return -EINVAL;
1770a9516c2SAlexey Kardashevskiy }
1780f3fea21SPhilippe Mathieu-Daudé
179*d6758495SDaniel P. Berrangé CpuModelExpansionInfo *
qmp_query_cpu_model_expansion(CpuModelExpansionType type,CpuModelInfo * model,Error ** errp)180*d6758495SDaniel P. Berrangé qmp_query_cpu_model_expansion(CpuModelExpansionType type,
181*d6758495SDaniel P. Berrangé CpuModelInfo *model,
182*d6758495SDaniel P. Berrangé Error **errp)
183*d6758495SDaniel P. Berrangé {
184*d6758495SDaniel P. Berrangé error_setg(errp, "CPU model expansion is not supported on this target");
185*d6758495SDaniel P. Berrangé return NULL;
186*d6758495SDaniel P. Berrangé }
187*d6758495SDaniel P. Berrangé
ppc_cpu_defs_entry(gpointer data,gpointer user_data)1880f3fea21SPhilippe Mathieu-Daudé static void ppc_cpu_defs_entry(gpointer data, gpointer user_data)
1890f3fea21SPhilippe Mathieu-Daudé {
1900f3fea21SPhilippe Mathieu-Daudé ObjectClass *oc = data;
1910f3fea21SPhilippe Mathieu-Daudé CpuDefinitionInfoList **first = user_data;
1920f3fea21SPhilippe Mathieu-Daudé const char *typename;
1930f3fea21SPhilippe Mathieu-Daudé CpuDefinitionInfo *info;
1940f3fea21SPhilippe Mathieu-Daudé
1950f3fea21SPhilippe Mathieu-Daudé typename = object_class_get_name(oc);
1960f3fea21SPhilippe Mathieu-Daudé info = g_malloc0(sizeof(*info));
1974b26aa9fSGavin Shan info->name = cpu_model_from_type(typename);
1980f3fea21SPhilippe Mathieu-Daudé
1990f3fea21SPhilippe Mathieu-Daudé QAPI_LIST_PREPEND(*first, info);
2000f3fea21SPhilippe Mathieu-Daudé }
2010f3fea21SPhilippe Mathieu-Daudé
qmp_query_cpu_definitions(Error ** errp)2020f3fea21SPhilippe Mathieu-Daudé CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
2030f3fea21SPhilippe Mathieu-Daudé {
2040f3fea21SPhilippe Mathieu-Daudé CpuDefinitionInfoList *cpu_list = NULL;
2050f3fea21SPhilippe Mathieu-Daudé GSList *list;
2060f3fea21SPhilippe Mathieu-Daudé int i;
2070f3fea21SPhilippe Mathieu-Daudé
2080f3fea21SPhilippe Mathieu-Daudé list = object_class_get_list(TYPE_POWERPC_CPU, false);
2090f3fea21SPhilippe Mathieu-Daudé g_slist_foreach(list, ppc_cpu_defs_entry, &cpu_list);
2100f3fea21SPhilippe Mathieu-Daudé g_slist_free(list);
2110f3fea21SPhilippe Mathieu-Daudé
2120f3fea21SPhilippe Mathieu-Daudé for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
2130f3fea21SPhilippe Mathieu-Daudé PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];
2140f3fea21SPhilippe Mathieu-Daudé ObjectClass *oc;
2150f3fea21SPhilippe Mathieu-Daudé CpuDefinitionInfo *info;
2160f3fea21SPhilippe Mathieu-Daudé
2170f3fea21SPhilippe Mathieu-Daudé oc = ppc_cpu_class_by_name(alias->model);
2180f3fea21SPhilippe Mathieu-Daudé if (oc == NULL) {
2190f3fea21SPhilippe Mathieu-Daudé continue;
2200f3fea21SPhilippe Mathieu-Daudé }
2210f3fea21SPhilippe Mathieu-Daudé
2220f3fea21SPhilippe Mathieu-Daudé info = g_malloc0(sizeof(*info));
2230f3fea21SPhilippe Mathieu-Daudé info->name = g_strdup(alias->alias);
2240f3fea21SPhilippe Mathieu-Daudé info->q_typename = g_strdup(object_class_get_name(oc));
2250f3fea21SPhilippe Mathieu-Daudé
2260f3fea21SPhilippe Mathieu-Daudé QAPI_LIST_PREPEND(cpu_list, info);
2270f3fea21SPhilippe Mathieu-Daudé }
2280f3fea21SPhilippe Mathieu-Daudé
2290f3fea21SPhilippe Mathieu-Daudé return cpu_list;
2300f3fea21SPhilippe Mathieu-Daudé }
231