Skip to contentSkip to conversation

Nios2 architecture support

GIT PULL Richard Henderson 2 participants 9 messages Jan 23, 2017 – Jan 24, 2017

lore
Share & tools
lore
#0 lore raw

This is me acking this new target. Hopefully Chris and/or Marek will be able to get some gpg keys signed relatively soon.

I had to make one change for the target, updating to rely on the common tlb_flush during reset.

r~

The following changes since commit 3879284d6517dc22529395bdb259f4183b589127:

Merge remote-tracking branch 'remotes/berrange/tags/pull-qio-2017-01-23-2' into staging (2017-01-23 15:59:09 +0000)

are available in the git repository at:

git://github.com/rth7680/qemu.git tags/pull-nios-20170123

for you to fetch changes up to 9a6aa7cc59b7ff0535392241e19c73cde146c506:

nios2: Add support for Nios-II R1 (2017-01-23 13:54:58 -0800)

----------------------------------------------------------------
nios2 target support

----------------------------------------------------------------
Chris Wulff (3):
nios2: Add architecture emulation support
nios2: Add IIC interrupt controller emulation
nios2: Add periodic timer emulation

Marek Vasut (4):
nios2: Add disas entries
nios2: Add usermode binaries emulation
nios2: Add Altera 10M50 GHRD emulation
nios2: Add support for Nios-II R1

 MAINTAINERS                          |    8 +
 arch_init.c                          |    2 +
 configure                            |    5 +
 default-configs/nios2-linux-user.mak |    1 +
 default-configs/nios2-softmmu.mak    |    6 +
 disas/Makefile.objs                  |    1 +
 disas/nios2.c                        | 3534 ++++++++++++++++++++++++++++++++++
 hw/intc/Makefile.objs                |    1 +
 hw/intc/nios2_iic.c                  |  103 +
 hw/nios2/10m50_devboard.c            |  126 ++
 hw/nios2/Makefile.objs               |    1 +
 hw/nios2/boot.c                      |  223 +++
 hw/nios2/boot.h                      |   11 +
 hw/nios2/cpu_pic.c                   |   70 +
 hw/timer/Makefile.objs               |    1 +
 hw/timer/altera_timer.c              |  237 +++
 include/disas/bfd.h                  |    6 +
 include/elf.h                        |    2 +
 include/sysemu/arch_init.h           |    1 +
 linux-user/elfload.c                 |   57 +
 linux-user/main.c                    |  140 +-
 linux-user/nios2/syscall_nr.h        |  329 ++++
 linux-user/nios2/target_cpu.h        |   39 +
 linux-user/nios2/target_signal.h     |   26 +
 linux-user/nios2/target_structs.h    |   58 +
 linux-user/nios2/target_syscall.h    |   37 +
 linux-user/nios2/termbits.h          |  220 +++
 linux-user/signal.c                  |  238 ++-
 linux-user/syscall_defs.h            |    8 +-
 qemu-doc.texi                        |    3 +
 target/nios2/Makefile.objs           |    4 +
 target/nios2/cpu.c                   |  237 +++
 target/nios2/cpu.h                   |  272 +++
 target/nios2/helper.c                |  313 +++
 target/nios2/helper.h                |   27 +
 target/nios2/mmu.c                   |  296 +++
 target/nios2/mmu.h                   |   50 +
 target/nios2/monitor.c               |   35 +
 target/nios2/op_helper.c             |   47 +
 target/nios2/translate.c             |  958 +++++++++
 40 files changed, 7726 insertions(+), 7 deletions(-)
 create mode 100644 default-configs/nios2-linux-user.mak
 create mode 100644 default-configs/nios2-softmmu.mak
 create mode 100644 disas/nios2.c
 create mode 100644 hw/intc/nios2_iic.c
 create mode 100644 hw/nios2/10m50_devboard.c
 create mode 100644 hw/nios2/Makefile.objs
 create mode 100644 hw/nios2/boot.c
 create mode 100644 hw/nios2/boot.h
 create mode 100644 hw/nios2/cpu_pic.c
 create mode 100644 hw/timer/altera_timer.c
 create mode 100644 linux-user/nios2/syscall_nr.h
 create mode 100644 linux-user/nios2/target_cpu.h
 create mode 100644 linux-user/nios2/target_signal.h
 create mode 100644 linux-user/nios2/target_structs.h
 create mode 100644 linux-user/nios2/target_syscall.h
 create mode 100644 linux-user/nios2/termbits.h
 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
