2 * QEMU LatticeMico32 CPU
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
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
17 * License along with this library; if not, see
18 * <http://www.gnu.org/licenses/lgpl-2.1.html>
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
24 #include "qemu-common.h"
27 static void lm32_cpu_set_pc(CPUState
*cs
, vaddr value
)
29 LM32CPU
*cpu
= LM32_CPU(cs
);
34 static void lm32_cpu_list_entry(gpointer data
, gpointer user_data
)
36 ObjectClass
*oc
= data
;
37 CPUListState
*s
= user_data
;
38 const char *typename
= object_class_get_name(oc
);
41 name
= g_strndup(typename
, strlen(typename
) - strlen(LM32_CPU_TYPE_SUFFIX
));
42 (*s
->cpu_fprintf
)(s
->file
, " %s\n", name
);
47 void lm32_cpu_list(FILE *f
, fprintf_function cpu_fprintf
)
51 .cpu_fprintf
= cpu_fprintf
,
55 list
= object_class_get_list_sorted(TYPE_LM32_CPU
, false);
56 (*cpu_fprintf
)(f
, "Available CPUs:\n");
57 g_slist_foreach(list
, lm32_cpu_list_entry
, &s
);
61 static void lm32_cpu_init_cfg_reg(LM32CPU
*cpu
)
63 CPULM32State
*env
= &cpu
->env
;
66 if (cpu
->features
& LM32_FEATURE_MULTIPLY
) {
70 if (cpu
->features
& LM32_FEATURE_DIVIDE
) {
74 if (cpu
->features
& LM32_FEATURE_SHIFT
) {
78 if (cpu
->features
& LM32_FEATURE_SIGN_EXTEND
) {
82 if (cpu
->features
& LM32_FEATURE_I_CACHE
) {
86 if (cpu
->features
& LM32_FEATURE_D_CACHE
) {
90 if (cpu
->features
& LM32_FEATURE_CYCLE_COUNT
) {
94 cfg
|= (cpu
->num_interrupts
<< CFG_INT_SHIFT
);
95 cfg
|= (cpu
->num_breakpoints
<< CFG_BP_SHIFT
);
96 cfg
|= (cpu
->num_watchpoints
<< CFG_WP_SHIFT
);
97 cfg
|= (cpu
->revision
<< CFG_REV_SHIFT
);
102 static bool lm32_cpu_has_work(CPUState
*cs
)
104 return cs
->interrupt_request
& CPU_INTERRUPT_HARD
;
107 /* CPUClass::reset() */
108 static void lm32_cpu_reset(CPUState
*s
)
110 LM32CPU
*cpu
= LM32_CPU(s
);
111 LM32CPUClass
*lcc
= LM32_CPU_GET_CLASS(cpu
);
112 CPULM32State
*env
= &cpu
->env
;
114 lcc
->parent_reset(s
);
116 /* reset cpu state */
117 memset(env
, 0, offsetof(CPULM32State
, end_reset_fields
));
119 lm32_cpu_init_cfg_reg(cpu
);
122 static void lm32_cpu_disas_set_info(CPUState
*cpu
, disassemble_info
*info
)
124 info
->mach
= bfd_mach_lm32
;
125 info
->print_insn
= print_insn_lm32
;
128 static void lm32_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
130 CPUState
*cs
= CPU(dev
);
131 LM32CPUClass
*lcc
= LM32_CPU_GET_CLASS(dev
);
132 Error
*local_err
= NULL
;
134 cpu_exec_realizefn(cs
, &local_err
);
135 if (local_err
!= NULL
) {
136 error_propagate(errp
, local_err
);
144 lcc
->parent_realize(dev
, errp
);
147 static void lm32_cpu_initfn(Object
*obj
)
149 CPUState
*cs
= CPU(obj
);
150 LM32CPU
*cpu
= LM32_CPU(obj
);
151 CPULM32State
*env
= &cpu
->env
;
158 static void lm32_basic_cpu_initfn(Object
*obj
)
160 LM32CPU
*cpu
= LM32_CPU(obj
);
163 cpu
->num_interrupts
= 32;
164 cpu
->num_breakpoints
= 4;
165 cpu
->num_watchpoints
= 4;
166 cpu
->features
= LM32_FEATURE_SHIFT
167 | LM32_FEATURE_SIGN_EXTEND
168 | LM32_FEATURE_CYCLE_COUNT
;
171 static void lm32_standard_cpu_initfn(Object
*obj
)
173 LM32CPU
*cpu
= LM32_CPU(obj
);
176 cpu
->num_interrupts
= 32;
177 cpu
->num_breakpoints
= 4;
178 cpu
->num_watchpoints
= 4;
179 cpu
->features
= LM32_FEATURE_MULTIPLY
180 | LM32_FEATURE_DIVIDE
182 | LM32_FEATURE_SIGN_EXTEND
183 | LM32_FEATURE_I_CACHE
184 | LM32_FEATURE_CYCLE_COUNT
;
187 static void lm32_full_cpu_initfn(Object
*obj
)
189 LM32CPU
*cpu
= LM32_CPU(obj
);
192 cpu
->num_interrupts
= 32;
193 cpu
->num_breakpoints
= 4;
194 cpu
->num_watchpoints
= 4;
195 cpu
->features
= LM32_FEATURE_MULTIPLY
196 | LM32_FEATURE_DIVIDE
198 | LM32_FEATURE_SIGN_EXTEND
199 | LM32_FEATURE_I_CACHE
200 | LM32_FEATURE_D_CACHE
201 | LM32_FEATURE_CYCLE_COUNT
;
204 static ObjectClass
*lm32_cpu_class_by_name(const char *cpu_model
)
209 typename
= g_strdup_printf(LM32_CPU_TYPE_NAME("%s"), cpu_model
);
210 oc
= object_class_by_name(typename
);
212 if (oc
!= NULL
&& (!object_class_dynamic_cast(oc
, TYPE_LM32_CPU
) ||
213 object_class_is_abstract(oc
))) {
219 static void lm32_cpu_class_init(ObjectClass
*oc
, void *data
)
221 LM32CPUClass
*lcc
= LM32_CPU_CLASS(oc
);
222 CPUClass
*cc
= CPU_CLASS(oc
);
223 DeviceClass
*dc
= DEVICE_CLASS(oc
);
225 device_class_set_parent_realize(dc
, lm32_cpu_realizefn
,
226 &lcc
->parent_realize
);
227 lcc
->parent_reset
= cc
->reset
;
228 cc
->reset
= lm32_cpu_reset
;
230 cc
->class_by_name
= lm32_cpu_class_by_name
;
231 cc
->has_work
= lm32_cpu_has_work
;
232 cc
->do_interrupt
= lm32_cpu_do_interrupt
;
233 cc
->cpu_exec_interrupt
= lm32_cpu_exec_interrupt
;
234 cc
->dump_state
= lm32_cpu_dump_state
;
235 cc
->set_pc
= lm32_cpu_set_pc
;
236 cc
->gdb_read_register
= lm32_cpu_gdb_read_register
;
237 cc
->gdb_write_register
= lm32_cpu_gdb_write_register
;
238 #ifdef CONFIG_USER_ONLY
239 cc
->handle_mmu_fault
= lm32_cpu_handle_mmu_fault
;
241 cc
->get_phys_page_debug
= lm32_cpu_get_phys_page_debug
;
242 cc
->vmsd
= &vmstate_lm32_cpu
;
244 cc
->gdb_num_core_regs
= 32 + 7;
245 cc
->gdb_stop_before_watchpoint
= true;
246 cc
->debug_excp_handler
= lm32_debug_excp_handler
;
247 cc
->disas_set_info
= lm32_cpu_disas_set_info
;
248 cc
->tcg_initialize
= lm32_translate_init
;
251 #define DEFINE_LM32_CPU_TYPE(cpu_model, initfn) \
253 .parent = TYPE_LM32_CPU, \
254 .name = LM32_CPU_TYPE_NAME(cpu_model), \
255 .instance_init = initfn, \
258 static const TypeInfo lm32_cpus_type_infos
[] = {
259 { /* base class should be registered first */
260 .name
= TYPE_LM32_CPU
,
262 .instance_size
= sizeof(LM32CPU
),
263 .instance_init
= lm32_cpu_initfn
,
265 .class_size
= sizeof(LM32CPUClass
),
266 .class_init
= lm32_cpu_class_init
,
268 DEFINE_LM32_CPU_TYPE("lm32-basic", lm32_basic_cpu_initfn
),
269 DEFINE_LM32_CPU_TYPE("lm32-standard", lm32_standard_cpu_initfn
),
270 DEFINE_LM32_CPU_TYPE("lm32-full", lm32_full_cpu_initfn
),
273 DEFINE_TYPES(lm32_cpus_type_infos
)