]>
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 | ||
20 | #include "cpu.h" | |
21 | #include "qemu-common.h" | |
22 | #include "migration/vmstate.h" | |
23 | #include "machine.h" | |
24 | ||
25 | static 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 | ||
525bd324 AG |
31 | mcc->parent_reset(s); |
32 | ||
33 | memset(env, 0, offsetof(CPUMoxieState, breakpoints)); | |
34 | env->pc = 0x1000; | |
35 | ||
36 | tlb_flush(env, 1); | |
37 | } | |
38 | ||
39 | static void moxie_cpu_realizefn(DeviceState *dev, Error **errp) | |
40 | { | |
41 | MoxieCPU *cpu = MOXIE_CPU(dev); | |
c643bed9 | 42 | MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev); |
525bd324 | 43 | |
525bd324 AG |
44 | cpu_reset(CPU(cpu)); |
45 | ||
c643bed9 | 46 | mcc->parent_realize(dev, errp); |
525bd324 AG |
47 | } |
48 | ||
49 | static void moxie_cpu_initfn(Object *obj) | |
50 | { | |
51 | CPUState *cs = CPU(obj); | |
52 | MoxieCPU *cpu = MOXIE_CPU(obj); | |
53 | static int inited; | |
54 | ||
55 | cs->env_ptr = &cpu->env; | |
56 | cpu_exec_init(&cpu->env); | |
57 | ||
58 | if (tcg_enabled() && !inited) { | |
59 | inited = 1; | |
60 | moxie_translate_init(); | |
61 | } | |
62 | } | |
63 | ||
64 | static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model) | |
65 | { | |
66 | ObjectClass *oc; | |
67 | ||
68 | if (cpu_model == NULL) { | |
69 | return NULL; | |
70 | } | |
71 | ||
72 | oc = object_class_by_name(cpu_model); | |
73 | if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) || | |
74 | object_class_is_abstract(oc))) { | |
75 | return NULL; | |
76 | } | |
77 | return oc; | |
78 | } | |
79 | ||
80 | static void moxie_cpu_class_init(ObjectClass *oc, void *data) | |
81 | { | |
82 | DeviceClass *dc = DEVICE_CLASS(oc); | |
83 | CPUClass *cc = CPU_CLASS(oc); | |
84 | MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc); | |
85 | ||
86 | mcc->parent_realize = dc->realize; | |
87 | dc->realize = moxie_cpu_realizefn; | |
88 | ||
89 | mcc->parent_reset = cc->reset; | |
90 | cc->reset = moxie_cpu_reset; | |
91 | ||
92 | cc->class_by_name = moxie_cpu_class_by_name; | |
93 | ||
53574064 | 94 | cc->do_interrupt = moxie_cpu_do_interrupt; |
878096ee AF |
95 | cc->dump_state = moxie_cpu_dump_state; |
96 | cpu_class_set_vmsd(cc, &vmstate_moxie_cpu); | |
525bd324 AG |
97 | } |
98 | ||
99 | static void moxielite_initfn(Object *obj) | |
100 | { | |
101 | /* Set cpu feature flags */ | |
102 | } | |
103 | ||
104 | static void moxie_any_initfn(Object *obj) | |
105 | { | |
106 | /* Set cpu feature flags */ | |
107 | } | |
108 | ||
109 | typedef struct MoxieCPUInfo { | |
110 | const char *name; | |
111 | void (*initfn)(Object *obj); | |
112 | } MoxieCPUInfo; | |
113 | ||
114 | static const MoxieCPUInfo moxie_cpus[] = { | |
115 | { .name = "MoxieLite", .initfn = moxielite_initfn }, | |
116 | { .name = "any", .initfn = moxie_any_initfn }, | |
117 | }; | |
118 | ||
119 | MoxieCPU *cpu_moxie_init(const char *cpu_model) | |
120 | { | |
121 | MoxieCPU *cpu; | |
122 | ObjectClass *oc; | |
123 | ||
124 | oc = moxie_cpu_class_by_name(cpu_model); | |
125 | if (oc == NULL) { | |
126 | return NULL; | |
127 | } | |
128 | cpu = MOXIE_CPU(object_new(object_class_get_name(oc))); | |
129 | cpu->env.cpu_model_str = cpu_model; | |
130 | ||
131 | object_property_set_bool(OBJECT(cpu), true, "realized", NULL); | |
132 | ||
133 | return cpu; | |
134 | } | |
135 | ||
136 | static void cpu_register(const MoxieCPUInfo *info) | |
137 | { | |
138 | TypeInfo type_info = { | |
139 | .parent = TYPE_MOXIE_CPU, | |
140 | .instance_size = sizeof(MoxieCPU), | |
141 | .instance_init = info->initfn, | |
142 | .class_size = sizeof(MoxieCPUClass), | |
143 | }; | |
144 | ||
145 | type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name); | |
146 | type_register(&type_info); | |
147 | g_free((void *)type_info.name); | |
148 | } | |
149 | ||
150 | static const TypeInfo moxie_cpu_type_info = { | |
151 | .name = TYPE_MOXIE_CPU, | |
152 | .parent = TYPE_CPU, | |
153 | .instance_size = sizeof(MoxieCPU), | |
154 | .instance_init = moxie_cpu_initfn, | |
155 | .class_size = sizeof(MoxieCPUClass), | |
156 | .class_init = moxie_cpu_class_init, | |
157 | }; | |
158 | ||
159 | static void moxie_cpu_register_types(void) | |
160 | { | |
161 | int i; | |
162 | type_register_static(&moxie_cpu_type_info); | |
163 | for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) { | |
164 | cpu_register(&moxie_cpus[i]); | |
165 | } | |
166 | } | |
167 | ||
168 | type_init(moxie_cpu_register_types) |