Nios II generic board config and semihosting support
v2 cover Nios II generic board config and semihosting support
This is a second attempt at sending this patch series:
http://lists.gnu.org/archive/html/qemu-devel/2018-05/msg04259.html
with some git format-patch/send-email hiccups ironed out (hopefully). The patch contents are unchanged.
OK, or any comments?
Thanks,
Julian
Julian Brown (2):
Add generic Nios II board.
Add Nios II semihosting support.
hw/nios2/Makefile.objs | 2 +- hw/nios2/boot.c | 5 +- hw/nios2/generic_nommu.c | 128 ++++++++++++++ qemu-options.hx | 8 +- target/nios2/Makefile.objs | 2 +- target/nios2/cpu.h | 4 +- target/nios2/helper.c | 11 ++ target/nios2/nios2-semi.c | 429 +++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 581 insertions(+), 8 deletions(-) create mode 100644 hw/nios2/generic_nommu.c create mode 100644 target/nios2/nios2-semi.c
Signature · 1 line
1.9.1
PATCH v2 1/2 Add generic Nios II board.
This patch adds support for a generic MMU-less Nios II board that can be used e.g. for bare-metal compiler testing. Nios II booting is also tweaked so that bare-metal binaries start executing in RAM starting at 0x00000000, rather than an alias at 0xc0000000, which allows features such as unwinding to work when binaries are linked to start at the beginning of the address space.
The generic_nommu.c parts are by Andrew Jenner, based on code by Marek Vasut.
Originally by Marek Vasut and Andrew Jenner.
--- hw/nios2/Makefile.objs | 2 +- hw/nios2/boot.c | 5 +- hw/nios2/generic_nommu.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 hw/nios2/generic_nommu.c
hw/nios2/Makefile.objs +1 -1
@@ -1 +1 @@ -obj-y = boot.o cpu_pic.o 10m50_devboard.o +obj-y = boot.o cpu_pic.o 10m50_devboard.o generic_nommu.o
hw/nios2/boot.c +4 -1
@@ -140,6 +140,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,uint64_t entry, low, high;uint32_t base32;int big_endian =0 ; +int kernel_space =0 ;#ifdef TARGET_WORDS_BIGENDIAN big_endian =1 ;
@@ -154,10 +155,12 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, kernel_size =load_elf (kernel_filename, translate_kernel_address,NULL , &entry,NULL ,NULL , big_endian,EM_ALTERA_NIOS2 ,0 ,0 ); + kernel_space =1 ; }/* Always boot into physical ram. */ - boot_info.bootstrap_pc = ddr_base +0xc0000000 + (entry &0x07ffffff ); + boot_info.bootstrap_pc = ddr_base + (kernel_space ?0xc0000000 :0 ) + + (entry &0x07ffffff );/* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size <0 ) {
hw/nios2/generic_nommu.c new file +128 -0
128 lines not on this page · raw message
PATCH v2 2/2 Add Nios II semihosting support.
In reply to Julian BrownThis patch (by Sandra Loosemore, mildly rebased) adds support for semihosting for Nios II bare-metal emulation.
--- qemu-options.hx | 8 +- target/nios2/Makefile.objs | 2 +- target/nios2/cpu.h | 4 +- target/nios2/helper.c | 11 ++ target/nios2/nios2-semi.c | 429 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 448 insertions(+), 6 deletions(-) create mode 100644 target/nios2/nios2-semi.c
qemu-options.hx +4 -4
@@ -3780,21 +3780,21 @@ ETEXI DEF("semihosting", 0, QEMU_OPTION_semihosting, "-semihosting semihosting mode\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32 | - QEMU_ARCH_MIPS) + QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2) STEXI @item -semihosting @findex -semihosting -Enable semihosting mode (ARM, M68K, Xtensa, MIPS only). +Enable semihosting mode (ARM, M68K, Xtensa, MIPS, Nios II only). ETEXI DEF("semihosting-config", HAS_ARG, QEMU_OPTION_semihosting_config, "-semihosting-config [enable=on|off][,target=native|gdb|auto][,arg=str[,...]]\n" \ " semihosting configuration\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32 | -QEMU_ARCH_MIPS) +QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2) STEXI @item -semihosting-config [enable=on|off][,target=native|gdb|auto][,arg=str[,...]] @findex -semihosting-config -Enable and configure semihosting (ARM, M68K, Xtensa, MIPS only). +Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II only). @table @option @item target=@code{native|gdb|auto} Defines where the semihosting calls will be addressed, to QEMU (@code{native})
target/nios2/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -obj-y += translate.o op_helper.o helper.o cpu.o mmu.o +obj-y += translate.o op_helper.o helper.o cpu.o mmu.o nios2-semi.o obj-$(CONFIG_SOFTMMU) += monitor.o $(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
target/nios2/cpu.h +3 -1
@@ -141,7 +141,7 @@ typedef struct Nios2CPUClass {#define R_PC 64/* Exceptions */ -#define EXCP_BREAK -1 +#define EXCP_BREAK 0x1000#define EXCP_RESET 0#define EXCP_PRESET 1#define EXCP_IRQ 2
@@ -223,6 +223,8 @@ void nios2_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,qemu_irq *nios2_cpu_pic_init (Nios2CPU *cpu);void nios2_check_interrupts (CPUNios2State *env); +void do_nios2_semihosting (CPUNios2State *env); +#define TARGET_PHYS_ADDR_SPACE_BITS 32#ifdef CONFIG_USER_ONLY # define TARGET_VIRT_ADDR_SPACE_BITS 31
target/nios2/helper.c +11 -0
@@ -25,6 +25,7 @@#include "exec/exec-all.h" #include "exec/log.h" #include "exec/helper-proto.h" +#include "exec/semihost.h" #if defined(CONFIG_USER_ONLY )
@@ -169,6 +170,16 @@ void nios2_cpu_do_interrupt(CPUState *cs)break ;case EXCP_BREAK : +qemu_log_mask (CPU_LOG_INT ,"BREAK exception at pc=%x\n" , + env->regs[R_PC ]); + +if (semihosting_enabled ()) { +qemu_log_mask (CPU_LOG_INT ,"Entering semihosting\n" ); + env->regs[R_PC ] +=4 ; +do_nios2_semihosting (env); +break ; + } +if ((env->regs[CR_STATUS ] &CR_STATUS_EH ) ==0 ) { env->regs[CR_BSTATUS ] = env->regs[CR_STATUS ]; env->regs[R_BA ] = env->regs[R_PC ] +4 ;
target/nios2/nios2-semi.c new file +429 -0
429 lines not on this page · raw message
Quoted 9 lines · Julian Brown
This is a second attempt at sending this patch series:
http://lists.gnu.org/archive/html/qemu-devel/2018-05/msg04259.html
with some git format-patch/send-email hiccups ironed out (hopefully). The patch contents are unchanged.
OK, or any comments?
Same problem as with v2, git format-patch + git send-email please.
Signature · 2 lines
Best regards, Marek Vasut
Quoted 9 lines · Julian Brown
This is a second attempt at sending this patch series:
http://lists.gnu.org/archive/html/qemu-devel/2018-05/msg04259.html
with some git format-patch/send-email hiccups ironed out (hopefully). The patch contents are unchanged.
OK, or any comments?
Same problem as with v1, git format-patch + git send-email please.
Signature · 2 lines
Best regards, Marek Vasut