10f3fea21SPhilippe Mathieu-Daudé /*
20f3fea21SPhilippe Mathieu-Daudé * QEMU PPC (monitor definitions)
30f3fea21SPhilippe Mathieu-Daudé *
40f3fea21SPhilippe Mathieu-Daudé * Copyright (c) 2003-2004 Fabrice Bellard
50f3fea21SPhilippe Mathieu-Daudé *
60f3fea21SPhilippe Mathieu-Daudé * Permission is hereby granted, free of charge, to any person obtaining a copy
70f3fea21SPhilippe Mathieu-Daudé * of this software and associated documentation files (the "Software"), to deal
80f3fea21SPhilippe Mathieu-Daudé * in the Software without restriction, including without limitation the rights
90f3fea21SPhilippe Mathieu-Daudé * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
100f3fea21SPhilippe Mathieu-Daudé * copies of the Software, and to permit persons to whom the Software is
110f3fea21SPhilippe Mathieu-Daudé * furnished to do so, subject to the following conditions:
120f3fea21SPhilippe Mathieu-Daudé *
130f3fea21SPhilippe Mathieu-Daudé * The above copyright notice and this permission notice shall be included in
140f3fea21SPhilippe Mathieu-Daudé * all copies or substantial portions of the Software.
150f3fea21SPhilippe Mathieu-Daudé *
160f3fea21SPhilippe Mathieu-Daudé * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
170f3fea21SPhilippe Mathieu-Daudé * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
180f3fea21SPhilippe Mathieu-Daudé * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
190f3fea21SPhilippe Mathieu-Daudé * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
200f3fea21SPhilippe Mathieu-Daudé * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
210f3fea21SPhilippe Mathieu-Daudé * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
220f3fea21SPhilippe Mathieu-Daudé * THE SOFTWARE.
230f3fea21SPhilippe Mathieu-Daudé */
240f3fea21SPhilippe Mathieu-Daudé
250f3fea21SPhilippe Mathieu-Daudé #include "qemu/osdep.h"
260f3fea21SPhilippe Mathieu-Daudé #include "cpu.h"
270f3fea21SPhilippe Mathieu-Daudé #include "monitor/monitor.h"
280f3fea21SPhilippe Mathieu-Daudé #include "qemu/ctype.h"
290f3fea21SPhilippe Mathieu-Daudé #include "monitor/hmp-target.h"
300f3fea21SPhilippe Mathieu-Daudé #include "monitor/hmp.h"
310f3fea21SPhilippe Mathieu-Daudé #include "qapi/qapi-commands-machine-target.h"
320f3fea21SPhilippe Mathieu-Daudé #include "cpu-models.h"
330f3fea21SPhilippe Mathieu-Daudé #include "cpu-qom.h"
340f3fea21SPhilippe Mathieu-Daudé
monitor_get_ccr(Monitor * mon,const struct MonitorDef * md,int val)350f3fea21SPhilippe Mathieu-Daudé static target_long monitor_get_ccr(Monitor *mon, const struct MonitorDef *md,
360f3fea21SPhilippe Mathieu-Daudé int val)
370f3fea21SPhilippe Mathieu-Daudé {
380f3fea21SPhilippe Mathieu-Daudé CPUArchState *env = mon_get_cpu_env(mon);
390f3fea21SPhilippe Mathieu-Daudé unsigned int u;
400f3fea21SPhilippe Mathieu-Daudé
412060436aSHarsh Prateek Bora u = ppc_get_cr(env);
420f3fea21SPhilippe Mathieu-Daudé
430f3fea21SPhilippe Mathieu-Daudé return u;
440f3fea21SPhilippe Mathieu-Daudé }
450f3fea21SPhilippe Mathieu-Daudé
monitor_get_xer(Monitor * mon,const struct MonitorDef * md,int val)460f3fea21SPhilippe Mathieu-Daudé static target_long monitor_get_xer(Monitor *mon, const struct MonitorDef *md,
470f3fea21SPhilippe Mathieu-Daudé int val)
480f3fea21SPhilippe Mathieu-Daudé {
490f3fea21SPhilippe Mathieu-Daudé CPUArchState *env = mon_get_cpu_env(mon);
500f3fea21SPhilippe Mathieu-Daudé return cpu_read_xer(env);
510f3fea21SPhilippe Mathieu-Daudé }
520f3fea21SPhilippe Mathieu-Daudé
monitor_get_decr(Monitor * mon,const struct MonitorDef * md,int val)530f3fea21SPhilippe Mathieu-Daudé static target_long monitor_get_decr(Monitor *mon, const struct MonitorDef *md,
540f3fea21SPhilippe Mathieu-Daudé int val)
550f3fea21SPhilippe Mathieu-Daudé {
560f3fea21SPhilippe Mathieu-Daudé CPUArchState *env = mon_get_cpu_env(mon);
570f3fea21SPhilippe Mathieu-Daudé if (!env->tb_env) {
580f3fea21SPhilippe Mathieu-Daudé return 0;
590f3fea21SPhilippe Mathieu-Daudé }
600f3fea21SPhilippe Mathieu-Daudé return cpu_ppc_load_decr(env);
610f3fea21SPhilippe Mathieu-Daudé }
620f3fea21SPhilippe Mathieu-Daudé
monitor_get_tbu(Monitor * mon,const struct MonitorDef * md,int val)630f3fea21SPhilippe Mathieu-Daudé static target_long monitor_get_tbu(Monitor *mon, const struct MonitorDef *md,
640f3fea21SPhilippe Mathieu-Daudé int val)
650f3fea21SPhilippe Mathieu-Daudé {
660f3fea21SPhilippe Mathieu-Daudé CPUArchState *env = mon_get_cpu_env(mon);
670f3fea21SPhilippe Mathieu-Daudé if (!env->tb_env) {
680f3fea21SPhilippe Mathieu-Daudé return 0;
690f3fea21SPhilippe Mathieu-Daudé }
700f3fea21SPhilippe Mathieu-Daudé return cpu_ppc_load_tbu(env);
710f3fea21SPhilippe Mathieu-Daudé }
720f3fea21SPhilippe Mathieu-Daudé
monitor_get_tbl(Monitor * mon,const struct MonitorDef * md,int val)730f3fea21SPhilippe Mathieu-Daudé static target_long monitor_get_tbl(Monitor *mon, const struct MonitorDef *md,
740f3fea21SPhilippe Mathieu-Daudé int val)
750f3fea21SPhilippe Mathieu-Daudé {
760f3fea21SPhilippe Mathieu-Daudé CPUArchState *env = mon_get_cpu_env(mon);
770f3fea21SPhilippe Mathieu-Daudé if (!env->tb_env) {
780f3fea21SPhilippe Mathieu-Daudé return 0;
790f3fea21SPhilippe Mathieu-Daudé }
800f3fea21SPhilippe Mathieu-Daudé return cpu_ppc_load_tbl(env);
810f3fea21SPhilippe Mathieu-Daudé }
820f3fea21SPhilippe Mathieu-Daudé
hmp_info_tlb(Monitor * mon,const QDict * qdict)830f3fea21SPhilippe Mathieu-Daudé void hmp_info_tlb(Monitor *mon, const QDict *qdict)
840f3fea21SPhilippe Mathieu-Daudé {
850f3fea21SPhilippe Mathieu-Daudé CPUArchState *env1 = mon_get_cpu_env(mon);
860f3fea21SPhilippe Mathieu-Daudé
870f3fea21SPhilippe Mathieu-Daudé if (!env1) {
880f3fea21SPhilippe Mathieu-Daudé monitor_printf(mon, "No CPU available\n");
890f3fea21SPhilippe Mathieu-Daudé return;
900f3fea21SPhilippe Mathieu-Daudé }
910f3fea21SPhilippe Mathieu-Daudé dump_mmu(env1);
920f3fea21SPhilippe Mathieu-Daudé }
930f3fea21SPhilippe Mathieu-Daudé
940f3fea21SPhilippe Mathieu-Daudé const MonitorDef monitor_defs[] = {
950f3fea21SPhilippe Mathieu-Daudé { "fpscr", offsetof(CPUPPCState, fpscr) },
960f3fea21SPhilippe Mathieu-Daudé /* Next instruction pointer */
970f3fea21SPhilippe Mathieu-Daudé { "nip|pc", offsetof(CPUPPCState, nip) },
980f3fea21SPhilippe Mathieu-Daudé { "lr", offsetof(CPUPPCState, lr) },
990f3fea21SPhilippe Mathieu-Daudé { "ctr", offsetof(CPUPPCState, ctr) },
1000f3fea21SPhilippe Mathieu-Daudé { "decr", 0, &monitor_get_decr, },
1010f3fea21SPhilippe Mathieu-Daudé { "ccr|cr", 0, &monitor_get_ccr, },
1020f3fea21SPhilippe Mathieu-Daudé /* Machine state register */
1030f3fea21SPhilippe Mathieu-Daudé { "xer", 0, &monitor_get_xer },
1040f3fea21SPhilippe Mathieu-Daudé { "msr", offsetof(CPUPPCState, msr) },
1050f3fea21SPhilippe Mathieu-Daudé { "tbu", 0, &monitor_get_tbu, },
10619e81ce5SNicholas Piggin #if defined(TARGET_PPC64)
10719e81ce5SNicholas Piggin { "tb", 0, &monitor_get_tbl, },
10819e81ce5SNicholas Piggin #else
1090f3fea21SPhilippe Mathieu-Daudé { "tbl", 0, &monitor_get_tbl, },
11019e81ce5SNicholas Piggin #endif
1110f3fea21SPhilippe Mathieu-Daudé { NULL },
1120f3fea21SPhilippe Mathieu-Daudé };
1130f3fea21SPhilippe Mathieu-Daudé
target_monitor_defs(void)1140f3fea21SPhilippe Mathieu-Daudé const MonitorDef *target_monitor_defs(void)
1150f3fea21SPhilippe Mathieu-Daudé {
1160f3fea21SPhilippe Mathieu-Daudé return monitor_defs;
1170f3fea21SPhilippe Mathieu-Daudé }
1180f3fea21SPhilippe Mathieu-Daudé
ppc_cpu_get_reg_num(const char * numstr,int maxnum,int * pregnum)1190f3fea21SPhilippe Mathieu-Daudé static int ppc_cpu_get_reg_num(const char *numstr, int maxnum, int *pregnum)
1200f3fea21SPhilippe Mathieu-Daudé {
1210f3fea21SPhilippe Mathieu-Daudé int regnum;
1220f3fea21SPhilippe Mathieu-Daudé char *endptr = NULL;
1230f3fea21SPhilippe Mathieu-Daudé
1240f3fea21SPhilippe Mathieu-Daudé if (!*numstr) {
1250f3fea21SPhilippe Mathieu-Daudé return false;
1260f3fea21SPhilippe Mathieu-Daudé }
1270f3fea21SPhilippe Mathieu-Daudé
1280f3fea21SPhilippe Mathieu-Daudé regnum = strtoul(numstr, &endptr, 10);
1290f3fea21SPhilippe Mathieu-Daudé if (*endptr || (regnum >= maxnum)) {
1300f3fea21SPhilippe Mathieu-Daudé return false;
1310f3fea21SPhilippe Mathieu-Daudé }
1320f3fea21SPhilippe Mathieu-Daudé *pregnum = regnum;
1330f3fea21SPhilippe Mathieu-Daudé
1340f3fea21SPhilippe Mathieu-Daudé return true;
1350f3fea21SPhilippe Mathieu-Daudé }
1360f3fea21SPhilippe Mathieu-Daudé
target_get_monitor_def(CPUState * cs,const char * name,uint64_t * pval)1370f3fea21SPhilippe Mathieu-Daudé int target_get_monitor_def(CPUState *cs, const char *name, uint64_t *pval)
1380f3fea21SPhilippe Mathieu-Daudé {
1390f3fea21SPhilippe Mathieu-Daudé int i, regnum;
140794511bcSPhilippe Mathieu-Daudé CPUPPCState *env = cpu_env(cs);
1410f3fea21SPhilippe Mathieu-Daudé
1420f3fea21SPhilippe Mathieu-Daudé /* General purpose registers */
1430f3fea21SPhilippe Mathieu-Daudé if ((qemu_tolower(name[0]) == 'r') &&
1440f3fea21SPhilippe Mathieu-Daudé ppc_cpu_get_reg_num(name + 1, ARRAY_SIZE(env->gpr), ®num)) {
1450f3fea21SPhilippe Mathieu-Daudé *pval = env->gpr[regnum];
1460f3fea21SPhilippe Mathieu-Daudé return 0;
1470f3fea21SPhilippe Mathieu-Daudé }
1480f3fea21SPhilippe Mathieu-Daudé
1490f3fea21SPhilippe Mathieu-Daudé /* Floating point registers */
1500f3fea21SPhilippe Mathieu-Daudé if ((qemu_tolower(name[0]) == 'f') &&
1510f3fea21SPhilippe Mathieu-Daudé ppc_cpu_get_reg_num(name + 1, 32, ®num)) {
1520f3fea21SPhilippe Mathieu-Daudé *pval = *cpu_fpr_ptr(env, regnum);
1530f3fea21SPhilippe Mathieu-Daudé return 0;
1540f3fea21SPhilippe Mathieu-Daudé }
1550f3fea21SPhilippe Mathieu-Daudé
1560f3fea21SPhilippe Mathieu-Daudé /* Special purpose registers */
1570f3fea21SPhilippe Mathieu-Daudé for (i = 0; i < ARRAY_SIZE(env->spr_cb); ++i) {
1580f3fea21SPhilippe Mathieu-Daudé ppc_spr_t *spr = &env->spr_cb[i];
1590f3fea21SPhilippe Mathieu-Daudé
1600f3fea21SPhilippe Mathieu-Daudé if (spr->name && (strcasecmp(name, spr->name) == 0)) {
1610f3fea21SPhilippe Mathieu-Daudé *pval = env->spr[i];
1620f3fea21SPhilippe Mathieu-Daudé return 0;
1630f3fea21SPhilippe Mathieu-Daudé }
1640f3fea21SPhilippe Mathieu-Daudé }
1650f3fea21SPhilippe Mathieu-Daudé
1660f3fea21SPhilippe Mathieu-Daudé /* Segment registers */
1670f3fea21SPhilippe Mathieu-Daudé #if !defined(CONFIG_USER_ONLY)
1680f3fea21SPhilippe Mathieu-Daudé if ((strncasecmp(name, "sr", 2) == 0) &&
1690f3fea21SPhilippe Mathieu-Daudé ppc_cpu_get_reg_num(name + 2, ARRAY_SIZE(env->sr), ®num)) {
1700f3fea21SPhilippe Mathieu-Daudé *pval = env->sr[regnum];
1710f3fea21SPhilippe Mathieu-Daudé return 0;
1720f3fea21SPhilippe Mathieu-Daudé }
1730f3fea21SPhilippe Mathieu-Daudé #endif
1740f3fea21SPhilippe Mathieu-Daudé
1750f3fea21SPhilippe Mathieu-Daudé return -EINVAL;
1760f3fea21SPhilippe Mathieu-Daudé }
1770f3fea21SPhilippe Mathieu-Daudé
ppc_cpu_defs_entry(gpointer data,gpointer user_data)1780f3fea21SPhilippe Mathieu-Daudé static void ppc_cpu_defs_entry(gpointer data, gpointer user_data)
1790f3fea21SPhilippe Mathieu-Daudé {
1800f3fea21SPhilippe Mathieu-Daudé ObjectClass *oc = data;
1810f3fea21SPhilippe Mathieu-Daudé CpuDefinitionInfoList **first = user_data;
1820f3fea21SPhilippe Mathieu-Daudé const char *typename;
1830f3fea21SPhilippe Mathieu-Daudé CpuDefinitionInfo *info;
1840f3fea21SPhilippe Mathieu-Daudé
1850f3fea21SPhilippe Mathieu-Daudé typename = object_class_get_name(oc);
1860f3fea21SPhilippe Mathieu-Daudé info = g_malloc0(sizeof(*info));
1874b26aa9fSGavin Shan info->name = cpu_model_from_type(typename);
1880f3fea21SPhilippe Mathieu-Daudé
1890f3fea21SPhilippe Mathieu-Daudé QAPI_LIST_PREPEND(*first, info);
1900f3fea21SPhilippe Mathieu-Daudé }
1910f3fea21SPhilippe Mathieu-Daudé
qmp_query_cpu_definitions(Error ** errp)1920f3fea21SPhilippe Mathieu-Daudé CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
1930f3fea21SPhilippe Mathieu-Daudé {
1940f3fea21SPhilippe Mathieu-Daudé CpuDefinitionInfoList *cpu_list = NULL;
1950f3fea21SPhilippe Mathieu-Daudé GSList *list;
1960f3fea21SPhilippe Mathieu-Daudé int i;
1970f3fea21SPhilippe Mathieu-Daudé
1980f3fea21SPhilippe Mathieu-Daudé list = object_class_get_list(TYPE_POWERPC_CPU, false);
1990f3fea21SPhilippe Mathieu-Daudé g_slist_foreach(list, ppc_cpu_defs_entry, &cpu_list);
2000f3fea21SPhilippe Mathieu-Daudé g_slist_free(list);
2010f3fea21SPhilippe Mathieu-Daudé
2020f3fea21SPhilippe Mathieu-Daudé for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
2030f3fea21SPhilippe Mathieu-Daudé PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];
2040f3fea21SPhilippe Mathieu-Daudé ObjectClass *oc;
2050f3fea21SPhilippe Mathieu-Daudé CpuDefinitionInfo *info;
2060f3fea21SPhilippe Mathieu-Daudé
2070f3fea21SPhilippe Mathieu-Daudé oc = ppc_cpu_class_by_name(alias->model);
2080f3fea21SPhilippe Mathieu-Daudé if (oc == NULL) {
2090f3fea21SPhilippe Mathieu-Daudé continue;
2100f3fea21SPhilippe Mathieu-Daudé }
2110f3fea21SPhilippe Mathieu-Daudé
2120f3fea21SPhilippe Mathieu-Daudé info = g_malloc0(sizeof(*info));
2130f3fea21SPhilippe Mathieu-Daudé info->name = g_strdup(alias->alias);
2140f3fea21SPhilippe Mathieu-Daudé info->q_typename = g_strdup(object_class_get_name(oc));
2150f3fea21SPhilippe Mathieu-Daudé
2160f3fea21SPhilippe Mathieu-Daudé QAPI_LIST_PREPEND(cpu_list, info);
2170f3fea21SPhilippe Mathieu-Daudé }
2180f3fea21SPhilippe Mathieu-Daudé
2190f3fea21SPhilippe Mathieu-Daudé return cpu_list;
2200f3fea21SPhilippe Mathieu-Daudé }
221