Skip to contentSkip to conversation

Altera NiosII Support (v2)

PATCH New [email protected] 1 participant 5 messages Nov 11, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Altera NiosII Support (v2)

From: Chris Wulff <[email protected]>

This set of patches adds support for the Altera NiosII soft-core processor. Included are support for the CPU core and the drivers needed to boot Linux (Interrupt controller, Timer and Serial port.) There are quite a few changes suggested by the first round review. These include:

* Better CPU code generation
* Better support for QOM
* A bunch of coding style cleanups (struct naming, merging GDB imported disassembly, etc.)
* Updated for changes to the current head of the tree

I've also dropped the device-tree based board configurations from this patch set. Those currently depend heavily on fdt-generic patches from Peter Crosthwaite that have yet to make it into the main tree. This set of patches builds the NiosII core without errors but will report no machine found. I will resubmit those board configurations under a separate patch set once the integration and cleanup is complete for the fdt-generic board configurations is completed.

Chris Wulff (4):
NiosII: Add support for the Altera NiosII soft-core CPU.
NiosII: Disassembly of NiosII instructions ported from GDB.
Altera: Add support for devices needed to boot Linux on NiosII.
NiosII: Build system and documentation integration.

 MAINTAINERS                          |    5 +
 Makefile.objs                        |    1 +
 arch_init.c                          |    2 +
 arch_init.h                          |    1 +
 configure                            |   11 +
 cpu-exec.c                           |   12 +-
 default-configs/nios2-linux-user.mak |    1 +
 default-configs/nios2-softmmu.mak    |    5 +
 dis-asm.h                            |    3 +
 disas.c                              |    3 +
 elf.h                                |    2 +
 exec.c                               |    6 +-
 gdbstub.c                            |   29 +
 hw/Makefile.objs                     |    5 +
 hw/altera_timer.c                    |  207 ++
 hw/altera_uart.c                     |  217 +++
 hw/altera_vic.c                      |  194 ++
 hw/nios2.h                           |   52 +
 hw/nios2/Makefile.objs               |    3 +
 hw/nios2_pic_cpu.c                   |   39 +
 linux-user/elfload.c                 |   29 +
 monitor.c                            |    5 +-
 nios2-dis.c                          | 3478 ++++++++++++++++++++++++++++++++++
 qapi-schema.json                     |    2 +-
 qemu-doc.texi                        |    3 +
 target-nios2/Makefile.objs           |    5 +
 target-nios2/altera_iic.c            |  101 +
 target-nios2/cpu.c                   |   83 +
 target-nios2/cpu.h                   |  302 +++
 target-nios2/helper.c                |  291 +++
 target-nios2/helper.h                |   45 +
 target-nios2/instruction.c           | 1405 ++++++++++++++
 target-nios2/instruction.h           |  279 +++
 target-nios2/machine.c               |   33 +
 target-nios2/mmu.c                   |  273 +++
 target-nios2/mmu.h                   |   49 +
 target-nios2/op_helper.c             |  119 ++
 target-nios2/translate.c             |  253 +++
 38 files changed, 7547 insertions(+), 6 deletions(-)
 create mode 100644 default-configs/nios2-linux-user.mak
 create mode 100644 default-configs/nios2-softmmu.mak
 create mode 100644 hw/altera_timer.c
 create mode 100644 hw/altera_uart.c
 create mode 100644 hw/altera_vic.c
 create mode 100644 hw/nios2.h
 create mode 100644 hw/nios2/Makefile.objs
 create mode 100644 hw/nios2_pic_cpu.c
 create mode 100644 nios2-dis.c
 create mode 100644 target-nios2/Makefile.objs
 create mode 100644 target-nios2/altera_iic.c
 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/op_helper.c
 create mode 100644 target-nios2/translate.c
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/4 NiosII: Add support for the Altera NiosII soft-core CPU. (v2)

From: Chris Wulff <[email protected]>