#1 lore raw

[Qemu-devel] [PULL 4/7] nios2: Add IIC interrupt controller emulation

From: Chris Wulff <[email protected]>

Add the Altera Nios2 internal interrupt controller model.

Cc Chris Wulff <[email protected]>
Cc Jeff Da Silva <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Sandra Loosemore <[email protected]>
Cc Yves Vandervennet <[email protected]>

Message-Id: <[email protected]>

---
 hw/intc/Makefile.objs |   1 +
 hw/intc/nios2_iic.c   | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)
 create mode 100644 hw/intc/nios2_iic.c
hw/intc/Makefile.objs +1 -0
index 2f44a2d..8948106 100644
@@ -41,3 +41,4 @@ obj-$(CONFIG_S390_FLIC_KVM) += s390_flic_kvm.o
 obj-$(CONFIG_ASPEED_SOC) += aspeed_vic.o
 obj-$(CONFIG_ARM_GIC) += arm_gicv3_cpuif.o
 obj-$(CONFIG_MIPS_CPS) += mips_gic.o
+obj-$(CONFIG_NIOS2) += nios2_iic.o
hw/intc/nios2_iic.c new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.9.3
#2 lore raw

[Qemu-devel] [PULL 5/7] nios2: Add periodic timer emulation

In reply to Richard Henderson

From: Chris Wulff <[email protected]>

Add the Altera timer model.

Cc Chris Wulff <[email protected]>
Cc Jeff Da Silva <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Sandra Loosemore <[email protected]>
Cc Yves Vandervennet <[email protected]>

Message-Id: <[email protected]>

---
 hw/timer/Makefile.objs  |   1 +
 hw/timer/altera_timer.c | 237 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 238 insertions(+)
 create mode 100644 hw/timer/altera_timer.c
hw/timer/Makefile.objs +1 -0
index c1e93a3..71994f2 100644
@@ -18,6 +18,7 @@ common-obj-$(CONFIG_IMX) += imx_gpt.o
 common-obj-$(CONFIG_LM32) += lm32_timer.o
 common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o
 
+obj-$(CONFIG_ALTERA_TIMER) += altera_timer.o
 obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o
 obj-$(CONFIG_EXYNOS4) += exynos4210_pwm.o
 obj-$(CONFIG_EXYNOS4) += exynos4210_rtc.o
hw/timer/altera_timer.c new file +237 -0

237 lines not on this page · raw message

Signature · 1 line
2.9.3
#3 lore raw

[Qemu-devel] [PULL 3/7] nios2: Add usermode binaries emulation

In reply to Richard Henderson

From: Marek Vasut <[email protected]>

Add missing bits for qemu-user required for emulating Altera Nios2 userspace binaries.

Cc Chris Wulff <[email protected]>
Cc Jeff Da Silva <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Sandra Loosemore <[email protected]>
Cc Yves Vandervennet <[email protected]>

Message-Id: <[email protected]>

---
 include/elf.h                     |   2 +
 linux-user/elfload.c              |  57 +++++++
 linux-user/main.c                 | 140 +++++++++++++++-
 linux-user/nios2/syscall_nr.h     | 329 ++++++++++++++++++++++++++++++++++++++
 linux-user/nios2/target_cpu.h     |  39 +++++
 linux-user/nios2/target_signal.h  |  26 +++
 linux-user/nios2/target_structs.h |  58 +++++++
 linux-user/nios2/target_syscall.h |  37 +++++
 linux-user/nios2/termbits.h       | 220 +++++++++++++++++++++++++
 linux-user/signal.c               | 238 ++++++++++++++++++++++++++-
 linux-user/syscall_defs.h         |   8 +-
 11 files changed, 1147 insertions(+), 7 deletions(-)
 create mode 100644 linux-user/nios2/syscall_nr.h
 create mode 100644 linux-user/nios2/target_cpu.h
 create mode 100644 linux-user/nios2/target_signal.h
 create mode 100644 linux-user/nios2/target_structs.h
 create mode 100644 linux-user/nios2/target_syscall.h
 create mode 100644 linux-user/nios2/termbits.h
