2017-01-19 01:01:41 +03:00
|
|
|
/*
|
|
|
|
* QEMU Nios II CPU
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Chris Wulff <crwulff@gmail.com>
|
|
|
|
*
|
|
|
|
* 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 "qemu/osdep.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2017-01-19 01:01:41 +03:00
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "exec/log.h"
|
|
|
|
#include "exec/gdbstub.h"
|
|
|
|
#include "hw/qdev-properties.h"
|
|
|
|
|
|
|
|
static void nios2_cpu_set_pc(CPUState *cs, vaddr value)
|
|
|
|
{
|
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
|
|
|
CPUNios2State *env = &cpu->env;
|
|
|
|
|
2022-04-21 18:16:47 +03:00
|
|
|
env->pc = value;
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool nios2_cpu_has_work(CPUState *cs)
|
|
|
|
{
|
2022-04-21 18:17:11 +03:00
|
|
|
return cs->interrupt_request & CPU_INTERRUPT_HARD;
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
|
|
|
|
cpu: Use DeviceClass reset instead of a special CPUClass reset
The CPUClass has a 'reset' method. This is a legacy from when
TYPE_CPU used not to inherit from TYPE_DEVICE. We don't need it any
more, as we can simply use the TYPE_DEVICE reset. The 'cpu_reset()'
function is kept as the API which most places use to reset a CPU; it
is now a wrapper which calls device_cold_reset() and then the
tracepoint function.
This change should not cause CPU objects to be reset more often
than they are at the moment, because:
* nobody is directly calling device_cold_reset() or
qdev_reset_all() on CPU objects
* no CPU object is on a qbus, so they will not be reset either
by somebody calling qbus_reset_all()/bus_cold_reset(), or
by the main "reset sysbus and everything in the qbus tree"
reset that most devices are reset by
Note that this does not change the need for each machine or whatever
to use qemu_register_reset() to arrange to call cpu_reset() -- that
is necessary because CPU objects are not on any qbus, so they don't
get reset when the qbus tree rooted at the sysbus bus is reset, and
this isn't being changed here.
All the changes to the files under target/ were made using the
included Coccinelle script, except:
(1) the deletion of the now-inaccurate and not terribly useful
"CPUClass::reset" comments was done with a perl one-liner afterwards:
perl -n -i -e '/ CPUClass::reset/ or print' target/*/*.c
(2) this bit of the s390 change was done by hand, because the
Coccinelle script is not sophisticated enough to handle the
parent_reset call being inside another function:
| @@ -96,8 +96,9 @@ static void s390_cpu_reset(CPUState *s, cpu_reset_type type)
| S390CPU *cpu = S390_CPU(s);
| S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
| CPUS390XState *env = &cpu->env;
|+ DeviceState *dev = DEVICE(s);
|
|- scc->parent_reset(s);
|+ scc->parent_reset(dev);
| cpu->env.sigp_order = 0;
| s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20200303100511.5498-1-peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-03-03 13:05:11 +03:00
|
|
|
static void nios2_cpu_reset(DeviceState *dev)
|
2017-01-19 01:01:41 +03:00
|
|
|
{
|
cpu: Use DeviceClass reset instead of a special CPUClass reset
The CPUClass has a 'reset' method. This is a legacy from when
TYPE_CPU used not to inherit from TYPE_DEVICE. We don't need it any
more, as we can simply use the TYPE_DEVICE reset. The 'cpu_reset()'
function is kept as the API which most places use to reset a CPU; it
is now a wrapper which calls device_cold_reset() and then the
tracepoint function.
This change should not cause CPU objects to be reset more often
than they are at the moment, because:
* nobody is directly calling device_cold_reset() or
qdev_reset_all() on CPU objects
* no CPU object is on a qbus, so they will not be reset either
by somebody calling qbus_reset_all()/bus_cold_reset(), or
by the main "reset sysbus and everything in the qbus tree"
reset that most devices are reset by
Note that this does not change the need for each machine or whatever
to use qemu_register_reset() to arrange to call cpu_reset() -- that
is necessary because CPU objects are not on any qbus, so they don't
get reset when the qbus tree rooted at the sysbus bus is reset, and
this isn't being changed here.
All the changes to the files under target/ were made using the
included Coccinelle script, except:
(1) the deletion of the now-inaccurate and not terribly useful
"CPUClass::reset" comments was done with a perl one-liner afterwards:
perl -n -i -e '/ CPUClass::reset/ or print' target/*/*.c
(2) this bit of the s390 change was done by hand, because the
Coccinelle script is not sophisticated enough to handle the
parent_reset call being inside another function:
| @@ -96,8 +96,9 @@ static void s390_cpu_reset(CPUState *s, cpu_reset_type type)
| S390CPU *cpu = S390_CPU(s);
| S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
| CPUS390XState *env = &cpu->env;
|+ DeviceState *dev = DEVICE(s);
|
|- scc->parent_reset(s);
|+ scc->parent_reset(dev);
| cpu->env.sigp_order = 0;
| s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20200303100511.5498-1-peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-03-03 13:05:11 +03:00
|
|
|
CPUState *cs = CPU(dev);
|
2017-01-19 01:01:41 +03:00
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
|
|
|
Nios2CPUClass *ncc = NIOS2_CPU_GET_CLASS(cpu);
|
|
|
|
CPUNios2State *env = &cpu->env;
|
|
|
|
|
cpu: Use DeviceClass reset instead of a special CPUClass reset
The CPUClass has a 'reset' method. This is a legacy from when
TYPE_CPU used not to inherit from TYPE_DEVICE. We don't need it any
more, as we can simply use the TYPE_DEVICE reset. The 'cpu_reset()'
function is kept as the API which most places use to reset a CPU; it
is now a wrapper which calls device_cold_reset() and then the
tracepoint function.
This change should not cause CPU objects to be reset more often
than they are at the moment, because:
* nobody is directly calling device_cold_reset() or
qdev_reset_all() on CPU objects
* no CPU object is on a qbus, so they will not be reset either
by somebody calling qbus_reset_all()/bus_cold_reset(), or
by the main "reset sysbus and everything in the qbus tree"
reset that most devices are reset by
Note that this does not change the need for each machine or whatever
to use qemu_register_reset() to arrange to call cpu_reset() -- that
is necessary because CPU objects are not on any qbus, so they don't
get reset when the qbus tree rooted at the sysbus bus is reset, and
this isn't being changed here.
All the changes to the files under target/ were made using the
included Coccinelle script, except:
(1) the deletion of the now-inaccurate and not terribly useful
"CPUClass::reset" comments was done with a perl one-liner afterwards:
perl -n -i -e '/ CPUClass::reset/ or print' target/*/*.c
(2) this bit of the s390 change was done by hand, because the
Coccinelle script is not sophisticated enough to handle the
parent_reset call being inside another function:
| @@ -96,8 +96,9 @@ static void s390_cpu_reset(CPUState *s, cpu_reset_type type)
| S390CPU *cpu = S390_CPU(s);
| S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
| CPUS390XState *env = &cpu->env;
|+ DeviceState *dev = DEVICE(s);
|
|- scc->parent_reset(s);
|+ scc->parent_reset(dev);
| cpu->env.sigp_order = 0;
| s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20200303100511.5498-1-peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-03-03 13:05:11 +03:00
|
|
|
ncc->parent_reset(dev);
|
2017-01-19 01:01:41 +03:00
|
|
|
|
2022-04-21 18:16:53 +03:00
|
|
|
memset(env->ctrl, 0, sizeof(env->ctrl));
|
2022-04-21 18:16:47 +03:00
|
|
|
env->pc = cpu->reset_addr;
|
2017-01-19 01:01:41 +03:00
|
|
|
|
|
|
|
#if defined(CONFIG_USER_ONLY)
|
|
|
|
/* Start in user mode with interrupts enabled. */
|
2022-04-21 18:17:10 +03:00
|
|
|
env->ctrl[CR_STATUS] = CR_STATUS_RSIE | CR_STATUS_U | CR_STATUS_PIE;
|
2022-04-21 18:17:24 +03:00
|
|
|
memset(env->regs, 0, sizeof(env->regs));
|
2017-01-19 01:01:41 +03:00
|
|
|
#else
|
2022-04-21 18:17:10 +03:00
|
|
|
env->ctrl[CR_STATUS] = CR_STATUS_RSIE;
|
2022-04-21 18:17:24 +03:00
|
|
|
nios2_update_crs(env);
|
|
|
|
memset(env->shadow_regs, 0, sizeof(env->shadow_regs));
|
2017-01-19 01:01:41 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-11-29 20:40:20 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2022-04-21 18:17:27 +03:00
|
|
|
static void eic_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
Nios2CPU *cpu = opaque;
|
|
|
|
CPUState *cs = CPU(cpu);
|
|
|
|
|
|
|
|
if (level) {
|
|
|
|
cpu_interrupt(cs, CPU_INTERRUPT_HARD);
|
|
|
|
} else {
|
|
|
|
cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void iic_set_irq(void *opaque, int irq, int level)
|
2020-11-29 20:40:20 +03:00
|
|
|
{
|
|
|
|
Nios2CPU *cpu = opaque;
|
|
|
|
CPUNios2State *env = &cpu->env;
|
|
|
|
CPUState *cs = CPU(cpu);
|
|
|
|
|
2022-04-21 18:16:53 +03:00
|
|
|
env->ctrl[CR_IPENDING] = deposit32(env->ctrl[CR_IPENDING], irq, 1, !!level);
|
2020-11-29 20:40:20 +03:00
|
|
|
|
2022-04-21 18:16:53 +03:00
|
|
|
if (env->ctrl[CR_IPENDING]) {
|
2020-11-29 20:40:20 +03:00
|
|
|
cpu_interrupt(cs, CPU_INTERRUPT_HARD);
|
2022-02-26 14:56:15 +03:00
|
|
|
} else {
|
2020-11-29 20:40:20 +03:00
|
|
|
cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-19 01:01:41 +03:00
|
|
|
static void nios2_cpu_initfn(Object *obj)
|
|
|
|
{
|
|
|
|
Nios2CPU *cpu = NIOS2_CPU(obj);
|
|
|
|
|
2019-03-29 00:26:22 +03:00
|
|
|
cpu_set_cpustate_pointers(cpu);
|
2017-01-19 01:01:41 +03:00
|
|
|
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2019-03-29 00:26:22 +03:00
|
|
|
mmu_init(&cpu->env);
|
2017-01-19 01:01:41 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-08-24 19:31:36 +03:00
|
|
|
static ObjectClass *nios2_cpu_class_by_name(const char *cpu_model)
|
2017-01-19 01:01:41 +03:00
|
|
|
{
|
2017-08-24 19:31:36 +03:00
|
|
|
return object_class_by_name(TYPE_NIOS2_CPU);
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
|
|
|
|
2022-04-21 18:17:08 +03:00
|
|
|
static void realize_cr_status(CPUState *cs)
|
|
|
|
{
|
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
|
|
|
|
|
|
|
/* Begin with all fields of all registers are reserved. */
|
|
|
|
memset(cpu->cr_state, 0, sizeof(cpu->cr_state));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The combination of writable and readonly is the set of all
|
|
|
|
* non-reserved fields. We apply writable as a mask to bits,
|
|
|
|
* and merge in existing readonly bits, before storing.
|
|
|
|
*/
|
|
|
|
#define WR_REG(C) cpu->cr_state[C].writable = -1
|
|
|
|
#define RO_REG(C) cpu->cr_state[C].readonly = -1
|
|
|
|
#define WR_FIELD(C, F) cpu->cr_state[C].writable |= R_##C##_##F##_MASK
|
|
|
|
#define RO_FIELD(C, F) cpu->cr_state[C].readonly |= R_##C##_##F##_MASK
|
|
|
|
|
|
|
|
WR_FIELD(CR_STATUS, PIE);
|
|
|
|
WR_REG(CR_ESTATUS);
|
|
|
|
WR_REG(CR_BSTATUS);
|
|
|
|
RO_REG(CR_CPUID);
|
|
|
|
RO_REG(CR_EXCEPTION);
|
|
|
|
WR_REG(CR_BADADDR);
|
|
|
|
|
2022-04-21 18:17:27 +03:00
|
|
|
if (cpu->eic_present) {
|
|
|
|
WR_FIELD(CR_STATUS, RSIE);
|
|
|
|
RO_FIELD(CR_STATUS, NMI);
|
|
|
|
WR_FIELD(CR_STATUS, PRS);
|
|
|
|
RO_FIELD(CR_STATUS, CRS);
|
|
|
|
WR_FIELD(CR_STATUS, IL);
|
|
|
|
WR_FIELD(CR_STATUS, IH);
|
|
|
|
} else {
|
|
|
|
RO_FIELD(CR_STATUS, RSIE);
|
|
|
|
WR_REG(CR_IENABLE);
|
|
|
|
RO_REG(CR_IPENDING);
|
|
|
|
}
|
2022-04-21 18:17:08 +03:00
|
|
|
|
|
|
|
if (cpu->mmu_present) {
|
|
|
|
WR_FIELD(CR_STATUS, U);
|
|
|
|
WR_FIELD(CR_STATUS, EH);
|
|
|
|
|
|
|
|
WR_FIELD(CR_PTEADDR, VPN);
|
|
|
|
WR_FIELD(CR_PTEADDR, PTBASE);
|
|
|
|
|
|
|
|
RO_FIELD(CR_TLBMISC, D);
|
|
|
|
RO_FIELD(CR_TLBMISC, PERM);
|
|
|
|
RO_FIELD(CR_TLBMISC, BAD);
|
|
|
|
RO_FIELD(CR_TLBMISC, DBL);
|
|
|
|
WR_FIELD(CR_TLBMISC, PID);
|
|
|
|
WR_FIELD(CR_TLBMISC, WE);
|
|
|
|
WR_FIELD(CR_TLBMISC, RD);
|
|
|
|
WR_FIELD(CR_TLBMISC, WAY);
|
|
|
|
|
|
|
|
WR_REG(CR_TLBACC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: ECC (config, eccinj) and MPU (config, mpubase, mpuacc) are
|
|
|
|
* unimplemented, so their corresponding control regs remain reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef WR_REG
|
|
|
|
#undef RO_REG
|
|
|
|
#undef WR_FIELD
|
|
|
|
#undef RO_FIELD
|
|
|
|
}
|
|
|
|
|
2017-01-19 01:01:41 +03:00
|
|
|
static void nios2_cpu_realizefn(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
CPUState *cs = CPU(dev);
|
2022-04-21 18:17:09 +03:00
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
2017-01-19 01:01:41 +03:00
|
|
|
Nios2CPUClass *ncc = NIOS2_CPU_GET_CLASS(dev);
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
2022-04-21 18:17:27 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
if (cpu->eic_present) {
|
|
|
|
qdev_init_gpio_in_named(DEVICE(cpu), eic_set_irq, "EIC", 1);
|
|
|
|
} else {
|
|
|
|
qdev_init_gpio_in_named(DEVICE(cpu), iic_set_irq, "IRQ", 32);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-19 01:01:41 +03:00
|
|
|
cpu_exec_realizefn(cs, &local_err);
|
|
|
|
if (local_err != NULL) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-21 18:17:08 +03:00
|
|
|
realize_cr_status(cs);
|
2017-01-19 01:01:41 +03:00
|
|
|
qemu_init_vcpu(cs);
|
|
|
|
cpu_reset(cs);
|
|
|
|
|
2022-04-21 18:17:09 +03:00
|
|
|
/* We have reserved storage for cpuid; might as well use it. */
|
|
|
|
cpu->env.ctrl[CR_CPUID] = cs->cpu_index;
|
|
|
|
|
2017-01-19 01:01:41 +03:00
|
|
|
ncc->parent_realize(dev, errp);
|
|
|
|
}
|
|
|
|
|
2021-09-11 19:54:25 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2022-04-21 18:17:27 +03:00
|
|
|
static bool eic_take_interrupt(Nios2CPU *cpu)
|
2017-01-19 01:01:41 +03:00
|
|
|
{
|
|
|
|
CPUNios2State *env = &cpu->env;
|
2022-04-21 18:17:27 +03:00
|
|
|
const uint32_t status = env->ctrl[CR_STATUS];
|
2017-01-19 01:01:41 +03:00
|
|
|
|
2022-04-21 18:17:27 +03:00
|
|
|
if (cpu->rnmi) {
|
|
|
|
return !(status & CR_STATUS_NMI);
|
|
|
|
}
|
|
|
|
if (!(status & CR_STATUS_PIE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (cpu->ril <= FIELD_EX32(status, CR_STATUS, IL)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (cpu->rrs != FIELD_EX32(status, CR_STATUS, CRS)) {
|
2017-01-19 01:01:41 +03:00
|
|
|
return true;
|
|
|
|
}
|
2022-04-21 18:17:27 +03:00
|
|
|
return status & CR_STATUS_RSIE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool iic_take_interrupt(Nios2CPU *cpu)
|
|
|
|
{
|
|
|
|
CPUNios2State *env = &cpu->env;
|
|
|
|
|
|
|
|
if (!(env->ctrl[CR_STATUS] & CR_STATUS_PIE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return env->ctrl[CR_IPENDING] & env->ctrl[CR_IENABLE];
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool nios2_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
|
|
|
|
{
|
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
|
|
|
|
|
|
|
if (interrupt_request & CPU_INTERRUPT_HARD) {
|
|
|
|
if (cpu->eic_present
|
|
|
|
? eic_take_interrupt(cpu)
|
|
|
|
: iic_take_interrupt(cpu)) {
|
|
|
|
cs->exception_index = EXCP_IRQ;
|
|
|
|
nios2_cpu_do_interrupt(cs);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-01-19 01:01:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
2021-09-11 19:54:25 +03:00
|
|
|
#endif /* !CONFIG_USER_ONLY */
|
2017-01-19 01:01:41 +03:00
|
|
|
|
|
|
|
static void nios2_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
|
|
|
|
{
|
|
|
|
/* NOTE: NiosII R2 is not supported yet. */
|
|
|
|
info->mach = bfd_arch_nios2;
|
2021-08-07 14:09:39 +03:00
|
|
|
info->print_insn = print_insn_nios2;
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
|
|
|
|
2020-03-16 20:21:41 +03:00
|
|
|
static int nios2_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
|
2017-01-19 01:01:41 +03:00
|
|
|
{
|
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
|
|
|
CPUNios2State *env = &cpu->env;
|
2022-04-21 18:17:08 +03:00
|
|
|
uint32_t val;
|
2017-01-19 01:01:41 +03:00
|
|
|
|
|
|
|
if (n < 32) { /* GP regs */
|
2022-04-21 18:17:08 +03:00
|
|
|
val = env->regs[n];
|
2017-01-19 01:01:41 +03:00
|
|
|
} else if (n == 32) { /* PC */
|
2022-04-21 18:17:08 +03:00
|
|
|
val = env->pc;
|
2017-01-19 01:01:41 +03:00
|
|
|
} else if (n < 49) { /* Status regs */
|
2022-04-21 18:17:08 +03:00
|
|
|
unsigned cr = n - 33;
|
|
|
|
if (nios2_cr_reserved(&cpu->cr_state[cr])) {
|
|
|
|
val = 0;
|
|
|
|
} else {
|
|
|
|
val = env->ctrl[n - 33];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Invalid regs */
|
|
|
|
return 0;
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
|
|
|
|
2022-04-21 18:17:08 +03:00
|
|
|
return gdb_get_reg32(mem_buf, val);
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int nios2_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
|
|
|
|
{
|
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
|
|
|
CPUClass *cc = CPU_GET_CLASS(cs);
|
|
|
|
CPUNios2State *env = &cpu->env;
|
2022-04-21 18:17:08 +03:00
|
|
|
uint32_t val;
|
2017-01-19 01:01:41 +03:00
|
|
|
|
|
|
|
if (n > cc->gdb_num_core_regs) {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-04-21 18:17:08 +03:00
|
|
|
val = ldl_p(mem_buf);
|
2017-01-19 01:01:41 +03:00
|
|
|
|
|
|
|
if (n < 32) { /* GP regs */
|
2022-04-21 18:17:08 +03:00
|
|
|
env->regs[n] = val;
|
2017-01-19 01:01:41 +03:00
|
|
|
} else if (n == 32) { /* PC */
|
2022-04-21 18:17:08 +03:00
|
|
|
env->pc = val;
|
2017-01-19 01:01:41 +03:00
|
|
|
} else if (n < 49) { /* Status regs */
|
2022-04-21 18:17:08 +03:00
|
|
|
unsigned cr = n - 33;
|
|
|
|
/* ??? Maybe allow the debugger to write to readonly fields. */
|
|
|
|
val &= cpu->cr_state[cr].writable;
|
|
|
|
val |= cpu->cr_state[cr].readonly & env->ctrl[cr];
|
|
|
|
env->ctrl[cr] = val;
|
|
|
|
} else {
|
|
|
|
g_assert_not_reached();
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property nios2_properties[] = {
|
2022-04-21 18:17:12 +03:00
|
|
|
DEFINE_PROP_BOOL("diverr_present", Nios2CPU, diverr_present, true),
|
2017-01-19 01:01:41 +03:00
|
|
|
DEFINE_PROP_BOOL("mmu_present", Nios2CPU, mmu_present, true),
|
|
|
|
/* ALTR,pid-num-bits */
|
|
|
|
DEFINE_PROP_UINT32("mmu_pid_num_bits", Nios2CPU, pid_num_bits, 8),
|
|
|
|
/* ALTR,tlb-num-ways */
|
|
|
|
DEFINE_PROP_UINT32("mmu_tlb_num_ways", Nios2CPU, tlb_num_ways, 16),
|
|
|
|
/* ALTR,tlb-num-entries */
|
|
|
|
DEFINE_PROP_UINT32("mmu_pid_num_entries", Nios2CPU, tlb_num_entries, 256),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2021-05-17 13:51:31 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
#include "hw/core/sysemu-cpu-ops.h"
|
|
|
|
|
|
|
|
static const struct SysemuCPUOps nios2_sysemu_ops = {
|
2021-05-17 13:51:37 +03:00
|
|
|
.get_phys_page_debug = nios2_cpu_get_phys_page_debug,
|
2021-05-17 13:51:31 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2021-02-04 19:39:23 +03:00
|
|
|
#include "hw/core/tcg-cpu-ops.h"
|
|
|
|
|
2021-02-28 02:21:17 +03:00
|
|
|
static const struct TCGCPUOps nios2_tcg_ops = {
|
2021-02-04 19:39:23 +03:00
|
|
|
.initialize = nios2_tcg_init,
|
|
|
|
|
2022-04-21 18:16:41 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2021-09-30 20:41:43 +03:00
|
|
|
.tlb_fill = nios2_cpu_tlb_fill,
|
2021-09-11 19:54:25 +03:00
|
|
|
.cpu_exec_interrupt = nios2_cpu_exec_interrupt,
|
2021-02-04 19:39:23 +03:00
|
|
|
.do_interrupt = nios2_cpu_do_interrupt,
|
|
|
|
.do_unaligned_access = nios2_cpu_do_unaligned_access,
|
|
|
|
#endif /* !CONFIG_USER_ONLY */
|
|
|
|
};
|
2017-01-19 01:01:41 +03:00
|
|
|
|
|
|
|
static void nios2_cpu_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
CPUClass *cc = CPU_CLASS(oc);
|
|
|
|
Nios2CPUClass *ncc = NIOS2_CPU_CLASS(oc);
|
|
|
|
|
2018-01-14 05:04:12 +03:00
|
|
|
device_class_set_parent_realize(dc, nios2_cpu_realizefn,
|
|
|
|
&ncc->parent_realize);
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, nios2_properties);
|
cpu: Use DeviceClass reset instead of a special CPUClass reset
The CPUClass has a 'reset' method. This is a legacy from when
TYPE_CPU used not to inherit from TYPE_DEVICE. We don't need it any
more, as we can simply use the TYPE_DEVICE reset. The 'cpu_reset()'
function is kept as the API which most places use to reset a CPU; it
is now a wrapper which calls device_cold_reset() and then the
tracepoint function.
This change should not cause CPU objects to be reset more often
than they are at the moment, because:
* nobody is directly calling device_cold_reset() or
qdev_reset_all() on CPU objects
* no CPU object is on a qbus, so they will not be reset either
by somebody calling qbus_reset_all()/bus_cold_reset(), or
by the main "reset sysbus and everything in the qbus tree"
reset that most devices are reset by
Note that this does not change the need for each machine or whatever
to use qemu_register_reset() to arrange to call cpu_reset() -- that
is necessary because CPU objects are not on any qbus, so they don't
get reset when the qbus tree rooted at the sysbus bus is reset, and
this isn't being changed here.
All the changes to the files under target/ were made using the
included Coccinelle script, except:
(1) the deletion of the now-inaccurate and not terribly useful
"CPUClass::reset" comments was done with a perl one-liner afterwards:
perl -n -i -e '/ CPUClass::reset/ or print' target/*/*.c
(2) this bit of the s390 change was done by hand, because the
Coccinelle script is not sophisticated enough to handle the
parent_reset call being inside another function:
| @@ -96,8 +96,9 @@ static void s390_cpu_reset(CPUState *s, cpu_reset_type type)
| S390CPU *cpu = S390_CPU(s);
| S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
| CPUS390XState *env = &cpu->env;
|+ DeviceState *dev = DEVICE(s);
|
|- scc->parent_reset(s);
|+ scc->parent_reset(dev);
| cpu->env.sigp_order = 0;
| s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20200303100511.5498-1-peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-03-03 13:05:11 +03:00
|
|
|
device_class_set_parent_reset(dc, nios2_cpu_reset, &ncc->parent_reset);
|
2017-01-19 01:01:41 +03:00
|
|
|
|
2017-08-24 19:31:36 +03:00
|
|
|
cc->class_by_name = nios2_cpu_class_by_name;
|
2017-01-19 01:01:41 +03:00
|
|
|
cc->has_work = nios2_cpu_has_work;
|
|
|
|
cc->dump_state = nios2_cpu_dump_state;
|
|
|
|
cc->set_pc = nios2_cpu_set_pc;
|
|
|
|
cc->disas_set_info = nios2_cpu_disas_set_info;
|
2019-04-02 12:47:37 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2021-05-17 13:51:31 +03:00
|
|
|
cc->sysemu_ops = &nios2_sysemu_ops;
|
2017-01-19 01:01:41 +03:00
|
|
|
#endif
|
|
|
|
cc->gdb_read_register = nios2_cpu_gdb_read_register;
|
|
|
|
cc->gdb_write_register = nios2_cpu_gdb_write_register;
|
|
|
|
cc->gdb_num_core_regs = 49;
|
2021-02-04 19:39:23 +03:00
|
|
|
cc->tcg_ops = &nios2_tcg_ops;
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo nios2_cpu_type_info = {
|
|
|
|
.name = TYPE_NIOS2_CPU,
|
|
|
|
.parent = TYPE_CPU,
|
|
|
|
.instance_size = sizeof(Nios2CPU),
|
|
|
|
.instance_init = nios2_cpu_initfn,
|
|
|
|
.class_size = sizeof(Nios2CPUClass),
|
|
|
|
.class_init = nios2_cpu_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void nios2_cpu_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&nios2_cpu_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(nios2_cpu_register_types)
|