---
 target-nios2/Makefile.objs |    5 +
 target-nios2/altera_iic.c  |  101 ++++
 target-nios2/cpu.c         |   83 +++
 target-nios2/cpu.h         |  302 ++++++++++
 target-nios2/helper.c      |  291 +++++++++
 target-nios2/helper.h      |   45 ++
 target-nios2/instruction.c | 1405 ++++++++++++++++++++++++++++++++++++++++++++
 target-nios2/instruction.h |  279 +++++++++
 target-nios2/machine.c     |   33 ++
 target-nios2/mmu.c         |  273 +++++++++
 target-nios2/mmu.h         |   49 ++
 target-nios2/op_helper.c   |  119 ++++
 target-nios2/translate.c   |  253 ++++++++
 13 files changed, 3238 insertions(+)
 create mode 100644 target-nios2/Makefile.objs
 create mode 100644 target-nios2/altera_iic.c
 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/op_helper.c
 create mode 100644 target-nios2/translate.c
target-nios2/Makefile.objs new file +5 -0
new file mode 100644
index 0000000..d072795
@@ -0,0 +1,5 @@
+obj-y += translate.o op_helper.o helper.o cpu.o instruction.o
+obj-$(CONFIG_SOFTMMU) += mmu.o machine.o
+obj-y += altera_iic.o
+
+$(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
target-nios2/altera_iic.c new file +101 -0

101 lines not on this page · raw message

target-nios2/cpu.c new file +83 -0

83 lines not on this page · raw message

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

302 lines not on this page · raw message

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

291 lines not on this page · raw message

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

45 lines not on this page · raw message

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

1,405 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 +33 -0
new file mode 100644
index 0000000..09198db
@@ -0,0 +1,33 @@
+/*
+ * 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>
+ */
+
+#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 +273 -0

273 lines not on this page · raw message

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

49 lines not on this page · raw message

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

119 lines not on this page · raw message

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

15 lines not on this page · raw message

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

Signature · 1 line
1.7.10.4

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

#2 lore raw

PATCH 2/4 NiosII: Disassembly of NiosII instructions ported from GDB. (v2)

In reply to [email protected]

From: Chris Wulff <[email protected]>

---
 Makefile.objs |    1 +
 nios2-dis.c   | 3478 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 3479 insertions(+)
 create mode 100644 nios2-dis.c
Makefile.objs +1 -0
index 593a592..2d6db47 100644
@@ -133,6 +133,7 @@ libdis-$(CONFIG_IA64_DIS) += ia64-dis.o
 libdis-$(CONFIG_M68K_DIS) += m68k-dis.o
 libdis-$(CONFIG_MICROBLAZE_DIS) += microblaze-dis.o
 libdis-$(CONFIG_MIPS_DIS) += mips-dis.o
+libdis-$(CONFIG_NIOS2_DIS) += nios2-dis.o
 libdis-$(CONFIG_PPC_DIS) += ppc-dis.o
 libdis-$(CONFIG_S390_DIS) += s390-dis.o
 libdis-$(CONFIG_SH4_DIS) += sh4-dis.o
nios2-dis.c new file +3478 -0

2,993 lines not on this page · raw message

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

Signature · 1 line
1.7.10.4

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

#3 lore raw

PATCH 3/4 Altera: Add support for devices needed to boot Linux on NiosII. (v2)

In reply to [email protected]

From: Chris Wulff <[email protected]>

---
 hw/Makefile.objs   |    5 ++
 hw/altera_timer.c  |  207 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/altera_uart.c   |  217 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/altera_vic.c    |  194 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/nios2.h         |   52 +++++++++++++
 hw/nios2_pic_cpu.c |   39 ++++++++++
 6 files changed, 714 insertions(+)
 create mode 100644 hw/altera_timer.c
 create mode 100644 hw/altera_uart.c
 create mode 100644 hw/altera_vic.c
 create mode 100644 hw/nios2.h
 create mode 100644 hw/nios2_pic_cpu.c
hw/Makefile.objs +5 -0
index af4ab0c..32275a5 100644
@@ -69,6 +69,11 @@ common-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o
 common-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o
 common-obj-$(CONFIG_XILINX_AXI) += stream.o
 
+# Altera devices
+common-obj-$(CONFIG_ALTERA) += altera_vic.o
+common-obj-$(CONFIG_ALTERA) += altera_uart.o
+common-obj-$(CONFIG_ALTERA) += altera_timer.o
+
 # PKUnity SoC devices
 common-obj-$(CONFIG_PUV3) += puv3_intc.o
 common-obj-$(CONFIG_PUV3) += puv3_ost.o
hw/altera_timer.c new file +207 -0

207 lines not on this page · raw message

hw/altera_uart.c new file +217 -0

217 lines not on this page · raw message

hw/altera_vic.c new file +194 -0

194 lines not on this page · raw message

hw/nios2.h new file +52 -0

52 lines not on this page · raw message

hw/nios2_pic_cpu.c new file +39 -0
new file mode 100644
index 0000000..5b6d05b
@@ -0,0 +1,39 @@
+/*
+ * QEMU Altera Nios II CPU interrupt wrapper logic.
+ *
+ * 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 "hw.h"
+#include "nios2.h"
+
+static void nios2_pic_cpu_handler(void *opaque, int irq, int level)
+{
+    Nios2CPU *cpu = opaque;
+    int type = irq ? CPU_INTERRUPT_NMI : CPU_INTERRUPT_HARD;
+
+    if (level) {
+        cpu_interrupt(&cpu->env, type);
+    } else {
+        cpu_reset_interrupt(&cpu->env, type);
+    }
+}
+
+qemu_irq *nios2_pic_init_cpu(Nios2CPU *cpu)
+{
+    return qemu_allocate_irqs(nios2_pic_cpu_handler, cpu, 2);
+}
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 4/4 NiosII: Build system and documentation integration.

In reply to [email protected]

From: Chris Wulff <[email protected]>

---
 MAINTAINERS                          |    5 +++++
 arch_init.c                          |    2 ++
 arch_init.h                          |    1 +
 configure                            |   11 +++++++++++
 cpu-exec.c                           |   12 +++++++++++-
 default-configs/nios2-linux-user.mak |    1 +
 default-configs/nios2-softmmu.mak    |    5 +++++
 dis-asm.h                            |    3 +++
 disas.c                              |    3 +++
 elf.h                                |    2 ++
 exec.c                               |    6 ++++--
 gdbstub.c                            |   29 +++++++++++++++++++++++++++++
 hw/nios2/Makefile.objs               |    3 +++
 linux-user/elfload.c                 |   29 +++++++++++++++++++++++++++++
 monitor.c                            |    5 +++--
 qapi-schema.json                     |    2 +-
 qemu-doc.texi                        |    3 +++
 17 files changed, 116 insertions(+), 6 deletions(-)
 create mode 100644 default-configs/nios2-linux-user.mak
 create mode 100644 default-configs/nios2-softmmu.mak
 create mode 100644 hw/nios2/Makefile.objs
MAINTAINERS +5 -0
index 8f5681f..615df35 100644
@@ -91,6 +91,11 @@ M: Aurelien Jarno <[email protected]>
 S: Odd Fixes
 F: target-mips/
 
+NiosII
+M: Chris Wulff <[email protected]>
+S: Odd Fixes
+F: target-nios2/
+
 PowerPC
 M: Alexander Graf <[email protected]>
 L: [email protected]
arch_init.c +2 -0
index e6effe8..0aafe8e 100644
@@ -84,6 +84,8 @@ int graphic_depth = 15;
 #define QEMU_ARCH QEMU_ARCH_MICROBLAZE
 #elif defined(TARGET_MIPS)
 #define QEMU_ARCH QEMU_ARCH_MIPS
+#elif defined(TARGET_NIOS2)
+#define QEMU_ARCH QEMU_ARCH_NIOS2
 #elif defined(TARGET_OPENRISC)
 #define QEMU_ARCH QEMU_ARCH_OPENRISC
 #elif defined(TARGET_PPC)
arch_init.h +1 -0
index 5fc780c..b2d736a 100644
@@ -20,6 +20,7 @@ enum {
     QEMU_ARCH_XTENSA = 4096,
     QEMU_ARCH_OPENRISC = 8192,
     QEMU_ARCH_UNICORE32 = 0x4000,
+    QEMU_ARCH_NIOS2 = 0x8000,
 };
 
 extern const uint32_t arch_type;
configure +11 -0
index 7290f50..554e44a 100755
@@ -924,6 +924,7 @@ mips-softmmu \
 mipsel-softmmu \
 mips64-softmmu \
 mips64el-softmmu \
+nios2-softmmu \
 or32-softmmu \
 ppc-softmmu \
 ppcemb-softmmu \
@@ -952,6 +953,7 @@ microblaze-linux-user \
 microblazeel-linux-user \
 mips-linux-user \
 mipsel-linux-user \
+nios2-linux-user \
 or32-linux-user \
 ppc-linux-user \
 ppc64-linux-user \
@@ -3808,6 +3810,11 @@ case "$target_arch2" in
     echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak
     target_long_alignment=8
   ;;
+  nios2)
+    target_nptl="yes"
+    target_phys_bits=32
+    target_libs_softmmu="$fdt_libs"
+  ;;
   or32)
     TARGET_ARCH=openrisc
     TARGET_BASE_ARCH=openrisc
@@ -4061,6 +4068,10 @@ for i in $ARCH $TARGET_BASE_ARCH ; do
     echo "CONFIG_MIPS_DIS=y"  >> $config_target_mak
     echo "CONFIG_MIPS_DIS=y"  >> $libdis_config_mak
   ;;
+  nios2)
+    echo "CONFIG_NIOS2_DIS=y"  >> $config_target_mak
+    echo "CONFIG_NIOS2_DIS=y"  >> $libdis_config_mak
+  ;;
   or32)
     echo "CONFIG_OPENRISC_DIS=y"  >> $config_target_mak
     echo "CONFIG_OPENRISC_DIS=y"  >> $libdis_config_mak
cpu-exec.c +11 -1
index 904ee73..f9da4d1 100644
@@ -220,6 +220,7 @@ int cpu_exec(CPUArchState *env)
 #elif defined(TARGET_LM32)
 #elif defined(TARGET_MICROBLAZE)
 #elif defined(TARGET_MIPS)
+#elif defined(TARGET_NIOS2)
 #elif defined(TARGET_OPENRISC)
 #elif defined(TARGET_SH4)
 #elif defined(TARGET_CRIS)
@@ -275,7 +276,8 @@ int cpu_exec(CPUArchState *env)
                     }
 #if defined(TARGET_ARM) || defined(TARGET_SPARC) || defined(TARGET_MIPS) || \
     defined(TARGET_PPC) || defined(TARGET_ALPHA) || defined(TARGET_CRIS) || \
-    defined(TARGET_MICROBLAZE) || defined(TARGET_LM32) || defined(TARGET_UNICORE32)
+    defined(TARGET_MICROBLAZE) || defined(TARGET_LM32) || \
+    defined(TARGET_UNICORE32) || defined(TARGET_NIOS2)
                     if (interrupt_request & CPU_INTERRUPT_HALT) {
                         env->interrupt_request &= ~CPU_INTERRUPT_HALT;
                         env->halted = 1;
@@ -529,6 +531,13 @@ int cpu_exec(CPUArchState *env)
                         do_interrupt(env);
                         next_tb = 0;
                     }
+#elif defined(TARGET_NIOS2)
+                    if ((interrupt_request & CPU_INTERRUPT_HARD)
+                        && (env->regs[CR_STATUS] & CR_STATUS_PIE)) {
+                        env->exception_index = EXCP_IRQ;
+                        do_interrupt(env);
+                        next_tb = 0;
+                    }
 #endif
                    /* Don't use the cached interrupt_request value,
                       do_interrupt may have updated the EXITTB flag. */
@@ -654,6 +663,7 @@ int cpu_exec(CPUArchState *env)
               | env->cc_dest | (env->cc_x << 4);
 #elif defined(TARGET_MICROBLAZE)
 #elif defined(TARGET_MIPS)
+#elif defined(TARGET_NIOS2)
 #elif defined(TARGET_OPENRISC)
 #elif defined(TARGET_SH4)
 #elif defined(TARGET_ALPHA)
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 +5 -0
new file mode 100644
index 0000000..a14708a
@@ -0,0 +1,5 @@
+# Default configuration for nios2-softmmu
+
+CONFIG_PTIMER=y
+CONFIG_PFLASH_CFI01=y
+CONFIG_ALTERA=y
dis-asm.h +3 -0
index 3944b3c..a7010bf 100644
@@ -221,6 +221,8 @@ enum bfd_architecture
   bfd_arch_ia64,      /* HP/Intel ia64 */
 #define bfd_mach_ia64_elf64    64
 #define bfd_mach_ia64_elf32    32
+  bfd_arch_nios2,
+#define bfd_mach_nios2          1
   bfd_arch_lm32,       /* Lattice Mico32 */
 #define bfd_mach_lm32 1
   bfd_arch_last
@@ -407,6 +409,7 @@ int print_insn_crisv10          (bfd_vma, disassemble_info*);
 int print_insn_microblaze       (bfd_vma, disassemble_info*);
 int print_insn_ia64             (bfd_vma, disassemble_info*);
 int print_insn_lm32             (bfd_vma, disassemble_info*);
+int print_insn_nios2            (bfd_vma, disassemble_info*);
 
 #if 0
 /* Fetch the disassembler for a given BFD, if that support is available.  */
disas.c +3 -0
index b801c8f..8469c2e 100644
@@ -245,6 +245,9 @@ void target_disas(FILE *out, target_ulong code, target_ulong size, int flags)
 #elif defined(TARGET_MICROBLAZE)
     disasm_info.mach = bfd_arch_microblaze;
     print_insn = print_insn_microblaze;
+#elif defined(TARGET_NIOS2)
+    disasm_info.mach = bfd_arch_nios2;
+    print_insn = print_insn_nios2;
 #elif defined(TARGET_LM32)
     disasm_info.mach = bfd_mach_lm32;
     print_insn = print_insn_lm32;
elf.h +2 -0
index a21ea53..e5e667b 100644
@@ -124,6 +124,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
 
exec.c +4 -2
index af94f9c..e6faf0f 100644
@@ -2860,7 +2860,8 @@ static uint64_t unassigned_mem_read(void *opaque, hwaddr addr,
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
 #endif
-#if defined(TARGET_ALPHA) || defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
+#if defined(TARGET_ALPHA) || defined(TARGET_SPARC) || \
+    defined(TARGET_MICROBLAZE) || defined(TARGET_NIOS2)
     cpu_unassigned_access(cpu_single_env, addr, 0, 0, 0, size);
 #endif
     return 0;
@@ -2872,7 +2873,8 @@ static void unassigned_mem_write(void *opaque, hwaddr addr,
 #ifdef DEBUG_UNASSIGNED
     printf("Unassigned mem write " TARGET_FMT_plx " = 0x%"PRIx64"\n", addr, val);
 #endif
-#if defined(TARGET_ALPHA) || defined(TARGET_SPARC) || defined(TARGET_MICROBLAZE)
+#if defined(TARGET_ALPHA) || defined(TARGET_SPARC) || \
+    defined(TARGET_MICROBLAZE) || defined(TARGET_NIOS2)
     cpu_unassigned_access(cpu_single_env, addr, 1, 0, 0, size);
 #endif
 }
gdbstub.c +29 -0
index d02ec75..3c741fb 100644
@@ -1367,6 +1367,33 @@ static int cpu_gdb_write_register(CPUMBState *env, uint8_t *mem_buf, int n)
     }
     return 4;
 }