include/elf.h +2 -0
index 1c2975d..0dbd3e9 100644
@@ -126,6 +126,8 @@ typedef int64_t  Elf64_Sxword;
  */
 #define EM_S390_OLD     0xA390
 
+#define EM_ALTERA_NIOS2 113     /* Altera Nios II soft-core processor */
+
 #define EM_MICROBLAZE      189
 #define EM_MICROBLAZE_OLD  0xBAAB
 
linux-user/elfload.c +57 -0

63 lines not on this page · raw message

linux-user/main.c +138 -2

158 lines not on this page · raw message

linux-user/nios2/syscall_nr.h new file +329 -0

329 lines not on this page · raw message

linux-user/nios2/target_cpu.h new file +39 -0
new file mode 100644
index 0000000..20ab479
@@ -0,0 +1,39 @@
+/*
+ * Nios2 specific CPU ABI and functions for linux-user
+ *
+ * Copyright (c) 2016 Marek Vasut <[email protected]>
+ *
+ * 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 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/>.
+ */
+
+#ifndef TARGET_CPU_H
+#define TARGET_CPU_H
+
+static inline void cpu_clone_regs(CPUNios2State *env, target_ulong newsp)
+{
+    if (newsp) {
+        env->regs[R_SP] = newsp;
+    }
+    env->regs[R_RET0] = 0;
+}
+
+static inline void cpu_set_tls(CPUNios2State *env, target_ulong newtls)
+{
+    /*
+     * Linux kernel 3.10 does not pay any attention to CLONE_SETTLS
+     * in copy_thread(), so QEMU need not do so either.
+     */
+}
+
+#endif
linux-user/nios2/target_signal.h new file +26 -0
new file mode 100644
index 0000000..23a8267
@@ -0,0 +1,26 @@
+#ifndef TARGET_SIGNAL_H
+#define TARGET_SIGNAL_H
+
+#include "cpu.h"
+
+/* this struct defines a stack used during syscall handling */
+
+typedef struct target_sigaltstack {
+    abi_long ss_sp;
+    abi_ulong ss_size;
+    abi_long ss_flags;
+} target_stack_t;
+
+/* sigaltstack controls  */
+#define TARGET_SS_ONSTACK     1
+#define TARGET_SS_DISABLE     2
+
+#define TARGET_MINSIGSTKSZ    2048
+#define TARGET_SIGSTKSZ       8192
+
+static inline abi_ulong get_sp_from_cpustate(CPUNios2State *state)
+{
+    return state->regs[R_SP];
+}
+
+#endif /* TARGET_SIGNAL_H */
linux-user/nios2/target_structs.h new file +58 -0

58 lines not on this page · raw message

linux-user/nios2/target_syscall.h new file +37 -0
new file mode 100644
index 0000000..ca6b7e6
@@ -0,0 +1,37 @@
+#ifndef TARGET_SYSCALL_H
+#define TARGET_SYSCALL_H
+
+#define UNAME_MACHINE "nios2"
+#define UNAME_MINIMUM_RELEASE "3.19.0"
+
+struct target_pt_regs {
+    unsigned long  r8;    /* r8-r15 Caller-saved GP registers */
+    unsigned long  r9;
+    unsigned long  r10;
+    unsigned long  r11;
+    unsigned long  r12;
+    unsigned long  r13;
+    unsigned long  r14;
+    unsigned long  r15;
+    unsigned long  r1;    /* Assembler temporary */
+    unsigned long  r2;    /* Retval LS 32bits */
+    unsigned long  r3;    /* Retval MS 32bits */
+    unsigned long  r4;    /* r4-r7 Register arguments */
+    unsigned long  r5;
+    unsigned long  r6;
+    unsigned long  r7;
+    unsigned long  orig_r2;    /* Copy of r2 ?? */
+    unsigned long  ra;    /* Return address */
+    unsigned long  fp;    /* Frame pointer */
+    unsigned long  sp;    /* Stack pointer */
+    unsigned long  gp;    /* Global pointer */
+    unsigned long  estatus;
+    unsigned long  ea;    /* Exception return address (pc) */
+    unsigned long  orig_r7;
+};
+
+#define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
+
+#endif  /* TARGET_SYSCALL_H */
linux-user/nios2/termbits.h new file +220 -0

