Re: Deprecation/removal of nios2 target support
On 4/18/24 10:06, Jeff Law wrote: ACK. Just one more note to the wider audience. I looked at QEMU's user mode support for nios2 on/off over the last couple years. It never seemed to work well enough be able to run the GCC testsuite reliably. I looked at the problems with the nios2 user-mode support in QEMU in some detail a few years ago. It looked like the problem was that it had copied the target syscall data structures from GLIBC and wasn't accounting for 32-bit target/64-bit host differences -- this particularly affected signal handling. I'm pretty sure we asked Intel if they wanted this fixed and they were not interested in pursuing that. The end result is that user-mode QEMU is not very useful for GLIBC or GDB testing. As a result, my tester builds nios2 and will run the testsuite, but all the execution tests are only built, they're not actually run. It's been fairly stable, but its not doing in-depth testing. Yes, as I noted in my previous message, there is nothing seriously wrong with the nios2 GCC port at present; it just seems kind of pointless to invest time in continuing to maintain it as a hobby when the architecture is dead. I think legacy customers generally would prefer to keep using the toolchains previously distributed by Altera/Intel or Mentor/Siemens instead of trying to build a new bleeding-edge toolchain from scratch, too. -Sandra
Deprecation/removal of nios2 target support
Tomorrow I plan to push patches to mark the nios2 target as obsolete in GCC 14. Background: Intel has EOL'ed the Nios II processor IP and is now directing their FPGA customers to a RISC-V platform instead. https://www.intel.com/content/www/us/en/content-details/781327/intel-is-discontinuing-ip-ordering-codes-listed-in-pdn2312-for-nios-ii-ip.html The Nios II hardware on loan from Intel that we were using for testing at Mentor Graphics/Siemens was returned around the first of the year. For some time we had been using QEMU to test the nios2-elf target, but we never had a QEMU test harness set up that would boot the Linux kernel, and user-mode QEMU on this target is too buggy/unmaintained to use for primary testing. So the current situation is that none of the listed maintainers for any of the GNU toolchain components have access to a fully working test configuration any more, we have all moved on to new jobs and different projects, Intel has also moved on to a different platform, and our former contacts on Intel's Nios II team have moved on as well. It seems like it's time to pull the plug. Therefore I'd like to mark Nios II as obsolete in GCC 14 now, and remove support from all toolchain components after the release is made. I'm not sure there is an established process for obsoleting/removing support in other components; besides binutils, GDB, and GLIBC, there's QEMU, newlib/libgloss, and the Linux kernel. But, we need to get the ball rolling somewhere. I did do some GCC testing on both ELF and Linux Nios II targets around the end of December and another round about a month ago, so I believe GCC 14 will pretty much be in working order. Beyond that, though, I think it would be better to remove support promptly, rather than having it hang around in an unmaintained/untestable zombie state, getting ever more bit-rotten. -Sandra
Re: [PATCH-for-8.2] target/nios2: Deprecate the Nios II architecture
On 11/17/23 01:46, Thomas Huth wrote: Being orphan for so long in QEMU, I guess it makes sense to mark it as deprecated here now. We can still reconsider if a new maintainer shows up... Reviewed-by: Thomas Huth I agree, but I'd be surprised if anybody steps forward, since Intel has pretty much dropped all support for the nios2 architecture now (their current FPGA products based on risc-v). At this point it looks very much like the upcoming GCC 14 release will be the last that includes support for this target. -Sandra
Re: [PATCH] MAINTAINERS: Mark the Nios II CPU as orphan
On 3/13/23 14:46, Philippe Mathieu-Daudé wrote: +CodeSourcery folks On 13/3/23 19:33, Thomas Huth wrote: Marek and Chris haven't been active for Nios II since years (the last time seems to have been in 2017), and we've got unhandled severe Nios II bug tickets in the bug tracker since a long time, so to avoid wrong expectations of people who are looking at the MAINTAINERS file, it's maybe best to mark the Nios II entry as orphan nowadays. Thanks for the heads up. We're still maintaining Nios II support in other components like GCC for now, but I am not sure whether it makes any sense for us to take on QEMU too at this point. I'll raise the issue, anyway. -Sandra
Re: [Qemu-devel] libvhost-user: undefined reference to MADV_NOHUGEPAGE
On 8/27/19 9:01 PM, Richard Henderson wrote: On 8/27/19 6:42 PM, Sandra Loosemore wrote: Sorry if that was not clear. The target is aarch64-none-elf with the provided semihosting facilities in QEMU. The host is x86_64-linux-gnu. We deliberately link against a pretty old glibc sysroot (looks like version 2.11.1), but we did that for last year's 3.0 release as well, and haven't made any other changes in the configure options etc that we use to build QEMU for this target. Still not clear. The combination "glibc" and "qemu semihosting" doesn't make sense. The triplet "aarch64-none-elf" is a gcc thing and has no referent in qemu. Are you building qemu-system-aarch64 for x86_64-linux, using an old x86_64 sysroot? Yes. We only use this configuration of QEMU as an instruction-set simulator so that we can test cross-compilers and gdb for bare-metal aarch64-none-elf target, using newlib as the target C library and the GDB semihosting support in QEMU for low-level fileio primitives. BTW, I did not run into this undefined-symbol error when building the equivalent configuration for bare-metal nios2-elf target with the same sysroot and host setup. That target does not build libvhost-user at all. In any case, glibc 2.11.1 is definitely out of support. Even CentOS 6 used 2.12 and we don't support that anymore either. Of the current long-term-support distros, I believe the oldest version of glibc is CentOS 7 with 2.17. As recently mentioned in https://lists.gnu.org/archive/html/qemu-devel/2019-08/msg04514.html we may accept a small patch with a large comment, but there are no guarantees how long we will keep such workarounds. I wouldn't mind just applying a local patch to fix the build. What I'm really trying to do is just get help in understanding what broke this, so I can come up with such a patch to un-break it again. I encourage you to re-examine why you're carrying around a 10 year old glibc. We update our host build environment infrequently, and we've still had customers requiring CentOS 6 support until quite recently. -Sandra
Re: [Qemu-devel] libvhost-user: undefined reference to MADV_NOHUGEPAGE
On 8/27/19 6:39 PM, Richard Henderson wrote: On 8/27/19 5:26 PM, Sandra Loosemore wrote: Yesterday I tried to build the recent 4.1 release system-mode QEMU for aarch64-none-elf and ran into a compilation error in ./contrib/libvhost-user/libvhost-user.c. Why are you attempting to compile qemu for a non-hosted (aka bare metal) configuration? That is certainly not a supported thing to do. We require POSIX (or Win32) at a minimum. I can only presume that you're intending a hosted configuration, and using a cross-compiler that doesn't actually match up. What is the intended host (and libc if this is for Linux, since there are at least 3)? Sorry if that was not clear. The target is aarch64-none-elf with the provided semihosting facilities in QEMU. The host is x86_64-linux-gnu. We deliberately link against a pretty old glibc sysroot (looks like version 2.11.1), but we did that for last year's 3.0 release as well, and haven't made any other changes in the configure options etc that we use to build QEMU for this target. -Sandra
[Qemu-devel] libvhost-user: undefined reference to MADV_NOHUGEPAGE
Yesterday I tried to build the recent 4.1 release system-mode QEMU for aarch64-none-elf and ran into a compilation error in ./contrib/libvhost-user/libvhost-user.c. It's complaining about MADV_NOHUGEPAGE not being defined. I'm not familiar with that code or even what it does; should that bit of logic be made conditional on MADV_NOHUGEPAGE being defined, or is this indicative of a configuration error for this target? I see the unguarded reference was also present in the 3.0 release so it seems like whatever changed is somewhere else, and I don't know where to look for it or what I should be looking for. :-S Does this sound familiar to anyone else? -Sandra
[Qemu-devel] [PATCH V3] gdbstub: Fix handler for 'F' packet
Handling of the 'F' packet has been broken since commit 4b20fab101b9e2d0fb47454209637a17fc7a13d5, which converted it to use the new packet parsing infrastructure. Per the GDB RSP specification https://sourceware.org/gdb/current/onlinedocs/gdb/The-F-Reply-Packet.html the second parameter may be omitted, but the rewritten implementation was failing to recognize this case. The result was that QEMU was repeatedly resending the fileio request and ignoring GDB's replies of successful completion. This patch restores the behavior of the previous code in allowing the errno parameter to be omitted and passing 0 to the callback in that case. Signed-off-by: Sandra Loosemore --- gdbstub.c | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index b92ba59..3e8bcd0 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1820,11 +1820,15 @@ static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) { -if (gdb_ctx->num_params >= 2 && gdb_ctx->s->current_syscall_cb) { +if (gdb_ctx->num_params >= 1 && gdb_ctx->s->current_syscall_cb) { target_ulong ret, err; ret = (target_ulong)gdb_ctx->params[0].val_ull; -err = (target_ulong)gdb_ctx->params[1].val_ull; +if (gdb_ctx->num_params >= 2) { +err = (target_ulong)gdb_ctx->params[1].val_ull; +} else { +err = 0; +} gdb_ctx->s->current_syscall_cb(gdb_ctx->s->c_cpu, ret, err); gdb_ctx->s->current_syscall_cb = NULL; } -- 2.8.1
Re: [Qemu-devel] [PATCH V2] gdbstub: Fix handler for 'F' packet
On 8/27/19 3:30 PM, no-re...@patchew.org wrote: === OUTPUT BEGIN === ERROR: space prohibited before that close parenthesis ')' #37: FILE: gdbstub.c:1827: +if (gdb_ctx->num_params >= 2 ) { Arggghh, I am sorry. I fixed this and then screwed up and resent the old patch over again. I'll try again. -Sandra
[Qemu-devel] [PATCH V2] gdbstub: Fix handler for 'F' packet
Handling of the 'F' packet has been broken since commit 4b20fab101b9e2d0fb47454209637a17fc7a13d5, which converted it to use the new packet parsing infrastructure. Per the GDB RSP specification https://sourceware.org/gdb/current/onlinedocs/gdb/The-F-Reply-Packet.html the second parameter may be omitted, but the rewritten implementation was failing to recognize this case. The result was that QEMU was repeatedly resending the fileio request and ignoring GDB's replies of successful completion. This patch restores the behavior of the previous code in allowing the errno parameter to be omitted and passing 0 to the callback in that case. Signed-off-by: Sandra Loosemore --- gdbstub.c | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index b92ba59..141568a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1820,11 +1820,15 @@ static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) { -if (gdb_ctx->num_params >= 2 && gdb_ctx->s->current_syscall_cb) { +if (gdb_ctx->num_params >= 1 && gdb_ctx->s->current_syscall_cb) { target_ulong ret, err; ret = (target_ulong)gdb_ctx->params[0].val_ull; -err = (target_ulong)gdb_ctx->params[1].val_ull; +if (gdb_ctx->num_params >= 2 ) { +err = (target_ulong)gdb_ctx->params[1].val_ull; +} else { +err = 0; +} gdb_ctx->s->current_syscall_cb(gdb_ctx->s->c_cpu, ret, err); gdb_ctx->s->current_syscall_cb = NULL; } -- 2.8.1
[Qemu-devel] [PATCH] gdbstub: Fix handler for 'F' packet
Handling of the 'F' packet has been broken since commit 4b20fab101b9e2d0fb47454209637a17fc7a13d5, which converted it to use the new packet parsing infrastructure. Per the GDB RSP specification https://sourceware.org/gdb/current/onlinedocs/gdb/The-F-Reply-Packet.html the second parameter may be omitted, but the rewritten implementation was failing to recognize this case. The result was that QEMU was repeatedly resending the fileio request and ignoring GDB's replies of successful completion. This patch restores the behavior of the previous code in allowing the errno parameter to be omitted and passing 0 to the callback in that case. Signed-off-by: Sandra Loosemore --- gdbstub.c | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index b92ba59..141568a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1820,11 +1820,15 @@ static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) { -if (gdb_ctx->num_params >= 2 && gdb_ctx->s->current_syscall_cb) { +if (gdb_ctx->num_params >= 1 && gdb_ctx->s->current_syscall_cb) { target_ulong ret, err; ret = (target_ulong)gdb_ctx->params[0].val_ull; -err = (target_ulong)gdb_ctx->params[1].val_ull; +if (gdb_ctx->num_params >= 2 ) { +err = (target_ulong)gdb_ctx->params[1].val_ull; +} else { +err = 0; +} gdb_ctx->s->current_syscall_cb(gdb_ctx->s->c_cpu, ret, err); gdb_ctx->s->current_syscall_cb = NULL; } -- 2.8.1
[Qemu-devel] [PATCH V2 0/2] Fix bug in nios2 and m68k semihosting
I noticed recently that the exit semihosting call on nios2 was ignoring its parameter and always returning status 0 instead. It turns out the handler was retrieving the value of the wrong register. Since the nios2 semihosting implementation was basically cut-and-pasted from that for m68k, I checked m68k also and it had the same bug. This set of patches fixes both of them. There are no changes to the actual patches from V1, only more informative commit messages with links to the respective semihosting protocol documents in newlib. Sandra Loosemore (2): target/nios2: Fix bug in semihosted exit handling target/m68k: Fix bug in semihosted exit handling target/m68k/m68k-semi.c | 4 ++-- target/nios2/nios2-semi.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) -- 2.8.1
[Qemu-devel] [PATCH V2 1/2] target/nios2: Fix bug in semihosted exit handling
This patch fixes a bug that caused semihosted exit to always return status 0; it was incorrectly using the value of register R_ARG0 (which contains the HOSTED_EXIT request number) instead of register R_ARG1. Note that per the newlib documentation for the nios2 semihosting protocol https://www.sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/nios2/nios2-semi.txt;h=ded3a093c03dbae84cb95b4cd45bc3e0d751eda2;hb=HEAD for the HOSTED_EXIT syscall the parameter is passed directly in the register instead of in a parameter block pointed to by the register. Signed-off-by: Sandra Loosemore Reviewed-by: Laurent Vivier --- target/nios2/nios2-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index d7a80dd..06c0861 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -215,8 +215,8 @@ void do_nios2_semihosting(CPUNios2State *env) args = env->regs[R_ARG1]; switch (nr) { case HOSTED_EXIT: -gdb_exit(env, env->regs[R_ARG0]); -exit(env->regs[R_ARG0]); +gdb_exit(env, env->regs[R_ARG1]); +exit(env->regs[R_ARG1]); case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); -- 2.8.1
Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
On 8/21/19 9:41 AM, Laurent Vivier wrote: Could add this information in the commit messages of each patch? Sure. V2 of the patches coming up shortly. -Sandra
[Qemu-devel] [PATCH V2 2/2] target/m68k: Fix bug in semihosted exit handling
This patch fixes a bug that caused semihosted exit to always return status 0; it was incorrectly using the value of D0 (which contains the HOSTED_EXIT request number) instead of D1. Note that per the newlib documentation for the m68k semihosting protocol https://www.sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/m68k/m68k-semi.txt;h=50520c15292aa7edf7eef28e09fd9202ce75b153;hb=HEAD for the HOSTED_EXIT syscall the parameter is passed directly in the register instead of in a parameter block pointed to by the register. Signed-off-by: Sandra Loosemore Reviewed-by: Laurent Vivier --- target/m68k/m68k-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 8e5fbfc..f189c92 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -194,8 +194,8 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) args = env->dregs[1]; switch (nr) { case HOSTED_EXIT: -gdb_exit(env, env->dregs[0]); -exit(env->dregs[0]); +gdb_exit(env, env->dregs[1]); +exit(env->dregs[1]); case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); -- 2.8.1
Re: [Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
On 8/21/19 8:41 AM, Laurent Vivier wrote: Le 21/08/2019 à 16:21, Sandra Loosemore a écrit : This patch fixes a bug that caused semihosted exit to always return status 0; it was incorrectly using the value of register R_ARG0 (which contains the HOSTED_EXIT request number) instead of register R_ARG1. Signed-off-by: Sandra Loosemore --- target/nios2/nios2-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index d7a80dd..06c0861 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -215,8 +215,8 @@ void do_nios2_semihosting(CPUNios2State *env) args = env->regs[R_ARG1]; switch (nr) { case HOSTED_EXIT: -gdb_exit(env, env->regs[R_ARG0]); -exit(env->regs[R_ARG0]); +gdb_exit(env, env->regs[R_ARG1]); +exit(env->regs[R_ARG1]); It's weird: in line 215, env->regs[R_ARG1] is args. Are you sure it's not something like: GET_ARG(0) gdb_exit(env, arg0); exit(arg0); same for m68k. Did you check the kernel code? It's not the kernel that's involved here, it's libgloss. And yes, the HOSTED_EXIT case takes an immediate argument in the register rather than a pointer to an argument block. Here's the documentation for nios2 semihosting. https://www.sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/nios2/nios2-semi.txt;h=ded3a093c03dbae84cb95b4cd45bc3e0d751eda2;hb=HEAD And m68k: https://www.sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/m68k/m68k-semi.txt;h=50520c15292aa7edf7eef28e09fd9202ce75b153;hb=HEAD Again, a lot of cutting and pasting involved here. ;-) -Sandra
[Qemu-devel] [PATCH 0/2] Fix bug in nios2 and m68k semihosting
I noticed recently that the exit semihosting call on nios2 was ignoring its parameter and always returning status 0 instead. It turns out the handler was retrieving the value of the wrong register. Since the nios2 semihosting implementation was basically cut-and-pasted from that for m68k, I checked m68k also and it had the same bug. This set of patches fixes both of them. Sandra Loosemore (2): target/nios2: Fix bug in semihosted exit handling target/m68k: Fix bug in semihosted exit handling target/m68k/m68k-semi.c | 4 ++-- target/nios2/nios2-semi.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) -- 2.8.1
[Qemu-devel] [PATCH 2/2] target/m68k: Fix bug in semihosted exit handling
This patch fixes a bug that caused semihosted exit to always return status 0; it was incorrectly using the value of D0 (which contains the HOSTED_EXIT request number) instead of D1. Signed-off-by: Sandra Loosemore --- target/m68k/m68k-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 8e5fbfc..f189c92 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -194,8 +194,8 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) args = env->dregs[1]; switch (nr) { case HOSTED_EXIT: -gdb_exit(env, env->dregs[0]); -exit(env->dregs[0]); +gdb_exit(env, env->dregs[1]); +exit(env->dregs[1]); case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); -- 2.8.1
[Qemu-devel] [PATCH 1/2] target/nios2: Fix bug in semihosted exit handling
This patch fixes a bug that caused semihosted exit to always return status 0; it was incorrectly using the value of register R_ARG0 (which contains the HOSTED_EXIT request number) instead of register R_ARG1. Signed-off-by: Sandra Loosemore --- target/nios2/nios2-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index d7a80dd..06c0861 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -215,8 +215,8 @@ void do_nios2_semihosting(CPUNios2State *env) args = env->regs[R_ARG1]; switch (nr) { case HOSTED_EXIT: -gdb_exit(env, env->regs[R_ARG0]); -exit(env->regs[R_ARG0]); +gdb_exit(env, env->regs[R_ARG1]); +exit(env->regs[R_ARG1]); case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); -- 2.8.1
Re: [Qemu-devel] [PATCH v7 0/2] Nios II generic board config and semihosting
On 4/29/19 9:55 AM, Peter Maydell wrote: On Wed, 3 Apr 2019 at 20:53, Sandra Loosemore wrote: This is the seventh version of the patch series last posted here: http://lists.nongnu.org/archive/html/qemu-devel/2019-03/msg06255.html Changes since v6: - Fixed block comment formatting for QEMU style. - Fixed fixme for interrupt handler (now added to libgloss BSP). - Added link to libgloss semihosting documentation. Sandra Loosemore (2): Add generic Nios II board. Add Nios II semihosting support. Since Nios II doesn't have anybody actively handling pull requests for it right now, I've applied these patches directly to master -- thanks! Thank you for taking care of this! -Sandra
Re: [Qemu-devel] [PATCH v7 2/2] Add Nios II semihosting support.
On 4/4/19 1:00 AM, Peter Maydell wrote: On Thu, 4 Apr 2019 at 13:44, Sandra Loosemore wrote: On 4/3/19 11:59 PM, Peter Maydell wrote: On Thu, 4 Apr 2019 at 02:53, Sandra Loosemore wrote: This patch adds support for libgloss semihosting to Nios II bare-metal emulation. The specification for the protocol can be found in the libgloss sources. Signed-off-by: Sandra Loosemore Signed-off-by: Julian Brown I gave a reviewed-by tag for this patch in v6 -- has something changed in v7 that made that no longer able to carry across? I fixed the formatting problems you asked me to address. What else am I supposed to do? I don't understand what you mean about the tag. If somebody provides you with a Reviewed-by tag and you submit a fresh version of the patchset then you should include that tag in your commit message; that records that the patch has been reviewed so that people know it doesn't need to be looked at again. https://wiki.qemu.org/Contribute/SubmitAPatch#Proper_use_of_Reviewed-by:_tags_can_aid_review Hmmm, OK; I missed that. So do I need to resubmit the patches just to add that tag? -Sandra
Re: [Qemu-devel] [PATCH v7 2/2] Add Nios II semihosting support.
On 4/3/19 11:59 PM, Peter Maydell wrote: On Thu, 4 Apr 2019 at 02:53, Sandra Loosemore wrote: This patch adds support for libgloss semihosting to Nios II bare-metal emulation. The specification for the protocol can be found in the libgloss sources. Signed-off-by: Sandra Loosemore Signed-off-by: Julian Brown I gave a reviewed-by tag for this patch in v6 -- has something changed in v7 that made that no longer able to carry across? I fixed the formatting problems you asked me to address. What else am I supposed to do? I don't understand what you mean about the tag. -Sandra
[Qemu-devel] [PATCH v7 2/2] Add Nios II semihosting support.
This patch adds support for libgloss semihosting to Nios II bare-metal emulation. The specification for the protocol can be found in the libgloss sources. Signed-off-by: Sandra Loosemore Signed-off-by: Julian Brown --- qemu-options.hx| 8 +- target/nios2/Makefile.objs | 2 +- target/nios2/cpu.h | 4 +- target/nios2/helper.c | 13 ++ target/nios2/nios2-semi.c | 455 + 5 files changed, 476 insertions(+), 6 deletions(-) create mode 100644 target/nios2/nios2-semi.c diff --git a/qemu-options.hx b/qemu-options.hx index 08749a3..4135d5d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3968,21 +3968,21 @@ ETEXI DEF("semihosting", 0, QEMU_OPTION_semihosting, "-semihostingsemihosting 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}) diff --git a/target/nios2/Makefile.objs b/target/nios2/Makefile.objs index 2a11c5c..010de0e 100644 --- a/target/nios2/Makefile.objs +++ b/target/nios2/Makefile.objs @@ -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) diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h index 047f376..afd30d5 100644 --- a/target/nios2/cpu.h +++ b/target/nios2/cpu.h @@ -141,7 +141,7 @@ typedef struct Nios2CPUClass { #define R_PC 64 /* Exceptions */ -#define EXCP_BREAK-1 +#define EXCP_BREAK0x1000 #define EXCP_RESET0 #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 diff --git a/target/nios2/helper.c b/target/nios2/helper.c index a8b8ec6..bb0a784 100644 --- a/target/nios2/helper.c +++ b/target/nios2/helper.c @@ -23,8 +23,10 @@ #include "cpu.h" #include "qemu/host-utils.h" #include "exec/exec-all.h" +#include "exec/cpu_ldst.h" #include "exec/log.h" #include "exec/helper-proto.h" +#include "exec/semihost.h" #if defined(CONFIG_USER_ONLY) @@ -169,6 +171,17 @@ 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]); +/* The semihosting instruction is "break 1". */ +if (semihosting_enabled() && +cpu_ldl_code(env, env->regs[R_PC]) == 0x003da07a) { +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; diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c new file mode 100644 index 000..cc2777d --- /dev/null +++ b/target/nios2/nios2-semi.c @@ -0,0 +1,455 @@ +/* + * Nios II Semihosting syscall interface. + * This code is derived from m68k-semi.c. + * The semihosting protocol implemented here is described in the + * libgloss sources: + * https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/nios2/nios2-semi.txt;hb=HEAD + * + * Copyright (c) 2017-2019 Mentor Graphics + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + *
[Qemu-devel] [PATCH v7 0/2] Nios II generic board config and semihosting
This is the seventh version of the patch series last posted here: http://lists.nongnu.org/archive/html/qemu-devel/2019-03/msg06255.html Changes since v6: - Fixed block comment formatting for QEMU style. - Fixed fixme for interrupt handler (now added to libgloss BSP). - Added link to libgloss semihosting documentation. Sandra Loosemore (2): Add generic Nios II board. Add Nios II semihosting support. default-configs/nios2-softmmu.mak | 1 + hw/nios2/Kconfig | 4 + hw/nios2/Makefile.objs| 1 + hw/nios2/boot.c | 18 +- hw/nios2/generic_nommu.c | 105 + qemu-options.hx | 8 +- target/nios2/Makefile.objs| 2 +- target/nios2/cpu.h| 4 +- target/nios2/helper.c | 13 ++ target/nios2/nios2-semi.c | 455 ++ 10 files changed, 599 insertions(+), 12 deletions(-) create mode 100644 hw/nios2/generic_nommu.c create mode 100644 target/nios2/nios2-semi.c -- 2.8.1
[Qemu-devel] [PATCH v7 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 with the linker script and startup code provided by libgloss. Nios II booting is also tweaked so that bare-metal binaries start executing in RAM starting at 0x, rather than an alias at 0xc000, 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 based on code by Andrew Jenner, which was in turn based on code by Marek Vasut. Originally by Marek Vasut and Andrew Jenner. Signed-off-by: Sandra Loosemore Signed-off-by: Julian Brown Signed-off-by: Andrew Jenner Signed-off-by: Marek Vasut --- default-configs/nios2-softmmu.mak | 1 + hw/nios2/Kconfig | 4 ++ hw/nios2/Makefile.objs| 1 + hw/nios2/boot.c | 18 --- hw/nios2/generic_nommu.c | 105 ++ 5 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 hw/nios2/generic_nommu.c diff --git a/default-configs/nios2-softmmu.mak b/default-configs/nios2-softmmu.mak index e11dc54..e130d02 100644 --- a/default-configs/nios2-softmmu.mak +++ b/default-configs/nios2-softmmu.mak @@ -3,3 +3,4 @@ # Boards: # CONFIG_NIOS2_10M50=y +CONFIG_NIOS2_GENERIC_NOMMU=y diff --git a/hw/nios2/Kconfig b/hw/nios2/Kconfig index ab953e0..b10ea64 100644 --- a/hw/nios2/Kconfig +++ b/hw/nios2/Kconfig @@ -4,5 +4,9 @@ config NIOS2_10M50 select SERIAL select ALTERA_TIMER +config NIOS2_GENERIC_NOMMU +bool +select NIOS2 + config NIOS2 bool diff --git a/hw/nios2/Makefile.objs b/hw/nios2/Makefile.objs index 89a419a..3e01798 100644 --- a/hw/nios2/Makefile.objs +++ b/hw/nios2/Makefile.objs @@ -1,2 +1,3 @@ obj-y = boot.o cpu_pic.o obj-$(CONFIG_NIOS2_10M50) += 10m50_devboard.o +obj-$(CONFIG_NIOS2_GENERIC_NOMMU) += generic_nommu.o diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c index 5f0ab2f..276068c 100644 --- a/hw/nios2/boot.c +++ b/hw/nios2/boot.c @@ -138,7 +138,6 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, if (kernel_filename) { int kernel_size, fdt_size; uint64_t entry, low, high; -uint32_t base32; int big_endian = 0; #ifdef TARGET_WORDS_BIGENDIAN @@ -149,17 +148,24 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, , , , big_endian, EM_ALTERA_NIOS2, 0, 0); -base32 = entry; -if (base32 == 0xc000) { +if ((uint32_t)entry == 0xc000) { +/* + * The Nios II processor reference guide documents that the + * kernel is placed at virtual memory address 0xc000, + * and we've got something that points there. Reload it + * and adjust the entry to get the address in physical RAM. + */ kernel_size = load_elf(kernel_filename, NULL, translate_kernel_address, NULL, , NULL, NULL, big_endian, EM_ALTERA_NIOS2, 0, 0); +boot_info.bootstrap_pc = ddr_base + 0xc000 + +(entry & 0x07ff); +} else { +/* Use the entry point in the ELF image. */ +boot_info.bootstrap_pc = (uint32_t)entry; } -/* Always boot into physical ram. */ -boot_info.bootstrap_pc = ddr_base + 0xc000 + (entry & 0x07ff); - /* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size < 0) { hwaddr uentry, loadaddr = LOAD_UIMAGE_LOADADDR_INVALID; diff --git a/hw/nios2/generic_nommu.c b/hw/nios2/generic_nommu.c new file mode 100644 index 000..1788ffa --- /dev/null +++ b/hw/nios2/generic_nommu.c @@ -0,0 +1,105 @@ +/* + * Generic simulator target with no MMU or devices. This emulation is + * compatible with the libgloss qemu-hosted.ld linker script for using + * QEMU as an instruction set simulator. + * + * Copyright (c) 2018-2019 Mentor Graphics + * + * Copyright (c) 2016 Marek Vasut + * + * Based on LabX device code + * + * Copyright (c) 2012 Chris Wulff + * + * 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
[Qemu-devel] [PATCH v6 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 with the linker script and startup code provided by libgloss. Nios II booting is also tweaked so that bare-metal binaries start executing in RAM starting at 0x, rather than an alias at 0xc000, 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 based on code by Andrew Jenner, which was in turn based on code by Marek Vasut. Originally by Marek Vasut and Andrew Jenner. Signed-off-by: Sandra Loosemore Signed-off-by: Julian Brown Signed-off-by: Andrew Jenner Signed-off-by: Marek Vasut --- default-configs/nios2-softmmu.mak | 1 + hw/nios2/Kconfig | 4 ++ hw/nios2/Makefile.objs| 1 + hw/nios2/boot.c | 17 --- hw/nios2/generic_nommu.c | 104 ++ 5 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 hw/nios2/generic_nommu.c diff --git a/default-configs/nios2-softmmu.mak b/default-configs/nios2-softmmu.mak index e11dc54..e130d02 100644 --- a/default-configs/nios2-softmmu.mak +++ b/default-configs/nios2-softmmu.mak @@ -3,3 +3,4 @@ # Boards: # CONFIG_NIOS2_10M50=y +CONFIG_NIOS2_GENERIC_NOMMU=y diff --git a/hw/nios2/Kconfig b/hw/nios2/Kconfig index ab953e0..b10ea64 100644 --- a/hw/nios2/Kconfig +++ b/hw/nios2/Kconfig @@ -4,5 +4,9 @@ config NIOS2_10M50 select SERIAL select ALTERA_TIMER +config NIOS2_GENERIC_NOMMU +bool +select NIOS2 + config NIOS2 bool diff --git a/hw/nios2/Makefile.objs b/hw/nios2/Makefile.objs index 89a419a..3e01798 100644 --- a/hw/nios2/Makefile.objs +++ b/hw/nios2/Makefile.objs @@ -1,2 +1,3 @@ obj-y = boot.o cpu_pic.o obj-$(CONFIG_NIOS2_10M50) += 10m50_devboard.o +obj-$(CONFIG_NIOS2_GENERIC_NOMMU) += generic_nommu.o diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c index 5f0ab2f..771877d 100644 --- a/hw/nios2/boot.c +++ b/hw/nios2/boot.c @@ -138,7 +138,6 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, if (kernel_filename) { int kernel_size, fdt_size; uint64_t entry, low, high; -uint32_t base32; int big_endian = 0; #ifdef TARGET_WORDS_BIGENDIAN @@ -149,16 +148,22 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, , , , big_endian, EM_ALTERA_NIOS2, 0, 0); -base32 = entry; -if (base32 == 0xc000) { +if ((uint32_t)entry == 0xc000) { +/* The Nios II processor reference guide documents that the + kernel is placed at virtual memory address 0xc000, + and we've got something that points there. Reload it + and adjust the entry to get the address in physical RAM. */ kernel_size = load_elf(kernel_filename, NULL, translate_kernel_address, NULL, , NULL, NULL, big_endian, EM_ALTERA_NIOS2, 0, 0); +boot_info.bootstrap_pc = ddr_base + 0xc000 + +(entry & 0x07ff); +} +else { +/* Use the entry point in the ELF image. */ +boot_info.bootstrap_pc = (uint32_t)entry; } - -/* Always boot into physical ram. */ -boot_info.bootstrap_pc = ddr_base + 0xc000 + (entry & 0x07ff); /* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size < 0) { diff --git a/hw/nios2/generic_nommu.c b/hw/nios2/generic_nommu.c new file mode 100644 index 000..af8983a --- /dev/null +++ b/hw/nios2/generic_nommu.c @@ -0,0 +1,104 @@ +/* + * Generic simulator target with no MMU or devices. This emulation is + * compatible with the libgloss qemu-hosted.ld linker script for using + * QEMU as an instruction set simulator. + * + * Copyright (c) 2018-2019 Mentor Graphics + * + * Copyright (c) 2016 Marek Vasut + * + * Based on LabX device code + * + * Copyright (c) 2012 Chris Wulff + * + * 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 &qu
[Qemu-devel] [PATCH v6 2/2] Add Nios II semihosting support.
This patch adds support for libgloss semihosting to Nios II bare-metal emulation. The specification for the protocol can be found in the libgloss sources. Signed-off-by: Sandra Loosemore Signed-off-by: Julian Brown --- qemu-options.hx| 8 +- target/nios2/Makefile.objs | 2 +- target/nios2/cpu.h | 4 +- target/nios2/helper.c | 13 ++ target/nios2/nios2-semi.c | 448 + 5 files changed, 469 insertions(+), 6 deletions(-) create mode 100644 target/nios2/nios2-semi.c diff --git a/qemu-options.hx b/qemu-options.hx index 08749a3..4135d5d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3968,21 +3968,21 @@ ETEXI DEF("semihosting", 0, QEMU_OPTION_semihosting, "-semihostingsemihosting 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}) diff --git a/target/nios2/Makefile.objs b/target/nios2/Makefile.objs index 2a11c5c..010de0e 100644 --- a/target/nios2/Makefile.objs +++ b/target/nios2/Makefile.objs @@ -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) diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h index 047f376..afd30d5 100644 --- a/target/nios2/cpu.h +++ b/target/nios2/cpu.h @@ -141,7 +141,7 @@ typedef struct Nios2CPUClass { #define R_PC 64 /* Exceptions */ -#define EXCP_BREAK-1 +#define EXCP_BREAK0x1000 #define EXCP_RESET0 #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 diff --git a/target/nios2/helper.c b/target/nios2/helper.c index a8b8ec6..bb0a784 100644 --- a/target/nios2/helper.c +++ b/target/nios2/helper.c @@ -23,8 +23,10 @@ #include "cpu.h" #include "qemu/host-utils.h" #include "exec/exec-all.h" +#include "exec/cpu_ldst.h" #include "exec/log.h" #include "exec/helper-proto.h" +#include "exec/semihost.h" #if defined(CONFIG_USER_ONLY) @@ -169,6 +171,17 @@ 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]); +/* The semihosting instruction is "break 1". */ +if (semihosting_enabled() && +cpu_ldl_code(env, env->regs[R_PC]) == 0x003da07a) { +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; diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c new file mode 100644 index 000..4e45a27 --- /dev/null +++ b/target/nios2/nios2-semi.c @@ -0,0 +1,448 @@ +/* + * Nios II Semihosting syscall interface. + * This code is derived from m68k-semi.c. + * + * Copyright (c) 2017-2019 Mentor Graphics + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 PURP
[Qemu-devel] [PATCH v6 0/2] Nios II generic board config and semihosting
This is the sixth version of the patch series last posted here: http://lists.nongnu.org/archive/html/qemu-devel/2019-02/msg03167.html Changes since v5 include: - The code to allow booting from a low memory address has been simplified and better commented. - Random devices not supported by the libgloss BSP have been removed from the new nios2-generic-nommu emulation. - FIXMEs in the semihosting code have been fixed, along with other nits from review. Also, the semihosting specification can now be found in libgloss. Sandra Loosemore (2): Add generic Nios II board. Add Nios II semihosting support. default-configs/nios2-softmmu.mak | 1 + hw/nios2/Kconfig | 4 + hw/nios2/Makefile.objs| 1 + hw/nios2/boot.c | 17 +- hw/nios2/generic_nommu.c | 104 + qemu-options.hx | 8 +- target/nios2/Makefile.objs| 2 +- target/nios2/cpu.h| 4 +- target/nios2/helper.c | 13 ++ target/nios2/nios2-semi.c | 448 ++ 10 files changed, 590 insertions(+), 12 deletions(-) create mode 100644 hw/nios2/generic_nommu.c create mode 100644 target/nios2/nios2-semi.c -- 2.8.1
Re: [Qemu-devel] [PATCH v5 1/2] Add generic Nios II board.
On 3/7/19 7:57 AM, Peter Maydell wrote: diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c index 5f0ab2f..c697047 100644 --- a/hw/nios2/boot.c +++ b/hw/nios2/boot.c @@ -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; @@ -155,10 +156,12 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, translate_kernel_address, NULL, , NULL, NULL, big_endian, EM_ALTERA_NIOS2, 0, 0); +kernel_space = 1; } /* Always boot into physical ram. */ -boot_info.bootstrap_pc = ddr_base + 0xc000 + (entry & 0x07ff); +boot_info.bootstrap_pc = ddr_base + (kernel_space ? 0xc000 : 0) + + (entry & 0x07ff); It's not clear to me what's going on here, or why an entry address of 0xc000_ is special, but I don't know anything about NiosII -- maybe it's clear if you do? The processor reference guide documents that the kernel is placed at virtual memory address 0xc000. https://www.intel.com/content/www/us/en/programmable/documentation/iga1409256728501.html#iga1409332620358 The problem the patch to boot.c is trying to solve is that we found things like unwind info were screwed up when using -kernel to load executables with an entry address other than 0xc000. Why isn't the bootstrap_pc just always the entry address ? Some comments on what is being done here and the use cases being addressed might assist. I wasn't able to work out what the remarks in the commit message meant, I'm afraid. Looking at the code, I don't think that the second call to load_elf() will return a different entry address to the first one (ie translate_kernel_address() is not applied to ). That means that kernel_space is only true if entry == 0xc000, and (kernel_space ? 0xc000 : 0) + (entry & 0x07ff); is almost the same thing as just 'entry'. It seems like these remarks are directed more at the existing code than the patch :-S TBH, I don't know why it was done that way originally. +static void nios2_generic_nommu_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 = 0x1000; +ram_addr_t ram_size = 0x0800; +qemu_irq *cpu_irq, irq[32]; +int i; The description says this is "generic", but it appears to be almost identical to the existing 10M50 board model, including having exactly the same devices at the same apparently arbitrary addresses. Could we instead add a machine parameter to the existing board so you could say "-machine 10m50-ghrd,mmu=no" (and drop the other changes -- it's not clear what they're needed for) ? If it really ought to be a separate board model, perhaps it should be in the same source file and share the common code. I didn't write this code, but the intent was actually to allow executables linked for the 3c120 devboards we'd been using for hardware testing to run in this emulation; not to emulate a mmu-less 10m50 board. The BSP that we contributed to libgloss locates the reset vector, etc appropriately for this emulation. I can't comment on whether the peripherals copied from the 10m50 emulation are actually necessary or useful for anything; we certainly don't intend to support manipulating them from the program being loaded, but maybe other parts of QEMU expect certain devices to be present (I've seen that on other targets like ARM). Andrew, do you have any state on this left? -Sandra
Re: [Qemu-devel] [PATCH v5 2/2] Add Nios II semihosting support.
On 3/8/19 9:04 AM, Peter Maydell wrote: On Fri, 8 Mar 2019 at 03:13, Sandra Loosemore wrote: On 3/7/19 7:58 AM, Peter Maydell wrote: On Wed, 13 Feb 2019 at 04:02, Sandra Loosemore wrote: This patch adds support for libgloss semihosting to Nios II bare-metal emulation. Signed-off-by: Sandra Loosemore Signed-off-by: Julian Brown Do you have a link to the spec that defines this semihosting ABI, please ? Well, I just wrote some derived from the comments in the libgloss sources; see the attachment. :-) Thanks. So who "owns" this ABI (ie has the authority to change it and should be the end documenting it)? How many projects or bits of software are implementing either end of it? Going back in ancient history, I implemented the m68k version in libgloss in 2006 to support a hardware debug stub that CodeSourcery was also providing at that time. We later moved the runtime side of it into target-agnostic code in an internal library, so when it came time to do a similar JTAG debug stub for bare-metal Nios II hardware testing in 2012, we re-used our existing code for both library and debug stub. Later Altera implemented the same protocol in some proprietary simulators they provided to us, and more recently we wrote these patches to add it to QEMU. We've shifted away from hardware testing and no longer use the original debug stub now. If we decide that QEMU owns the spec we can put the documentation into docs/specs/. Making QEMU the "owner" of the ABI seems a little peculiar to me since it is only one client among several, and is a latecomer too. I think libgloss would make a little more sense. OTOH, I have no problem with making the documentation part of QEMU. -Sandra
Re: [Qemu-devel] [PATCH v5 2/2] Add Nios II semihosting support.
On 3/7/19 7:58 AM, Peter Maydell wrote: On Wed, 13 Feb 2019 at 04:02, Sandra Loosemore wrote: This patch adds support for libgloss semihosting to Nios II bare-metal emulation. Signed-off-by: Sandra Loosemore Signed-off-by: Julian Brown Do you have a link to the spec that defines this semihosting ABI, please ? Well, I just wrote some derived from the comments in the libgloss sources; see the attachment. :-) FWIW this is pretty much a direct copy of the m68k semihosting protocol, which CodeSourcery contributed ages ago to both libgloss and qemu. -Sandra Nios II Semihosting Protocol The runtime (libgloss) indicates a semihosting request to the debug agent by issuing a "break 1" instruction. r4 and r5 are used to pass parameters per the normal C ABI on nios2. r4 contains a request code. r5 is typically a pointer to a 4-word parameter block, except for the exit operation where it is an immediate integer value. The result of the operation is returned in the first word of the parameter block. The second word is used to return an errno value, encoded per the "Errno Values" section of the RSP documentation in the GDB User Manual. The supported r4 request codes are: #define HOSTED_EXIT 0 Terminate program execution; send a 'W' stop reply to GDB. r5 contains the exit code, as an immediate integer rather than indirectly in a parameter block. This semihosting request isn't expected to return. #define HOSTED_INIT_SIM 1 Reserved/unimplemented. #define HOSTED_OPEN 2 Open file; 'Fopen' GDB fileio request. r5 points to a parameter block containing: [0] pointer to filename [1] filename length [2] open flags, encoded per the GDB RSP documentation [3] mode, encoded per the GDB RSP documentation Return values in parameter block: [0] file descriptor or -1 on error [1] errno, encoded per the GDB RSP documentation #define HOSTED_CLOSE 3 Close file; 'Fclose' GDB fileio request. r5 points to a parameter block containing: [0] file descriptor Return values in parameter block: [0] return status [1] errno, encoded per the GDB RSP documentation #define HOSTED_READ 4 Read from file; 'Fread' GDB fileio request. r5 points to a parameter block containing: [0] file descriptor [1] pointer to buffer [2] buffer size Return values in parameter block: [0] number of bytes read [1] errno, encoded per the GDB RSP documentation #define HOSTED_WRITE 5 Write to file; 'Fwrite' GDB fileio request. r5 points to a parameter block containing: [0] file descriptor [1] pointer to buffer [2] byte count Return values in parameter block: [0] number of bytes written [1] errno, encoded per the GDB RSP documentation #define HOSTED_LSEEK 6 File seek; 'Flseek' GDB fileio request. r5 points to a parameter block containing: [0] file descriptor [1] high word of 64-bit offset [2] low word of 64-bit offset [3] seek flag, encoded per the GDB RSP documentation Return values in parameter block: [0] high word of 64-bit result [1] low word of 64-bit result [2] errno, encoded per the GDB RSP documentation #define HOSTED_RENAME 7 File rename; 'Frename' GDB fileio request. r5 points to a parameter block containing: [0] oldname pointer [1] oldname length [2] newname pointer [3] newname length Return values in parameter block: [0] return status [1] errno, encoded per the GDB RSP documentation #define HOSTED_UNLINK 8 File unlink/delete; 'Funlink' GDB fileio request. r5 points to a parameter block containing: [0] filename pointer [1] filename length Return values in parameter block: [0] return status [1] errno, encoded per the GDB RSP documentation #define HOSTED_STAT 9 File information; 'Fstat' GDB fileio request. r5 points to a parameter block containing: [0] filename pointer [1] filename length [2] pointer to stat buf, using the structure definition in the GDB RSP documentation Return values in parameter block: [0] return status [1] errno, encoded per the GDB RSP documentation #define HOSTED_FSTAT 10 File information; 'Ffstat' GDB fileio request. r5 points to a parameter block containing: [0] file descriptor [1] pointer to stat buf, using the structure definition in the GDB RSP documentation Return values in parameter block: [0] return status [1] errno, encoded per the GDB RSP documentation #define HOSTED_GETTIMEOFDAY 11 Get current time; 'Fgettimeofday' GDB fileio request. r5 points to a parameter block containing: [0] timeval pointer, using the structure definition in the GDB RSP documentation Return values in parameter block: [0] return status [1] errno, encoded per the GDB RSP documentation #define HOSTED_ISATTY 12 Return true if the file descriptor is the GDB console; 'Fisatty' GDB fileio request. r5 points to a parameter block containing: [0] file descrip
Re: [Qemu-devel] [ping**2] [PATCH v5 0/2] Nios II generic board config and semihosting
On 2/24/19 10:04 PM, Sandra Loosemore wrote: Ping? http://lists.nongnu.org/archive/html/qemu-devel/2019-02/msg03167.html -Sandra
[Qemu-devel] [ping] [PATCH] Fix breakpoint support in Nios II user-mode emulation.
Ping? http://lists.nongnu.org/archive/html/qemu-devel/2019-02/msg03483.html -Sandra
[Qemu-devel] [ping] [PATCH v5 0/2] Nios II generic board config and semihosting
Ping? http://lists.nongnu.org/archive/html/qemu-devel/2019-02/msg03167.html -Sandra
Re: [Qemu-devel] [PATCH] gdbstub: Send a reply to the vKill packet.
On 2/14/19 10:48 AM, Peter Maydell wrote: On Tue, 12 Feb 2019 at 21:52, Sandra Loosemore wrote: Per the GDB remote protocol documentation https://sourceware.org/gdb/current/onlinedocs/gdb/Packets.html#index-vKill-packet the debug stub is expected to send a reply to the 'vKill' packet. At least some versions of GDB crash if the gdb stub simply exits without sending a reply. This patch fixes QEMU's gdb stub to conform to the expected behavior. Note that QEMU's existing handling of the legacy 'k' packet is correct: in that case GDB does not expect a reply, and QEMU does not send one. Signed-off-by: Sandra Loosemore Thanks, applied to target-arm.next. As an aside, do you know if there is any kind of test suite for the remote protocol that implementors of a debug stub can use to check that they're conforming to it? Well, I discovered this problem by running the GDB testsuite (using QEMU for nios2-elf target with the other target-specific patches I recently posted). I'm not sure if it's designed to exhaustively test the entire remote protocol, but it does a pretty good job of covering user-visible GDB features that depend on the remote target doing something reasonable, even if it's just saying "Huh? I don't know how to do that." :-) -Sandra
[Qemu-devel] [PATCH] Fix breakpoint support in Nios II user-mode emulation.
Nios II user-mode emulation was missing handling for EXCP_DEBUG, making the gdb stub essentially useless. This patch adds the missing piece. The new code was copied from the existing EXCP_TRAP handling and is also similar to what other targets (e.g., arm) do with EXCP_DEBUG. Signed-off-by: Sandra Loosemore --- linux-user/nios2/cpu_loop.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c index b96b1aa..5aa1eca 100644 --- a/linux-user/nios2/cpu_loop.c +++ b/linux-user/nios2/cpu_loop.c @@ -73,6 +73,12 @@ void cpu_loop(CPUNios2State *env) queue_signal(env, info.si_signo, QEMU_SI_FAULT, ); break; } +case EXCP_DEBUG: +info.si_signo = TARGET_SIGTRAP; +info.si_errno = 0; +info.si_code = TARGET_TRAP_BRKPT; +queue_signal(env, info.si_signo, QEMU_SI_FAULT, ); +break; case 0xaa: switch (env->regs[R_PC]) { /*case 0x1000:*/ /* TODO:__kuser_helper_version */ -- 2.8.1
[Qemu-devel] [PATCH v5 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 0x, rather than an alias at 0xc000, 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. Signed-off-by: Sandra Loosemore Signed-off-by: Julian Brown Signed-off-by: Andrew Jenner Signed-off-by: Marek Vasut --- default-configs/nios2-softmmu.mak | 1 + hw/nios2/Makefile.objs| 1 + hw/nios2/boot.c | 5 +- hw/nios2/generic_nommu.c | 130 ++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 hw/nios2/generic_nommu.c diff --git a/default-configs/nios2-softmmu.mak b/default-configs/nios2-softmmu.mak index ab42d0f..95ed1c2 100644 --- a/default-configs/nios2-softmmu.mak +++ b/default-configs/nios2-softmmu.mak @@ -5,3 +5,4 @@ CONFIG_SERIAL=y CONFIG_PTIMER=y CONFIG_ALTERA_TIMER=y CONFIG_NIOS2_10M50=y +CONFIG_NIOS2_GENERIC_NOMMU=y diff --git a/hw/nios2/Makefile.objs b/hw/nios2/Makefile.objs index 89a419a..3e01798 100644 --- a/hw/nios2/Makefile.objs +++ b/hw/nios2/Makefile.objs @@ -1,2 +1,3 @@ obj-y = boot.o cpu_pic.o obj-$(CONFIG_NIOS2_10M50) += 10m50_devboard.o +obj-$(CONFIG_NIOS2_GENERIC_NOMMU) += generic_nommu.o diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c index 5f0ab2f..c697047 100644 --- a/hw/nios2/boot.c +++ b/hw/nios2/boot.c @@ -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; @@ -155,10 +156,12 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base, translate_kernel_address, NULL, , NULL, NULL, big_endian, EM_ALTERA_NIOS2, 0, 0); +kernel_space = 1; } /* Always boot into physical ram. */ -boot_info.bootstrap_pc = ddr_base + 0xc000 + (entry & 0x07ff); +boot_info.bootstrap_pc = ddr_base + (kernel_space ? 0xc000 : 0) + + (entry & 0x07ff); /* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size < 0) { diff --git a/hw/nios2/generic_nommu.c b/hw/nios2/generic_nommu.c new file mode 100644 index 000..502567f --- /dev/null +++ b/hw/nios2/generic_nommu.c @@ -0,0 +1,130 @@ +/* + * Generic simulator target with no MMU + * + * Copyright (c) 2018-2019 Mentor Graphics + * + * Copyright (c) 2016 Marek Vasut + * + * Based on LabX device code + * + * Copyright (c) 2012 Chris Wulff + * + * 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"generic-nommu.dtb" + +static void nios2_generic_nommu_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 = 0x1000; +ram_addr_t ram_size = 0x0800; +qemu_irq *cpu_irq, irq[32]; +int i; + +/* Physical TCM (tb_ram_1k) with alias at 0xc000 */ +memory_region_init_ram(phys_tcm, NULL, "nios2.tcm", tc
[Qemu-devel] [PATCH v5 0/2] Nios II generic board config and semihosting
This is the fifth version of the patch series last posted here: http://lists.nongnu.org/archive/html/qemu-devel/2018-08/msg01987.html Since the previous version, I've updated the copyrights on the new files, refreshed the patches against current trunk, and fixed bugs in the implementations of lseek() and gettimeofday(). The original version of these patches was rejected because there was no corresponding open-source BSP or I/O library support, making it difficult to test the code. I contributed those pieces to libgloss last summer (commit fddc74d12bf7f765c04c3182a7237ecf23893d27), so that should no longer be a blocking issue. Sandra Loosemore (2): Add generic Nios II board. Add Nios II semihosting support. default-configs/nios2-softmmu.mak | 1 + hw/nios2/Makefile.objs| 1 + hw/nios2/boot.c | 5 +- hw/nios2/generic_nommu.c | 130 +++ qemu-options.hx | 8 +- target/nios2/Makefile.objs| 2 +- target/nios2/cpu.h| 4 +- target/nios2/helper.c | 11 + target/nios2/nios2-semi.c | 446 ++ 9 files changed, 601 insertions(+), 7 deletions(-) create mode 100644 hw/nios2/generic_nommu.c create mode 100644 target/nios2/nios2-semi.c -- 2.8.1
[Qemu-devel] [PATCH v5 2/2] Add Nios II semihosting support.
This patch adds support for libgloss semihosting to Nios II bare-metal emulation. Signed-off-by: Sandra Loosemore Signed-off-by: Julian Brown --- qemu-options.hx| 8 +- target/nios2/Makefile.objs | 2 +- target/nios2/cpu.h | 4 +- target/nios2/helper.c | 11 ++ target/nios2/nios2-semi.c | 446 + 5 files changed, 465 insertions(+), 6 deletions(-) create mode 100644 target/nios2/nios2-semi.c diff --git a/qemu-options.hx b/qemu-options.hx index 06ef1a7..5019ede 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3712,21 +3712,21 @@ ETEXI DEF("semihosting", 0, QEMU_OPTION_semihosting, "-semihostingsemihosting 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}) diff --git a/target/nios2/Makefile.objs b/target/nios2/Makefile.objs index 2a11c5c..010de0e 100644 --- a/target/nios2/Makefile.objs +++ b/target/nios2/Makefile.objs @@ -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) diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h index 047f376..afd30d5 100644 --- a/target/nios2/cpu.h +++ b/target/nios2/cpu.h @@ -141,7 +141,7 @@ typedef struct Nios2CPUClass { #define R_PC 64 /* Exceptions */ -#define EXCP_BREAK-1 +#define EXCP_BREAK0x1000 #define EXCP_RESET0 #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 diff --git a/target/nios2/helper.c b/target/nios2/helper.c index a8b8ec6..ca3b087 100644 --- a/target/nios2/helper.c +++ b/target/nios2/helper.c @@ -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; diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c new file mode 100644 index 000..9db518a --- /dev/null +++ b/target/nios2/nios2-semi.c @@ -0,0 +1,446 @@ +/* + * Nios II Semihosting syscall interface. + * This code is derived from m68k-semi.c. + * + * Copyright (c) 2017-2019 Mentor Graphics + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "qemu/osdep.h" + +#include "cpu.h" +#if defined(CONFIG_USER_ONLY) +#inclu
[Qemu-devel] [PATCH] gdbstub: Send a reply to the vKill packet.
Per the GDB remote protocol documentation https://sourceware.org/gdb/current/onlinedocs/gdb/Packets.html#index-vKill-packet the debug stub is expected to send a reply to the 'vKill' packet. At least some versions of GDB crash if the gdb stub simply exits without sending a reply. This patch fixes QEMU's gdb stub to conform to the expected behavior. Note that QEMU's existing handling of the legacy 'k' packet is correct: in that case GDB does not expect a reply, and QEMU does not send one. Signed-off-by: Sandra Loosemore --- gdbstub.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gdbstub.c b/gdbstub.c index 70cf330..eb129f6 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1363,6 +1363,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) break; } else if (strncmp(p, "Kill;", 5) == 0) { /* Kill the target */ +put_packet(s, "OK"); error_report("QEMU: Terminated via GDBstub"); exit(0); } else { -- 2.8.1
Re: [Qemu-devel] [PATCH] Fix breakpoints in nios2 user-mode emulation.
On 09/12/2018 12:39 PM, Alex Bennée wrote: Richard Henderson writes: On 09/11/2018 02:29 PM, Sandra Loosemore wrote: Without this patch, QEMU exits immediately when it execution stops at a breakpoint, instead of reporting it to GDB. Signed-off-by: Sandra Loosemore --- linux-user/nios2/cpu_loop.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c index dac7a06..a5ae37f 100644 --- a/linux-user/nios2/cpu_loop.c +++ b/linux-user/nios2/cpu_loop.c @@ -71,6 +71,9 @@ void cpu_loop(CPUNios2State *env) gdbsig = TARGET_SIGTRAP; break; } +case EXCP_DEBUG: +gdbsig = TARGET_SIGTRAP; +break; This really isn't complete. You set gdbsig from odd places instead of using queue_signal; you fail to honor the return value from gdb_handlesig. But I suppose those should be separate patches, so Reviewed-by: Richard Henderson At least the cpu_loops have been separated now.. I guess the next step is to audit each one for common features? There do seem to be some magic numbers in the nios loop which I find concerning. I'm not sure where the 0xaa value came from, but it is used to indicate syscalls through the kuser page mapped at address 0x1000 in user space. The addresses are a fixed ABI although not terribly well-documented AFAICT. There's code in target/nios2 that catches attempts to execute code on that page, and in the Linux kernel the code that goes on the kuser page is at the end of arch/nios2/kernel/entry.S. This all could certainly be better documented in the QEMU cpu_loop code too. -Sandra
Re: [Qemu-devel] [PATCH] Fix breakpoints in nios2 user-mode emulation.
On 09/12/2018 11:49 AM, Richard Henderson wrote: On 09/11/2018 02:29 PM, Sandra Loosemore wrote: Without this patch, QEMU exits immediately when it execution stops at a breakpoint, instead of reporting it to GDB. Signed-off-by: Sandra Loosemore --- linux-user/nios2/cpu_loop.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c index dac7a06..a5ae37f 100644 --- a/linux-user/nios2/cpu_loop.c +++ b/linux-user/nios2/cpu_loop.c @@ -71,6 +71,9 @@ void cpu_loop(CPUNios2State *env) gdbsig = TARGET_SIGTRAP; break; } +case EXCP_DEBUG: +gdbsig = TARGET_SIGTRAP; +break; This really isn't complete. You set gdbsig from odd places instead of using queue_signal; you fail to honor the return value from gdb_handlesig. But I suppose those should be separate patches, so Reviewed-by: Richard Henderson Yes, I thought this code was rather ugly. But I thought a minimal patch to un-break GDB use would be easier to get in than any kind of rewrite, particularly given that I'm not terribly familiar with current best practices in the QEMU development community, etc. -Sandra
[Qemu-devel] [PATCH] Fix breakpoints in nios2 user-mode emulation.
Without this patch, QEMU exits immediately when it execution stops at a breakpoint, instead of reporting it to GDB. Signed-off-by: Sandra Loosemore --- linux-user/nios2/cpu_loop.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linux-user/nios2/cpu_loop.c b/linux-user/nios2/cpu_loop.c index dac7a06..a5ae37f 100644 --- a/linux-user/nios2/cpu_loop.c +++ b/linux-user/nios2/cpu_loop.c @@ -71,6 +71,9 @@ void cpu_loop(CPUNios2State *env) gdbsig = TARGET_SIGTRAP; break; } +case EXCP_DEBUG: +gdbsig = TARGET_SIGTRAP; +break; case 0xaa: switch (env->regs[R_PC]) { /*case 0x1000:*/ /* TODO:__kuser_helper_version */ -- 2.8.1
[Qemu-devel] [Bug 1791796] Re: unimplemented thread syscalls in nios2 user-mode emulation
If you need a Nios II GNU/Linux toolchain, I think the most recent CodeBench Lite release will work: https://sourcery.mentor.com/GNUToolchain/subscription42545 We're planning on adding user-mode QEMU to the upcoming 2018.11 release that's actually what I've been testing it for. Results on the GCC testsuite actually don't look too bad, but I have a patch I haven't submitted yet that's required to make the GDB stub work, and there are a lot of GDB test failures I haven't triaged yet. -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1791796 Title: unimplemented thread syscalls in nios2 user-mode emulation Status in QEMU: New Bug description: This bug is reported against the 3.0 release. I noticed that the GCC test gcc.dg/torture/tls/tls-test.c is failing when run in user-mode qemu for nios2 target. The problem appears to be that the thread-related syscalls are unimplemented in qemu. Here is output from running with -strace: 22484 brk(NULL) = 0x5000 22484 uname(0x7fffef5a) = 0 22484 faccessat(AT_FDCWD,"/etc/ld.so.preload",R_OK,0x5) = -1 errno=2 (No such file or directory) 22484 openat(AT_FDCWD,"/scratch/sandra/nios2-linux-trunk3/obj/test-2018.11-99-nios2-linux-gnu/host-x86_64-linux-gnu/sourceryg++-2018.11/nios2-linux-gnu/libc/./lib/./tls/libm.so.6",O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 errno=2 (No such file or directory) 22484 fstatat64(AT_FDCWD,"/scratch/sandra/nios2-linux-trunk3/obj/test-2018.11-99-nios2-linux-gnu/host-x86_64-linux-gnu/sourceryg++-2018.11/nios2-linux-gnu/libc/./lib/./tls",0x7fffe870,0) = -1 errno=2 (No such file or directory) 22484 openat(AT_FDCWD,"/scratch/sandra/nios2-linux-trunk3/obj/test-2018.11-99-nios2-linux-gnu/host-x86_64-linux-gnu/sourceryg++-2018.11/nios2-linux-gnu/libc/./lib/./libm.so.6",O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3 22484 read(3,0x7fffe954,512) = 512 22484 fstat64(3,0x7fffe870) = 0 22484 mmap2(NULL,803596,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x7f716000 22484 mmap2(0x7f7d8000,12288,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0xc1) = 0x7f7d8000 22484 close(3) = 0 22484 openat(AT_FDCWD,"/scratch/sandra/nios2-linux-trunk3/obj/test-2018.11-99-nios2-linux-gnu/host-x86_64-linux-gnu/sourceryg++-2018.11/nios2-linux-gnu/libc/./lib/./libpthread.so.0",O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3 22484 read(3,0x7fffe948,512) = 512 22484 mmap2(NULL,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0x7f714000 22484 fstat64(3,0x7fffe864) = 0 22484 mmap2(NULL,120700,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x7f6f6000 22484 mprotect(0x7f70e000,4096,PROT_NONE) = 0 22484 mmap2(0x7f70f000,12288,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x18) = 0x7f70f000 22484 mmap2(0x7f712000,6012,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 0x7f712000 22484 close(3) = 0 22484 openat(AT_FDCWD,"/scratch/sandra/nios2-linux-trunk3/obj/test-2018.11-99-nios2-linux-gnu/host-x86_64-linux-gnu/sourceryg++-2018.11/nios2-linux-gnu/libc/./lib/./libc.so.6",O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3 22484 read(3,0x7fffe93c,512) = 512 22484 fstat64(3,0x7fffe858) = 0 22484 mmap2(NULL,1491048,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x7f589000 22484 mmap2(0x7f6de000,86016,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x154) = 0x7f6de000 22484 mmap2(0x7f6f3000,8296,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 0x7f6f3000 22484 close(3) = 0 22484 mprotect(0x7f6de000,65536,PROT_READ) = 0 22484 mprotect(0x7f70f000,8192,PROT_READ) = 0 22484 mprotect(0x7f7d8000,4096,PROT_READ) = 0 22484 mprotect(0x3000,4096,PROT_READ) = 0 22484 mprotect(0x7f7fc000,4096,PROT_READ) = 0 22484 set_tid_address(2138131700,2147480980,2147480988,2147480988,87148,47) = 22484 22484 set_robust_list(2138131708,12,2147480988,0,87148,47) = -1 errno=38 (Function not implemented) 22484 rt_sigaction(32,0x736c,NULL) = 0 22484 rt_sigaction(33,0x736c,NULL) = -1 errno=22 (Invalid argument) 22484 rt_sigprocmask(SIG_UNBLOCK,0x74a8,NULL) = 0 22484 getrlimit(3,2147480732,3,0,62512,47) = 0 22484 mmap2(NULL,8392704,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|0x2,-1,0) = 0x7ed88000 22484 mprotect(0x7ed89000,8388608,PROT_READ|PROT_WRITE) = 0 22484 brk(NULL) = 0x5000 22484 brk(0x00026000) = 0x00026000 22484 clone(CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,child_stack=0x7f588018,parent_tidptr=0x7f5884fc,tls=0x7f58f928,child_tidptr=0x7f5884fc) = 22503 22484 io_setup(4001536,2136506392,2136507644,2136507644,2136537384,4100) = -1 errno=38 (Function not implemented) 22484 futex(0x7f5884fc,FUTEX_WAIT,22503,NULL,NULL,0)22484 set_robust_list(2136507652,12,0,4100,2136508076,4100) = -1 errno=38 (Function not
[Qemu-devel] [Bug 1791796] [NEW] unimplemented thread syscalls in nios2 user-mode emulation
Public bug reported: This bug is reported against the 3.0 release. I noticed that the GCC test gcc.dg/torture/tls/tls-test.c is failing when run in user-mode qemu for nios2 target. The problem appears to be that the thread-related syscalls are unimplemented in qemu. Here is output from running with -strace: 22484 brk(NULL) = 0x5000 22484 uname(0x7fffef5a) = 0 22484 faccessat(AT_FDCWD,"/etc/ld.so.preload",R_OK,0x5) = -1 errno=2 (No such file or directory) 22484 openat(AT_FDCWD,"/scratch/sandra/nios2-linux-trunk3/obj/test-2018.11-99-nios2-linux-gnu/host-x86_64-linux-gnu/sourceryg++-2018.11/nios2-linux-gnu/libc/./lib/./tls/libm.so.6",O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 errno=2 (No such file or directory) 22484 fstatat64(AT_FDCWD,"/scratch/sandra/nios2-linux-trunk3/obj/test-2018.11-99-nios2-linux-gnu/host-x86_64-linux-gnu/sourceryg++-2018.11/nios2-linux-gnu/libc/./lib/./tls",0x7fffe870,0) = -1 errno=2 (No such file or directory) 22484 openat(AT_FDCWD,"/scratch/sandra/nios2-linux-trunk3/obj/test-2018.11-99-nios2-linux-gnu/host-x86_64-linux-gnu/sourceryg++-2018.11/nios2-linux-gnu/libc/./lib/./libm.so.6",O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3 22484 read(3,0x7fffe954,512) = 512 22484 fstat64(3,0x7fffe870) = 0 22484 mmap2(NULL,803596,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x7f716000 22484 mmap2(0x7f7d8000,12288,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0xc1) = 0x7f7d8000 22484 close(3) = 0 22484 openat(AT_FDCWD,"/scratch/sandra/nios2-linux-trunk3/obj/test-2018.11-99-nios2-linux-gnu/host-x86_64-linux-gnu/sourceryg++-2018.11/nios2-linux-gnu/libc/./lib/./libpthread.so.0",O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3 22484 read(3,0x7fffe948,512) = 512 22484 mmap2(NULL,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0x7f714000 22484 fstat64(3,0x7fffe864) = 0 22484 mmap2(NULL,120700,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x7f6f6000 22484 mprotect(0x7f70e000,4096,PROT_NONE) = 0 22484 mmap2(0x7f70f000,12288,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x18) = 0x7f70f000 22484 mmap2(0x7f712000,6012,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 0x7f712000 22484 close(3) = 0 22484 openat(AT_FDCWD,"/scratch/sandra/nios2-linux-trunk3/obj/test-2018.11-99-nios2-linux-gnu/host-x86_64-linux-gnu/sourceryg++-2018.11/nios2-linux-gnu/libc/./lib/./libc.so.6",O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3 22484 read(3,0x7fffe93c,512) = 512 22484 fstat64(3,0x7fffe858) = 0 22484 mmap2(NULL,1491048,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x7f589000 22484 mmap2(0x7f6de000,86016,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x154) = 0x7f6de000 22484 mmap2(0x7f6f3000,8296,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 0x7f6f3000 22484 close(3) = 0 22484 mprotect(0x7f6de000,65536,PROT_READ) = 0 22484 mprotect(0x7f70f000,8192,PROT_READ) = 0 22484 mprotect(0x7f7d8000,4096,PROT_READ) = 0 22484 mprotect(0x3000,4096,PROT_READ) = 0 22484 mprotect(0x7f7fc000,4096,PROT_READ) = 0 22484 set_tid_address(2138131700,2147480980,2147480988,2147480988,87148,47) = 22484 22484 set_robust_list(2138131708,12,2147480988,0,87148,47) = -1 errno=38 (Function not implemented) 22484 rt_sigaction(32,0x736c,NULL) = 0 22484 rt_sigaction(33,0x736c,NULL) = -1 errno=22 (Invalid argument) 22484 rt_sigprocmask(SIG_UNBLOCK,0x74a8,NULL) = 0 22484 getrlimit(3,2147480732,3,0,62512,47) = 0 22484 mmap2(NULL,8392704,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|0x2,-1,0) = 0x7ed88000 22484 mprotect(0x7ed89000,8388608,PROT_READ|PROT_WRITE) = 0 22484 brk(NULL) = 0x5000 22484 brk(0x00026000) = 0x00026000 22484 clone(CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,child_stack=0x7f588018,parent_tidptr=0x7f5884fc,tls=0x7f58f928,child_tidptr=0x7f5884fc) = 22503 22484 io_setup(4001536,2136506392,2136507644,2136507644,2136537384,4100) = -1 errno=38 (Function not implemented) 22484 futex(0x7f5884fc,FUTEX_WAIT,22503,NULL,NULL,0)22484 set_robust_list(2136507652,12,0,4100,2136508076,4100) = -1 errno=38 (Function not implemented) 22484 madvise(2128117760,8372224,4,2136507672,528660,4100) = 0 22484 exit(0) = 0 22484 fstat64(1,0x7fffef48) = 0 22484 write(1,0x51e8,42)FAIL: a= 10, thr_a = 10 Addr = 0x7f715120 = 42 22484 exit_group(1) sandra@build2-trusty-cs:/scratch/sandra/nios2-linux-trunk3$ 22484 mmap2(NULL,1491048,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x7f589000 22484 mmap2(0x7f6de000,86016,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x154) = 0x7f6de000 22484 mmap2(0x7f6f3000,8296,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 0x7f6f3000 22484 close(3) = 0 22484 mprotect(0x7f6de000,65536,PROT_READ) = 0 22484 mprotect(0x7f70f000,8192,PROT_READ) = 0 22484 mprotect(0x7f7d8000,4096,PROT_READ) = 0 22484 mprotect(0x3000,4096,PROT_READ) = 0 22484 mprotect(0x7f7fc000,4096,PROT_READ) = 0
[Qemu-devel] [Bug 1791763] [NEW] broken signal handling in nios2 user-mode emulation
Public bug reported: This bug is against the 3.0 release. It appears that the signal handling parts of the nios2 user-mode emulation have never really been completed or tested. Some examples of failing tests from the GCC testsuite are gcc.dg/pr78185.c and gcc.dg/cleanup-10.c. Some problems I've identified and tried to fix with the attached patch are: - Code copied from the Linux kernel wasn't adjusted to differentiate between host and target data types and address spaces. - The sigaltstack() system call returns EINVAL because fields are listed in the wrong order in struct target_sigaltstack. With this patch, the system calls to set up the signal handler are returning successfully, but the handler isn't being invoked, so something is still wrong. I think I need another pair of eyes to look over this code. ** Affects: qemu Importance: Undecided Status: New ** Patch added: "partial patch" https://bugs.launchpad.net/bugs/1791763/+attachment/5187164/+files/wip-qemu.patch -- You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1791763 Title: broken signal handling in nios2 user-mode emulation Status in QEMU: New Bug description: This bug is against the 3.0 release. It appears that the signal handling parts of the nios2 user-mode emulation have never really been completed or tested. Some examples of failing tests from the GCC testsuite are gcc.dg/pr78185.c and gcc.dg/cleanup-10.c. Some problems I've identified and tried to fix with the attached patch are: - Code copied from the Linux kernel wasn't adjusted to differentiate between host and target data types and address spaces. - The sigaltstack() system call returns EINVAL because fields are listed in the wrong order in struct target_sigaltstack. With this patch, the system calls to set up the signal handler are returning successfully, but the handler isn't being invoked, so something is still wrong. I think I need another pair of eyes to look over this code. To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1791763/+subscriptions
Re: [Qemu-devel] [PATCH v3 2/2] Add Nios II semihosting support.
On 05/18/2018 03:35 PM, Sandra Loosemore wrote: On 05/18/2018 02:19 PM, Julian Brown wrote: On Fri, 18 May 2018 21:52:04 +0200 Marek Vasut wrote: On 05/18/2018 09:23 PM, Julian Brown wrote: This patch (by Sandra Loosemore, mildly rebased) adds support for semihosting for Nios II bare-metal emulation. Signed-off-by: Julian Brown Signed-off-by: Sandra Loosemore 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. 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.
On 05/18/2018 02:19 PM, Julian Brown wrote: On Fri, 18 May 2018 21:52:04 +0200 Marek Vasut <ma...@denx.de> wrote: On 05/18/2018 09:23 PM, Julian Brown wrote: This patch (by Sandra Loosemore, mildly rebased) adds support for semihosting for Nios II bare-metal emulation. Signed-off-by: Julian Brown <jul...@codesourcery.com> Signed-off-by: Sandra Loosemore <san...@codesourcery.com> 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 V8 2/7] nios2: Add architecture emulation support
On 01/16/2017 03:21 PM, Alexander Graf wrote: +static void nios2_cpu_disas_set_info(CPUState *cpu, disassemble_info *info) +{ +/* NOTE: NiosII R2 is not supported yet. */ +info->mach = bfd_arch_nios2; +#ifdef TARGET_WORDS_BIGENDIAN +info->print_insn = print_insn_big_nios2; +#else +info->print_insn = print_insn_little_nios2; +#endif I take it there is no runtime switch for endianness? Most architectures eventually got one and moved to a single default endianness for softmmu with swizzling for the "other" one (LE for ARM, BE for ppc). Maybe QEMU should just error out if configured for big-endianness on this target. Per the published Nios II Processor Reference Handbook, "The Nios II architecture uses little-endian byte ordering." When I was working on preparing the nios2 binutils patches for submission, Altera asked me to retain the big-endian hooks because they didn't want to rule out officially supporting that feature. I had no way to test anything big-endian, of course. -Sandra
Re: [Qemu-devel] [V3,1/7] nios2: Add disas entries
On 11/06/2016 08:55 PM, Guenter Roeck wrote: On Tue, Oct 18, 2016 at 11:50:25PM +0200, Marek Vasut wrote: 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 Signed-off-by: Marek Vasut <ma...@denx.de> Cc: Chris Wulff <crwu...@gmail.com> Cc: Jeff Da Silva <jdasi...@altera.com> Cc: Ley Foon Tan <lf...@altera.com> Cc: Sandra Loosemore <san...@codesourcery.com> Cc: Yves Vandervennet <yvand...@altera.com> --- V3: No change V2: Replace the nios2.c with GPL2 licensed version checkpatch.pl reports: total: 1967 errors, 150 warnings, 3559 lines checked on this file. When applying it, git reports a number of whitespace problems. Is that expected ? Guenter I don't know what checkpatch.pl is, or what "errors" it might be complaining about, but I'd strongly discourage doing anything to this code that would cause it to diverge from the binutils code it was derived from, even trivial whitespace changes. That would only complicate propagating updates to the code to both components. (I can't say I have any such patches in my queue right now, but I also can't rule out such changes in the future) -Sandra the nios2 binutils maintainer
Re: [Qemu-devel] [PATCH 1/7] nios2: Add disas entries
On 06/13/2016 01:40 PM, Marek Vasut wrote: On 06/13/2016 09:15 PM, Eric Blake wrote: On 06/13/2016 01:05 PM, Marek Vasut wrote: 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: +++ b/disas/nios2.c @@ -0,0 +1,3620 @@ +/* + * This file is a concatenation of the following files from binutils: + * include/opcode/nios2.h + * include/opcode/nios2r1.h + * include/opcode/nios2r2.h + * opcodes/nios2-opc.c + * opcodes/nios2-dis.c + */ + +/* Nios II opcode list for GAS, the GNU assembler. + Copyright (C) 2012-2016 Free Software Foundation, Inc. + Contributed by Nigel Gray (ng...@altera.com). + Contributed by Mentor Graphics, Inc. + + This file is part of GAS, the GNU Assembler, and GDB, the GNU disassembler. + + GAS/GDB is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. This is a non-starter. Qemu is a GPLv2-only project because of some of the files it has already borrowed from other places, so we CANNOT use GPLv3 files. You'll have to implement this from scratch, or pull from binutils at the point prior to where upstream binutils upgraded to GPLv3. Ouch, I see. I hope Sandra (on CC) might have some idea how to best go about this licensing thing. I briefly checked and the nios2 stuff landed in binutils under gpl3 already. H. Upstream binutils was already using GPLv3 at the time the nios2 support was contributed. I believe Altera's original out-of-tree patch set was GPLv2 but it is extremely bit-rotten at this point and doesn't include the new R2 instruction set or abstractions to support multiple ISA variants (I had to do a lot of refactoring of the old opcodes/disassembler support that amounted to almost a complete rewrite). I could look into whether Mentor Graphics could relicense our changes under GPLv2, but I'm not sure that would be possible or helpful given that both Altera and Mentor have already assigned copyright to the FSF? I'm not a legal expert. :-( -Sandra