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