]> git.proxmox.com Git - mirror_qemu.git/blame - target-moxie/cpu.c
cpu: move exec-all.h inclusion out of cpu.h
[mirror_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
d24688fb 20#include "qemu/osdep.h"
da34e65c 21#include "qapi/error.h"
525bd324
AG
22#include "cpu.h"
23#include "qemu-common.h"
24#include "migration/vmstate.h"
25#include "machine.h"
63c91552 26#include "exec/exec-all.h"
525bd324 27
a10b978c
AF
28static void moxie_cpu_set_pc(CPUState *cs, vaddr value)
29{
30 MoxieCPU *cpu = MOXIE_CPU(cs);
31
32 cpu->env.pc = value;
33}
34
8c2e1b00
AF
35static bool moxie_cpu_has_work(CPUState *cs)
36{
37 return cs->interrupt_request & CPU_INTERRUPT_HARD;
38}
39
525bd324
AG
40static void moxie_cpu_reset(CPUState *s)
41{
42 MoxieCPU *cpu = MOXIE_CPU(s);
43 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu);
44 CPUMoxieState *env = &cpu->env;
45
525bd324
AG
46 mcc->parent_reset(s);
47
f0c3c505 48 memset(env, 0, sizeof(CPUMoxieState));
525bd324
AG
49 env->pc = 0x1000;
50
00c8cb0a 51 tlb_flush(s, 1);
525bd324
AG
52}
53
9f87a4ca
PC
54static void moxie_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
55{
56 info->mach = bfd_arch_moxie;
57 info->print_insn = print_insn_moxie;
58}
59
525bd324
AG
60static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
61{
14a10fc3 62 CPUState *cs = CPU(dev);
c643bed9 63 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev);
525bd324 64
14a10fc3
AF
65 qemu_init_vcpu(cs);
66 cpu_reset(cs);
525bd324 67
c643bed9 68 mcc->parent_realize(dev, errp);
525bd324
AG
69}
70
71static void moxie_cpu_initfn(Object *obj)
72{
73 CPUState *cs = CPU(obj);
74 MoxieCPU *cpu = MOXIE_CPU(obj);
75 static int inited;
76
77 cs->env_ptr = &cpu->env;
4bad9e39 78 cpu_exec_init(cs, &error_abort);
525bd324
AG
79
80 if (tcg_enabled() && !inited) {
81 inited = 1;
82 moxie_translate_init();
83 }
84}
85
86static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
87{
88 ObjectClass *oc;
89
90 if (cpu_model == NULL) {
91 return NULL;
92 }
93
94 oc = object_class_by_name(cpu_model);
95 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
96 object_class_is_abstract(oc))) {
97 return NULL;
98 }
99 return oc;
100}
101
102static void moxie_cpu_class_init(ObjectClass *oc, void *data)
103{
104 DeviceClass *dc = DEVICE_CLASS(oc);
105 CPUClass *cc = CPU_CLASS(oc);
106 MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc);
107
108 mcc->parent_realize = dc->realize;
109 dc->realize = moxie_cpu_realizefn;
110
111 mcc->parent_reset = cc->reset;
112 cc->reset = moxie_cpu_reset;
113
114 cc->class_by_name = moxie_cpu_class_by_name;
115
8c2e1b00 116 cc->has_work = moxie_cpu_has_work;
53574064 117 cc->do_interrupt = moxie_cpu_do_interrupt;
878096ee 118 cc->dump_state = moxie_cpu_dump_state;
a10b978c 119 cc->set_pc = moxie_cpu_set_pc;
7510454e
AF
120#ifdef CONFIG_USER_ONLY
121 cc->handle_mmu_fault = moxie_cpu_handle_mmu_fault;
122#else
00b941e5
AF
123 cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug;
124 cc->vmsd = &vmstate_moxie_cpu;
125#endif
9f87a4ca 126 cc->disas_set_info = moxie_cpu_disas_set_info;
4c315c27
MA
127
128 /*
129 * Reason: moxie_cpu_initfn() calls cpu_exec_init(), which saves
130 * the object in cpus -> dangling pointer after final
131 * object_unref().
132 */
133 dc->cannot_destroy_with_object_finalize_yet = true;
525bd324
AG
134}
135
136static void moxielite_initfn(Object *obj)
137{
138 /* Set cpu feature flags */
139}
140
141static void moxie_any_initfn(Object *obj)
142{
143 /* Set cpu feature flags */
144}
145
146typedef struct MoxieCPUInfo {
147 const char *name;
148 void (*initfn)(Object *obj);
149} MoxieCPUInfo;
150
151static const MoxieCPUInfo moxie_cpus[] = {
152 { .name = "MoxieLite", .initfn = moxielite_initfn },
153 { .name = "any", .initfn = moxie_any_initfn },
154};
155
156MoxieCPU *cpu_moxie_init(const char *cpu_model)
157{
9262685b 158 return MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
525bd324
AG
159}
160
161static void cpu_register(const MoxieCPUInfo *info)
162{
163 TypeInfo type_info = {
164 .parent = TYPE_MOXIE_CPU,
165 .instance_size = sizeof(MoxieCPU),
166 .instance_init = info->initfn,
167 .class_size = sizeof(MoxieCPUClass),
168 };
169
170 type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name);
171 type_register(&type_info);
172 g_free((void *)type_info.name);
173}
174
175static const TypeInfo moxie_cpu_type_info = {
176 .name = TYPE_MOXIE_CPU,
177 .parent = TYPE_CPU,
178 .instance_size = sizeof(MoxieCPU),
179 .instance_init = moxie_cpu_initfn,
180 .class_size = sizeof(MoxieCPUClass),
181 .class_init = moxie_cpu_class_init,
182};
183
184static void moxie_cpu_register_types(void)
185{
186 int i;
187 type_register_static(&moxie_cpu_type_info);
188 for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) {
189 cpu_register(&moxie_cpus[i]);
190 }
191}
192
193type_init(moxie_cpu_register_types)