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
);
43 for (i
= 0; i
< 8; i
++) {
44 u
|= env
->crf
[i
] << (32 - (4 * (i
+ 1)));
50 static target_long
monitor_get_xer(Monitor
*mon
, const struct MonitorDef
*md
,
53 CPUArchState
*env
= mon_get_cpu_env(mon
);
54 return cpu_read_xer(env
);
57 static target_long
monitor_get_decr(Monitor
*mon
, const struct MonitorDef
*md
,
60 CPUArchState
*env
= mon_get_cpu_env(mon
);
64 return cpu_ppc_load_decr(env
);
67 static target_long
monitor_get_tbu(Monitor
*mon
, const struct MonitorDef
*md
,
70 CPUArchState
*env
= mon_get_cpu_env(mon
);
74 return cpu_ppc_load_tbu(env
);
77 static target_long
monitor_get_tbl(Monitor
*mon
, const struct MonitorDef
*md
,
80 CPUArchState
*env
= mon_get_cpu_env(mon
);
84 return cpu_ppc_load_tbl(env
);
87 void hmp_info_tlb(Monitor
*mon
, const QDict
*qdict
)
89 CPUArchState
*env1
= mon_get_cpu_env(mon
);
92 monitor_printf(mon
, "No CPU available\n");
98 const MonitorDef monitor_defs
[] = {
99 { "fpscr", offsetof(CPUPPCState
, fpscr
) },
100 /* Next instruction pointer */
101 { "nip|pc", offsetof(CPUPPCState
, nip
) },
102 { "lr", offsetof(CPUPPCState
, lr
) },
103 { "ctr", offsetof(CPUPPCState
, ctr
) },
104 { "decr", 0, &monitor_get_decr
, },
105 { "ccr|cr", 0, &monitor_get_ccr
, },
106 /* Machine state register */
107 { "xer", 0, &monitor_get_xer
},
108 { "msr", offsetof(CPUPPCState
, msr
) },
109 { "tbu", 0, &monitor_get_tbu
, },
110 { "tbl", 0, &monitor_get_tbl
, },
114 const MonitorDef
*target_monitor_defs(void)
119 static int ppc_cpu_get_reg_num(const char *numstr
, int maxnum
, int *pregnum
)
128 regnum
= strtoul(numstr
, &endptr
, 10);
129 if (*endptr
|| (regnum
>= maxnum
)) {
137 int target_get_monitor_def(CPUState
*cs
, const char *name
, uint64_t *pval
)
140 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
141 CPUPPCState
*env
= &cpu
->env
;
143 /* General purpose registers */
144 if ((qemu_tolower(name
[0]) == 'r') &&
145 ppc_cpu_get_reg_num(name
+ 1, ARRAY_SIZE(env
->gpr
), ®num
)) {
146 *pval
= env
->gpr
[regnum
];
150 /* Floating point registers */
151 if ((qemu_tolower(name
[0]) == 'f') &&
152 ppc_cpu_get_reg_num(name
+ 1, 32, ®num
)) {
153 *pval
= *cpu_fpr_ptr(env
, regnum
);
157 /* Special purpose registers */
158 for (i
= 0; i
< ARRAY_SIZE(env
->spr_cb
); ++i
) {
159 ppc_spr_t
*spr
= &env
->spr_cb
[i
];
161 if (spr
->name
&& (strcasecmp(name
, spr
->name
) == 0)) {
167 /* Segment registers */
168 #if !defined(CONFIG_USER_ONLY)
169 if ((strncasecmp(name
, "sr", 2) == 0) &&
170 ppc_cpu_get_reg_num(name
+ 2, ARRAY_SIZE(env
->sr
), ®num
)) {
171 *pval
= env
->sr
[regnum
];
179 static void ppc_cpu_defs_entry(gpointer data
, gpointer user_data
)
181 ObjectClass
*oc
= data
;
182 CpuDefinitionInfoList
**first
= user_data
;
183 const char *typename
;
184 CpuDefinitionInfo
*info
;
186 typename
= object_class_get_name(oc
);
187 info
= g_malloc0(sizeof(*info
));
188 info
->name
= g_strndup(typename
,
189 strlen(typename
) - strlen(POWERPC_CPU_TYPE_SUFFIX
));
191 QAPI_LIST_PREPEND(*first
, info
);
194 CpuDefinitionInfoList
*qmp_query_cpu_definitions(Error
**errp
)
196 CpuDefinitionInfoList
*cpu_list
= NULL
;
200 list
= object_class_get_list(TYPE_POWERPC_CPU
, false);
201 g_slist_foreach(list
, ppc_cpu_defs_entry
, &cpu_list
);
204 for (i
= 0; ppc_cpu_aliases
[i
].alias
!= NULL
; i
++) {
205 PowerPCCPUAlias
*alias
= &ppc_cpu_aliases
[i
];
207 CpuDefinitionInfo
*info
;
209 oc
= ppc_cpu_class_by_name(alias
->model
);
214 info
= g_malloc0(sizeof(*info
));
215 info
->name
= g_strdup(alias
->alias
);
216 info
->q_typename
= g_strdup(object_class_get_name(oc
));
218 QAPI_LIST_PREPEND(cpu_list
, info
);