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