]> git.proxmox.com Git - qemu.git/blame - target-moxie/cpu.c
cpu: Turn cpu_dump_{state,statistics}() into CPUState hooks
[qemu.git] / target-moxie / cpu.c
CommitLineData
525bd324
AG
1/*
2 * QEMU Moxie CPU
3 *
4 * Copyright (c) 2013 Anthony Green
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "cpu.h"
21#include "qemu-common.h"
22#include "migration/vmstate.h"
23#include "machine.h"
24
25static void moxie_cpu_reset(CPUState *s)
26{
27 MoxieCPU *cpu = MOXIE_CPU(s);
28 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu);
29 CPUMoxieState *env = &cpu->env;
30
31 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
32 qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
33 log_cpu_state(env, 0);
34 }
35
36 mcc->parent_reset(s);
37
38 memset(env, 0, offsetof(CPUMoxieState, breakpoints));
39 env->pc = 0x1000;
40
41 tlb_flush(env, 1);
42}
43
44static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
45{
46 MoxieCPU *cpu = MOXIE_CPU(dev);
47 MoxieCPUClass *occ = MOXIE_CPU_GET_CLASS(dev);
48
49 qemu_init_vcpu(&cpu->env);
50 cpu_reset(CPU(cpu));
51
52 occ->parent_realize(dev, errp);
53}
54
55static void moxie_cpu_initfn(Object *obj)
56{
57 CPUState *cs = CPU(obj);
58 MoxieCPU *cpu = MOXIE_CPU(obj);
59 static int inited;
60
61 cs->env_ptr = &cpu->env;
62 cpu_exec_init(&cpu->env);
63
64 if (tcg_enabled() && !inited) {
65 inited = 1;
66 moxie_translate_init();
67 }
68}
69
70static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
71{
72 ObjectClass *oc;
73
74 if (cpu_model == NULL) {
75 return NULL;
76 }
77
78 oc = object_class_by_name(cpu_model);
79 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
80 object_class_is_abstract(oc))) {
81 return NULL;
82 }
83 return oc;
84}
85
86static void moxie_cpu_class_init(ObjectClass *oc, void *data)
87{
88 DeviceClass *dc = DEVICE_CLASS(oc);
89 CPUClass *cc = CPU_CLASS(oc);
90 MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc);
91
92 mcc->parent_realize = dc->realize;
93 dc->realize = moxie_cpu_realizefn;
94
95 mcc->parent_reset = cc->reset;
96 cc->reset = moxie_cpu_reset;
97
98 cc->class_by_name = moxie_cpu_class_by_name;
99
53574064 100 cc->do_interrupt = moxie_cpu_do_interrupt;
878096ee
AF
101 cc->dump_state = moxie_cpu_dump_state;
102 cpu_class_set_vmsd(cc, &vmstate_moxie_cpu);
525bd324
AG
103}
104
105static void moxielite_initfn(Object *obj)
106{
107 /* Set cpu feature flags */
108}
109
110static void moxie_any_initfn(Object *obj)
111{
112 /* Set cpu feature flags */
113}
114
115typedef struct MoxieCPUInfo {
116 const char *name;
117 void (*initfn)(Object *obj);
118} MoxieCPUInfo;
119
120static const MoxieCPUInfo moxie_cpus[] = {
121 { .name = "MoxieLite", .initfn = moxielite_initfn },
122 { .name = "any", .initfn = moxie_any_initfn },
123};
124
125MoxieCPU *cpu_moxie_init(const char *cpu_model)
126{
127 MoxieCPU *cpu;
128 ObjectClass *oc;
129
130 oc = moxie_cpu_class_by_name(cpu_model);
131 if (oc == NULL) {
132 return NULL;
133 }
134 cpu = MOXIE_CPU(object_new(object_class_get_name(oc)));
135 cpu->env.cpu_model_str = cpu_model;
136
137 object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
138
139 return cpu;
140}
141
142static void cpu_register(const MoxieCPUInfo *info)
143{
144 TypeInfo type_info = {
145 .parent = TYPE_MOXIE_CPU,
146 .instance_size = sizeof(MoxieCPU),
147 .instance_init = info->initfn,
148 .class_size = sizeof(MoxieCPUClass),
149 };
150
151 type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name);
152 type_register(&type_info);
153 g_free((void *)type_info.name);
154}
155
156static const TypeInfo moxie_cpu_type_info = {
157 .name = TYPE_MOXIE_CPU,
158 .parent = TYPE_CPU,
159 .instance_size = sizeof(MoxieCPU),
160 .instance_init = moxie_cpu_initfn,
161 .class_size = sizeof(MoxieCPUClass),
162 .class_init = moxie_cpu_class_init,
163};
164
165static void moxie_cpu_register_types(void)
166{
167 int i;
168 type_register_static(&moxie_cpu_type_info);
169 for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) {
170 cpu_register(&moxie_cpus[i]);
171 }
172}
173
174type_init(moxie_cpu_register_types)