diff mbox series

bsd-user: improve support for sparc syscall flags

Message ID 20200125114753.61820-1-salvador@qindel.com
State New
Headers show
Series bsd-user: improve support for sparc syscall flags | expand

Commit Message

Salvador Fandiño Jan. 25, 2020, 11:47 a.m. UTC
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(-)

Comments

no-reply@patchew.org Jan. 25, 2020, 11:55 a.m. UTC | #1
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
Laurent Vivier Jan. 25, 2020, 3:52 p.m. UTC | #2
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
Salvador Fandiño Jan. 25, 2020, 7:09 p.m. UTC | #3
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.
diff mbox series

Patch

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) */