220 lines not on this page · raw message

linux-user/signal.c +236 -2

256 lines not on this page · raw message

linux-user/syscall_defs.h +5 -3
index 0b15466..b83e7a5 100644
@@ -70,7 +70,8 @@
 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SH4) \
     || defined(TARGET_M68K) || defined(TARGET_CRIS) \
     || defined(TARGET_UNICORE32) || defined(TARGET_S390X) \
-    || defined(TARGET_OPENRISC) || defined(TARGET_TILEGX)
+    || defined(TARGET_OPENRISC) || defined(TARGET_TILEGX) \
+    || defined(TARGET_NIOS2)
 
 #define TARGET_IOC_SIZEBITS	14
 #define TARGET_IOC_DIRBITS	2
@@ -417,7 +418,7 @@ int do_sigaction(int sig, const struct target_sigaction *act,
     || defined(TARGET_M68K) || defined(TARGET_ALPHA) || defined(TARGET_CRIS) \
     || defined(TARGET_MICROBLAZE) || defined(TARGET_UNICORE32) \
     || defined(TARGET_S390X) || defined(TARGET_OPENRISC) \
-    || defined(TARGET_TILEGX)
+    || defined(TARGET_TILEGX) || defined(TARGET_NIOS2)
 
 #if defined(TARGET_SPARC)
 #define TARGET_SA_NOCLDSTOP    8u
@@ -1974,7 +1975,8 @@ struct target_stat {
     abi_ulong  target_st_ctime_nsec;
     unsigned int __unused[2];
 };
-#elif defined(TARGET_OPENRISC) || defined(TARGET_TILEGX)
+#elif defined(TARGET_OPENRISC) || defined(TARGET_TILEGX) || \
+      defined(TARGET_NIOS2)
 
 /* These are the asm-generic versions of the stat and stat64 structures */
 
Signature · 1 line
2.9.3
#4 lore raw

[Qemu-devel] [PULL 6/7] nios2: Add Altera 10M50 GHRD emulation

In reply to Richard Henderson

From: Marek Vasut <[email protected]>

Add the Altera 10M50 Nios2 GHRD model. This allows emulating the 10M50 development kit with the Nios2 GHRD loaded in the FPGA. It is possible to boot Linux kernel and run userspace, thus far only from initrd as storage support is not yet implemented.

Cc Chris Wulff <[email protected]>
Cc Jeff Da Silva <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Sandra Loosemore <[email protected]>
Cc Yves Vandervennet <[email protected]>

Message-Id: <[email protected]>

---
 hw/nios2/10m50_devboard.c | 126 ++++++++++++++++++++++++++
 hw/nios2/Makefile.objs    |   1 +
 hw/nios2/boot.c           | 223 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/nios2/boot.h           |  11 +++
 hw/nios2/cpu_pic.c        |  70 +++++++++++++++
 5 files changed, 431 insertions(+)
 create mode 100644 hw/nios2/10m50_devboard.c
 create mode 100644 hw/nios2/Makefile.objs
 create mode 100644 hw/nios2/boot.c
 create mode 100644 hw/nios2/boot.h
 create mode 100644 hw/nios2/cpu_pic.c
hw/nios2/10m50_devboard.c new file +126 -0
new file mode 100644
index 0000000..62e5738
@@ -0,0 +1,126 @@
+/*
+ * Altera 10M50 Nios2 GHRD
+ *
+ * Copyright (c) 2016 Marek Vasut <[email protected]>
+ *
+ * Based on LabX device code
+ *
+ * Copyright (c) 2012 Chris Wulff <[email protected]>
+ *
+ * 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 "qapi/error.h"
+#include "qemu-common.h"
+#include "cpu.h"
+
+#include "hw/sysbus.h"
+#include "hw/hw.h"
+#include "hw/char/serial.h"
+#include "sysemu/sysemu.h"
+#include "hw/boards.h"
+#include "exec/memory.h"
+#include "exec/address-spaces.h"
+#include "qemu/config-file.h"
+
+#include "boot.h"
+
+#define BINARY_DEVICE_TREE_FILE    "10m50-devboard.dtb"
+
+static void nios2_10m50_ghrd_init(MachineState *machine)
+{
+    Nios2CPU *cpu;
+    DeviceState *dev;
+    MemoryRegion *address_space_mem = get_system_memory();
+    MemoryRegion *phys_tcm = g_new(MemoryRegion, 1);
+    MemoryRegion *phys_tcm_alias = g_new(MemoryRegion, 1);
+    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
+    MemoryRegion *phys_ram_alias = g_new(MemoryRegion, 1);
+    ram_addr_t tcm_base = 0x0;
+    ram_addr_t tcm_size = 0x1000;    /* 1 kiB, but QEMU limit is 4 kiB */
+    ram_addr_t ram_base = 0x08000000;
+    ram_addr_t ram_size = 0x08000000;
+    qemu_irq *cpu_irq, irq[32];
+    int i;
+
+    /* Physical TCM (tb_ram_1k) with alias at 0xc0000000 */
+    memory_region_init_ram(phys_tcm, NULL, "nios2.tcm", tcm_size, &error_abort);
+    memory_region_init_alias(phys_tcm_alias, NULL, "nios2.tcm.alias",
+                             phys_tcm, 0, tcm_size);
+    vmstate_register_ram_global(phys_tcm);
+    memory_region_add_subregion(address_space_mem, tcm_base, phys_tcm);
+    memory_region_add_subregion(address_space_mem, 0xc0000000 + tcm_base,
+                                phys_tcm_alias);
+
+    /* Physical DRAM with alias at 0xc0000000 */
+    memory_region_init_ram(phys_ram, NULL, "nios2.ram", ram_size, &error_abort);
+    memory_region_init_alias(phys_ram_alias, NULL, "nios2.ram.alias",
+                             phys_ram, 0, ram_size);
+    vmstate_register_ram_global(phys_ram);
+    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
+    memory_region_add_subregion(address_space_mem, 0xc0000000 + ram_base,
+                                phys_ram_alias);
+
+    /* Create CPU -- FIXME */
+    cpu = cpu_nios2_init("nios2");
+
+    /* Register: CPU interrupt controller (PIC) */
+    cpu_irq = nios2_cpu_pic_init(cpu);
+
+    /* Register: Internal Interrupt Controller (IIC) */
+    dev = qdev_create(NULL, "altera,iic");
+    qdev_prop_set_ptr(dev, "cpu", cpu);
+    qdev_init_nofail(dev);
+    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, cpu_irq[0]);
+    for (i = 0; i < 32; i++) {
+        irq[i] = qdev_get_gpio_in(dev, i);
+    }
+
+    /* Register: Altera 16550 UART */
+    serial_mm_init(address_space_mem, 0xf8001600, 2, irq[1], 115200,
+                   serial_hds[0], DEVICE_NATIVE_ENDIAN);
+
+    /* Register: Timer sys_clk_timer  */
+    dev = qdev_create(NULL, "ALTR.timer");
+    qdev_prop_set_uint32(dev, "clock-frequency", 75 * 1000000);
+    qdev_init_nofail(dev);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0xf8001440);
+    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[0]);
+
+    /* Register: Timer sys_clk_timer_1  */
+    dev = qdev_create(NULL, "ALTR.timer");
+    qdev_prop_set_uint32(dev, "clock-frequency", 75 * 1000000);
+    qdev_init_nofail(dev);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0xe0000880);
+    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[5]);
+
+    /* Configure new exception vectors and reset CPU for it to take effect. */
+    cpu->reset_addr = 0xd4000000;
+    cpu->exception_addr = 0xc8000120;
+    cpu->fast_tlb_miss_addr = 0xc0000100;
+
+    nios2_load_kernel(cpu, ram_base, ram_size, machine->initrd_filename,
+                      BINARY_DEVICE_TREE_FILE, NULL);
+}
+
+static void nios2_10m50_ghrd_machine_init(struct MachineClass *mc)
+{
+    mc->desc = "Altera 10M50 GHRD Nios II design";
+    mc->init = nios2_10m50_ghrd_init;
+    mc->is_default = 1;
+}
+
+DEFINE_MACHINE("10m50-ghrd", nios2_10m50_ghrd_machine_init);
hw/nios2/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..6b5c421
@@ -0,0 +1 @@
+obj-y = boot.o cpu_pic.o 10m50_devboard.o
hw/nios2/boot.c new file +223 -0

