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