scsi: move host_status handling into SCSI drivers
[qemu/ar7.git] / target / moxie / cpu.c
blob83bec34d36c64253748297e2538267df6a5b6bcd
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 Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qapi/error.h"
22 #include "cpu.h"
23 #include "migration/vmstate.h"
24 #include "machine.h"
26 static void moxie_cpu_set_pc(CPUState *cs, vaddr value)
28 MoxieCPU *cpu = MOXIE_CPU(cs);
30 cpu->env.pc = value;
33 static bool moxie_cpu_has_work(CPUState *cs)
35 return cs->interrupt_request & CPU_INTERRUPT_HARD;
38 static void moxie_cpu_reset(DeviceState *dev)
40 CPUState *s = CPU(dev);
41 MoxieCPU *cpu = MOXIE_CPU(s);
42 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu);
43 CPUMoxieState *env = &cpu->env;
45 mcc->parent_reset(dev);
47 memset(env, 0, offsetof(CPUMoxieState, end_reset_fields));
48 env->pc = 0x1000;
51 static void moxie_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
53 info->mach = bfd_arch_moxie;
54 info->print_insn = print_insn_moxie;
57 static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
59 CPUState *cs = CPU(dev);
60 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev);
61 Error *local_err = NULL;
63 cpu_exec_realizefn(cs, &local_err);
64 if (local_err != NULL) {
65 error_propagate(errp, local_err);
66 return;
69 qemu_init_vcpu(cs);
70 cpu_reset(cs);
72 mcc->parent_realize(dev, errp);
75 static void moxie_cpu_initfn(Object *obj)
77 MoxieCPU *cpu = MOXIE_CPU(obj);
79 cpu_set_cpustate_pointers(cpu);
82 static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
84 ObjectClass *oc;
85 char *typename;
87 typename = g_strdup_printf(MOXIE_CPU_TYPE_NAME("%s"), cpu_model);
88 oc = object_class_by_name(typename);
89 g_free(typename);
90 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
91 object_class_is_abstract(oc))) {
92 return NULL;
94 return oc;
97 #include "hw/core/tcg-cpu-ops.h"
99 static struct TCGCPUOps moxie_tcg_ops = {
100 .initialize = moxie_translate_init,
101 .tlb_fill = moxie_cpu_tlb_fill,
103 #ifndef CONFIG_USER_ONLY
104 .do_interrupt = moxie_cpu_do_interrupt,
105 #endif /* !CONFIG_USER_ONLY */
108 static void moxie_cpu_class_init(ObjectClass *oc, void *data)
110 DeviceClass *dc = DEVICE_CLASS(oc);
111 CPUClass *cc = CPU_CLASS(oc);
112 MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc);
114 device_class_set_parent_realize(dc, moxie_cpu_realizefn,
115 &mcc->parent_realize);
116 device_class_set_parent_reset(dc, moxie_cpu_reset, &mcc->parent_reset);
118 cc->class_by_name = moxie_cpu_class_by_name;
120 cc->has_work = moxie_cpu_has_work;
121 cc->dump_state = moxie_cpu_dump_state;
122 cc->set_pc = moxie_cpu_set_pc;
123 #ifndef CONFIG_USER_ONLY
124 cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug;
125 cc->vmsd = &vmstate_moxie_cpu;
126 #endif
127 cc->disas_set_info = moxie_cpu_disas_set_info;
128 cc->tcg_ops = &moxie_tcg_ops;
131 static void moxielite_initfn(Object *obj)
133 /* Set cpu feature flags */
136 static void moxie_any_initfn(Object *obj)
138 /* Set cpu feature flags */
141 #define DEFINE_MOXIE_CPU_TYPE(cpu_model, initfn) \
143 .parent = TYPE_MOXIE_CPU, \
144 .instance_init = initfn, \
145 .name = MOXIE_CPU_TYPE_NAME(cpu_model), \
148 static const TypeInfo moxie_cpus_type_infos[] = {
149 { /* base class should be registered first */
150 .name = TYPE_MOXIE_CPU,
151 .parent = TYPE_CPU,
152 .instance_size = sizeof(MoxieCPU),
153 .instance_init = moxie_cpu_initfn,
154 .class_size = sizeof(MoxieCPUClass),
155 .class_init = moxie_cpu_class_init,
157 DEFINE_MOXIE_CPU_TYPE("MoxieLite", moxielite_initfn),
158 DEFINE_MOXIE_CPU_TYPE("any", moxie_any_initfn),
161 DEFINE_TYPES(moxie_cpus_type_infos)