223 lines not on this page · raw message

hw/nios2/boot.h new file +11 -0
new file mode 100644
index 0000000..3116753
@@ -0,0 +1,11 @@
+#ifndef NIOS2_BOOT_H
+#define NIOS2_BOOT_H
+
+#include "hw/hw.h"
+#include "cpu.h"
+
+void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, uint32_t ramsize,
+                       const char *initrd_filename, const char *dtb_filename,
+                       void (*machine_cpu_reset)(Nios2CPU *));
+
+#endif /* NIOS2_BOOT_H */
hw/nios2/cpu_pic.c new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.9.3
#5 lore raw

[Qemu-devel] [PULL 7/7] nios2: Add support for Nios-II R1

In reply to Richard Henderson

From: Marek Vasut <[email protected]>

Add remaining bits of the Altera NiosII R1 support into qemu, which is documentation, MAINTAINERS file entry, configure bits, arch_init and configuration files for both linux-user (userland binaries) and softmmu (hardware emulation).

Cc Chris Wulff <[email protected]>
Cc Jeff Da Silva <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Sandra Loosemore <[email protected]>
Cc Yves Vandervennet <[email protected]>

Message-Id: <[email protected]>

---
 MAINTAINERS                          | 8 ++++++++
 arch_init.c                          | 2 ++
 configure                            | 5 +++++
 default-configs/nios2-linux-user.mak | 1 +
 default-configs/nios2-softmmu.mak    | 6 ++++++
 include/sysemu/arch_init.h           | 1 +
 qemu-doc.texi                        | 3 +++
 7 files changed, 26 insertions(+)
 create mode 100644 default-configs/nios2-linux-user.mak
 create mode 100644 default-configs/nios2-softmmu.mak
