hw/intc/slavio_intctl: Avoid shifting left into sign bit
[qemu.git] / target-moxie / cpu.c
blob47b617f5cd2aa733d287b5466af81758ae078e82
1 /*
2 * QEMU Moxie CPU
4 * Copyright (c) 2013 Anthony Green
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.
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.
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/>.
20 #include "cpu.h"
21 #include "qemu-common.h"
22 #include "migration/vmstate.h"
23 #include "machine.h"
25 static void moxie_cpu_set_pc(CPUState *cs, vaddr value)
27 MoxieCPU *cpu = MOXIE_CPU(cs);
29 cpu->env.pc = value;
32 static bool moxie_cpu_has_work(CPUState *cs)
34 return cs->interrupt_request & CPU_INTERRUPT_HARD;
37 static void moxie_cpu_reset(CPUState *s)
39 MoxieCPU *cpu = MOXIE_CPU(s);
40 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu);
41 CPUMoxieState *env = &cpu->env;
43 mcc->parent_reset(s);
45 memset(env, 0, sizeof(CPUMoxieState));
46 env->pc = 0x1000;
48 tlb_flush(s, 1);
51 static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
53 CPUState *cs = CPU(dev);
54 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev);
56 qemu_init_vcpu(cs);
57 cpu_reset(cs);
59 mcc->parent_realize(dev, errp);
62 static void moxie_cpu_initfn(Object *obj)
64 CPUState *cs = CPU(obj);
65 MoxieCPU *cpu = MOXIE_CPU(obj);
66 static int inited;
68 cs->env_ptr = &cpu->env;
69 cpu_exec_init(&cpu->env);
71 if (tcg_enabled() && !inited) {
72 inited = 1;
73 moxie_translate_init();
77 static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
79 ObjectClass *oc;
81 if (cpu_model == NULL) {
82 return NULL;
85 oc = object_class_by_name(cpu_model);
86 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
87 object_class_is_abstract(oc))) {
88 return NULL;
90 return oc;
93 static void moxie_cpu_class_init(ObjectClass *oc, void *data)
95 DeviceClass *dc = DEVICE_CLASS(oc);
96 CPUClass *cc = CPU_CLASS(oc);
97 MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc);
99 mcc->parent_realize = dc->realize;
100 dc->realize = moxie_cpu_realizefn;
102 mcc->parent_reset = cc->reset;
103 cc->reset = moxie_cpu_reset;
105 cc->class_by_name = moxie_cpu_class_by_name;
107 cc->has_work = moxie_cpu_has_work;
108 cc->do_interrupt = moxie_cpu_do_interrupt;
109 cc->dump_state = moxie_cpu_dump_state;
110 cc->set_pc = moxie_cpu_set_pc;
111 #ifdef CONFIG_USER_ONLY
112 cc->handle_mmu_fault = moxie_cpu_handle_mmu_fault;
113 #else
114 cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug;
115 cc->vmsd = &vmstate_moxie_cpu;
116 #endif
119 static void moxielite_initfn(Object *obj)
121 /* Set cpu feature flags */
124 static void moxie_any_initfn(Object *obj)
126 /* Set cpu feature flags */
129 typedef struct MoxieCPUInfo {
130 const char *name;
131 void (*initfn)(Object *obj);
132 } MoxieCPUInfo;
134 static const MoxieCPUInfo moxie_cpus[] = {
135 { .name = "MoxieLite", .initfn = moxielite_initfn },
136 { .name = "any", .initfn = moxie_any_initfn },
139 MoxieCPU *cpu_moxie_init(const char *cpu_model)
141 return MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
144 static void cpu_register(const MoxieCPUInfo *info)
146 TypeInfo type_info = {
147 .parent = TYPE_MOXIE_CPU,
148 .instance_size = sizeof(MoxieCPU),
149 .instance_init = info->initfn,
150 .class_size = sizeof(MoxieCPUClass),
153 type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name);
154 type_register(&type_info);
155 g_free((void *)type_info.name);
158 static const TypeInfo moxie_cpu_type_info = {
159 .name = TYPE_MOXIE_CPU,
160 .parent = TYPE_CPU,
161 .instance_size = sizeof(MoxieCPU),
162 .instance_init = moxie_cpu_initfn,
163 .class_size = sizeof(MoxieCPUClass),
164 .class_init = moxie_cpu_class_init,
167 static void moxie_cpu_register_types(void)
169 int i;
170 type_register_static(&moxie_cpu_type_info);
171 for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) {
172 cpu_register(&moxie_cpus[i]);
176 type_init(moxie_cpu_register_types)