2012-04-12 02:17:53 +02:00
|
|
|
/*
|
|
|
|
* QEMU MicroBlaze CPU
|
|
|
|
*
|
2012-04-12 02:26:28 +02:00
|
|
|
* Copyright (c) 2009 Edgar E. Iglesias
|
|
|
|
* Copyright (c) 2009-2012 PetaLogix Qld Pty Ltd.
|
2012-04-12 02:17:53 +02:00
|
|
|
* Copyright (c) 2012 SUSE LINUX Products GmbH
|
2014-01-13 04:35:26 +01:00
|
|
|
* Copyright (c) 2009 Edgar E. Iglesias, Axis Communications AB.
|
2012-04-12 02:17:53 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see
|
|
|
|
* <http://www.gnu.org/licenses/lgpl-2.1.html>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "qemu-common.h"
|
2013-04-23 14:27:09 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2013-01-20 19:03:32 +01:00
|
|
|
#include "migration/vmstate.h"
|
2012-04-12 02:17:53 +02:00
|
|
|
|
|
|
|
|
2013-06-21 19:09:18 +02:00
|
|
|
static void mb_cpu_set_pc(CPUState *cs, vaddr value)
|
|
|
|
{
|
|
|
|
MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
|
|
|
|
|
|
|
|
cpu->env.sregs[SR_PC] = value;
|
|
|
|
}
|
|
|
|
|
2013-08-25 18:53:55 +02:00
|
|
|
static bool mb_cpu_has_work(CPUState *cs)
|
|
|
|
{
|
|
|
|
return cs->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI);
|
|
|
|
}
|
|
|
|
|
2014-01-13 04:35:26 +01:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
static void microblaze_cpu_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
MicroBlazeCPU *cpu = opaque;
|
|
|
|
CPUState *cs = CPU(cpu);
|
|
|
|
int type = irq ? CPU_INTERRUPT_NMI : CPU_INTERRUPT_HARD;
|
|
|
|
|
|
|
|
if (level) {
|
|
|
|
cpu_interrupt(cs, type);
|
|
|
|
} else {
|
|
|
|
cpu_reset_interrupt(cs, type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-12 02:17:53 +02:00
|
|
|
/* CPUClass::reset() */
|
|
|
|
static void mb_cpu_reset(CPUState *s)
|
|
|
|
{
|
|
|
|
MicroBlazeCPU *cpu = MICROBLAZE_CPU(s);
|
|
|
|
MicroBlazeCPUClass *mcc = MICROBLAZE_CPU_GET_CLASS(cpu);
|
|
|
|
CPUMBState *env = &cpu->env;
|
|
|
|
|
|
|
|
mcc->parent_reset(s);
|
|
|
|
|
2013-08-26 21:22:53 +02:00
|
|
|
memset(env, 0, sizeof(CPUMBState));
|
2012-06-01 05:23:28 +02:00
|
|
|
env->res_addr = RES_ADDR_NONE;
|
2013-09-04 02:19:44 +02:00
|
|
|
tlb_flush(s, 1);
|
2012-04-12 02:26:28 +02:00
|
|
|
|
|
|
|
/* Disable stack protector. */
|
|
|
|
env->shr = ~0;
|
|
|
|
|
|
|
|
env->pvr.regs[0] = PVR0_PVR_FULL_MASK \
|
|
|
|
| PVR0_USE_BARREL_MASK \
|
|
|
|
| PVR0_USE_DIV_MASK \
|
|
|
|
| PVR0_USE_HW_MUL_MASK \
|
|
|
|
| PVR0_USE_EXC_MASK \
|
|
|
|
| PVR0_USE_ICACHE_MASK \
|
|
|
|
| PVR0_USE_DCACHE_MASK \
|
|
|
|
| PVR0_USE_MMU \
|
|
|
|
| (0xb << 8);
|
|
|
|
env->pvr.regs[2] = PVR2_D_OPB_MASK \
|
|
|
|
| PVR2_D_LMB_MASK \
|
|
|
|
| PVR2_I_OPB_MASK \
|
|
|
|
| PVR2_I_LMB_MASK \
|
|
|
|
| PVR2_USE_MSR_INSTR \
|
|
|
|
| PVR2_USE_PCMP_INSTR \
|
|
|
|
| PVR2_USE_BARREL_MASK \
|
|
|
|
| PVR2_USE_DIV_MASK \
|
|
|
|
| PVR2_USE_HW_MUL_MASK \
|
|
|
|
| PVR2_USE_MUL64_MASK \
|
|
|
|
| PVR2_USE_FPU_MASK \
|
|
|
|
| PVR2_USE_FPU2_MASK \
|
|
|
|
| PVR2_FPU_EXC_MASK \
|
|
|
|
| 0;
|
|
|
|
env->pvr.regs[10] = 0x0c000000; /* Default to spartan 3a dsp family. */
|
|
|
|
env->pvr.regs[11] = PVR11_USE_MMU | (16 << 17);
|
|
|
|
|
|
|
|
#if defined(CONFIG_USER_ONLY)
|
|
|
|
/* start in user mode with interrupts enabled. */
|
|
|
|
env->sregs[SR_MSR] = MSR_EE | MSR_IE | MSR_VM | MSR_UM;
|
|
|
|
env->pvr.regs[10] = 0x0c000000; /* Spartan 3a dsp. */
|
|
|
|
#else
|
|
|
|
env->sregs[SR_MSR] = 0;
|
|
|
|
mmu_init(&env->mmu);
|
|
|
|
env->mmu.c_mmu = 3;
|
|
|
|
env->mmu.c_mmu_tlb_access = 3;
|
|
|
|
env->mmu.c_mmu_zones = 16;
|
|
|
|
#endif
|
2012-04-12 02:17:53 +02:00
|
|
|
}
|
|
|
|
|
2013-01-05 15:27:31 +01:00
|
|
|
static void mb_cpu_realizefn(DeviceState *dev, Error **errp)
|
|
|
|
{
|
2013-07-27 02:53:25 +02:00
|
|
|
CPUState *cs = CPU(dev);
|
2013-01-05 15:27:31 +01:00
|
|
|
MicroBlazeCPUClass *mcc = MICROBLAZE_CPU_GET_CLASS(dev);
|
|
|
|
|
2013-07-27 02:53:25 +02:00
|
|
|
cpu_reset(cs);
|
|
|
|
qemu_init_vcpu(cs);
|
2013-01-05 15:27:31 +01:00
|
|
|
|
|
|
|
mcc->parent_realize(dev, errp);
|
|
|
|
}
|
|
|
|
|
2012-04-12 02:34:40 +02:00
|
|
|
static void mb_cpu_initfn(Object *obj)
|
|
|
|
{
|
2013-01-17 12:13:41 +01:00
|
|
|
CPUState *cs = CPU(obj);
|
2012-04-12 02:34:40 +02:00
|
|
|
MicroBlazeCPU *cpu = MICROBLAZE_CPU(obj);
|
|
|
|
CPUMBState *env = &cpu->env;
|
2013-01-20 01:10:52 +01:00
|
|
|
static bool tcg_initialized;
|
2012-04-12 02:34:40 +02:00
|
|
|
|
2013-01-17 12:13:41 +01:00
|
|
|
cs->env_ptr = env;
|
2012-04-12 02:34:40 +02:00
|
|
|
cpu_exec_init(env);
|
|
|
|
|
|
|
|
set_float_rounding_mode(float_round_nearest_even, &env->fp_status);
|
2013-01-20 01:10:52 +01:00
|
|
|
|
2014-01-13 04:35:26 +01:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
/* Inbound IRQ and FIR lines */
|
|
|
|
qdev_init_gpio_in(DEVICE(cpu), microblaze_cpu_set_irq, 2);
|
|
|
|
#endif
|
|
|
|
|
2013-01-20 01:10:52 +01:00
|
|
|
if (tcg_enabled() && !tcg_initialized) {
|
|
|
|
tcg_initialized = true;
|
|
|
|
mb_tcg_init();
|
|
|
|
}
|
2012-04-12 02:34:40 +02:00
|
|
|
}
|
|
|
|
|
2013-01-20 19:03:32 +01:00
|
|
|
static const VMStateDescription vmstate_mb_cpu = {
|
|
|
|
.name = "cpu",
|
|
|
|
.unmigratable = 1,
|
|
|
|
};
|
|
|
|
|
2013-04-23 14:27:09 +02:00
|
|
|
static Property mb_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("xlnx.base-vectors", MicroBlazeCPU, base_vectors, 0),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2012-04-12 02:17:53 +02:00
|
|
|
static void mb_cpu_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
2013-01-20 19:03:32 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2012-04-12 02:17:53 +02:00
|
|
|
CPUClass *cc = CPU_CLASS(oc);
|
|
|
|
MicroBlazeCPUClass *mcc = MICROBLAZE_CPU_CLASS(oc);
|
|
|
|
|
2013-01-05 15:27:31 +01:00
|
|
|
mcc->parent_realize = dc->realize;
|
|
|
|
dc->realize = mb_cpu_realizefn;
|
|
|
|
|
2012-04-12 02:17:53 +02:00
|
|
|
mcc->parent_reset = cc->reset;
|
|
|
|
cc->reset = mb_cpu_reset;
|
2013-01-20 19:03:32 +01:00
|
|
|
|
2013-08-25 18:53:55 +02:00
|
|
|
cc->has_work = mb_cpu_has_work;
|
2013-02-02 10:57:51 +01:00
|
|
|
cc->do_interrupt = mb_cpu_do_interrupt;
|
2013-05-27 01:33:50 +02:00
|
|
|
cc->dump_state = mb_cpu_dump_state;
|
2013-06-21 19:09:18 +02:00
|
|
|
cc->set_pc = mb_cpu_set_pc;
|
2013-06-29 04:18:45 +02:00
|
|
|
cc->gdb_read_register = mb_cpu_gdb_read_register;
|
|
|
|
cc->gdb_write_register = mb_cpu_gdb_write_register;
|
2013-08-26 03:01:33 +02:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
cc->handle_mmu_fault = mb_cpu_handle_mmu_fault;
|
|
|
|
#else
|
2013-06-29 18:55:54 +02:00
|
|
|
cc->do_unassigned_access = mb_cpu_unassigned_access;
|
|
|
|
cc->get_phys_page_debug = mb_cpu_get_phys_page_debug;
|
|
|
|
#endif
|
2013-01-20 19:03:32 +01:00
|
|
|
dc->vmsd = &vmstate_mb_cpu;
|
2013-04-23 14:27:09 +02:00
|
|
|
dc->props = mb_properties;
|
2013-06-28 23:18:47 +02:00
|
|
|
cc->gdb_num_core_regs = 32 + 5;
|
2012-04-12 02:17:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo mb_cpu_type_info = {
|
|
|
|
.name = TYPE_MICROBLAZE_CPU,
|
|
|
|
.parent = TYPE_CPU,
|
|
|
|
.instance_size = sizeof(MicroBlazeCPU),
|
2012-04-12 02:34:40 +02:00
|
|
|
.instance_init = mb_cpu_initfn,
|
2012-04-12 02:17:53 +02:00
|
|
|
.class_size = sizeof(MicroBlazeCPUClass),
|
|
|
|
.class_init = mb_cpu_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void mb_cpu_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&mb_cpu_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(mb_cpu_register_types)
|