All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bsd-user: improve support for sparc syscall flags
@ 2020-01-24 18:31 salvador
  2020-01-24 19:44 ` no-reply
  0 siblings, 1 reply; 9+ messages in thread
From: salvador @ 2020-01-24 18:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, sfandino, Salvador Fandino

From: Salvador Fandino <salvador@qindel.com>

Under sparc and sparc64, both NetBSD and OpenSSH use two bits of the
syscall number as flags. Until now, those bits where only supported
for sparc64 when emulating OpenBSD.

This patch extends support for syscall flags to the sparc architecture
and NetBSD emulation. It had allowed my to run simple NetBSD sparc
applications with qemu-sparc on a FreeBSD x64 machine.

The code supporting OpenBSD sparc and sparc64 emulation has been
refactored in order to make it simpler and similar to the new one for
NetBSD.

Signed-off-by: Salvador Fandino <salvador@qindel.com>
---
 bsd-user/main.c              | 68 ++++++++++++++++++++++++------------
 bsd-user/netbsd/syscall_nr.h | 52 +++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 22 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 770c2b267a..e249d66e26 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -491,7 +491,7 @@ static void flush_windows(CPUSPARCState *env)
 void cpu_loop(CPUSPARCState *env)
 {
     CPUState *cs = env_cpu(env);
-    int trapnr, ret, syscall_nr;
+    int trapnr, ret, syscall_nr, syscall_flags;
     //target_siginfo_t info;
 
     while (1) {
@@ -511,21 +511,29 @@ void cpu_loop(CPUSPARCState *env)
         case 0x100:
 #endif
             syscall_nr = env->gregs[1];
-            if (bsd_type == target_freebsd)
+            if (bsd_type == target_freebsd) {
                 ret = do_freebsd_syscall(env, syscall_nr,
                                          env->regwptr[0], env->regwptr[1],
                                          env->regwptr[2], env->regwptr[3],
                                          env->regwptr[4], env->regwptr[5], 0, 0);
-            else if (bsd_type == target_netbsd)
+            }
+            else if (bsd_type == target_netbsd) {
+                syscall_flags = syscall_nr & (TARGET_NETBSD_SYSCALL_G7RFLAG |
+                                              TARGET_NETBSD_SYSCALL_G5RFLAG |
+                                              TARGET_NETBSD_SYSCALL_G2RFLAG);
+                syscall_nr &= ~(TARGET_NETBSD_SYSCALL_G7RFLAG |
+                                TARGET_NETBSD_SYSCALL_G5RFLAG |
+                                TARGET_NETBSD_SYSCALL_G2RFLAG);
                 ret = do_netbsd_syscall(env, syscall_nr,
                                         env->regwptr[0], env->regwptr[1],
                                         env->regwptr[2], env->regwptr[3],
                                         env->regwptr[4], env->regwptr[5]);
+            }
             else { //if (bsd_type == target_openbsd)
-#if defined(TARGET_SPARC64)
-                syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG |
-                                TARGET_OPENBSD_SYSCALL_G2RFLAG);
-#endif
+                syscall_flags = syscall_nr & (TARGET_OPENBSD_SYSCALL_G2RFLAG |
+                                              TARGET_OPENBSD_SYSCALL_G7RFLAG);
+                syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G2RFLAG |
+                                TARGET_OPENBSD_SYSCALL_G7RFLAG);
                 ret = do_openbsd_syscall(env, syscall_nr,
                                          env->regwptr[0], env->regwptr[1],
                                          env->regwptr[2], env->regwptr[3],
@@ -547,23 +555,39 @@ void cpu_loop(CPUSPARCState *env)
             }
             env->regwptr[0] = ret;
             /* next instruction */
-#if defined(TARGET_SPARC64)
-            if (bsd_type == target_openbsd &&
-                env->gregs[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG) {
-                env->pc = env->gregs[2];
-                env->npc = env->pc + 4;
-            } else if (bsd_type == target_openbsd &&
-                       env->gregs[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG) {
-                env->pc = env->gregs[7];
-                env->npc = env->pc + 4;
-            } else {
+            if (bsd_type == target_openbsd) {
+                switch (syscall_flags) {
+                case 0:
+                    env->pc = env->npc;
+                    break;
+                case TARGET_OPENBSD_SYSCALL_G7RFLAG:
+                    env->pc = env->gregs[7];
+                    break;
+                default: /* G2 or G2|G7 */
+                    env->pc = env->gregs[2];
+                    break;
+                }
+            }
+            else if (bsd_type == target_netbsd) {
+                switch (syscall_flags) {
+                case 0:
+                    env->pc = env->npc;
+                    break;
+                case TARGET_NETBSD_SYSCALL_G7RFLAG:
+                    env->pc = env->gregs[7];
+                    break;
+                case TARGET_NETBSD_SYSCALL_G5RFLAG:
+                    env->pc = env->gregs[5];
+                    break;
+                case TARGET_NETBSD_SYSCALL_G2RFLAG:
+                    env->pc = env->gregs[2];
+                    break;
+                }
+            }
+            else  {
                 env->pc = env->npc;
-                env->npc = env->npc + 4;
             }
-#else
-            env->pc = env->npc;
-            env->npc = env->npc + 4;
-#endif
+            env->npc = env->pc + 4;
             break;
         case 0x83: /* flush windows */
 #ifdef TARGET_ABI32
diff --git a/bsd-user/netbsd/syscall_nr.h b/bsd-user/netbsd/syscall_nr.h
index 2e9ab5378e..79022b0b4e 100644
--- a/bsd-user/netbsd/syscall_nr.h
+++ b/bsd-user/netbsd/syscall_nr.h
@@ -371,3 +371,55 @@
 #define TARGET_NETBSD_NR_pset_assign 414
 #define TARGET_NETBSD_NR__pset_bind  415
 #define TARGET_NETBSD_NR___posix_fadvise50   416
+
+/*	$NetBSD: trap.h,v 1.18 2011/03/27 18:47:08 martin Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Lawrence Berkeley Laboratory.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)trap.h	8.1 (Berkeley) 6/11/93
+ */
+/*
+ * Sun4m support by Aaron Brown, Harvard University.
+ * Changes Copyright (c) 1995 The President and Fellows of Harvard College.
+ * All rights reserved.
+ */
+
+/* flags to system call (flags in %g1 along with syscall number) */
+#define	TARGET_NETBSD_SYSCALL_G2RFLAG	0x400	/* on success, return to %g2 rather than npc */
+#define	TARGET_NETBSD_SYSCALL_G7RFLAG	0x800	/* use %g7 as above (deprecated) */
+#define	TARGET_NETBSD_SYSCALL_G5RFLAG	0xc00	/* use %g5 as above (only ABI compatible way) */
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] bsd-user: improve support for sparc syscall flags
  2020-01-24 18:31 [PATCH] bsd-user: improve support for sparc syscall flags salvador
@ 2020-01-24 19:44 ` no-reply
  2020-01-24 22:27   ` Salvador Fandiño
  0 siblings, 1 reply; 9+ messages in thread
From: no-reply @ 2020-01-24 19:44 UTC (permalink / raw)
  To: salvador; +Cc: qemu-trivial, sfandino, salvador, qemu-devel

Patchew URL: https://patchew.org/QEMU/20200124183113.58039-1-salvador@qindel.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20200124183113.58039-1-salvador@qindel.com
Subject: [PATCH] bsd-user: improve support for sparc syscall flags

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

From https://github.com/patchew-project/qemu
 * [new tag]         patchew/20200124183113.58039-1-salvador@qindel.com -> patchew/20200124183113.58039-1-salvador@qindel.com
Switched to a new branch 'test'
74a56ab bsd-user: improve support for sparc syscall flags

=== OUTPUT BEGIN ===
ERROR: else should follow close brace '}'
#47: FILE: bsd-user/main.c:520:
+            }
+            else if (bsd_type == target_netbsd) {

ERROR: else should follow close brace '}'
#104: FILE: bsd-user/main.c:571:
             }
+            else if (bsd_type == target_netbsd) {

ERROR: else should follow close brace '}'
#120: FILE: bsd-user/main.c:587:
+            }
+            else  {

ERROR: code indent should never use tabs
#136: FILE: bsd-user/netbsd/syscall_nr.h:375:
+/*^I$NetBSD: trap.h,v 1.18 2011/03/27 18:47:08 martin Exp $ */$

ERROR: code indent should never use tabs
#140: FILE: bsd-user/netbsd/syscall_nr.h:379:
+ *^IThe Regents of the University of California.  All rights reserved.$

ERROR: code indent should never use tabs
#148: FILE: bsd-user/netbsd/syscall_nr.h:387:
+ *^IThis product includes software developed by the University of$

ERROR: code indent should never use tabs
#149: FILE: bsd-user/netbsd/syscall_nr.h:388:
+ *^ICalifornia, Lawrence Berkeley Laboratory.$

ERROR: code indent should never use tabs
#175: FILE: bsd-user/netbsd/syscall_nr.h:414:
+ *^I@(#)trap.h^I8.1 (Berkeley) 6/11/93$

ERROR: line over 90 characters
#184: FILE: bsd-user/netbsd/syscall_nr.h:423:
+#define        TARGET_NETBSD_SYSCALL_G2RFLAG   0x400   /* on success, return to %g2 rather than npc */

ERROR: code indent should never use tabs
#184: FILE: bsd-user/netbsd/syscall_nr.h:423:
+#define^ITARGET_NETBSD_SYSCALL_G2RFLAG^I0x400^I/* on success, return to %g2 rather than npc */$

WARNING: line over 80 characters
#185: FILE: bsd-user/netbsd/syscall_nr.h:424:
+#define        TARGET_NETBSD_SYSCALL_G7RFLAG   0x800   /* use %g7 as above (deprecated) */

ERROR: code indent should never use tabs
#185: FILE: bsd-user/netbsd/syscall_nr.h:424:
+#define^ITARGET_NETBSD_SYSCALL_G7RFLAG^I0x800^I/* use %g7 as above (deprecated) */$

ERROR: line over 90 characters
#186: FILE: bsd-user/netbsd/syscall_nr.h:425:
+#define        TARGET_NETBSD_SYSCALL_G5RFLAG   0xc00   /* use %g5 as above (only ABI compatible way) */

ERROR: code indent should never use tabs
#186: FILE: bsd-user/netbsd/syscall_nr.h:425:
+#define^ITARGET_NETBSD_SYSCALL_G5RFLAG^I0xc00^I/* use %g5 as above (only ABI compatible way) */$

total: 13 errors, 1 warnings, 153 lines checked

Commit 74a56abec155 (bsd-user: improve support for sparc syscall flags) 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


The full log is available at
http://patchew.org/logs/20200124183113.58039-1-salvador@qindel.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] bsd-user: improve support for sparc syscall flags
  2020-01-24 19:44 ` no-reply
