4 * Copyright (c) 2009 Edgar E. Iglesias
5 * Copyright (c) 2009-2012 PetaLogix Qld Pty Ltd.
6 * Copyright (c) 2012 SUSE LINUX Products GmbH
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see
20 * <http://www.gnu.org/licenses/lgpl-2.1.html>
24 #include "qemu-common.h"
25 #include "migration/vmstate.h"
28 /* CPUClass::reset() */
29 static void mb_cpu_reset(CPUState
*s
)
31 MicroBlazeCPU
*cpu
= MICROBLAZE_CPU(s
);
32 MicroBlazeCPUClass
*mcc
= MICROBLAZE_CPU_GET_CLASS(cpu
);
33 CPUMBState
*env
= &cpu
->env
;
35 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
36 qemu_log("CPU Reset (CPU %d)\n", s
->cpu_index
);
37 log_cpu_state(env
, 0);
42 memset(env
, 0, offsetof(CPUMBState
, breakpoints
));
43 env
->res_addr
= RES_ADDR_NONE
;
46 /* Disable stack protector. */
49 env
->pvr
.regs
[0] = PVR0_PVR_FULL_MASK \
50 | PVR0_USE_BARREL_MASK \
52 | PVR0_USE_HW_MUL_MASK \
54 | PVR0_USE_ICACHE_MASK \
55 | PVR0_USE_DCACHE_MASK \
58 env
->pvr
.regs
[2] = PVR2_D_OPB_MASK \
62 | PVR2_USE_MSR_INSTR \
63 | PVR2_USE_PCMP_INSTR \
64 | PVR2_USE_BARREL_MASK \
66 | PVR2_USE_HW_MUL_MASK \
67 | PVR2_USE_MUL64_MASK \
69 | PVR2_USE_FPU2_MASK \
72 env
->pvr
.regs
[10] = 0x0c000000; /* Default to spartan 3a dsp family. */
73 env
->pvr
.regs
[11] = PVR11_USE_MMU
| (16 << 17);
75 #if defined(CONFIG_USER_ONLY)
76 /* start in user mode with interrupts enabled. */
77 env
->sregs
[SR_MSR
] = MSR_EE
| MSR_IE
| MSR_VM
| MSR_UM
;
78 env
->pvr
.regs
[10] = 0x0c000000; /* Spartan 3a dsp. */
80 env
->sregs
[SR_MSR
] = 0;
83 env
->mmu
.c_mmu_tlb_access
= 3;
84 env
->mmu
.c_mmu_zones
= 16;
88 static void mb_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
90 MicroBlazeCPU
*cpu
= MICROBLAZE_CPU(dev
);
91 MicroBlazeCPUClass
*mcc
= MICROBLAZE_CPU_GET_CLASS(dev
);
94 qemu_init_vcpu(&cpu
->env
);
96 mcc
->parent_realize(dev
, errp
);
99 static void mb_cpu_initfn(Object
*obj
)
101 CPUState
*cs
= CPU(obj
);
102 MicroBlazeCPU
*cpu
= MICROBLAZE_CPU(obj
);
103 CPUMBState
*env
= &cpu
->env
;
104 static bool tcg_initialized
;
109 set_float_rounding_mode(float_round_nearest_even
, &env
->fp_status
);
111 if (tcg_enabled() && !tcg_initialized
) {
112 tcg_initialized
= true;
117 static const VMStateDescription vmstate_mb_cpu
= {
122 static void mb_cpu_class_init(ObjectClass
*oc
, void *data
)
124 DeviceClass
*dc
= DEVICE_CLASS(oc
);
125 CPUClass
*cc
= CPU_CLASS(oc
);
126 MicroBlazeCPUClass
*mcc
= MICROBLAZE_CPU_CLASS(oc
);
128 mcc
->parent_realize
= dc
->realize
;
129 dc
->realize
= mb_cpu_realizefn
;
131 mcc
->parent_reset
= cc
->reset
;
132 cc
->reset
= mb_cpu_reset
;
134 dc
->vmsd
= &vmstate_mb_cpu
;
137 static const TypeInfo mb_cpu_type_info
= {
138 .name
= TYPE_MICROBLAZE_CPU
,
140 .instance_size
= sizeof(MicroBlazeCPU
),
141 .instance_init
= mb_cpu_initfn
,
142 .class_size
= sizeof(MicroBlazeCPUClass
),
143 .class_init
= mb_cpu_class_init
,
146 static void mb_cpu_register_types(void)
148 type_register_static(&mb_cpu_type_info
);
151 type_init(mb_cpu_register_types
)