qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH V8 2/7] nios2: Add architecture emulation suppor


From: Marek Vasut
Subject: Re: [Qemu-devel] [PATCH V8 2/7] nios2: Add architecture emulation support
Date: Tue, 17 Jan 2017 09:49:27 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0

On 01/17/2017 09:16 AM, Alexander Graf wrote:
> 
> 
>> Am 17.01.2017 um 01:18 schrieb Marek Vasut <address@hidden>:
>>
>>> On 01/16/2017 11:21 PM, Alexander Graf wrote:
>>>
>>>
>>>> On 31/12/2016 14:22, Marek Vasut wrote:
>>>> From: Chris Wulff <address@hidden>
>>>>
>>>> Add support for emulating Altera NiosII R1 architecture into qemu.
>>>> This patch is based on previous work by Chris Wulff from 2012 and
>>>> updated to latest mainline QEMU.
>>>>
>>>> Signed-off-by: Marek Vasut <address@hidden>
>>>> Cc: Chris Wulff <address@hidden>
>>>> Cc: Jeff Da Silva <address@hidden>
>>>> Cc: Ley Foon Tan <address@hidden>
>>>> Cc: Sandra Loosemore <address@hidden>
>>>> Cc: Yves Vandervennet <address@hidden>
>>>> ---
>>>> V3: Thorough cleanup, deal with the review comments all over the place
>>>> V4: - Use extract32()
>>>>    - Fix gen_goto_tb() , suppress tcg_gen_goto_tb()
>>>>    - Clean up gen_check_supervisor() helper
>>>>    - Use TCGMemOp type for flags
>>>>    - Drop jump labels from wrctl/rdctl
>>>>    - More TCG cleanup
>>>> V5: - Simplify load/store handling
>>>>    - Handle loads into R_ZERO from protected page, add comment
>>>> V6: - Fix division opcode handling
>>>>    - Add missing disas handling
>>>>    - V5 review comments cleanup
>>>> V7: - Drop newline at the end of file
>>>> V8: - Rebase on top of qemu/master
>>>>    - Move the target-nios2 to target/nios2
>>>> ---
>>>> target/nios2/Makefile.objs |   4 +
>>>> target/nios2/cpu.c         | 232 +++++++++++
>>>> target/nios2/cpu.h         | 269 +++++++++++++
>>>> target/nios2/helper.c      | 313 +++++++++++++++
>>>> target/nios2/helper.h      |  27 ++
>>>> target/nios2/mmu.c         | 292 ++++++++++++++
>>>> target/nios2/mmu.h         |  54 +++
>>>> target/nios2/monitor.c     |  35 ++
>>>> target/nios2/op_helper.c   |  47 +++
>>>> target/nios2/translate.c   | 953
>>>> +++++++++++++++++++++++++++++++++++++++++++++
>>>> 10 files changed, 2226 insertions(+)
>>>> create mode 100644 target/nios2/Makefile.objs
>>>> create mode 100644 target/nios2/cpu.c
>>>> create mode 100644 target/nios2/cpu.h
>>>> create mode 100644 target/nios2/helper.c
>>>> create mode 100644 target/nios2/helper.h
>>>> create mode 100644 target/nios2/mmu.c
>>>> create mode 100644 target/nios2/mmu.h
>>>> create mode 100644 target/nios2/monitor.c
>>>> create mode 100644 target/nios2/op_helper.c
>>>> create mode 100644 target/nios2/translate.c
>>>>
>>>> diff --git a/target/nios2/Makefile.objs b/target/nios2/Makefile.objs
>>>> new file mode 100644
>>>> index 0000000..2a11c5c
>>>> --- /dev/null
>>>> +++ b/target/nios2/Makefile.objs
>>>> @@ -0,0 +1,4 @@
>>>> +obj-y += translate.o op_helper.o helper.o cpu.o mmu.o
>>>> +obj-$(CONFIG_SOFTMMU) += monitor.o
>>>> +
>>>> +$(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
>>>> diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
>>>> new file mode 100644
>>>> index 0000000..658d684
>>>> --- /dev/null
>>>> +++ b/target/nios2/cpu.c
>>>> @@ -0,0 +1,232 @@
>>>> +/*
>>>> + * QEMU Nios II CPU
>>>> + *
>>>> + * Copyright (c) 2012 Chris Wulff <address@hidden>
>>>> + *
>>>> + * 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"
>>>> +#include "qemu-common.h"
>>>> +#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;
>>>> +
>>>> +    env->regs[R_PC] = value;
>>>> +}
>>>> +
>>>> +static bool nios2_cpu_has_work(CPUState *cs)
>>>> +{
>>>> +    return cs->interrupt_request & (CPU_INTERRUPT_HARD |
>>>> CPU_INTERRUPT_NMI);
>>>> +}
>>>> +
>>>> +/* CPUClass::reset() */
>>>> +static void nios2_cpu_reset(CPUState *cs)
>>>> +{
>>>> +    Nios2CPU *cpu = NIOS2_CPU(cs);
>>>> +    Nios2CPUClass *ncc = NIOS2_CPU_GET_CLASS(cpu);
>>>> +    CPUNios2State *env = &cpu->env;
>>>> +
>>>> +    if (qemu_loglevel_mask(CPU_LOG_RESET)) {
>>>> +        qemu_log("CPU Reset (CPU %d)\n", cs->cpu_index);
>>>> +        log_cpu_state(cs, 0);
>>>> +    }
>>>> +
>>>> +    ncc->parent_reset(cs);
>>>> +
>>>> +    tlb_flush(cs, 1);
>>>> +
>>>> +    memset(env->regs, 0, sizeof(uint32_t) * NUM_CORE_REGS);
>>>> +    env->regs[R_PC] = cpu->reset_addr;
>>>> +
>>>> +#if defined(CONFIG_USER_ONLY)
>>>> +    /* Start in user mode with interrupts enabled. */
>>>> +    env->regs[CR_STATUS] = CR_STATUS_U | CR_STATUS_PIE;
>>>
>>> So what is the value of CR_STATUS after reset in softmmu land then?
>>> Random value from before reset? Probably not what you want :).
>>
>> Dropped, yeah.
> 
> Dropped? That wasn't my intention :).
> 
> I was just too tired to grasp the code. CR_STATUS is 0 for softmmu thanks to 
> the memset, so irqs are disabled. For linux-user, applications expect irqs to 
> work, so it needs to be explicitly set to on.
> 
> The code above is perfectly correct I think.

I ran into an issue booting Linux, so now I'm explicitly initing the
CR_STATUS in both cases. For user case, to the above, otherwise to 0.

-- 
Best regards,
Marek Vasut



reply via email to

[Prev in Thread] Current Thread [Next in Thread]