@ 2020-01-24 22:27   ` Salvador Fandiño
  2020-01-24 22:31     ` salvador
  0 siblings, 1 reply; 9+ messages in thread
From: Salvador Fandiño @ 2020-01-24 22:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, sfandino


On 24/1/20 20:44, no-reply@patchew.org wrote:
> Patchew URL: https://patchew.org/QEMU/20200124183113.58039-1-salvador@qindel.com/
>
>
>
> Hi,
>
> This series seems to have some coding style problems. See output below for
> more information:

A new patch is coming fixing the errors found by patchew in bsd-user/main.c

I am not changing any of the new code in bsd-user/netbsd/syscall_nr.h as 
it has been copied from NetBSD source, in the same way it was done for 
bsd-user/openbsd/syscall_nr.h.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] bsd-user: improve support for sparc syscall flags
  2020-01-24 22:27   ` Salvador Fandiño
@ 2020-01-24 22:31     ` salvador
  2020-01-24 22:49       ` no-reply
  0 siblings, 1 reply; 9+ messages in thread
From: salvador @ 2020-01-24 22:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, sfandino, Salvador Fandino

From: Salvador Fandino <salvador@qindel.com>

Under sparc and sparc64, both NetBSD and OpenSSH use two bits of the
syscall number as flags. Until now, those bits where only supported
for sparc64 when emulating OpenBSD.

This patch extends support for syscall flags to the sparc architecture
and NetBSD emulation. It had allowed my to run simple NetBSD sparc
applications with qemu-sparc on a FreeBSD x64 machine.

The code supporting OpenBSD sparc and sparc64 emulation has been
refactored in order to make it simpler and similar to the new one for
NetBSD.

Signed-off-by: Salvador Fandino <salvador@qindel.com>
---
 bsd-user/main.c              | 66 +++++++++++++++++++++++-------------
 bsd-user/netbsd/syscall_nr.h | 52 ++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 23 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 770c2b267a..9158ecbc5c 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -491,7 +491,7 @@ static void flush_windows(CPUSPARCState *env)
 void cpu_loop(CPUSPARCState *env)
 {
     CPUState *cs = env_cpu(env);
-    int trapnr, ret, syscall_nr;
+    int trapnr, ret, syscall_nr, syscall_flags;
     //target_siginfo_t info;
 
     while (1) {
@@ -511,21 +511,27 @@ void cpu_loop(CPUSPARCState *env)
         case 0x100:
 #endif
             syscall_nr = env->gregs[1];
-            if (bsd_type == target_freebsd)
+            if (bsd_type == target_freebsd) {
                 ret = do_freebsd_syscall(env, syscall_nr,
                                          env->regwptr[0], env->regwptr[1],
                                          env->regwptr[2], env->regwptr[3],
                                          env->regwptr[4], env->regwptr[5], 0, 0);
-            else if (bsd_type == target_netbsd)
+            } else if (bsd_type == target_netbsd) {
+                syscall_flags = syscall_nr & (TARGET_NETBSD_SYSCALL_G7RFLAG |
+                                              TARGET_NETBSD_SYSCALL_G5RFLAG |
+                                              TARGET_NETBSD_SYSCALL_G2RFLAG);
+                syscall_nr &= ~(TARGET_NETBSD_SYSCALL_G7RFLAG |
+                                TARGET_NETBSD_SYSCALL_G5RFLAG |
+                                TARGET_NETBSD_SYSCALL_G2RFLAG);
                 ret = do_netbsd_syscall(env, syscall_nr,
                                         env->regwptr[0], env->regwptr[1],
                                         env->regwptr[2], env->regwptr[3],
                                         env->regwptr[4], env->regwptr[5]);
-            else { //if (bsd_type == target_openbsd)
-#if defined(TARGET_SPARC64)
-                syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG |
-                                TARGET_OPENBSD_SYSCALL_G2RFLAG);
-#endif
+            } else { //if (bsd_type == target_openbsd)
+                syscall_flags = syscall_nr & (TARGET_OPENBSD_SYSCALL_G2RFLAG |
+                                              TARGET_OPENBSD_SYSCALL_G7RFLAG);
+                syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G2RFLAG |
+                                TARGET_OPENBSD_SYSCALL_G7RFLAG);
                 ret = do_openbsd_syscall(env, syscall_nr,
                                          env->regwptr[0], env->regwptr[1],
                                          env->regwptr[2], env->regwptr[3],
@@ -547,23 +553,37 @@ void cpu_loop(CPUSPARCState *env)
             }
             env->regwptr[0] = ret;
             /* next instruction */
-#if defined(TARGET_SPARC64)
-            if (bsd_type == target_openbsd &&
-                env->gregs[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG) {
-                env->pc = env->gregs[2];
-                env->npc = env->pc + 4;
-            } else if (bsd_type == target_openbsd &&
-                       env->gregs[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG) {
-                env->pc = env->gregs[7];
-                env->npc = env->pc + 4;
-            } else {
+            if (bsd_type == target_openbsd) {
+                switch (syscall_flags) {
+                case 0:
+                    env->pc = env->npc;
+                    break;
+                case TARGET_OPENBSD_SYSCALL_G7RFLAG:
+                    env->pc = env->gregs[7];
+                    break;
+                default: /* G2 or G2|G7 */
+                    env->pc = env->gregs[2];
+                    break;
+                }
+            } else if (bsd_type == target_netbsd) {
+                switch (syscall_flags) {
+                case 0:
+                    env->pc = env->npc;
+                    break;
+                case TARGET_NETBSD_SYSCALL_G7RFLAG:
+                    env->pc = env->gregs[7];
+                    break;
+                case TARGET_NETBSD_SYSCALL_G5RFLAG:
+                    env->pc = env->gregs[5];
+                    break;
+                case TARGET_NETBSD_SYSCALL_G2RFLAG:
+                    env->pc = env->gregs[2];
+                    break;
+                }
+            } else  {  //if (bsd_type == target_freebsd)
                 env->pc = env->npc;
-                env->npc = env->npc + 4;
             }
-#else
-            env->pc = env->npc;
-            env->npc = env->npc + 4;
-#endif
+            env->npc = env->pc + 4;
             break;
         case 0x83: /* flush windows */
 #ifdef TARGET_ABI32
diff --git a/bsd-user/netbsd/syscall_nr.h b/bsd-user/netbsd/syscall_nr.h
index 2e9ab5378e..79022b0b4e 100644
--- a/bsd-user/netbsd/syscall_nr.h
+++ b/bsd-user/netbsd/syscall_nr.h
@@ -371,3 +371,55 @@
 #define TARGET_NETBSD_NR_pset_assign 414
 #define TARGET_NETBSD_NR__pset_bind  415
 #define TARGET_NETBSD_NR___posix_fadvise50   416
+
+/*	$NetBSD: trap.h,v 1.18 2011/03/27 18:47:08 martin Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Lawrence Berkeley Laboratory.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)trap.h	8.1 (Berkeley) 6/11/93
+ */
+/*
+ * Sun4m support by Aaron Brown, Harvard University.
+ * Changes Copyright (c) 1995 The President and Fellows of Harvard College.
+ * All rights reserved.
+ */
+
+/* flags to system call (flags in %g1 along with syscall number) */
+#define	TARGET_NETBSD_SYSCALL_G2RFLAG	0x400	/* on success, return to %g2 rather than npc */
+#define	TARGET_NETBSD_SYSCALL_G7RFLAG	0x800	/* use %g7 as above (deprecated) */
+#define	TARGET_NETBSD_SYSCALL_G5RFLAG	0xc00	/* use %g5 as above (only ABI compatible way) */
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] bsd-user: improve support for sparc syscall flags
  2020-01-24 22:31     ` salvador