+
+#elif defined(TARGET_NIOS2)
+
+static int cpu_gdb_read_register(CPUNios2State *env, uint8_t *mem_buf, int n)
+{
+    if (n > NUM_CORE_REGS) {
+        return 0;
+    }
+
+    GET_REG32(env->regs[n]);
+    return 0;
+}
+
+static int cpu_gdb_write_register(CPUNios2State *env, uint8_t *mem_buf, int n)
+{
+    uint32_t tmp;
+
+    if (n > NUM_CORE_REGS) {
+        return 0;
+    }
+
+    tmp = ldl_p(mem_buf);
+
+    env->regs[n] = tmp;
+    return 4;
+}
+
 #elif defined (TARGET_CRIS)
 
 #define NUM_CORE_REGS 49
@@ -2030,6 +2057,8 @@ static void gdb_set_cpu_pc(GDBState *s, target_ulong pc)
     }
 #elif defined (TARGET_MICROBLAZE)
     s->c_cpu->sregs[SR_PC] = pc;
+#elif defined(TARGET_NIOS2)
+    s->c_cpu->regs[R_PC] = pc;
 #elif defined(TARGET_OPENRISC)
     s->c_cpu->pc = pc;
 #elif defined (TARGET_CRIS)
hw/nios2/Makefile.objs new file +3 -0
new file mode 100644
index 0000000..5a92c78
@@ -0,0 +1,3 @@
+obj-y += nios2_pic_cpu.o
+
+obj-y := $(addprefix ../,$(obj-y))
linux-user/elfload.c +29 -0
index 1d8bcb4..31e77a9 100644
@@ -804,6 +804,35 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMBState *env
 
 #endif /* TARGET_MICROBLAZE */
 
