Skip to contentSkip to conversation

nios2: Add disas entries

PATCH Superseded Marek Vasut 3 participants 21 messages Sep 27, 2016 – Nov 1, 2016

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#13 lore raw

PATCH 4/7 nios2: Add IIC interrupt controller emulation

In reply to Marek Vasut

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]>
---
 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 05ec21b..3c29fe7 100644
@@ -38,3 +38,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
#14 lore raw

PATCH 5/7 nios2: Add periodic timer emulation

In reply to Marek Vasut

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]>
---
 hw/timer/Makefile.objs  |   1 +
 hw/timer/altera_timer.c | 236 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 237 insertions(+)
 create mode 100644 hw/timer/altera_timer.c
hw/timer/Makefile.objs +1 -0
index 7ba8c23..0867a64 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 +236 -0

236 lines not on this page · raw message

Signature · 1 line
2.9.3
#12 lore raw

PATCH 3/7 nios2: Add usermode binaries emulation

In reply to Marek Vasut

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]>
---
 include/elf.h                     |   2 +
 linux-user/elfload.c              |  58 +++++++
 linux-user/main.c                 | 136 +++++++++++++++-
 linux-user/nios2/syscall_nr.h     | 330 ++++++++++++++++++++++++++++++++++++++
 linux-user/nios2/target_cpu.h     |  38 +++++
 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               | 237 ++++++++++++++++++++++++++-
 linux-user/syscall_defs.h         |   7 +-
 11 files changed, 1142 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 +58 -0

64 lines not on this page · raw message

linux-user/main.c +134 -2

154 lines not on this page · raw message

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

330 lines not on this page · raw message

linux-user/nios2/target_cpu.h new file +38 -0
new file mode 100644
index 0000000..5b1e195
@@ -0,0 +1,38 @@
+/*
+ * 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..23da0d6
@@ -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 +235 -2

255 lines not on this page · raw message

linux-user/syscall_defs.h +4 -3
index 9fdbe86..36b0c1e 100644
@@ -68,7 +68,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
@@ -387,7 +388,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
@@ -1944,7 +1945,7 @@ 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
#16 lore raw

PATCH 7/7 nios2: Add support for Nios-II R1

In reply to Marek Vasut

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]>
---
 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 f3c1f7f..ad366ca 100644
@@ -158,6 +158,14 @@ S: Maintained
 F: target-moxie/
 F: disas/moxie.c
 
+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 5cc58b2..20d83ff 100644
@@ -64,6 +64,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 8fa62ad..21d1e34 100755
@@ -5669,6 +5669,8 @@ case "$target_name" in
   ;;
   moxie)
   ;;
+  nios2)
+  ;;
   or32)
     TARGET_ARCH=openrisc
     TARGET_BASE_ARCH=openrisc
@@ -5862,6 +5864,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 1c9dad1..fe60e11 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 f37fd31..1e40d09 100644
@@ -2856,6 +2856,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
#15 lore raw

PATCH 6/7 nios2: Add Altera 10M50 GHRD emulation

In reply to Marek Vasut

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]>
---
 hw/nios2/10m50_devboard.c | 125 ++++++++++++++++++++++++++
 hw/nios2/Makefile.objs    |   1 +
 hw/nios2/boot.c           | 223 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/nios2/boot.h           |  11 +++
 4 files changed, 360 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
hw/nios2/10m50_devboard.c new file +125 -0
new file mode 100644
index 0000000..8312fd9
@@ -0,0 +1,125 @@
+/*
+ * 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->env.reset_addr = 0xd4000000;
+    cpu->env.exception_addr = 0xc8000120;
+    cpu->env.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..edf3046
@@ -0,0 +1,11 @@
+#ifndef __NIOS2_BOOT__
+#define __NIOS2_BOOT__
+
+#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__ */
Signature · 1 line
2.9.3
#1 lore raw

PATCH 2/7 nios2: Add architecture emulation support

In reply to Marek Vasut

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]>
---
 hw/nios2/cpu_pic.c         |   70 +++
 target-nios2/Makefile.objs |    4 +
 target-nios2/cpu.c         |  229 +++++++
 target-nios2/cpu.h         |  267 +++++++++
 target-nios2/helper.c      |  304 ++++++++++
 target-nios2/helper.h      |   41 ++
 target-nios2/instruction.c | 1427 ++++++++++++++++++++++++++++++++++++++++++++
 target-nios2/instruction.h |  279 +++++++++
 target-nios2/machine.c     |   38 ++
 target-nios2/mmu.c         |  292 +++++++++
 target-nios2/mmu.h         |   54 ++
 target-nios2/monitor.c     |   35 ++
 target-nios2/op_helper.c   |   86 +++
 target-nios2/translate.c   |  242 ++++++++
 14 files changed, 3368 insertions(+)
 create mode 100644 hw/nios2/cpu_pic.c
 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/instruction.c
 create mode 100644 target-nios2/instruction.h
 create mode 100644 target-nios2/machine.c
 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
hw/nios2/cpu_pic.c new file +70 -0
new file mode 100644
index 0000000..0f95987
@@ -0,0 +1,70 @@
+/*
+ * Altera Nios2 CPU PIC
+ *
+ * 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.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 "qemu/config-file.h"
+
+#include "boot.h"
+
+static void nios2_pic_cpu_handler(void *opaque, int irq, int level)
+{
+    Nios2CPU *cpu = opaque;
+    CPUNios2State *env = &cpu->env;
+    CPUState *cs = CPU(cpu);
+    int type = irq ? CPU_INTERRUPT_NMI : CPU_INTERRUPT_HARD;
+
+    if (type == CPU_INTERRUPT_HARD) {
+        env->irq_pending = level;
+
+        if (level && (env->regs[CR_STATUS] & CR_STATUS_PIE)) {
+            env->irq_pending = 0;
+            cpu_interrupt(cs, type);
+        } else if (!level) {
+            env->irq_pending = 0;
+            cpu_reset_interrupt(cs, type);
+        }
+    } else {
+        if (level) {
+            cpu_interrupt(cs, type);
+        } else {
+            cpu_reset_interrupt(cs, type);
+        }
+    }
+}
+
+void nios2_check_interrupts(CPUNios2State *env)
+{
+    Nios2CPU *cpu = nios2_env_get_cpu(env);
+    CPUState *cs = CPU(cpu);
+
+    if (env->irq_pending) {
+        env->irq_pending = 0;
+        cpu_interrupt(cs, CPU_INTERRUPT_HARD);
+    }
+}
+
+qemu_irq *nios2_cpu_pic_init(Nios2CPU *cpu)
+{
+    return qemu_allocate_irqs(nios2_pic_cpu_handler, cpu, 2);
+}
target-nios2/Makefile.objs new file +4 -0
new file mode 100644
index 0000000..ea6a528
@@ -0,0 +1,4 @@
+obj-y += translate.o op_helper.o helper.o cpu.o mmu.o instruction.o
+obj-$(CONFIG_SOFTMMU) += monitor.o
+
+$(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
target-nios2/cpu.c new file +229 -0

229 lines not on this page · raw message

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

267 lines not on this page · raw message

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

304 lines not on this page · raw message

target-nios2/helper.h new file +41 -0

41 lines not on this page · raw message

target-nios2/instruction.c new file +1427 -0

1,427 lines not on this page · raw message

target-nios2/instruction.h new file +279 -0

279 lines not on this page · raw message

target-nios2/machine.c new file +38 -0
new file mode 100644
index 0000000..da2cb04
@@ -0,0 +1,38 @@
+/*
+ * Altera Nios II MMU emulation for qemu.
+ *
+ * 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>
+ */
+
+/*
+ * FIXME: Convert to VMstate
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+#include "hw/boards.h"
+
+void cpu_save(QEMUFile *f, void *opaque)
+{
+    /* TODO */
+}
+
+int cpu_load(QEMUFile *f, void *opaque, int version_id)
+{
+    /* TODO */
+    return 0;
+}
target-nios2/mmu.c new file +292 -0

292 lines not on this page · raw message

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

49 lines not on this page · raw message

target-nios2/monitor.c new file +35 -0
new file mode 100644
index 0000000..f3fa4cd

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

target-nios2/op_helper.c new file +86 -0

86 lines not on this page · raw message

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

242 lines not on this page · 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.

#0 lore raw

PATCH v2 1/7 nios2: Add disas entries

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

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]>

---
V2: Replace the nios2.c with GPL2 licensed version

---
 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.

#2 lore raw

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

In reply to Marek Vasut
Quoted 1 line
 hw/nios2/cpu_pic.c         |   70 +++

Why is this in this patch?

Quoted 3 lines
 target-nios2/instruction.c | 1427 ++++++++++++++++++++++++++++++++++++++++++++
 target-nios2/instruction.h |  279 +++++++++
 target-nios2/translate.c   |  242 ++++++++

Why are these files separate?

target-nios2/cpu.c line 148

Quoted 6 lines
target-nios2/cpu.c new file +6 -0
+    if (n < 32)		/* GP regs */
+        return gdb_get_reg32(mem_buf, env->regs[n]);
+    else if (n == 32)	/* PC */
+        return gdb_get_reg32(mem_buf, env->regs[R_PC]);
+    else if (n < 49)	/* Status regs */
+        return gdb_get_reg32(mem_buf, env->regs[n - 1]);

Use checkpatch.pl; the formatting is wrong.

There's no particular reason why R_PC needs to be 64; if you change it to 32, you can simplify this.

target-nios2/cpu.h line 176