MAINTAINERS +8 -0
index ad10004..69047e0 100644
@@ -181,6 +181,14 @@ F: disas/moxie.c
 F: hw/moxie/
 F: default-configs/moxie-softmmu.mak
 
+NiosII
+M: Chris Wulff <[email protected]>
+M: Marek Vasut <[email protected]>
+S: Maintained
+F: target/nios2/
+F: hw/nios2/
+F: disas/nios2.c
+
 OpenRISC
 M: Jia Liu <[email protected]>
 S: Maintained
arch_init.c +2 -0
index 6c4e287..828a271 100644
@@ -63,6 +63,8 @@ int graphic_depth = 32;
 #define QEMU_ARCH QEMU_ARCH_MIPS
 #elif defined(TARGET_MOXIE)
 #define QEMU_ARCH QEMU_ARCH_MOXIE
+#elif defined(TARGET_NIOS2)
+#define QEMU_ARCH QEMU_ARCH_NIOS2
 #elif defined(TARGET_OPENRISC)
 #define QEMU_ARCH QEMU_ARCH_OPENRISC
 #elif defined(TARGET_PPC)
configure +5 -0
index 53a39ba..baacbb0 100755
@@ -5933,6 +5933,8 @@ case "$target_name" in
   ;;
   moxie)
   ;;
+  nios2)
+  ;;
   or32)
     TARGET_ARCH=openrisc
     TARGET_BASE_ARCH=openrisc
