]> Git Repo - qemu.git/blob - target-moxie/cpu.c
nbd: allow setting of an export name for qemu-nbd server
[qemu.git] / target-moxie / cpu.c
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 "qemu/osdep.h"
21 #include "cpu.h"
22 #include "qemu-common.h"
23 #include "migration/vmstate.h"
24 #include "machine.h"
25
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
33 static bool moxie_cpu_has_work(CPUState *cs)
34 {
35     return cs->interrupt_request & CPU_INTERRUPT_HARD;
36 }
37
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
44     mcc->parent_reset(s);
45
46     memset(env, 0, sizeof(CPUMoxieState));
47     env->pc = 0x1000;
48
49     tlb_flush(s, 1);
50 }
51
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
58 static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
59 {
60     CPUState *cs = CPU(dev);
61     MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev);
62
63     qemu_init_vcpu(cs);
64     cpu_reset(cs);
65
66     mcc->parent_realize(dev, errp);
67 }
68
69 static void moxie_cpu_initfn(Object *obj)
70 {
71     CPUState *cs = CPU(obj);
72     MoxieCPU *cpu = MOXIE_CPU(obj);
73     static int inited;
74
75     cs->env_ptr = &cpu->env;
76     cpu_exec_init(cs, &error_abort);
77
78     if (tcg_enabled() && !inited) {
79         inited = 1;
80         moxie_translate_init();
81     }
82 }
83
84 static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
85 {
86     ObjectClass *oc;
87
88     if (cpu_model == NULL) {
89         return NULL;
90     }
91
92     oc = object_class_by_name(cpu_model);
93     if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
94                        object_class_is_abstract(oc))) {
95         return NULL;
96     }
97     return oc;
98 }
99
100 static void moxie_cpu_class_init(ObjectClass *oc, void *data)
101 {
102     DeviceClass *dc = DEVICE_CLASS(oc);
103     CPUClass *cc = CPU_CLASS(oc);
104     MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc);
105
106     mcc->parent_realize = dc->realize;
107     dc->realize = moxie_cpu_realizefn;
108
109     mcc->parent_reset = cc->reset;
110     cc->reset = moxie_cpu_reset;
111
112     cc->class_by_name = moxie_cpu_class_by_name;
113
114     cc->has_work = moxie_cpu_has_work;
115     cc->do_interrupt = moxie_cpu_do_interrupt;
116     cc->dump_state = moxie_cpu_dump_state;
117     cc->set_pc = moxie_cpu_set_pc;
118 #ifdef CONFIG_USER_ONLY
119     cc->handle_mmu_fault = moxie_cpu_handle_mmu_fault;
120 #else
121     cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug;
122     cc->vmsd = &vmstate_moxie_cpu;
123 #endif
124     cc->disas_set_info = moxie_cpu_disas_set_info;
125
126     /*
127      * Reason: moxie_cpu_initfn() calls cpu_exec_init(), which saves
128      * the object in cpus -> dangling pointer after final
129      * object_unref().
130      */
131     dc->cannot_destroy_with_object_finalize_yet = true;
132 }
133
134 static void moxielite_initfn(Object *obj)
135 {
136     /* Set cpu feature flags */
137 }
138
139 static void moxie_any_initfn(Object *obj)
140 {
141     /* Set cpu feature flags */
142 }
143
144 typedef struct MoxieCPUInfo {
145     const char *name;
146     void (*initfn)(Object *obj);
147 } MoxieCPUInfo;
148
149 static const MoxieCPUInfo moxie_cpus[] = {
150     { .name = "MoxieLite",      .initfn = moxielite_initfn },
151     { .name = "any",            .initfn = moxie_any_initfn },
152 };
153
154 MoxieCPU *cpu_moxie_init(const char *cpu_model)
155 {
156     return MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
157 }
158
159 static void cpu_register(const MoxieCPUInfo *info)
160 {
161     TypeInfo type_info = {
162         .parent = TYPE_MOXIE_CPU,
163         .instance_size = sizeof(MoxieCPU),
164         .instance_init = info->initfn,
165         .class_size = sizeof(MoxieCPUClass),
166     };
167
168     type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name);
169     type_register(&type_info);
170     g_free((void *)type_info.name);
171 }
172
173 static const TypeInfo moxie_cpu_type_info = {
174     .name = TYPE_MOXIE_CPU,
175     .parent = TYPE_CPU,
176     .instance_size = sizeof(MoxieCPU),
177     .instance_init = moxie_cpu_initfn,
178     .class_size = sizeof(MoxieCPUClass),
179     .class_init = moxie_cpu_class_init,
180 };
181
182 static void moxie_cpu_register_types(void)
183 {
184     int i;
185     type_register_static(&moxie_cpu_type_info);
186     for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) {
187         cpu_register(&moxie_cpus[i]);
188     }
189 }
190
191 type_init(moxie_cpu_register_types)
This page took 0.033931 seconds and 4 git commands to generate.