]>
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 | * | |
70c9483a | 16 | * You should have received a copy of the GNU Lesser General Public License |
525bd324 AG |
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 | ||
1f5c00cf | 47 | memset(env, 0, offsetof(CPUMoxieState, end_reset_fields)); |
525bd324 | 48 | env->pc = 0x1000; |
525bd324 AG |
49 | } |
50 | ||
9f87a4ca PC |
51 | static void moxie_cpu_disas_set_info(CPUState *cpu, disassemble_info *info) |
52 | { | |
53 | info->mach = bfd_arch_moxie; | |
54 | info->print_insn = print_insn_moxie; | |
55 | } | |
56 | ||
525bd324 AG |
57 | static void moxie_cpu_realizefn(DeviceState *dev, Error **errp) |
58 | { | |
14a10fc3 | 59 | CPUState *cs = CPU(dev); |
c643bed9 | 60 | MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev); |
ce5b1bbf LV |
61 | Error *local_err = NULL; |
62 | ||
63 | cpu_exec_realizefn(cs, &local_err); | |
64 | if (local_err != NULL) { | |
65 | error_propagate(errp, local_err); | |
66 | return; | |
67 | } | |
525bd324 | 68 | |
14a10fc3 AF |
69 | qemu_init_vcpu(cs); |
70 | cpu_reset(cs); | |
525bd324 | 71 | |
c643bed9 | 72 | mcc->parent_realize(dev, errp); |
525bd324 AG |
73 | } |
74 | ||
75 | static void moxie_cpu_initfn(Object *obj) | |
76 | { | |
525bd324 | 77 | MoxieCPU *cpu = MOXIE_CPU(obj); |
525bd324 | 78 | |
7506ed90 | 79 | cpu_set_cpustate_pointers(cpu); |
525bd324 AG |
80 | } |
81 | ||
82 | static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model) | |
83 | { | |
a7f981cc IM |
84 | ObjectClass *oc; |
85 | char *typename; | |
86 | ||
0255db23 | 87 | typename = g_strdup_printf(MOXIE_CPU_TYPE_NAME("%s"), cpu_model); |
a7f981cc IM |
88 | oc = object_class_by_name(typename); |
89 | g_free(typename); | |
525bd324 AG |
90 | if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) || |
91 | object_class_is_abstract(oc))) { | |
92 | return NULL; | |
93 | } | |
94 | return oc; | |
95 | } | |
96 | ||
97 | static void moxie_cpu_class_init(ObjectClass *oc, void *data) | |
98 | { | |
99 | DeviceClass *dc = DEVICE_CLASS(oc); | |
100 | CPUClass *cc = CPU_CLASS(oc); | |
101 | MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc); | |
102 | ||
bf853881 PMD |
103 | device_class_set_parent_realize(dc, moxie_cpu_realizefn, |
104 | &mcc->parent_realize); | |
525bd324 AG |
105 | mcc->parent_reset = cc->reset; |
106 | cc->reset = moxie_cpu_reset; | |
107 | ||
108 | cc->class_by_name = moxie_cpu_class_by_name; | |
109 | ||
8c2e1b00 | 110 | cc->has_work = moxie_cpu_has_work; |
53574064 | 111 | cc->do_interrupt = moxie_cpu_do_interrupt; |
878096ee | 112 | cc->dump_state = moxie_cpu_dump_state; |
a10b978c | 113 | cc->set_pc = moxie_cpu_set_pc; |
ccfd61fc RH |
114 | cc->tlb_fill = moxie_cpu_tlb_fill; |
115 | #ifndef CONFIG_USER_ONLY | |
00b941e5 AF |
116 | cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug; |
117 | cc->vmsd = &vmstate_moxie_cpu; | |
118 | #endif | |
9f87a4ca | 119 | cc->disas_set_info = moxie_cpu_disas_set_info; |
55c3ceef | 120 | cc->tcg_initialize = moxie_translate_init; |
525bd324 AG |
121 | } |
122 | ||
123 | static void moxielite_initfn(Object *obj) | |
124 | { | |
125 | /* Set cpu feature flags */ | |
126 | } | |
127 | ||
128 | static void moxie_any_initfn(Object *obj) | |
129 | { | |
130 | /* Set cpu feature flags */ | |
131 | } | |
132 | ||
0255db23 IM |
133 | #define DEFINE_MOXIE_CPU_TYPE(cpu_model, initfn) \ |
134 | { \ | |
135 | .parent = TYPE_MOXIE_CPU, \ | |
136 | .instance_init = initfn, \ | |
137 | .name = MOXIE_CPU_TYPE_NAME(cpu_model), \ | |
138 | } | |
525bd324 | 139 | |
0255db23 IM |
140 | static const TypeInfo moxie_cpus_type_infos[] = { |
141 | { /* base class should be registered first */ | |
142 | .name = TYPE_MOXIE_CPU, | |
143 | .parent = TYPE_CPU, | |
525bd324 | 144 | .instance_size = sizeof(MoxieCPU), |
0255db23 | 145 | .instance_init = moxie_cpu_initfn, |
525bd324 | 146 | .class_size = sizeof(MoxieCPUClass), |
0255db23 IM |
147 | .class_init = moxie_cpu_class_init, |
148 | }, | |
149 | DEFINE_MOXIE_CPU_TYPE("MoxieLite", moxielite_initfn), | |
150 | DEFINE_MOXIE_CPU_TYPE("any", moxie_any_initfn), | |
525bd324 AG |
151 | }; |
152 | ||
0255db23 | 153 | DEFINE_TYPES(moxie_cpus_type_infos) |