@@ -6135,6 +6137,9 @@ for i in $ARCH $TARGET_BASE_ARCH ; do
   moxie*)
     disas_config "MOXIE"
   ;;
+  nios2)
+    disas_config "NIOS2"
+  ;;
   or32)
     disas_config "OPENRISC"
   ;;
default-configs/nios2-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..5be3eb7
@@ -0,0 +1 @@
+# Default configuration for nios2-linux-user
default-configs/nios2-softmmu.mak new file +6 -0
new file mode 100644
index 0000000..74dc70c
@@ -0,0 +1,6 @@
+# Default configuration for nios2-softmmu
+
+CONFIG_NIOS2=y
+CONFIG_SERIAL=y
+CONFIG_PTIMER=y
+CONFIG_ALTERA_TIMER=y
include/sysemu/arch_init.h +1 -0
index 20b01e3..2bf16b2 100644
@@ -23,6 +23,7 @@ enum {
     QEMU_ARCH_UNICORE32 = (1 << 14),
     QEMU_ARCH_MOXIE = (1 << 15),
     QEMU_ARCH_TRICORE = (1 << 16),
+    QEMU_ARCH_NIOS2 = (1 << 17),
 };
 
 extern const uint32_t arch_type;
qemu-doc.texi +3 -0
index 0b2746f..fe7b69b 100644
@@ -2901,6 +2901,9 @@ The binary format is detected automatically.
 @command{qemu-mips} TODO.
 @command{qemu-mipsel} TODO.
 
+@cindex user mode (NiosII)
+@command{qemu-nios2} TODO.
+
 @cindex user mode (PowerPC)
 @command{qemu-ppc64abi32} TODO.
 @command{qemu-ppc64} TODO.
Signature · 1 line
2.9.3
#6 lore raw

[Qemu-devel] [PULL 1/7] nios2: Add architecture emulation support

In reply to Richard Henderson

From: Chris Wulff <[email protected]>

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.

Cc Chris Wulff <[email protected]>
Cc Jeff Da Silva <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Sandra Loosemore <[email protected]>
Cc Yves Vandervennet <[email protected]>
Cc Alexander Graf <[email protected]>

Message-Id: <[email protected]>

[rth: Remove tlb_flush from nios2_cpu_reset.]
---
 target/nios2/Makefile.objs |   4 +
 target/nios2/cpu.c         | 237 +++++++++++
 target/nios2/cpu.h         | 272 +++++++++++++
 target/nios2/helper.c      | 313 +++++++++++++++
 target/nios2/helper.h      |  27 ++
 target/nios2/mmu.c         | 296 ++++++++++++++
 target/nios2/mmu.h         |  50 +++
 target/nios2/monitor.c     |  35 ++
 target/nios2/op_helper.c   |  47 +++
 target/nios2/translate.c   | 958 +++++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 2239 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
target/nios2/Makefile.objs new file +4 -0
new file mode 100644
index 0000000..2a11c5c
@@ -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)
target/nios2/cpu.c new file +237 -0

237 lines not on this page · raw message

target/nios2/cpu.h new file +272 -0

272 lines not on this page · raw message

target/nios2/helper.c new file +313 -0

313 lines not on this page · raw message

target/nios2/helper.h new file +27 -0
new file mode 100644
index 0000000..b0cb914
@@ -0,0 +1,27 @@
+/*
+ * Altera Nios II helper routines header.
+ *
+ * Copyright (c) 2012 Chris Wulff <[email protected]>
+ *
+ * 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>
+ */
+
+DEF_HELPER_2(raise_exception, void, env, i32)
+
+#if !defined(CONFIG_USER_ONLY)
+DEF_HELPER_2(mmu_read_debug, void, env, i32)
+DEF_HELPER_3(mmu_write, void, env, i32, i32)
+DEF_HELPER_1(check_interrupts, void, env)
+#endif
target/nios2/mmu.c new file +296 -0

296 lines not on this page · raw message

target/nios2/mmu.h new file +50 -0

50 lines not on this page · raw message

