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/>.
21 #include "qemu-common.h"
22 #include "migration/vmstate.h"
25 static void moxie_cpu_set_pc(CPUState
*cs
, vaddr value
)
27 MoxieCPU
*cpu
= MOXIE_CPU(cs
);
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
;
45 memset(env
, 0, sizeof(CPUMoxieState
));
51 static void moxie_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
53 CPUState
*cs
= CPU(dev
);
54 MoxieCPUClass
*mcc
= MOXIE_CPU_GET_CLASS(dev
);
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
);
68 cs
->env_ptr
= &cpu
->env
;
69 cpu_exec_init(&cpu
->env
);
71 if (tcg_enabled() && !inited
) {
73 moxie_translate_init();
77 static ObjectClass
*moxie_cpu_class_by_name(const char *cpu_model
)
81 if (cpu_model
== 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
))) {
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
;
114 cc
->get_phys_page_debug
= moxie_cpu_get_phys_page_debug
;
115 cc
->vmsd
= &vmstate_moxie_cpu
;
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
{
131 void (*initfn
)(Object
*obj
);
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
,
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)
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
)