Quoted 7 lines
target-nios2/cpu.h new file +7 -0
+struct CPUNios2State {
+    uint32_t regs[NUM_CORE_REGS];
+
+    /* Addresses that are hard-coded in the FPGA build settings */
+    uint32_t reset_addr;
+    uint32_t exception_addr;
+    uint32_t fast_tlb_miss_addr;

These three should go after ...

target-nios2/cpu.h line 184

Quoted 8 lines
target-nios2/cpu.h new file +8 -0
+
+#if !defined(CONFIG_USER_ONLY)
+    Nios2MMU mmu;
+
+    uint32_t irq_pending;
+#endif
+
+    CPU_COMMON

... here, or even into ...

Quoted 5 lines
target-nios2/cpu.h new file +5 -0
+};
+
+/**
+ * Nios2CPU:
+ * @env: #CPUNios2State

target-nios2/cpu.h line 199

Quoted 10 lines
target-nios2/cpu.h new file +10 -0
+ *
+ * A Nios2 CPU.
+ */
+typedef struct Nios2CPU {
+    /*< private >*/
+    CPUState parent_obj;
+    /*< public >*/
+
+    CPUNios2State env;
+    bool mmu_present;

... here.

target-nios2/instruction.c line 43

Quoted 2 lines
target-nios2/instruction.c new file +2 -0
+static inline void t_gen_helper_raise_exception(DisasContext *dc,
+                                                uint32_t index)

Remove all of the inline markers and let the compiler decide.

target-nios2/instruction.c line 92

Quoted 9 lines
target-nios2/instruction.c new file +9 -0
+static void gen_check_supervisor(DisasContext *dc, TCGLabel *label)
+{
+    TCGLabel *l1 = gen_new_label();
+
+    TCGv_i32 tmp = tcg_temp_new();
+    tcg_gen_andi_tl(tmp, dc->cpu_R[CR_STATUS], CR_STATUS_U);
+    tcg_gen_brcond_tl(TCG_COND_EQ, dc->cpu_R[R_ZERO], tmp, l1);
+    t_gen_helper_raise_exception(dc, EXCP_SUPERI);
+    tcg_gen_br(label);

The supervisor check should be done at translate time by checking dc->tb->flags & CR_STATUS_U.

target-nios2/instruction.c line 130

Quoted 7 lines
target-nios2/instruction.c new file +7 -0
+#ifdef CALL_TRACING
+    TCGv_i32 tmp = tcg_const_i32(dc->pc);
+    TCGv_i32 tmp2 = tcg_const_i32((dc->pc & 0xF0000000) | (instr->imm26 * 4));
+    gen_helper_call_status(tmp, tmp2);
+    tcg_temp_free_i32(tmp);
+    tcg_temp_free_i32(tmp2);
+#endif

What's the point of this?

Quoted 7 lines
target-nios2/instruction.c new file +7 -0
+/*
+ * I-Type instructions
+ */
+
+/* rB <- 0x000000 : Mem8[rA + @(IMM16)] */
+static void ldbu(DisasContext *dc, uint32_t code)
+{

target-nios2/instruction.c line 165

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+    I_TYPE(instr, code);
+
+    TCGv addr = tcg_temp_new();
+    tcg_gen_addi_tl(addr, dc->cpu_R[instr->a],
+                    (int32_t)((int16_t)instr->imm16));
+
+    tcg_gen_qemu_ld8u(dc->cpu_R[instr->b], addr, dc->mem_idx);
+
+    tcg_temp_free(addr);
+}

You should have helper functions so that you don't have to replicate 12 line functions. Use the tcg_gen_qemu_ld_tl function, and the TCGMemOp flags to help merge all load instructions, and all store instructions.

target-nios2/instruction.c line 174

Quoted 8 lines
target-nios2/instruction.c new file +8 -0
+/* rB <- rA + IMM16 */
+static void addi(DisasContext *dc, uint32_t code)
+{
+    I_TYPE(instr, code);
+
+    TCGv imm = tcg_temp_new();
+    tcg_gen_addi_tl(dc->cpu_R[instr->b], dc->cpu_R[instr->a],
+                    (int32_t)((int16_t)instr->imm16));

The double cast is pointless, as are the extra parenthesis.

You're not doing anything to make sure that r0 reads as 0, and ignores writes. You need to look at target-alpha, target-mips, or target-sparc to see various ways in which a zero register may be handled.

You should handle the special case of movi, documented as addi rb, r0, imm, so that the common method of loading a small value does not require extra tcg opcodes.

Similarly for the other (common) aliases, like mov and nop, which are both aliased to add.

target-nios2/instruction.c line 323

Quoted 6 lines
target-nios2/instruction.c new file +6 -0
+/* Initializes the data cache line currently caching address rA + @(IMM16) */
+static void initda(DisasContext *dc __attribute__((unused)),
+                   uint32_t code __attribute__((unused)))
+{
+    /* TODO */
+}

This will always be a nop for qemu.

Quoted 7 lines
target-nios2/instruction.c new file +7 -0
+static void blt(DisasContext *dc, uint32_t code)
+{
+    I_TYPE(instr, code);
+
+    TCGLabel *l1 = gen_new_label();
+
+    tcg_gen_brcond_tl(TCG_COND_LT, dc->cpu_R[instr->a],

target-nios2/instruction.c line 369

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+                      dc->cpu_R[instr->b], l1);
+
+    gen_goto_tb(dc, 0, dc->pc + 4);
+
+    gen_set_label(l1);
+
+    gen_goto_tb(dc, 1, dc->pc + 4 + (int16_t)(instr->imm16 & 0xFFFC));
+
+    dc->is_jmp = DISAS_TB_JUMP;
+}

These really require a helper function.

target-nios2/instruction.c line 446

Quoted 2 lines
target-nios2/instruction.c new file +2 -0
+/* rB <- 0x000000 : Mem8[rA + @(IMM16)] (bypassing cache) */
+static void ldbuio(DisasContext *dc, uint32_t code)

Reuse ldbu; qemu will never implement caches.

target-nios2/instruction.c line 467

Quoted 9 lines
target-nios2/instruction.c new file +9 -0
+/* rB <- (rA * @(IMM16))(31..0) */
+static void muli(DisasContext *dc, uint32_t code)
+{
+    I_TYPE(instr, code);
+
+    TCGv imm = tcg_temp_new();
+    tcg_gen_muli_i32(dc->cpu_R[instr->b], dc->cpu_R[instr->a],
+                     (int32_t)((int16_t)instr->imm16));
+    tcg_temp_free(imm);

imm is unused.

Quoted 55 lines
target-nios2/instruction.c new file +55 -0
+static const Nios2Instruction i_type_instructions[I_TYPE_COUNT] = {
+    [CALL]    = INSTRUCTION(call),
+    [JMPI]    = INSTRUCTION(jmpi),
+    [0x02]    = INSTRUCTION_ILLEGAL(),
+    [LDBU]    = INSTRUCTION(ldbu),
+    [ADDI]    = INSTRUCTION(addi),
+    [STB]     = INSTRUCTION(stb),
+    [BR]      = INSTRUCTION(br),
+    [LDB]     = INSTRUCTION(ldb),
+    [CMPGEI]  = INSTRUCTION(cmpgei),
+    [0x09]    = INSTRUCTION_ILLEGAL(),
+    [0x0a]    = INSTRUCTION_ILLEGAL(),
+    [LDHU]    = INSTRUCTION(ldhu),
+    [ANDI]    = INSTRUCTION(andi),
+    [STH]     = INSTRUCTION(sth),
+    [BGE]     = INSTRUCTION(bge),
+    [LDH]     = INSTRUCTION(ldh),
+    [CMPLTI]  = INSTRUCTION(cmplti),
+    [0x11]    = INSTRUCTION_ILLEGAL(),
+    [0x12]    = INSTRUCTION_ILLEGAL(),
+    [INITDA]  = INSTRUCTION(initda),
+    [ORI]     = INSTRUCTION(ori),
+    [STW]     = INSTRUCTION(stw),
+    [BLT]     = INSTRUCTION(blt),
+    [LDW]     = INSTRUCTION(ldw),
+    [CMPNEI]  = INSTRUCTION(cmpnei),
+    [0x19]    = INSTRUCTION_ILLEGAL(),
+    [0x1a]    = INSTRUCTION_ILLEGAL(),
+    [FLUSHDA] = INSTRUCTION_NOP(flushda),
+    [XORI]    = INSTRUCTION(xori),
+    [0x1d]    = INSTRUCTION_ILLEGAL(),
+    [BNE]     = INSTRUCTION(bne),
+    [0x1f]    = INSTRUCTION_ILLEGAL(),
+    [CMPEQI]  = INSTRUCTION(cmpeqi),
+    [0x21]    = INSTRUCTION_ILLEGAL(),
+    [0x22]    = INSTRUCTION_ILLEGAL(),
+    [LDBUIO]  = INSTRUCTION(ldbuio),
+    [MULI]    = INSTRUCTION(muli),
+    [STBIO]   = INSTRUCTION(stbio),
+    [BEQ]     = INSTRUCTION(beq),
+    [LDBIO]   = INSTRUCTION(ldbio),
+    [CMPGEUI] = INSTRUCTION(cmpgeui),
+    [0x29]    = INSTRUCTION_ILLEGAL(),
+    [0x2a]    = INSTRUCTION_ILLEGAL(),
+    [LDHUIO]  = INSTRUCTION(ldhuio),
+    [ANDHI]   = INSTRUCTION(andhi),
+    [STHIO]   = INSTRUCTION(sthio),
+    [BGEU]    = INSTRUCTION(bgeu),
+    [LDHIO]   = INSTRUCTION(ldhio),
+    [CMPLTUI] = INSTRUCTION(cmpltui),
+    [0x31]    = INSTRUCTION_ILLEGAL(),
+    [CUSTOM]  = INSTRUCTION_UNIMPLEMENTED(custom),
+    [INITD]   = INSTRUCTION(initd),
+    [ORHI]    = INSTRUCTION(orhi),
+    [STWIO]   = INSTRUCTION(stwio),

target-nios2/instruction.c line 769

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+    [BLTU]    = INSTRUCTION(bltu),
+    [LDWIO]   = INSTRUCTION(ldwio),
+    [RDPRS]   = INSTRUCTION_UNIMPLEMENTED(rdprs),
+    [0x39]    = INSTRUCTION_ILLEGAL(),
+    [R_TYPE]  = { "<R-type instruction>", handle_r_type_instr },
+    [FLUSHD]  = INSTRUCTION_NOP(flushd),
+    [XORHI]   = INSTRUCTION(xorhi),
+    [0x3d]    = INSTRUCTION_ILLEGAL(),
+    [0x3e]    = INSTRUCTION_ILLEGAL(),
+    [0x3f]    = INSTRUCTION_ILLEGAL(),

Is there really any point to using a table, as opposed to a switch statement? At least with a switch you can use default to catch all of the illegals at once.

Quoted 6 lines
target-nios2/instruction.c new file +6 -0
+/* rC <- ((unsigned)rA * (unsigned)rB))(31..0) */
+static void mulxuu(DisasContext *dc, uint32_t code)
+{
+    R_TYPE(instr, code);
+
+    TCGv_i64 t0, t1;

target-nios2/instruction.c line 860

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+
+    t0 = tcg_temp_new_i64();
+    t1 = tcg_temp_new_i64();
+
+    tcg_gen_extu_i32_i64(t0, dc->cpu_R[instr->a]);
+    tcg_gen_extu_i32_i64(t1, dc->cpu_R[instr->b]);
+    tcg_gen_mul_i64(t0, t0, t1);
+
+    tcg_gen_shri_i64(t0, t0, 32);
+    tcg_gen_extrl_i64_i32(dc->cpu_R[instr->c], t0);
  TCGv t0 = tcg_temp_new();
  tcg_gen_mulu2_tl(t0, dc->cpu_R[instr->c],
                   dc->cpu_R[instr->a],
                   dc->cpu_R[instr->b]);
  tcg_temp_free(t0);
Quoted 6 lines
target-nios2/instruction.c new file +6 -0
+/* rC <- ((signed)rA * (unsigned)rB))(31..0) */
+static void mulxsu(DisasContext *dc, uint32_t code)
+{
+    R_TYPE(instr, code);
+
+    TCGv_i64 t0, t1;

target-nios2/instruction.c line 986

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+
+    t0 = tcg_temp_new_i64();
+    t1 = tcg_temp_new_i64();
+
+    tcg_gen_ext_i32_i64(t0, dc->cpu_R[instr->a]);
+    tcg_gen_extu_i32_i64(t1, dc->cpu_R[instr->b]);
+    tcg_gen_mul_i64(t0, t0, t1);
+
+    tcg_gen_shri_i64(t0, t0, 32);
+    tcg_gen_extrl_i64_i32(dc->cpu_R[instr->c], t0);

Similarly, using tcg_gen_mulsu2_tl. To be fair, a patch for this was posted yesterday, and will be included in a tcg pull soon. See

https://patchwork.ozlabs.org/patch/675859/

target-nios2/instruction.c line 1050

Quoted 12 lines
target-nios2/instruction.c new file +12 -0
+static void callr(DisasContext *dc, uint32_t code)
+{
+    R_TYPE(instr, code);
+
+#ifdef CALL_TRACING
+    TCGv_i32 tmp = tcg_const_i32(dc->pc);
+    gen_helper_call_status(tmp, dc->cpu_R[instr->a]);
+    tcg_temp_free_i32(tmp);
+#endif
+
+    tcg_gen_movi_tl(dc->cpu_R[R_RA], dc->pc + 4);
+    tcg_gen_mov_tl(dc->cpu_R[R_PC], dc->cpu_R[instr->a]);

Does the hardware actually prevent rA == RA like this? The documentation is unclear. If the hardware actually performs the described actions in parallel, then you need to swap these two lines.

target-nios2/instruction.c line 1076

Quoted 13 lines
target-nios2/instruction.c new file +13 -0
+/* rC <- ((signed)rA * (signed)rB))(31..0) */
+static void mulxss(DisasContext *dc, uint32_t code)
+{
+    R_TYPE(instr, code);
+
+    TCGv_i64 t0, t1;
+
+    t0 = tcg_temp_new_i64();
+    t1 = tcg_temp_new_i64();
+
+    tcg_gen_ext_i32_i64(t0, dc->cpu_R[instr->a]);
+    tcg_gen_ext_i32_i64(t1, dc->cpu_R[instr->b]);
+    tcg_gen_mul_i64(t0, t0, t1);

Similarly, tcg_gen_muls2_tl.

target-nios2/instruction.c line 1106

Quoted 8 lines
target-nios2/instruction.c new file +8 -0
+/* rC <- rA / rB */
+static void divu(DisasContext *dc, uint32_t code)
+{
+    R_TYPE(instr, code);
+
+    gen_helper_divu(dc->cpu_R[instr->c], dc->cpu_R[instr->a],
+                    dc->cpu_R[instr->b]);
+}

You can perform this inline. C.f. target-mips

Since divide-by-zero is undefined, this can be done with

  TCGv t0 = tcg_const_tl(0);
  tcg_gen_setcond_tl(TCG_COND_EQ, t0, dc->cpu_R[instr->b], t0);
  tcg_gen_or_tl(t0, t0, dc->cpu_R[instr->b]);
  tcg_gen_divu_tl(dc->cpu_R[instr->c], dc->cpu_R[instr->a], t0);
  tcg_temp_free_tl(t0);

Review

Quoted 2 lines
(quoted diff) +2 -0
+    gen_helper_divs(dc->cpu_R[instr->c], dc->cpu_R[instr->a],
+                    dc->cpu_R[instr->b]);

Similarly.

target-nios2/instruction.c line 1254

Quoted 8 lines
target-nios2/instruction.c new file +8 -0
+/*
+ * bstatus ← status
+ * PIE <- 0
+ * U <- 0
+ * ba <- PC + 4
+ * PC <- break handler address
+ */
+static void __break(DisasContext *dc, uint32_t code __attribute__((unused)))

This symbol is in the system namespace. Just use break_insn or something.

Quoted 56 lines
target-nios2/instruction.c new file +56 -0
+static const Nios2Instruction r_type_instructions[R_TYPE_COUNT] = {
+    [0x00]   = INSTRUCTION_ILLEGAL(),
+    [ERET]   = INSTRUCTION(eret),
+    [ROLI]   = INSTRUCTION(roli),
+    [ROL]    = INSTRUCTION(rol),
+    [FLUSHP] = INSTRUCTION(flushp),
+    [RET]    = INSTRUCTION(ret),
+    [NOR]    = INSTRUCTION(nor),
+    [MULXUU] = INSTRUCTION(mulxuu),
+    [CMPGE]  = INSTRUCTION(cmpge),
+    [BRET]   = INSTRUCTION(bret),
+    [0x0a]   = INSTRUCTION_ILLEGAL(),
+    [ROR]    = INSTRUCTION(ror),
+    [FLUSHI] = INSTRUCTION(flushi),
+    [JMP]    = INSTRUCTION(jmp),
+    [AND]    = INSTRUCTION(and),
+    [0x0f]   = INSTRUCTION_ILLEGAL(),
+    [CMPLT]  = INSTRUCTION(cmplt),
+    [0x11]   = INSTRUCTION_ILLEGAL(),
+    [SLLI]   = INSTRUCTION(slli),
+    [SLL]    = INSTRUCTION(sll),
+    [WRPRS]  = INSTRUCTION_UNIMPLEMENTED(wrprs),
+    [0x15]   = INSTRUCTION_ILLEGAL(),
+    [OR]     = INSTRUCTION(or),
+    [MULXSU] = INSTRUCTION(mulxsu),
+    [CMPNE]  = INSTRUCTION(cmpne),
+    [0x19]   = INSTRUCTION_ILLEGAL(),
+    [SRLI]   = INSTRUCTION(srli),
+    [SRL]    = INSTRUCTION(srl),
+    [NEXTPC] = INSTRUCTION(nextpc),
+    [CALLR]  = INSTRUCTION(callr),
+    [XOR]    = INSTRUCTION(xor),
+    [MULXSS] = INSTRUCTION(mulxss),
+    [CMPEQ]  = INSTRUCTION(cmpeq),
+    [0x21]   = INSTRUCTION_ILLEGAL(),
+    [0x22]   = INSTRUCTION_ILLEGAL(),
+    [0x23]   = INSTRUCTION_ILLEGAL(),
+    [DIVU]   = INSTRUCTION(divu),
+    [DIV]    = { "div", _div },
+    [RDCTL]  = INSTRUCTION(rdctl),
+    [MUL]    = INSTRUCTION(mul),
+    [CMPGEU] = INSTRUCTION(cmpgeu),
+    [INITI]  = INSTRUCTION(initi),
+    [0x2a]   = INSTRUCTION_ILLEGAL(),
+    [0x2b]   = INSTRUCTION_ILLEGAL(),
+    [0x2c]   = INSTRUCTION_ILLEGAL(),
+    [TRAP]   = INSTRUCTION(trap),
+    [WRCTL]  = INSTRUCTION(wrctl),
+    [0x2f]   = INSTRUCTION_ILLEGAL(),
+    [CMPLTU] = INSTRUCTION(cmpltu),
+    [ADD]    = INSTRUCTION(add),
+    [0x32]   = INSTRUCTION_ILLEGAL(),
+    [0x33]   = INSTRUCTION_ILLEGAL(),
+    [BREAK]  = { "break", __break },
+    [0x35]   = INSTRUCTION_ILLEGAL(),
+    [SYNC]   = INSTRUCTION(nop),

target-nios2/instruction.c line 1354

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+    [0x37]   = INSTRUCTION_ILLEGAL(),
+    [0x38]   = INSTRUCTION_ILLEGAL(),
+    [SUB]    = INSTRUCTION(sub),
+    [SRAI]   = INSTRUCTION(srai),
+    [SRA]    = INSTRUCTION(sra),
+    [0x3c]   = INSTRUCTION_ILLEGAL(),
+    [0x3d]   = INSTRUCTION_ILLEGAL(),
+    [0x3e]   = INSTRUCTION_ILLEGAL(),
+    [0x3f]   = INSTRUCTION_ILLEGAL(),
+};

Similar comment wrt the I-type table.

Quoted 6 lines
target-nios2/instruction.c new file +6 -0
+const char *instruction_get_string(uint32_t code)
+{
+    uint32_t op = get_opcode(code);
+
+    if (unlikely(op >= I_TYPE_COUNT)) {
+        return "";

target-nios2/instruction.c line 1426

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+    } else if (op == R_TYPE) {
+        uint32_t opx = get_opxcode(code);
+        if (unlikely(opx >= R_TYPE_COUNT)) {
+            return "";
+        }
+        return r_type_instructions[opx].name;
+    } else {
+        return i_type_instructions[op].name;
+    }
+}

What is this function used for?

target-nios2/instruction.h line 40

Quoted 7 lines
target-nios2/instruction.h new file +7 -0
+/* I-Type instruction */
+typedef struct Nios2IType {
+    uint32_t op:6;
+    uint32_t imm16:16;
+    uint32_t b:5;
+    uint32_t a:5;
+} QEMU_PACKED Nios2IType;

These bitfields are a non-starter. Layout of them is non-portable in more ways than is worth going into here. You must use extract32 and sextract32 to extract the fields.

target-nios2/instruction.h line 49

Quoted 9 lines
target-nios2/instruction.h new file +9 -0
+
+union i_type_u {
+    uint32_t      v;
+    Nios2IType i;
+};
+
+#define I_TYPE(instr, op) \
+    union i_type_u instr_u = { .v = op }; \
+    Nios2IType *instr = &instr_u.i

You could probably still hide everything behind this macro, with an inline function returning a structure (defined *without* bitfields).

target-nios2/instruction.h line 238

Quoted 11 lines
target-nios2/instruction.h new file +11 -0
+/*
+ * Return values for instruction handlers
+ */
+#define INSTR_UNIMPL     -2  /* Unimplemented instruction */
+#define INSTR_ERR        -1  /* Error in instruction */
+#define PC_INC_NORMAL     0  /* Normal PC increment after instruction */
+#define PC_INC_BY_INSTR   1  /* PC got incremented by instruction */
+#define INSTR_BREAK       2  /* Break encountered */
+#define INSTR_EXCEPTION 255  /* Instruction generated an exception
+                                (the exception cause will be stored
+                                in struct nios2 */

What's the gain over using a simple enum with sequential values?

Quoted 8 lines
target-nios2/machine.c new file +8 -0
+/*
+ * FIXME: Convert to VMstate
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+#include "hw/boards.h"
+

target-nios2/machine.c line 38

Quoted 10 lines
target-nios2/machine.c new file +10 -0
+void cpu_save(QEMUFile *f, void *opaque)
+{
+    /* TODO */
+}
+
+int cpu_load(QEMUFile *f, void *opaque, int version_id)
+{
+    /* TODO */
+    return 0;
+}

Fixing this is no longer optional.

target-nios2/op_helper.c line 58

Quoted 10 lines
target-nios2/op_helper.c new file +10 -0
+void helper_memalign(CPUNios2State *env, uint32_t addr, uint32_t dr, uint32_t wr, uint32_t mask)
+{
+    if (addr & mask) {
+        qemu_log("unaligned access addr=%x mask=%x, wr=%d dr=r%d\n",
+                 addr, mask, wr, dr);
+        env->regs[CR_BADADDR] = addr;
+        env->regs[CR_EXCEPTION] = EXCP_UNALIGN << 2;
+        helper_raise_exception(env, EXCP_UNALIGN);
+    }
+}

What is this doing that cc->do_unaligned_access doesn't?

target-nios2/translate.c line 87

Quoted 3 lines
target-nios2/translate.c new file +3 -0
+    /* Initialize DC */
+    dc->cpu_env = cpu_env;
+    dc->cpu_R   = cpu_R;

What is this assignment for? Are you planning to implement shadow registers at some point?

r~

Tested-by on v2 1/7
#17 lore raw
In reply to Marek Vasut

Hi Marek,

Quoted 9 lines · Marek Vasut

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

With Waldemar Brodkorb and I, we tested this series using 10m50 kernel defconfig with Buildroot generated system. In order to ease the test, we added the device tree and a initramfs to the kernel image.

Here is the result:

Welcome to Buildroot

# cat /proc/cpuinfo
CPU:		Nios II/fast
MMU:		present
FPU:		none
Clocking:	75.00 MHz
BogoMips:	150.00
Calibration:	75000000 loops
HW:
 MUL:		yes
 MULX:		no
 DIV:		yes
Icache:		32kB, line length: 32
Dcache:		32kB, line length: 32
TLB:		16 ways, 256 entries, 8 PID bits
# uname -a
Linux buildroot 4.8.1 #2 Fri Oct 14 19:10:18 CEST 2016 nios2 GNU/Linux

When this series will be accepted in Qemu, I'll add a demo defconfig in Buildroot in order to ease runtime testing.

Best regards,
Romain

Quoted 9 lines
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]>

---
V2: Replace the nios2.c with GPL2 licensed version
---

#3 lore raw

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

In reply to Richard Henderson
Quoted 3 lines · Richard Henderson
Quoted 1 line
 hw/nios2/cpu_pic.c         |   70 +++

Why is this in this patch?

Ah, good catch, moved to 10m50 support patch.

Quoted 6 lines
Quoted 4 lines
 target-nios2/instruction.c | 1427
++++++++++++++++++++++++++++++++++++++++++++
 target-nios2/instruction.h |  279 +++++++++
 target-nios2/translate.c   |  242 ++++++++

Why are these files separate?

Remnant of the old code, will merge them.

Quoted 8 lines

target-nios2/cpu.c line 148

Quoted 6 lines
target-nios2/cpu.c new file +6 -0
+    if (n < 32)        /* GP regs */
+        return gdb_get_reg32(mem_buf, env->regs[n]);
+    else if (n == 32)    /* PC */
+        return gdb_get_reg32(mem_buf, env->regs[R_PC]);
+    else if (n < 49)    /* Status regs */
+        return gdb_get_reg32(mem_buf, env->regs[n - 1]);

Use checkpatch.pl; the formatting is wrong.

Fixed across the entire series, thanks.

Quoted 2 lines

There's no particular reason why R_PC needs to be 64; if you change it to 32, you can simplify this.

I believe this is in fact needed, see [1] page 18 (section 2, Register file), quote:

"
The Nios II architecture supports a flat register file, consisting of thirty-two 32-bit general-purpose integer
registers, and up to thirty-two 32-bit control registers. The architecture supports supervisor and user
modes that allow system code to protect the control registers from errant applications.
"

So the CPU supports 32 general purpose regs (R_ZERO..R_RA), then up-to 32 Control registers (CR_STATUS..CR_MPUACC) and then the PC .

[1]
https://www.altera.com/content/dam/altera-www/global/en_US/pdfs/literature/hb/nios2/n2cpu_nii5v1.pdf

Quoted 30 lines

target-nios2/cpu.h line 176

Quoted 7 lines
target-nios2/cpu.h new file +7 -0
+struct CPUNios2State {
+    uint32_t regs[NUM_CORE_REGS];
+
+    /* Addresses that are hard-coded in the FPGA build settings */
+    uint32_t reset_addr;
+    uint32_t exception_addr;
+    uint32_t fast_tlb_miss_addr;

These three should go after ...

target-nios2/cpu.h line 184

Quoted 8 lines
target-nios2/cpu.h new file +8 -0
+
+#if !defined(CONFIG_USER_ONLY)
+    Nios2MMU mmu;
+
+    uint32_t irq_pending;
+#endif
+
+    CPU_COMMON

... here, or even into ...

Quoted 9 lines
target-nios2/cpu.h new file +9 -0
+};
+
+/**
+ * Nios2CPU:
+ * @env: #CPUNios2State
+ *
+ * A Nios2 CPU.
+ */
+typedef struct Nios2CPU {
Quoted 8 lines

target-nios2/cpu.h line 199

Quoted 6 lines
target-nios2/cpu.h new file +6 -0
+    /*< private >*/
+    CPUState parent_obj;
+    /*< public >*/
+
+    CPUNios2State env;
+    bool mmu_present;

... here.

Moved here, it looks more sensible as it's not something one can change at runtime.

Quoted 4 lines

target-nios2/instruction.c line 43

Quoted 2 lines
target-nios2/instruction.c new file +2 -0
+static inline void t_gen_helper_raise_exception(DisasContext *dc,
+                                                uint32_t index)

Remove all of the inline markers and let the compiler decide.

Done globally, thanks.

Quoted 4 lines
Quoted 4 lines
target-nios2/instruction.c new file +4 -0
+static void gen_check_supervisor(DisasContext *dc, TCGLabel *label)
+{
+    TCGLabel *l1 = gen_new_label();
+
Quoted 8 lines

target-nios2/instruction.c line 92

Quoted 5 lines
target-nios2/instruction.c new file +5 -0
+    TCGv_i32 tmp = tcg_temp_new();
+    tcg_gen_andi_tl(tmp, dc->cpu_R[CR_STATUS], CR_STATUS_U);
+    tcg_gen_brcond_tl(TCG_COND_EQ, dc->cpu_R[R_ZERO], tmp, l1);
+    t_gen_helper_raise_exception(dc, EXCP_SUPERI);
+    tcg_gen_br(label);

The supervisor check should be done at translate time by checking dc->tb->flags & CR_STATUS_U.

Fixed.

Quoted 10 lines

target-nios2/instruction.c line 130

Quoted 8 lines
target-nios2/instruction.c new file +3 -0
+#ifdef CALL_TRACING
+    TCGv_i32 tmp = tcg_const_i32(dc->pc);
+    TCGv_i32 tmp2 = tcg_const_i32((dc->pc & 0xF0000000) |

(instr->imm26 * 4));

target-nios2/instruction.c new file +4 -0
+    gen_helper_call_status(tmp, tmp2);
+    tcg_temp_free_i32(tmp);
+    tcg_temp_free_i32(tmp2);
+#endif

What's the point of this?

Seems like some stale debug helper, removed, thanks.

Quoted 13 lines
Quoted 13 lines
target-nios2/instruction.c new file +13 -0
+/*
+ * I-Type instructions
+ */
+
+/* rB <- 0x000000 : Mem8[rA + @(IMM16)] */
+static void ldbu(DisasContext *dc, uint32_t code)
+{
+    I_TYPE(instr, code);
+
+    TCGv addr = tcg_temp_new();
+    tcg_gen_addi_tl(addr, dc->cpu_R[instr->a],
+                    (int32_t)((int16_t)instr->imm16));
+
Quoted 8 lines

target-nios2/instruction.c line 165

Quoted 4 lines
target-nios2/instruction.c new file +4 -0
+    tcg_gen_qemu_ld8u(dc->cpu_R[instr->b], addr, dc->mem_idx);
+
+    tcg_temp_free(addr);
+}

You should have helper functions so that you don't have to replicate 12 line functions. Use the tcg_gen_qemu_ld_tl function, and the TCGMemOp flags to help merge all load instructions, and all store instructions.

Oh nice, thanks.

Quoted 10 lines

target-nios2/instruction.c line 174

Quoted 8 lines
target-nios2/instruction.c new file +8 -0
+/* rB <- rA + IMM16 */
+static void addi(DisasContext *dc, uint32_t code)
+{
+    I_TYPE(instr, code);
+
+    TCGv imm = tcg_temp_new();
+    tcg_gen_addi_tl(dc->cpu_R[instr->b], dc->cpu_R[instr->a],
+                    (int32_t)((int16_t)instr->imm16));

The double cast is pointless, as are the extra parenthesis.

The int16_t cast is needed as the imm16 is signed value. The int32() cast is indeed pointless, so removed. Thanks.

Quoted 3 lines

You're not doing anything to make sure that r0 reads as 0, and ignores writes. You need to look at target-alpha, target-mips, or target-sparc to see various ways in which a zero register may be handled.

Any hint on this one ?

Quoted 6 lines

You should handle the special case of movi, documented as addi rb, r0, imm, so that the common method of loading a small value does not require extra tcg opcodes.

Similarly for the other (common) aliases, like mov and nop, which are both aliased to add.

Fixed

Quoted 9 lines

target-nios2/instruction.c line 323

Quoted 7 lines

+/* Initializes the data cache line currently caching address rA + @(IMM16) */

target-nios2/instruction.c new file +5 -0
+static void initda(DisasContext *dc __attribute__((unused)),
+                   uint32_t code __attribute__((unused)))
+{
+    /* TODO */
+}

This will always be a nop for qemu.

Replaced with NOP instructions.

Quoted 11 lines
Quoted 11 lines
target-nios2/instruction.c new file +11 -0
+static void blt(DisasContext *dc, uint32_t code)
+{
+    I_TYPE(instr, code);
+
+    TCGLabel *l1 = gen_new_label();
+
+    tcg_gen_brcond_tl(TCG_COND_LT, dc->cpu_R[instr->a],
+                      dc->cpu_R[instr->b], l1);
+
+    gen_goto_tb(dc, 0, dc->pc + 4);
+
Quoted 8 lines

target-nios2/instruction.c line 288

Quoted 6 lines
target-nios2/instruction.c new file +6 -0
+    gen_set_label(l1);
+
+    gen_goto_tb(dc, 1, dc->pc + 4 + (int16_t)(instr->imm16 & 0xFFFC));
+
+    dc->is_jmp = DISAS_TB_JUMP;
+}

These really require a helper function.

Yes, fixed.

Quoted 5 lines

target-nios2/instruction.c line 446

Quoted 2 lines
target-nios2/instruction.c new file +2 -0
+/* rB <- 0x000000 : Mem8[rA + @(IMM16)] (bypassing cache) */
+static void ldbuio(DisasContext *dc, uint32_t code)

Reuse ldbu; qemu will never implement caches.

Quoted 11 lines

target-nios2/instruction.c line 467

Quoted 9 lines
target-nios2/instruction.c new file +9 -0
+/* rB <- (rA * @(IMM16))(31..0) */
+static void muli(DisasContext *dc, uint32_t code)
+{
+    I_TYPE(instr, code);
+
+    TCGv imm = tcg_temp_new();
+    tcg_gen_muli_i32(dc->cpu_R[instr->b], dc->cpu_R[instr->a],
+                     (int32_t)((int16_t)instr->imm16));
+    tcg_temp_free(imm);

imm is unused.

I reworked this some more, so fixed.

Quoted 66 lines
Quoted 55 lines
target-nios2/instruction.c new file +55 -0
+static const Nios2Instruction i_type_instructions[I_TYPE_COUNT] = {
+    [CALL]    = INSTRUCTION(call),
+    [JMPI]    = INSTRUCTION(jmpi),
+    [0x02]    = INSTRUCTION_ILLEGAL(),
+    [LDBU]    = INSTRUCTION(ldbu),
+    [ADDI]    = INSTRUCTION(addi),
+    [STB]     = INSTRUCTION(stb),
+    [BR]      = INSTRUCTION(br),
+    [LDB]     = INSTRUCTION(ldb),
+    [CMPGEI]  = INSTRUCTION(cmpgei),
+    [0x09]    = INSTRUCTION_ILLEGAL(),
+    [0x0a]    = INSTRUCTION_ILLEGAL(),
+    [LDHU]    = INSTRUCTION(ldhu),
+    [ANDI]    = INSTRUCTION(andi),
+    [STH]     = INSTRUCTION(sth),
+    [BGE]     = INSTRUCTION(bge),
+    [LDH]     = INSTRUCTION(ldh),
+    [CMPLTI]  = INSTRUCTION(cmplti),
+    [0x11]    = INSTRUCTION_ILLEGAL(),
+    [0x12]    = INSTRUCTION_ILLEGAL(),
+    [INITDA]  = INSTRUCTION(initda),
+    [ORI]     = INSTRUCTION(ori),
+    [STW]     = INSTRUCTION(stw),
+    [BLT]     = INSTRUCTION(blt),
+    [LDW]     = INSTRUCTION(ldw),
+    [CMPNEI]  = INSTRUCTION(cmpnei),
+    [0x19]    = INSTRUCTION_ILLEGAL(),
+    [0x1a]    = INSTRUCTION_ILLEGAL(),
+    [FLUSHDA] = INSTRUCTION_NOP(flushda),
+    [XORI]    = INSTRUCTION(xori),
+    [0x1d]    = INSTRUCTION_ILLEGAL(),
+    [BNE]     = INSTRUCTION(bne),
+    [0x1f]    = INSTRUCTION_ILLEGAL(),
+    [CMPEQI]  = INSTRUCTION(cmpeqi),
+    [0x21]    = INSTRUCTION_ILLEGAL(),
+    [0x22]    = INSTRUCTION_ILLEGAL(),
+    [LDBUIO]  = INSTRUCTION(ldbuio),
+    [MULI]    = INSTRUCTION(muli),
+    [STBIO]   = INSTRUCTION(stbio),
+    [BEQ]     = INSTRUCTION(beq),
+    [LDBIO]   = INSTRUCTION(ldbio),
+    [CMPGEUI] = INSTRUCTION(cmpgeui),
+    [0x29]    = INSTRUCTION_ILLEGAL(),
+    [0x2a]    = INSTRUCTION_ILLEGAL(),
+    [LDHUIO]  = INSTRUCTION(ldhuio),
+    [ANDHI]   = INSTRUCTION(andhi),
+    [STHIO]   = INSTRUCTION(sthio),
+    [BGEU]    = INSTRUCTION(bgeu),
+    [LDHIO]   = INSTRUCTION(ldhio),
+    [CMPLTUI] = INSTRUCTION(cmpltui),
+    [0x31]    = INSTRUCTION_ILLEGAL(),
+    [CUSTOM]  = INSTRUCTION_UNIMPLEMENTED(custom),
+    [INITD]   = INSTRUCTION(initd),
+    [ORHI]    = INSTRUCTION(orhi),
+    [STWIO]   = INSTRUCTION(stwio),

target-nios2/instruction.c line 769

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+    [BLTU]    = INSTRUCTION(bltu),
+    [LDWIO]   = INSTRUCTION(ldwio),
+    [RDPRS]   = INSTRUCTION_UNIMPLEMENTED(rdprs),
+    [0x39]    = INSTRUCTION_ILLEGAL(),
+    [R_TYPE]  = { "<R-type instruction>", handle_r_type_instr },
+    [FLUSHD]  = INSTRUCTION_NOP(flushd),
+    [XORHI]   = INSTRUCTION(xorhi),
+    [0x3d]    = INSTRUCTION_ILLEGAL(),
+    [0x3e]    = INSTRUCTION_ILLEGAL(),
+    [0x3f]    = INSTRUCTION_ILLEGAL(),
Quoted 3 lines

Is there really any point to using a table, as opposed to a switch statement? At least with a switch you can use default to catch all of the illegals at once.

I don't need to track the instructions encodings separately, since the NIOS2 only supports 40 I-/R-instructions .

Quoted 43 lines
Quoted 6 lines
target-nios2/instruction.c new file +6 -0
+/* rC <- ((unsigned)rA * (unsigned)rB))(31..0) */
+static void mulxuu(DisasContext *dc, uint32_t code)
+{
+    R_TYPE(instr, code);
+
+    TCGv_i64 t0, t1;

target-nios2/instruction.c line 860

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+
+    t0 = tcg_temp_new_i64();
+    t1 = tcg_temp_new_i64();
+
+    tcg_gen_extu_i32_i64(t0, dc->cpu_R[instr->a]);
+    tcg_gen_extu_i32_i64(t1, dc->cpu_R[instr->b]);
+    tcg_gen_mul_i64(t0, t0, t1);
+
+    tcg_gen_shri_i64(t0, t0, 32);
+    tcg_gen_extrl_i64_i32(dc->cpu_R[instr->c], t0);
  TCGv t0 = tcg_temp_new();
  tcg_gen_mulu2_tl(t0, dc->cpu_R[instr->c],
                   dc->cpu_R[instr->a],
                   dc->cpu_R[instr->b]);
  tcg_temp_free(t0);
Quoted 6 lines
target-nios2/instruction.c new file +6 -0
+/* rC <- ((signed)rA * (unsigned)rB))(31..0) */
+static void mulxsu(DisasContext *dc, uint32_t code)
+{
+    R_TYPE(instr, code);
+
+    TCGv_i64 t0, t1;

target-nios2/instruction.c line 986

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+
+    t0 = tcg_temp_new_i64();
+    t1 = tcg_temp_new_i64();
+
+    tcg_gen_ext_i32_i64(t0, dc->cpu_R[instr->a]);
+    tcg_gen_extu_i32_i64(t1, dc->cpu_R[instr->b]);
+    tcg_gen_mul_i64(t0, t0, t1);
+
+    tcg_gen_shri_i64(t0, t0, 32);
+    tcg_gen_extrl_i64_i32(dc->cpu_R[instr->c], t0);

Similarly, using tcg_gen_mulsu2_tl. To be fair, a patch for this was posted yesterday, and will be included in a tcg pull soon. See

Quoted 1 line

https://patchwork.ozlabs.org/patch/675859/

Oh, nice, I picked this patch and replaced all those mulx*() functions.

Quoted 8 lines
Quoted 8 lines
target-nios2/instruction.c new file +8 -0
+static void callr(DisasContext *dc, uint32_t code)
+{
+    R_TYPE(instr, code);
+
+#ifdef CALL_TRACING
+    TCGv_i32 tmp = tcg_const_i32(dc->pc);
+    gen_helper_call_status(tmp, dc->cpu_R[instr->a]);
+    tcg_temp_free_i32(tmp);
Quoted 8 lines

target-nios2/instruction.c line 1050

Quoted 4 lines
target-nios2/instruction.c new file +4 -0
+#endif
+
+    tcg_gen_movi_tl(dc->cpu_R[R_RA], dc->pc + 4);
+    tcg_gen_mov_tl(dc->cpu_R[R_PC], dc->cpu_R[instr->a]);

Does the hardware actually prevent rA == RA like this? The documentation is unclear. If the hardware actually performs the described actions in parallel, then you need to swap these two lines.

That would only make sense, so swapped.

Quoted 7 lines
Quoted 7 lines
target-nios2/instruction.c new file +7 -0
+/* rC <- ((signed)rA * (signed)rB))(31..0) */
+static void mulxss(DisasContext *dc, uint32_t code)
+{
+    R_TYPE(instr, code);
+
+    TCGv_i64 t0, t1;
+
Quoted 8 lines

target-nios2/instruction.c line 1076

Quoted 6 lines
target-nios2/instruction.c new file +6 -0
+    t0 = tcg_temp_new_i64();
+    t1 = tcg_temp_new_i64();
+
+    tcg_gen_ext_i32_i64(t0, dc->cpu_R[instr->a]);
+    tcg_gen_ext_i32_i64(t1, dc->cpu_R[instr->b]);
+    tcg_gen_mul_i64(t0, t0, t1);

Similarly, tcg_gen_muls2_tl.

Fixed.

Quoted 11 lines

target-nios2/instruction.c line 1106

Quoted 8 lines
target-nios2/instruction.c new file +8 -0
+/* rC <- rA / rB */
+static void divu(DisasContext *dc, uint32_t code)
+{
+    R_TYPE(instr, code);
+
+    gen_helper_divu(dc->cpu_R[instr->c], dc->cpu_R[instr->a],
+                    dc->cpu_R[instr->b]);
+}

You can perform this inline. C.f. target-mips

Quoted 7 lines

Since divide-by-zero is undefined, this can be done with

  TCGv t0 = tcg_const_tl(0);
  tcg_gen_setcond_tl(TCG_COND_EQ, t0, dc->cpu_R[instr->b], t0);
  tcg_gen_or_tl(t0, t0, dc->cpu_R[instr->b]);
  tcg_gen_divu_tl(dc->cpu_R[instr->c], dc->cpu_R[instr->a], t0);
  tcg_temp_free_tl(t0);

Just so I get it completely, isn't this handled somehow by the tcg_gen_divu_tl() itself ?

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    gen_helper_divs(dc->cpu_R[instr->c], dc->cpu_R[instr->a],
+                    dc->cpu_R[instr->b]);

Similarly.

Fixed

Quoted 11 lines
Quoted 9 lines
target-nios2/instruction.c new file +8 -0
+/*
+ * bstatus ← status
+ * PIE <- 0
+ * U <- 0
+ * ba <- PC + 4
+ * PC <- break handler address
+ */
+static void __break(DisasContext *dc, uint32_t code

__attribute__((unused)))

This symbol is in the system namespace. Just use break_insn or something.

Fixed

Quoted 79 lines
Quoted 56 lines
target-nios2/instruction.c new file +56 -0
+static const Nios2Instruction r_type_instructions[R_TYPE_COUNT] = {
+    [0x00]   = INSTRUCTION_ILLEGAL(),
+    [ERET]   = INSTRUCTION(eret),
+    [ROLI]   = INSTRUCTION(roli),
+    [ROL]    = INSTRUCTION(rol),
+    [FLUSHP] = INSTRUCTION(flushp),
+    [RET]    = INSTRUCTION(ret),
+    [NOR]    = INSTRUCTION(nor),
+    [MULXUU] = INSTRUCTION(mulxuu),
+    [CMPGE]  = INSTRUCTION(cmpge),
+    [BRET]   = INSTRUCTION(bret),
+    [0x0a]   = INSTRUCTION_ILLEGAL(),
+    [ROR]    = INSTRUCTION(ror),
+    [FLUSHI] = INSTRUCTION(flushi),
+    [JMP]    = INSTRUCTION(jmp),
+    [AND]    = INSTRUCTION(and),
+    [0x0f]   = INSTRUCTION_ILLEGAL(),
+    [CMPLT]  = INSTRUCTION(cmplt),
+    [0x11]   = INSTRUCTION_ILLEGAL(),
+    [SLLI]   = INSTRUCTION(slli),
+    [SLL]    = INSTRUCTION(sll),
+    [WRPRS]  = INSTRUCTION_UNIMPLEMENTED(wrprs),
+    [0x15]   = INSTRUCTION_ILLEGAL(),
+    [OR]     = INSTRUCTION(or),
+    [MULXSU] = INSTRUCTION(mulxsu),
+    [CMPNE]  = INSTRUCTION(cmpne),
+    [0x19]   = INSTRUCTION_ILLEGAL(),
+    [SRLI]   = INSTRUCTION(srli),
+    [SRL]    = INSTRUCTION(srl),
+    [NEXTPC] = INSTRUCTION(nextpc),
+    [CALLR]  = INSTRUCTION(callr),
+    [XOR]    = INSTRUCTION(xor),
+    [MULXSS] = INSTRUCTION(mulxss),
+    [CMPEQ]  = INSTRUCTION(cmpeq),
+    [0x21]   = INSTRUCTION_ILLEGAL(),
+    [0x22]   = INSTRUCTION_ILLEGAL(),
+    [0x23]   = INSTRUCTION_ILLEGAL(),
+    [DIVU]   = INSTRUCTION(divu),
+    [DIV]    = { "div", _div },
+    [RDCTL]  = INSTRUCTION(rdctl),
+    [MUL]    = INSTRUCTION(mul),
+    [CMPGEU] = INSTRUCTION(cmpgeu),
+    [INITI]  = INSTRUCTION(initi),
+    [0x2a]   = INSTRUCTION_ILLEGAL(),
+    [0x2b]   = INSTRUCTION_ILLEGAL(),
+    [0x2c]   = INSTRUCTION_ILLEGAL(),
+    [TRAP]   = INSTRUCTION(trap),
+    [WRCTL]  = INSTRUCTION(wrctl),
+    [0x2f]   = INSTRUCTION_ILLEGAL(),
+    [CMPLTU] = INSTRUCTION(cmpltu),
+    [ADD]    = INSTRUCTION(add),
+    [0x32]   = INSTRUCTION_ILLEGAL(),
+    [0x33]   = INSTRUCTION_ILLEGAL(),
+    [BREAK]  = { "break", __break },
+    [0x35]   = INSTRUCTION_ILLEGAL(),
+    [SYNC]   = INSTRUCTION(nop),

target-nios2/instruction.c line 1354

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+    [0x37]   = INSTRUCTION_ILLEGAL(),
+    [0x38]   = INSTRUCTION_ILLEGAL(),
+    [SUB]    = INSTRUCTION(sub),
+    [SRAI]   = INSTRUCTION(srai),
+    [SRA]    = INSTRUCTION(sra),
+    [0x3c]   = INSTRUCTION_ILLEGAL(),
+    [0x3d]   = INSTRUCTION_ILLEGAL(),
+    [0x3e]   = INSTRUCTION_ILLEGAL(),
+    [0x3f]   = INSTRUCTION_ILLEGAL(),
+};

Similar comment wrt the I-type table.

Quoted 10 lines
target-nios2/instruction.c new file +10 -0
+const char *instruction_get_string(uint32_t code)
+{
+    uint32_t op = get_opcode(code);
+
+    if (unlikely(op >= I_TYPE_COUNT)) {
+        return "";
+    } else if (op == R_TYPE) {
+        uint32_t opx = get_opxcode(code);
+        if (unlikely(opx >= R_TYPE_COUNT)) {
+            return "";
Quoted 8 lines

target-nios2/instruction.c line 1426

Quoted 6 lines
target-nios2/instruction.c new file +6 -0
+        }
+        return r_type_instructions[opx].name;
+    } else {
+        return i_type_instructions[op].name;
+    }
+}

What is this function used for?

Nothing, removed.

Quoted 11 lines

target-nios2/instruction.h line 40

Quoted 7 lines
target-nios2/instruction.h new file +7 -0
+/* I-Type instruction */
+typedef struct Nios2IType {
+    uint32_t op:6;
+    uint32_t imm16:16;
+    uint32_t b:5;
+    uint32_t a:5;
+} QEMU_PACKED Nios2IType;

These bitfields are a non-starter. Layout of them is non-portable in more ways than is worth going into here. You must use extract32 and sextract32 to extract the fields.

Fixed

Quoted 4 lines
Quoted 4 lines
target-nios2/instruction.h new file +4 -0
+
+union i_type_u {
+    uint32_t      v;
+    Nios2IType i;
Quoted 8 lines

target-nios2/instruction.h line 49

Quoted 5 lines
target-nios2/instruction.h new file +5 -0
+};
+
+#define I_TYPE(instr, op) \
+    union i_type_u instr_u = { .v = op }; \
+    Nios2IType *instr = &instr_u.i

You could probably still hide everything behind this macro, with an inline function returning a structure (defined *without* bitfields).

Yes, fixed.

Quoted 5 lines
Quoted 5 lines
target-nios2/instruction.h new file +5 -0
+/*
+ * Return values for instruction handlers
+ */
+#define INSTR_UNIMPL     -2  /* Unimplemented instruction */
+#define INSTR_ERR        -1  /* Error in instruction */
Quoted 8 lines

target-nios2/instruction.h line 238

Quoted 6 lines
target-nios2/instruction.h new file +6 -0
+#define PC_INC_NORMAL     0  /* Normal PC increment after instruction */
+#define PC_INC_BY_INSTR   1  /* PC got incremented by instruction */
+#define INSTR_BREAK       2  /* Break encountered */
+#define INSTR_EXCEPTION 255  /* Instruction generated an exception
+                                (the exception cause will be stored
+                                in struct nios2 */

What's the gain over using a simple enum with sequential values?

These are unused, so removed.

Quoted 12 lines
Quoted 12 lines
target-nios2/machine.c new file +12 -0
+/*
+ * FIXME: Convert to VMstate
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+#include "hw/boards.h"
+
+void cpu_save(QEMUFile *f, void *opaque)
+{
+    /* TODO */
+}
Quoted 8 lines

target-nios2/machine.c line 38

Quoted 6 lines
target-nios2/machine.c new file +6 -0
+
+int cpu_load(QEMUFile *f, void *opaque, int version_id)
+{
+    /* TODO */
+    return 0;
+}

Fixing this is no longer optional.

This file wasn't even compiled, so removed.

Quoted 5 lines
Quoted 5 lines

+void helper_memalign(CPUNios2State *env, uint32_t addr, uint32_t dr, uint32_t wr, uint32_t mask)

target-nios2/op_helper.c new file +3 -0
+{
+    if (addr & mask) {
+        qemu_log("unaligned access addr=%x mask=%x, wr=%d dr=r%d\n",
Quoted 8 lines

target-nios2/op_helper.c line 58

Quoted 6 lines
target-nios2/op_helper.c new file +6 -0
+                 addr, mask, wr, dr);
+        env->regs[CR_BADADDR] = addr;
+        env->regs[CR_EXCEPTION] = EXCP_UNALIGN << 2;
+        helper_raise_exception(env, EXCP_UNALIGN);
+    }
+}

What is this doing that cc->do_unaligned_access doesn't?

Switched to do_unaligned_access, thanks.

Quoted 6 lines

target-nios2/translate.c line 87

Quoted 3 lines
target-nios2/translate.c new file +3 -0
+    /* Initialize DC */
+    dc->cpu_env = cpu_env;
+    dc->cpu_R   = cpu_R;

What is this assignment for? Are you planning to implement shadow registers at some point?

Eventually yes, but so far I haven't seen that used at all.

Quoted 1 line

r~

Thanks for the review!

Signature · 2 lines
Best regards,
Marek Vasut
#18 lore raw
In reply to Romain Naour
Quoted 1 line · Romain Naour

Hi Marek,

Hi!

Quoted 35 lines · Marek Vasut
Quoted 9 lines

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

With Waldemar Brodkorb and I, we tested this series using 10m50 kernel defconfig with Buildroot generated system. In order to ease the test, we added the device tree and a initramfs to the kernel image.

Here is the result:

Welcome to Buildroot

# cat /proc/cpuinfo
CPU:		Nios II/fast
MMU:		present
FPU:		none
Clocking:	75.00 MHz
BogoMips:	150.00
Calibration:	75000000 loops
HW:
 MUL:		yes
 MULX:		no
 DIV:		yes
Icache:		32kB, line length: 32
Dcache:		32kB, line length: 32
TLB:		16 ways, 256 entries, 8 PID bits
# uname -a
Linux buildroot 4.8.1 #2 Fri Oct 14 19:10:18 CEST 2016 nios2 GNU/Linux
Quoted 4 lines

When this series will be accepted in Qemu, I'll add a demo defconfig in Buildroot in order to ease runtime testing.

Great, thanks ! I'm glad to see it really becomes usable for other people too :)

I handled the feedback and pushed updated patches to:
http://git.bfuser.eu/?p=marex/qemu.git;a=shortlog;h=refs/heads/nios2/master

Signature · 2 lines
Best regards,
Marek Vasut
#4 lore raw

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

In reply to Marek Vasut
Quoted 15 lines · Marek Vasut
Quoted 2 lines

There's no particular reason why R_PC needs to be 64; if you change it to 32, you can simplify this.

I believe this is in fact needed, see [1] page 18 (section 2, Register file), quote:

"
The Nios II architecture supports a flat register file, consisting of thirty-two 32-bit general-purpose integer
registers, and up to thirty-two 32-bit control registers. The architecture supports supervisor and user
modes that allow system code to protect the control registers from errant applications.
"

Quoted 2 lines

So the CPU supports 32 general purpose regs (R_ZERO..R_RA), then up-to 32 Control registers (CR_STATUS..CR_MPUACC) and then the PC .

The architecture manual doesn't imply anything about the numbering of these registers.

Quoted 5 lines
Quoted 3 lines

You're not doing anything to make sure that r0 reads as 0, and ignores writes. You need to look at target-alpha, target-mips, or target-sparc to see various ways in which a zero register may be handled.

Any hint on this one ?

Well, there's three hints right there. But look at target-alpha, and the functions load_gpr and dest_gpr (note that for alpha, 31 is the zero register).

Quoted 10 lines
Quoted 7 lines

Since divide-by-zero is undefined, this can be done with

  TCGv t0 = tcg_const_tl(0);
  tcg_gen_setcond_tl(TCG_COND_EQ, t0, dc->cpu_R[instr->b], t0);
  tcg_gen_or_tl(t0, t0, dc->cpu_R[instr->b]);
  tcg_gen_divu_tl(dc->cpu_R[instr->c], dc->cpu_R[instr->a], t0);
  tcg_temp_free_tl(t0);

Just so I get it completely, isn't this handled somehow by the tcg_gen_divu_tl() itself ?

No, tcg_gen_divu_tl is a plain host divide instruction.

For guests that require exceptions to be raised, we handle those manually beforehand. At which point extra checks in tcg_gen_divu_tl are wasted.

r~

#5 lore raw

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

Quoted 16 lines · Richard Henderson
Quoted 15 lines · Marek Vasut
Quoted 2 lines

There's no particular reason why R_PC needs to be 64; if you change it to 32, you can simplify this.

I believe this is in fact needed, see [1] page 18 (section 2, Register file), quote:

"
The Nios II architecture supports a flat register file, consisting of thirty-two 32-bit general-purpose integer
registers, and up to thirty-two 32-bit control registers. The architecture supports supervisor and user
modes that allow system code to protect the control registers from errant applications.
"

Quoted 5 lines
Quoted 2 lines

So the CPU supports 32 general purpose regs (R_ZERO..R_RA), then up-to 32 Control registers (CR_STATUS..CR_MPUACC) and then the PC .

The architecture manual doesn't imply anything about the numbering of these registers.

But the instruction encoding does, so I can use the field from the instruction to directly index the register array.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

You're not doing anything to make sure that r0 reads as 0, and ignores writes. You need to look at target-alpha, target-mips, or target-sparc to see various ways in which a zero register may be handled.

Any hint on this one ?

Well, there's three hints right there. But look at target-alpha, and the functions load_gpr and dest_gpr (note that for alpha, 31 is the zero register).

Thanks, I hope this is fixed now, although I mostly special-case the R_ZERO handling throughout the code. Any writes to R_ZERO are now ignored and any usage is converted to mov/movi instructions where applicable.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Since divide-by-zero is undefined, this can be done with

  TCGv t0 = tcg_const_tl(0);
  tcg_gen_setcond_tl(TCG_COND_EQ, t0, dc->cpu_R[instr->b], t0);
  tcg_gen_or_tl(t0, t0, dc->cpu_R[instr->b]);
  tcg_gen_divu_tl(dc->cpu_R[instr->c], dc->cpu_R[instr->a], t0);
  tcg_temp_free_tl(t0);
Quoted 8 lines
Quoted 2 lines

Just so I get it completely, isn't this handled somehow by the tcg_gen_divu_tl() itself ?

No, tcg_gen_divu_tl is a plain host divide instruction.

For guests that require exceptions to be raised, we handle those manually beforehand. At which point extra checks in tcg_gen_divu_tl are wasted.

OK, got it, thanks!

Signature · 2 lines
Best regards,
Marek Vasut
#6 lore raw

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

Quoted 2 lines · Marek Vasut

But the instruction encoding does, so I can use the field from the instruction to directly index the register array.

Well, no, you can't.

In fact, it would be cleaner to have multiple arrays -- one for general registers and one for control registers -- that you *could* actually directly index. There are only two instructions that touch the control registers, rdctl and wrctl. In those instructions you're having to explicitly add 32.

Quoted 4 lines

Thanks, I hope this is fixed now, although I mostly special-case the R_ZERO handling throughout the code. Any writes to R_ZERO are now ignored and any usage is converted to mov/movi instructions where applicable.

We've done that in the past, but in the end it is much cleaner to minimize the number of places in which you have to check for R_ZERO.

r~

#7 lore raw

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

Quoted 11 lines · Richard Henderson
Quoted 2 lines · Marek Vasut

But the instruction encoding does, so I can use the field from the instruction to directly index the register array.

Well, no, you can't.

In fact, it would be cleaner to have multiple arrays -- one for general registers and one for control registers -- that you *could* actually directly index. There are only two instructions that touch the control registers, rdctl and wrctl. In those instructions you're having to explicitly add 32.

Well yes, that's true.

Quoted 7 lines
Quoted 4 lines

Thanks, I hope this is fixed now, although I mostly special-case the R_ZERO handling throughout the code. Any writes to R_ZERO are now ignored and any usage is converted to mov/movi instructions where applicable.

We've done that in the past, but in the end it is much cleaner to minimize the number of places in which you have to check for R_ZERO.

Isn't it a bit more performant if you generate as little TCG instructions as possible ?

Quoted 1 line

r~

Signature · 2 lines
Best regards,
Marek Vasut
#8 lore raw

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

Quoted 10 lines · Marek Vasut
Quoted 7 lines
Quoted 4 lines

Thanks, I hope this is fixed now, although I mostly special-case the R_ZERO handling throughout the code. Any writes to R_ZERO are now ignored and any usage is converted to mov/movi instructions where applicable.

We've done that in the past, but in the end it is much cleaner to minimize the number of places in which you have to check for R_ZERO.

Isn't it a bit more performant if you generate as little TCG instructions as possible ?

Well, yes and no.

We're always going to run the tcg optimizers, so the resulting code should be the same either way.

Processing a little more data can be preferable to fewer branch prediction failures. And the best way to avoid those is to not have the branch at all. Especially when it's unlikely that the data will be created in the first place.

r~

#9 lore raw

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

Quoted 9 lines · Richard Henderson
Quoted 8 lines · Marek Vasut
Quoted 7 lines
Quoted 4 lines

Thanks, I hope this is fixed now, although I mostly special-case the R_ZERO handling throughout the code. Any writes to R_ZERO are now ignored and any usage is converted to mov/movi instructions where applicable.

We've done that in the past, but in the end it is much cleaner to minimize the number of places in which you have to check for R_ZERO.

Quoted 7 lines
Quoted 2 lines

Isn't it a bit more performant if you generate as little TCG instructions as possible ?

Well, yes and no.

We're always going to run the tcg optimizers, so the resulting code should be the same either way.

I see, I'd have to dig deeper into the TCG.

Quoted 4 lines

Processing a little more data can be preferable to fewer branch prediction failures. And the best way to avoid those is to not have the branch at all. Especially when it's unlikely that the data will be created in the first place.

OK, but I need to make sure stores to ZERO register are ignored, right ?

Signature · 2 lines
Best regards,
Marek Vasut
#10 lore raw

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

Quoted 6 lines · Marek Vasut
Quoted 4 lines

Processing a little more data can be preferable to fewer branch prediction failures. And the best way to avoid those is to not have the branch at all. Especially when it's unlikely that the data will be created in the first place.

OK, but I need to make sure stores to ZERO register are ignored, right ?

Yes.

Just remember that since nios2 doesn't have condition codes, where side effects of an instruction can be useful alone, the *only* likely case of ZERO as a destination register is in the (designated) NOP psuedo-op.

r~

#11 lore raw

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

Quoted 6 lines · Richard Henderson
Quoted 5 lines · Marek Vasut
Quoted 4 lines

Processing a little more data can be preferable to fewer branch prediction failures. And the best way to avoid those is to not have the branch at all. Especially when it's unlikely that the data will be created in the first place.

Quoted 7 lines
Quoted 1 line

OK, but I need to make sure stores to ZERO register are ignored, right ?

Yes.

Just remember that since nios2 doesn't have condition codes, where side effects of an instruction can be useful alone, the *only* likely case of ZERO as a destination register is in the (designated) NOP psuedo-op.

Got it, thanks.

Signature · 2 lines
Best regards,
Marek Vasut
#19 lore raw
In reply to Marek Vasut

Hi Marek, all,

Quoted 43 lines · Marek Vasut
Quoted 1 line · Romain Naour

Hi Marek,

Hi!

Quoted 38 lines · Marek Vasut
Quoted 9 lines

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

With Waldemar Brodkorb and I, we tested this series using 10m50 kernel defconfig with Buildroot generated system. In order to ease the test, we added the device tree and a initramfs to the kernel image.

Here is the result:

Welcome to Buildroot

# cat /proc/cpuinfo
CPU:		Nios II/fast
MMU:		present
FPU:		none
Clocking:	75.00 MHz
BogoMips:	150.00
Calibration:	75000000 loops
HW:
 MUL:		yes
 MULX:		no
 DIV:		yes
Icache:		32kB, line length: 32
Dcache:		32kB, line length: 32
TLB:		16 ways, 256 entries, 8 PID bits
# uname -a
Linux buildroot 4.8.1 #2 Fri Oct 14 19:10:18 CEST 2016 nios2 GNU/Linux

When this series will be accepted in Qemu, I'll add a demo defconfig in Buildroot in order to ease runtime testing.

Quoted 8 lines
Quoted 1 line

Great, thanks ! I'm glad to see it really becomes usable for other people too :)

I handled the feedback and pushed updated patches to:
http://git.bfuser.eu/?p=marex/qemu.git;a=shortlog;h=refs/heads/nios2/master

Thanks, I tried your latest nios2 Qemu (v3 series) + patch 2/3 v6 with a 4.8.5 Linux kernel. It still boot :)

Best regards,
Romain

#20 lore raw
Quoted 1 line · Romain Naour

Hi Marek, all,

Hi,

Quoted 49 lines · Marek Vasut
Quoted 48 lines · Romain Naour
Quoted 1 line

Hi Marek,

Hi!

Quoted 35 lines · Marek Vasut
Quoted 9 lines

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

With Waldemar Brodkorb and I, we tested this series using 10m50 kernel defconfig with Buildroot generated system. In order to ease the test, we added the device tree and a initramfs to the kernel image.

Here is the result:

Welcome to Buildroot

# cat /proc/cpuinfo
CPU:		Nios II/fast
MMU:		present
FPU:		none
Clocking:	75.00 MHz
BogoMips:	150.00
Calibration:	75000000 loops
HW:
 MUL:		yes
 MULX:		no
 DIV:		yes
Icache:		32kB, line length: 32
Dcache:		32kB, line length: 32
TLB:		16 ways, 256 entries, 8 PID bits
# uname -a
Linux buildroot 4.8.1 #2 Fri Oct 14 19:10:18 CEST 2016 nios2 GNU/Linux
Quoted 4 lines

When this series will be accepted in Qemu, I'll add a demo defconfig in Buildroot in order to ease runtime testing.

Great, thanks ! I'm glad to see it really becomes usable for other people too :)

Quoted 6 lines
Quoted 3 lines

I handled the feedback and pushed updated patches to:
http://git.bfuser.eu/?p=marex/qemu.git;a=shortlog;h=refs/heads/nios2/master

Thanks, I tried your latest nios2 Qemu (v3 series) + patch 2/3 v6 with a 4.8.5 Linux kernel. It still boot :)

Great, thanks for checking :)

Signature · 2 lines
Best regards,
Marek Vasut