target/nios2/monitor.c new file +35 -0
new file mode 100644
index 0000000..422c816
@@ -0,0 +1,35 @@
+/*
+ * QEMU monitor
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu/osdep.h"
+#include "cpu.h"
+#include "monitor/monitor.h"
+#include "monitor/hmp-target.h"
+#include "hmp.h"
+
+void hmp_info_tlb(Monitor *mon, const QDict *qdict)
+{
+    CPUArchState *env1 = mon_get_cpu_env();
+
+    dump_mmu((FILE *)mon, (fprintf_function)monitor_printf, env1);
+}
target/nios2/op_helper.c new file +47 -0

47 lines not on this page · raw message

target/nios2/translate.c new file +958 -0

958 lines not on this page · raw message

Signature · 1 line
2.9.3
#7 lore raw

[Qemu-devel] [PULL 2/7] nios2: Add disas entries

In reply to Richard Henderson

From: Marek Vasut <[email protected]>

Add nios2 disassembler support. This patch is composed from binutils files from commit "Opcodes and assembler support for Nios II R2". The files from binutils used in this patch are:

include/opcode/nios2.h
include/opcode/nios2r1.h
include/opcode/nios2r2.h
opcodes/nios2-opc.c
opcodes/nios2-dis.c

Checkpatch says total: 114 errors, 0 warnings, 3609 lines checked , which is caused by a different coding style in those files. These warnings and errors are not addressed To let these files be easily synchronized between binutils and qemu.

Cc Chris Wulff <[email protected]>
Cc Jeff Da Silva <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Sandra Loosemore <[email protected]>
Cc Yves Vandervennet <[email protected]>

Message-Id: <[email protected]>

---
 disas/Makefile.objs |    1 +
 disas/nios2.c       | 3534 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/disas/bfd.h |    6 +
 3 files changed, 3541 insertions(+)
 create mode 100644 disas/nios2.c
disas/Makefile.objs +1 -0
index 09bc992..ac79d16 100644
@@ -14,6 +14,7 @@ common-obj-$(CONFIG_IA64_DIS) += ia64.o
 common-obj-$(CONFIG_M68K_DIS) += m68k.o
 common-obj-$(CONFIG_MICROBLAZE_DIS) += microblaze.o
 common-obj-$(CONFIG_MIPS_DIS) += mips.o
+common-obj-$(CONFIG_NIOS2_DIS) += nios2.o
 common-obj-$(CONFIG_MOXIE_DIS) += moxie.o
 common-obj-$(CONFIG_PPC_DIS) += ppc.o
 common-obj-$(CONFIG_S390_DIS) += s390.o
disas/nios2.c new file +3534 -0

2,993 lines not on this page · raw message

include/disas/bfd.h +6 -0
index 8a3488c..0435b8c 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.9.3

Part of the diff is not shown here. View the raw message.

#8 lore raw
In reply to Richard Henderson
Quoted 16 lines · Richard Henderson

This is me acking this new target. Hopefully Chris and/or Marek will be able to get some gpg keys signed relatively soon.

I had to make one change for the target, updating to rely on the common tlb_flush during reset.

r~

The following changes since commit 3879284d6517dc22529395bdb259f4183b589127:

Merge remote-tracking branch 'remotes/berrange/tags/pull-qio-2017-01-23-2' into staging (2017-01-23 15:59:09 +0000)

are available in the git repository at:

Quoted 8 lines

git://github.com/rth7680/qemu.git tags/pull-nios-20170123

for you to fetch changes up to 9a6aa7cc59b7ff0535392241e19c73cde146c506:

nios2: Add support for Nios-II R1 (2017-01-23 13:54:58 -0800)

----------------------------------------------------------------
nios2 target support

Fails to build, OSX:

/Users/pm215/src/qemu-for-merges/target/nios2/helper.c:293:63: error:
format specifies type 'unsigne
d long' but the argument has type 'vaddr' (aka 'unsigned long long') [-Werror,-Wformat]

            qemu_log("cpu_get_phys_page debug MISS: %08lX\n", addr);
                                                    ~~~~~     ^~~~
                                                    %08llX

thanks
-- PMM