@ 2020-01-24 22:49       ` no-reply
  2020-01-25 11:47         ` salvador
  0 siblings, 1 reply; 9+ messages in thread
From: no-reply @ 2020-01-24 22:49 UTC (permalink / raw)
  To: salvador; +Cc: qemu-trivial, sfandino, salvador, qemu-devel

Patchew URL: https://patchew.org/QEMU/20200124223118.58596-1-salvador@qindel.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20200124223118.58596-1-salvador@qindel.com
Subject: [PATCH] bsd-user: improve support for sparc syscall flags

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Switched to a new branch 'test'
636238f bsd-user: improve support for sparc syscall flags

=== OUTPUT BEGIN ===
ERROR: do not use C99 // comments
#62: FILE: bsd-user/main.c:530:
+            } else { //if (bsd_type == target_openbsd)

ERROR: do not use C99 // comments
#111: FILE: bsd-user/main.c:583:
+            } else  {  //if (bsd_type == target_freebsd)

ERROR: code indent should never use tabs
#132: FILE: bsd-user/netbsd/syscall_nr.h:375:
+/*^I$NetBSD: trap.h,v 1.18 2011/03/27 18:47:08 martin Exp $ */$

ERROR: code indent should never use tabs
#136: FILE: bsd-user/netbsd/syscall_nr.h:379:
+ *^IThe Regents of the University of California.  All rights reserved.$

ERROR: code indent should never use tabs
#144: FILE: bsd-user/netbsd/syscall_nr.h:387:
+ *^IThis product includes software developed by the University of$

ERROR: code indent should never use tabs
#145: FILE: bsd-user/netbsd/syscall_nr.h:388:
+ *^ICalifornia, Lawrence Berkeley Laboratory.$

ERROR: code indent should never use tabs
#171: FILE: bsd-user/netbsd/syscall_nr.h:414:
+ *^I@(#)trap.h^I8.1 (Berkeley) 6/11/93$

ERROR: line over 90 characters
#180: FILE: bsd-user/netbsd/syscall_nr.h:423:
+#define        TARGET_NETBSD_SYSCALL_G2RFLAG   0x400   /* on success, return to %g2 rather than npc */

ERROR: code indent should never use tabs
#180: FILE: bsd-user/netbsd/syscall_nr.h:423:
+#define^ITARGET_NETBSD_SYSCALL_G2RFLAG^I0x400^I/* on success, return to %g2 rather than npc */$

WARNING: line over 80 characters
#181: FILE: bsd-user/netbsd/syscall_nr.h:424:
+#define        TARGET_NETBSD_SYSCALL_G7RFLAG   0x800   /* use %g7 as above (deprecated) */

ERROR: code indent should never use tabs
#181: FILE: bsd-user/netbsd/syscall_nr.h:424:
+#define^ITARGET_NETBSD_SYSCALL_G7RFLAG^I0x800^I/* use %g7 as above (deprecated) */$

ERROR: line over 90 characters
#182: FILE: bsd-user/netbsd/syscall_nr.h:425:
+#define        TARGET_NETBSD_SYSCALL_G5RFLAG   0xc00   /* use %g5 as above (only ABI compatible way) */

ERROR: code indent should never use tabs
#182: FILE: bsd-user/netbsd/syscall_nr.h:425:
+#define^ITARGET_NETBSD_SYSCALL_G5RFLAG^I0xc00^I/* use %g5 as above (only ABI compatible way) */$

total: 12 errors, 1 warnings, 149 lines checked

Commit 636238f7ed82 (bsd-user: improve support for sparc syscall flags) 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


The full log is available at
http://patchew.org/logs/20200124223118.58596-1-salvador@qindel.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] bsd-user: improve support for sparc syscall flags
  2020-01-24 22:49       ` no-reply
@ 2020-01-25 11:47         ` salvador
  2020-01-25 11:55           ` no-reply
  0 siblings, 1 reply; 9+ messages in thread
From: salvador @ 2020-01-25 11:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, sfandino, Salvador Fandino

From: Salvador Fandino <salvador@qindel.com>

Under sparc and sparc64, both NetBSD and OpenSSH use two bits of the
syscall number as flags. Until now, those bits where only supported
for sparc64 when emulating OpenBSD.

This patch extends support for syscall flags to the sparc architecture
and NetBSD emulation. It had allowed my to run simple NetBSD sparc
applications with qemu-sparc on a FreeBSD x64 machine.

The code supporting OpenBSD sparc and sparc64 emulation has been
refactored in order to make it simpler and similar to the new one for
NetBSD.

Signed-off-by: Salvador Fandino <salvador@qindel.com>
---
 bsd-user/main.c              | 66 +++++++++++++++++++++++-------------
 bsd-user/netbsd/syscall_nr.h | 52 ++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 23 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 770c2b267a..5706261f15 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -491,7 +491,7 @@ static void flush_windows(CPUSPARCState *env)
 void cpu_loop(CPUSPARCState *env)
 {
     CPUState *cs = env_cpu(env);
-    int trapnr, ret, syscall_nr;
+    int trapnr, ret, syscall_nr, syscall_flags;
     //target_siginfo_t info;
 
     while (1) {
@@ -511,21 +511,27 @@ void cpu_loop(CPUSPARCState *env)
         case 0x100:
 #endif
             syscall_nr = env->gregs[1];
-            if (bsd_type == target_freebsd)
+            if (bsd_type == target_freebsd) {
                 ret = do_freebsd_syscall(env, syscall_nr,
                                          env->regwptr[0], env->regwptr[1],
                                          env->regwptr[2], env->regwptr[3],
                                          env->regwptr[4], env->regwptr[5], 0, 0);
-            else if (bsd_type == target_netbsd)
+            } else if (bsd_type == target_netbsd) {
+                syscall_flags = syscall_nr & (TARGET_NETBSD_SYSCALL_G7RFLAG |
+                                              TARGET_NETBSD_SYSCALL_G5RFLAG |
+                                              TARGET_NETBSD_SYSCALL_G2RFLAG);
+                syscall_nr &= ~(TARGET_NETBSD_SYSCALL_G7RFLAG |
+                                TARGET_NETBSD_SYSCALL_G5RFLAG |
+                                TARGET_NETBSD_SYSCALL_G2RFLAG);
                 ret = do_netbsd_syscall(env, syscall_nr,
                                         env->regwptr[0], env->regwptr[1],
                                         env->regwptr[2], env->regwptr[3],
                                         env->regwptr[4], env->regwptr[5]);
-            else { //if (bsd_type == target_openbsd)
-#if defined(TARGET_SPARC64)
-                syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG |
-                                TARGET_OPENBSD_SYSCALL_G2RFLAG);
-#endif
+            } else { /* if (bsd_type == target_openbsd) */
+                syscall_flags = syscall_nr & (TARGET_OPENBSD_SYSCALL_G2RFLAG |
+                                              TARGET_OPENBSD_SYSCALL_G7RFLAG);
+                syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G2RFLAG |
+                                TARGET_OPENBSD_SYSCALL_G7RFLAG);
                 ret = do_openbsd_syscall(env, syscall_nr,
                                          env->regwptr[0], env->regwptr[1],
                                          env->regwptr[2], env->regwptr[3],
@@ -547,23 +553,37 @@ void cpu_loop(CPUSPARCState *env)
             }
             env->regwptr[0] = ret;
             /* next instruction */
-#if defined(TARGET_SPARC64)
-            if (bsd_type == target_openbsd &&
-                env->gregs[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG) {
-                env->pc = env->gregs[2];
-                env->npc = env->pc + 4;
-            } else if (bsd_type == target_openbsd &&
-                       env->gregs[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG) {
-                env->pc = env->gregs[7];
-                env->npc = env->pc + 4;
-            } else {
+            if (bsd_type == target_openbsd) {
+                switch (syscall_flags) {
+                case 0:
+                    env->pc = env->npc;
+                    break;
+                case TARGET_OPENBSD_SYSCALL_G7RFLAG:
+                    env->pc = env->gregs[7];
+                    break;
+                default: /* G2 or G2|G7 */
+                    env->pc = env->gregs[2];
+                    break;
+                }
+            } else if (bsd_type == target_netbsd) {
+                switch (syscall_flags) {
+                case 0:
+                    env->pc = env->npc;
+                    break;
+                case TARGET_NETBSD_SYSCALL_G7RFLAG:
+                    env->pc = env->gregs[7];
+                    break;
+                case TARGET_NETBSD_SYSCALL_G5RFLAG:
+                    env->pc = env->gregs[5];
+                    break;
+                case TARGET_NETBSD_SYSCALL_G2RFLAG:
+                    env->pc = env->gregs[2];
+                    break;
+                }
+            } else  {  /* if (bsd_type == target_freebsd) */
                 env->pc = env->npc;
-                env->npc = env->npc + 4;
             }
-#else
-            env->pc = env->npc;
-            env->npc = env->npc + 4;
-#endif
+            env->npc = env->pc + 4;
             break;
         case 0x83: /* flush windows */
 #ifdef TARGET_ABI32
diff --git a/bsd-user/netbsd/syscall_nr.h b/bsd-user/netbsd/syscall_nr.h
index 2e9ab5378e..79022b0b4e 100644
--- a/bsd-user/netbsd/syscall_nr.h
+++ b/bsd-user/netbsd/syscall_nr.h
@@ -371,3 +371,55 @@
 #define TARGET_NETBSD_NR_pset_assign 414
 #define TARGET_NETBSD_NR__pset_bind  415
 #define TARGET_NETBSD_NR___posix_fadvise50   416
+
+/*	$NetBSD: trap.h,v 1.18 2011/03/27 18:47:08 martin Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Lawrence Berkeley Laboratory.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)trap.h	8.1 (Berkeley) 6/11/93
+ */
+/*
+ * Sun4m support by Aaron Brown, Harvard University.
+ * Changes Copyright (c) 1995 The President and Fellows of Harvard College.
+ * All rights reserved.
+ */
+
+/* flags to system call (flags in %g1 along with syscall number) */
+#define	TARGET_NETBSD_SYSCALL_G2RFLAG	0x400	/* on success, return to %g2 rather than npc */
+#define	TARGET_NETBSD_SYSCALL_G7RFLAG	0x800	/* use %g7 as above (deprecated) */
+#define	TARGET_NETBSD_SYSCALL_G5RFLAG	0xc00	/* use %g5 as above (only ABI compatible way) */
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] bsd-user: improve support for sparc syscall flags
  2020-01-25 11:47         ` salvador
@ 2020-01-25 11:55           ` no-reply
  2020-01-25 15:52             ` Laurent Vivier
  0 siblings, 1 reply; 9+ messages in thread
From: no-reply @ 2020-01-25 11:55 UTC (permalink / raw)
  To: salvador; +Cc: qemu-trivial, sfandino, salvador, qemu-devel

Patchew URL: https://patchew.org/QEMU/20200125114753.61820-1-salvador@qindel.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20200125114753.61820-1-salvador@qindel.com
Subject: [PATCH] bsd-user: improve support for sparc syscall flags

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]      patchew/20200124005131.16276-1-f4bug@amsat.org -> patchew/20200124005131.16276-1-f4bug@amsat.org
 * [new tag]         patchew/20200125114753.61820-1-salvador@qindel.com -> patchew/20200125114753.61820-1-salvador@qindel.com
Switched to a new branch 'test'
e256a0f bsd-user: improve support for sparc syscall flags

=== OUTPUT BEGIN ===
ERROR: code indent should never use tabs
#132: FILE: bsd-user/netbsd/syscall_nr.h:375:
+/*^I$NetBSD: trap.h,v 1.18 2011/03/27 18:47:08 martin Exp $ */$

ERROR: code indent should never use tabs
#136: FILE: bsd-user/netbsd/syscall_nr.h:379:
+ *^IThe Regents of the University of California.  All rights reserved.$

ERROR: code indent should never use tabs
#144: FILE: bsd-user/netbsd/syscall_nr.h:387:
+ *^IThis product includes software developed by the University of$

ERROR: code indent should never use tabs
#145: FILE: bsd-user/netbsd/syscall_nr.h:388:
+ *^ICalifornia, Lawrence Berkeley Laboratory.$

ERROR: code indent should never use tabs
#171: FILE: bsd-user/netbsd/syscall_nr.h:414:
+ *^I@(#)trap.h^I8.1 (Berkeley) 6/11/93$

ERROR: line over 90 characters
#180: FILE: bsd-user/netbsd/syscall_nr.h:423:
+#define        TARGET_NETBSD_SYSCALL_G2RFLAG   0x400   /* on success, return to %g2 rather than npc */

ERROR: code indent should never use tabs
#180: FILE: bsd-user/netbsd/syscall_nr.h:423:
+#define^ITARGET_NETBSD_SYSCALL_G2RFLAG^I0x400^I/* on success, return to %g2 rather than npc */$

WARNING: line over 80 characters
#181: FILE: bsd-user/netbsd/syscall_nr.h:424:
+#define        TARGET_NETBSD_SYSCALL_G7RFLAG   0x800   /* use %g7 as above (deprecated) */

ERROR: code indent should never use tabs
#181: FILE: bsd-user/netbsd/syscall_nr.h:424:
+#define^ITARGET_NETBSD_SYSCALL_G7RFLAG^I0x800^I/* use %g7 as above (deprecated) */$

ERROR: line over 90 characters
#182: FILE: bsd-user/netbsd/syscall_nr.h:425:
+#define        TARGET_NETBSD_SYSCALL_G5RFLAG   0xc00   /* use %g5 as above (only ABI compatible way) */

ERROR: code indent should never use tabs
#182: FILE: bsd-user/netbsd/syscall_nr.h:425:
+#define^ITARGET_NETBSD_SYSCALL_G5RFLAG^I0xc00^I/* use %g5 as above (only ABI compatible way) */$

total: 10 errors, 1 warnings, 149 lines checked

Commit e256a0ff22ca (bsd-user: improve support for sparc syscall flags) 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


The full log is available at
http://patchew.org/logs/20200125114753.61820-1-salvador@qindel.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] bsd-user: improve support for sparc syscall flags
  2020-01-25 11:55           ` no-reply
@ 2020-01-25 15:52             ` Laurent Vivier
  2020-01-25 19:09               ` Salvador Fandiño
  0 siblings, 1 reply; 9+ messages in thread
From: Laurent Vivier @ 2020-01-25 15:52 UTC (permalink / raw)
  To: qemu-devel, salvador; +Cc: qemu-trivial, sfandino

Le 25/01/2020 à 12:55, no-reply@patchew.org a écrit :
> Patchew URL: https://patchew.org/QEMU/20200125114753.61820-1-salvador@qindel.com/
> 
> 
> 
> Hi,
> 
> This series seems to have some coding style problems. See output below for
> more information:
> 

Salvador,

you can use scripts/checkpatch.pl in the QEMU directory to check your
patch for style before sending them.

And don't send them as a reply but as a new thread, using versioning in
the subject ("[PATCH v4]").

Thanks,
Laurent



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] bsd-user: improve support for sparc syscall flags
  2020-01-25 15:52             ` Laurent Vivier
@ 2020-01-25 19:09               ` Salvador Fandiño
  0 siblings, 0 replies; 9+ messages in thread
From: Salvador Fandiño @ 2020-01-25 19:09 UTC (permalink / raw)
  To: Laurent Vivier, qemu-devel; +Cc: qemu-trivial, sfandino

[-- Attachment #1: Type: text/plain, Size: 977 bytes --]


On 25/1/20 16:52, Laurent Vivier wrote:
> Le 25/01/2020 à 12:55, no-reply@patchew.org a écrit :
>> Patchew URL: https://patchew.org/QEMU/20200125114753.61820-1-salvador@qindel.com/
>>
>>
>>
>> Hi,
>>
>> This series seems to have some coding style problems. See output below for
>> more information:
>>
> Salvador,
>
> you can use scripts/checkpatch.pl in the QEMU directory to check your
> patch for style before sending them.
>
> And don't send them as a reply but as a new thread, using versioning in
> the subject ("[PATCH v4]").

ok, I will do that in the future.

In any case, the style problems found by patchew for the last version of 
the patch I have submitted are for a fragment of a file copied verbatim 
from the NetBSD source code (in the same way the equivalent fragment was 
copied from OpenBSD when support for that OS was added). It is mostly 
the copyright header and a few defines. IMO, style shouldn't be 
corrected there.


[-- Attachment #2: Type: text/html, Size: 1798 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-01-25 19:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24 18:31 [PATCH] bsd-user: improve support for sparc syscall flags salvador
2020-01-24 19:44 ` no-reply
2020-01-24 22:27   ` Salvador Fandiño
2020-01-24 22:31     ` salvador
2020-01-24 22:49       ` no-reply
2020-01-25 11:47         ` salvador
2020-01-25 11:55           ` no-reply
2020-01-25 15:52             ` Laurent Vivier
2020-01-25 19:09               ` Salvador Fandiño

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.