Nios II generic board config and semihosting support
v3 cover Nios II generic board config and semihosting support
This is a third attempt at sending the patch series:
http://lists.gnu.org/archive/html/qemu-devel/2018-05/msg04259.html
Turns out the git format-patch "--inline" option didn't do what I thought it did. Apologies for the noise!
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 v3 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
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v3 1/2] Add generic Nios II board.
Quoted 7 lines · Julian Brown
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 at0xc0000000, which allows features such as unwinding to work when binaries are linked to start at the beginning of the address space.
So why dont you just use the 10m50 GHRD for this , why do you need custom board ?
[...]
hw/nios2/generic_nommu.c line 116
Quoted 4 lines
hw/nios2/generic_nommu.c new file +4
-0+/* Configure new exception vectors and reset CPU for it to take effect. */ + cpu->reset_addr =0xd0000000 ;//0xd4000000; + cpu->exception_addr =0xc8000120 ; + cpu->fast_tlb_miss_addr =0x7fff400 ;//0xc0000100;
This //0xfoo should probably go away
Signature · 2 lines
Best regards, Marek Vasut
Re: [Qemu-devel] [PATCH v3 1/2] Add generic Nios II board.
Quoted 10 lines · On Fri, 18 May 2018 21:50:55 +0200 Marek Vasut <[email protected]> wrote:
Quoted 7 lines · Julian Brown
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 at0xc0000000, which allows features such as unwinding to work when binaries are linked to start at the beginning of the address space.So why dont you just use the 10m50 GHRD for this , why do you need custom board ?
I think because we wanted a board with no MMU, since our startup code doesn't support that. Maybe Andrew can confirm/deny?
Thanks,
Julian
Re: [Qemu-devel] [PATCH v3 1/2] Add generic Nios II board.
Quoted 11 lines · Julian Brown
Quoted 8 lines · On Fri, 18 May 2018 21:50:55 +0200 Marek Vasut <[email protected]> wrote:
Quoted 7 lines · Julian Brown
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 at0xc0000000, which allows features such as unwinding to work when binaries are linked to start at the beginning of the address space.
Quoted 5 lines
Quoted 2 lines
So why dont you just use the 10m50 GHRD for this , why do you need custom board ?
I think because we wanted a board with no MMU, since our startup code doesn't support that. Maybe Andrew can confirm/deny?
Yes, that's correct.
Thanks,
Andrew
PATCH v3 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
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v3 2/2] Add Nios II semihosting support.
Quoted 5 lines · Julian Brown
This patch (by Sandra Loosemore, mildly rebased) adds support for semihosting for Nios II bare-metal emulation.
Signed-off-by Julian Brown <[email protected]>Signed-off-by Sandra Loosemore <[email protected]>
Is there some documentation for this stuff ? It looks interesting, but how can I try it here ?
[...]
Signature · 2 lines
Best regards, Marek Vasut
Re: [Qemu-devel] [PATCH v3 2/2] Add Nios II semihosting support.
Quoted 9 lines · On Fri, 18 May 2018 21:52:04 +0200 Marek Vasut <[email protected]> wrote:
Quoted 5 lines · Julian Brown
This patch (by Sandra Loosemore, mildly rebased) adds support for semihosting for Nios II bare-metal emulation.
Signed-off-by Julian Brown <[email protected]>Signed-off-by Sandra Loosemore <[email protected]>Is there some documentation for this stuff ? It looks interesting, but how can I try it here ?
There's no documentation AFAIK apart from that the entry points are the same as m68k, semihosting is invoked with "break 1", and r4/r5 are used for passing arguments. I'm not actually sure how you can try this stuff without our startup code or other infrastructure (that I'm pretty sure we can't divulge). Sandra, any ideas?
Thanks,
Julian
Re: [Qemu-devel] [PATCH v3 2/2] Add Nios II semihosting support.
Quoted 10 lines · Julian Brown
Quoted 7 lines · On Fri, 18 May 2018 21:52:04 +0200 Marek Vasut <[email protected]> wrote:
Quoted 5 lines · Julian Brown
This patch (by Sandra Loosemore, mildly rebased) adds support for semihosting for Nios II bare-metal emulation.
Signed-off-by Julian Brown <[email protected]>Signed-off-by Sandra Loosemore <[email protected]>
Quoted 6 lines
Quoted 2 lines
Is there some documentation for this stuff ? It looks interesting, but how can I try it here ?
There's no documentation AFAIK apart from that the entry points are the same as m68k, semihosting is invoked with "break 1", and r4/r5 are used for passing arguments.
So, how is anyone supposed to test this if it's shrouded in mystery ?
Quoted 3 lines
I'm not actually sure how you can try this
stuff without our startup code or other infrastructure (that I'm pretty sure we can't divulge). Sandra, any ideas?
So what use is this code in mainline QEMU then ?
Signature · 2 lines
Best regards, Marek Vasut
Re: [Qemu-devel] [PATCH v3 2/2] Add Nios II semihosting support.
In reply to Julian BrownQuoted 10 lines · Julian Brown
Quoted 7 lines · On Fri, 18 May 2018 21:52:04 +0200 Marek Vasut <[email protected]> wrote:
Quoted 5 lines · Julian Brown
This patch (by Sandra Loosemore, mildly rebased) adds support for semihosting for Nios II bare-metal emulation.
Signed-off-by Julian Brown <[email protected]>Signed-off-by Sandra Loosemore <[email protected]>
Quoted 8 lines
Quoted 2 lines
Is there some documentation for this stuff ? It looks interesting, but how can I try it here ?
There's no documentation AFAIK apart from that the entry points are the same as m68k, semihosting is invoked with "break 1", and r4/r5 are used for passing arguments. I'm not actually sure how you can try this stuff without our startup code or other infrastructure (that I'm pretty sure we can't divulge). Sandra, any ideas?
I don't see any reason why we couldn't contribute libgloss support, except that I don't have time to write such a BSP right now. :-( I recently did this for C-SKY, though, and the semihosting parts were just a straightforward copy from the m68k port.
FWIW, CodeSourcery's Nios II ELF toolchains have been using this semihosting protocol with a different BSP library all along, and Altera also supports it in the proprietary simulators they've provided to us for testing.
-Sandra
Re: [Qemu-devel] [PATCH v3 2/2] Add Nios II semihosting support.
Quoted 14 lines · Sandra Loosemore
Quoted 13 lines · Julian Brown
Quoted 9 lines · On Fri, 18 May 2018 21:52:04 +0200 Marek Vasut <[email protected]> wrote:
Quoted 5 lines · Julian Brown
This patch (by Sandra Loosemore, mildly rebased) adds support for semihosting for Nios II bare-metal emulation.
Signed-off-by Julian Brown <[email protected]>Signed-off-by Sandra Loosemore <[email protected]>Is there some documentation for this stuff ? It looks interesting, but how can I try it here ?
Quoted 7 lines
Quoted 5 lines
There's no documentation AFAIK apart from that the entry points are the same as m68k, semihosting is invoked with "break 1", and r4/r5 are used for passing arguments. I'm not actually sure how you can try this stuff without our startup code or other infrastructure (that I'm pretty sure we can't divulge). Sandra, any ideas?
I don't see any reason why we couldn't contribute libgloss support, except that I don't have time to write such a BSP right now. :-( I recently did this for C-SKY, though, and the semihosting parts were just a straightforward copy from the m68k port.
I've posted a patch with libgloss semihosting support for nios2 here:
https://sourceware.org/ml/newlib/2018/msg00610.html
I hope this is enough to unblock consideration of the corresponding QEMU patch set now. Here's a link to the original patch posting:
http://lists.nongnu.org/archive/html/qemu-devel/2018-05/msg04571.html
-Sandra
Re: [Qemu-devel] [PATCH v3 2/2] Add Nios II semihosting support.
Quoted 26 lines · On Thu, 2 Aug 2018 15:56:47 -0600 Sandra Loosemore <[email protected]>…
Quoted 20 lines · Sandra Loosemore
Quoted 10 lines · Julian Brown
Quoted 7 lines · On Fri, 18 May 2018 21:52:04 +0200 Marek Vasut <[email protected]> wrote:
Quoted 5 lines · Julian Brown
This patch (by Sandra Loosemore, mildly rebased) adds support for semihosting for Nios II bare-metal emulation.
Signed-off-by Julian Brown <[email protected]>Signed-off-by Sandra Loosemore <[email protected]>Quoted 8 lines
Quoted 2 lines
Is there some documentation for this stuff ? It looks interesting, but how can I try it here ?
There's no documentation AFAIK apart from that the entry points are the same as m68k, semihosting is invoked with "break 1", and r4/r5 are used for passing arguments. I'm not actually sure how you can try this stuff without our startup code or other infrastructure (that I'm pretty sure we can't divulge). Sandra, any ideas?
Quoted 4 lines
I don't see any reason why we couldn't contribute libgloss support, except that I don't have time to write such a BSP right now. :-( I recently did this for C-SKY, though, and the semihosting parts were just a straightforward copy from the m68k port.
Quoted 8 lines
I've posted a patch with libgloss semihosting support for nios2 here:
https://sourceware.org/ml/newlib/2018/msg00610.html
I hope this is enough to unblock consideration of the corresponding QEMU patch set now. Here's a link to the original patch posting:
http://lists.nongnu.org/archive/html/qemu-devel/2018-05/msg04571.html
For completeness I've re-tested with a rebased QEMU and posted again (with a couple of checkpatch.pl nits fixed, but otherwise identical):
http://lists.nongnu.org/archive/html/qemu-devel/2018-08/msg01987.html
Thank you,
Julian
Quoted 6 lines · Julian Brown
This is a third attempt at sending the patch series:
http://lists.gnu.org/archive/html/qemu-devel/2018-05/msg04259.html
Turns out the git format-patch "--inline" option didn't do what I thought it did. Apologies for the noise!
Success !
Signature · 2 lines
Best regards, Marek Vasut
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v3 0/2] Nios II generic board config and semihosting support
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'659c5a97f6 Add Nios II semihosting support.c917ea3908 Add generic Nios II board.
=== OUTPUT BEGIN ===
Checking PATCH 1/2: Add generic Nios II board....
ERROR: code indent should never use tabs
#38: FILE: hw/nios2/boot.c:143:
+^Iint kernel_space = 0;$
ERROR: code indent should never use tabs
#46: FILE: hw/nios2/boot.c:158:
+^I kernel_space = 1;$
ERROR: code indent should never use tabs
#52: FILE: hw/nios2/boot.c:163:
+^I + (entry & 0x07ffffff);$
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #57:
new file mode 100644
ERROR: do not use C99 // comments
#175: FILE: hw/nios2/generic_nommu.c:114:
+ cpu->reset_addr = 0xd0000000; //0xd4000000;
ERROR: do not use C99 // comments
#177: FILE: hw/nios2/generic_nommu.c:116:
+ cpu->fast_tlb_miss_addr = 0x7fff400; //0xc0000100;
total: 5 errors, 1 warnings, 150 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 2/2: Add Nios II semihosting support....
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #105:
new file mode 100644
ERROR: braces {} are necessary for all arms of this statement #194: FILE: target/nios2/nios2-semi.c:85:
+ if (flags & GDB_O_WRONLY)
[...]
+ else if (flags & GDB_O_RDWR)
[...]
+ else
[...]
ERROR: braces {} are necessary for all arms of this statement #196: FILE: target/nios2/nios2-semi.c:87:
+ else if (flags & GDB_O_RDWR)
[...]
+ else
[...]
ERROR: trailing statements should be on next line
#201: FILE: target/nios2/nios2-semi.c:92:
+ if (flags & GDB_O_APPEND) hf |= O_APPEND;
ERROR: braces {} are necessary for all arms of this statement #201: FILE: target/nios2/nios2-semi.c:92:
+ if (flags & GDB_O_APPEND) hf |= O_APPEND;
[...]
ERROR: trailing statements should be on next line
#202: FILE: target/nios2/nios2-semi.c:93:
+ if (flags & GDB_O_CREAT) hf |= O_CREAT;
ERROR: braces {} are necessary for all arms of this statement #202: FILE: target/nios2/nios2-semi.c:93:
+ if (flags & GDB_O_CREAT) hf |= O_CREAT;
[...]
ERROR: trailing statements should be on next line
#203: FILE: target/nios2/nios2-semi.c:94:
+ if (flags & GDB_O_TRUNC) hf |= O_TRUNC;
ERROR: braces {} are necessary for all arms of this statement #203: FILE: target/nios2/nios2-semi.c:94:
+ if (flags & GDB_O_TRUNC) hf |= O_TRUNC;
[...]
ERROR: trailing statements should be on next line
#204: FILE: target/nios2/nios2-semi.c:95:
+ if (flags & GDB_O_EXCL) hf |= O_EXCL;
ERROR: braces {} are necessary for all arms of this statement #204: FILE: target/nios2/nios2-semi.c:95:
+ if (flags & GDB_O_EXCL) hf |= O_EXCL;
[...]
WARNING: line over 80 characters
#209: FILE: target/nios2/nios2-semi.c:100:
+static void translate_stat(CPUNios2State *env, target_ulong addr, struct stat *s)
ERROR: do not use assignment in if condition
#213: FILE: target/nios2/nios2-semi.c:104:
+ if (!(p = lock_user(VERIFY_WRITE, addr, sizeof(struct nios2_gdb_stat), 0)))
WARNING: line over 80 characters
#238: FILE: target/nios2/nios2-semi.c:129:
+static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, uint32_t err)
WARNING: line over 80 characters
#252: FILE: target/nios2/nios2-semi.c:143:
+static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, uint32_t err)
ERROR: do not use assignment in if condition
#493: FILE: target/nios2/nios2-semi.c:384:
+ if (!(p = lock_user(VERIFY_WRITE,
ERROR: line over 90 characters
#533: FILE: target/nios2/nios2-semi.c:424:
+ cpu_abort(CPU(nios2_env_get_cpu(env)), "Unsupported semihosting syscall %d\n", nr);
total: 13 errors, 4 warnings, 498 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]