+#ifdef TARGET_NIOS2
+
+#define ELF_START_MMAP 0x80000000
+
+#define elf_check_arch(x) ((x) == EM_ALTERA_NIOS2)
+
+#define ELF_CLASS   ELFCLASS32
+#define ELF_ARCH    EM_ALTERA_NIOS2
+
+static inline void init_thread(struct target_pt_regs *regs,
+                               struct image_info *infop)
+{
+    /* TODO */
+}
+
+#define ELF_EXEC_PAGESIZE        4096
+
+#define USE_ELF_CORE_DUMP
+/* TODO - #define ELF_NREG 38 */
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs.  */
+static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUState *env)
+{
+    /* TODO */
+}
+
+#endif /* TARGET_NIOS2 */
+
 #ifdef TARGET_OPENRISC
 
 #define ELF_START_MMAP 0x08000000
monitor.c +3 -2
index c0e32d6..ca93008 100644
@@ -1764,7 +1764,8 @@ static void tlb_info(Monitor *mon)
 
 #endif
 
-#if defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_XTENSA)
+#if defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_XTENSA) || \
+    defined(TARGET_NIOS2)
 static void tlb_info(Monitor *mon)
 {
     CPUArchState *env1 = mon_get_cpu();
@@ -2529,7 +2530,7 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_pci,
     },
 #if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \
-    defined(TARGET_PPC) || defined(TARGET_XTENSA)
+    defined(TARGET_PPC) || defined(TARGET_XTENSA) || defined(TARGET_NIOS2)
     {
         .name       = "tlb",
         .args_type  = "",
qapi-schema.json +1 -1
index 542e3ac..b7e72d9 100644
@@ -2871,7 +2871,7 @@
 ##
 { 'enum': 'TargetType',
   'data': [ 'alpha', 'arm', 'cris', 'i386', 'lm32', 'm68k', 'microblazeel',
-            'microblaze', 'mips64el', 'mips64', 'mipsel', 'mips', 'or32',
+            'microblaze', 'mips64el', 'mips64', 'mipsel', 'mips', 'nios2', 'or32',
             'ppc64', 'ppcemb', 'ppc', 's390x', 'sh4eb', 'sh4', 'sparc64',
             'sparc', 'unicore32', 'x86_64', 'xtensaeb', 'xtensa' ] }
 
qemu-doc.texi +3 -0
index 35cabbc..3515f15 100644
@@ -2475,6 +2475,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
1.7.10.4