From nobody Sun May 19 04:55:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1579890759; cv=none; d=zohomail.com; s=zohoarc; b=D82yPGGq9sUfvlRfEa4PZTv9xHRzY/7sW/5jjfWlzQ/AU2WKg2sHVz7YsdqpT2bXehTD+Z6izvllP5GM2BQFASkD1uJuT8JC5RAXCCnVK2dyEkLtEEEB9iCMXjIGqAeRE0Ekn94Mir2hUupVjFIb5wryQVFNrkG9cto7UnX/sKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579890759; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=3oy440in57iFcISI0gRxa2GTdchoBB5gQC6yhOD7uXI=; b=MlmLm3thoHV+XEL7tRh4hQkYZ2jqZqJlWDUCos00R9C7r9cvNIMHxF39lWaKfCQaj6owV7fGoVbOIqvNtbsXLW9zt/vacEC2O3AmG8X2HMkWC1TMdMB17GT+v1hP70gOT97/7dfV9oI222+7CLI5k7Kxs8YOXRAiwBYJjW2AIEA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579890759387127.33414789038193; Fri, 24 Jan 2020 10:32:39 -0800 (PST) Received: from localhost ([::1]:46320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iv3kz-0000RM-HW for importer@patchew.org; Fri, 24 Jan 2020 13:32:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41809) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iv3k6-00080E-1n for qemu-devel@nongnu.org; Fri, 24 Jan 2020 13:31:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iv3k2-0003fu-Aw for qemu-devel@nongnu.org; Fri, 24 Jan 2020 13:31:41 -0500 Received: from smtp.qindel.com ([89.140.90.34]:44376 helo=thor.qindel.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iv3jw-0003Yn-Vi; Fri, 24 Jan 2020 13:31:38 -0500 Received: from localhost (localhost [127.0.0.1]) by thor.qindel.com (Postfix) with ESMTP id C9C2760619; Fri, 24 Jan 2020 19:31:27 +0100 (CET) Received: from thor.qindel.com ([127.0.0.1]) by localhost (thor.qindel.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 8jcJvlVuwB8h; Fri, 24 Jan 2020 19:31:27 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by thor.qindel.com (Postfix) with ESMTP id 8936760620; Fri, 24 Jan 2020 19:31:27 +0100 (CET) Received: from thor.qindel.com ([127.0.0.1]) by localhost (thor.qindel.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id hCTe-qOpN652; Fri, 24 Jan 2020 19:31:27 +0100 (CET) Received: from freeso.my.domain (unknown [82.213.225.96]) by thor.qindel.com (Postfix) with ESMTPSA id 2C9B360619; Fri, 24 Jan 2020 19:31:27 +0100 (CET) X-Virus-Scanned: amavisd-new at thor.qindel.com From: salvador@qindel.com To: qemu-devel@nongnu.org Subject: [PATCH] bsd-user: improve support for sparc syscall flags Date: Fri, 24 Jan 2020 19:31:13 +0100 Message-Id: <20200124183113.58039-1-salvador@qindel.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 89.140.90.34 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, sfandino@yahoo.com, Salvador Fandino Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Salvador Fandino 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 --- 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 =3D env_cpu(env); - int trapnr, ret, syscall_nr; + int trapnr, ret, syscall_nr, syscall_flags; //target_siginfo_t info; =20 while (1) { @@ -511,21 +511,29 @@ void cpu_loop(CPUSPARCState *env) case 0x100: #endif syscall_nr =3D env->gregs[1]; - if (bsd_type =3D=3D target_freebsd) + if (bsd_type =3D=3D target_freebsd) { ret =3D 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 =3D=3D target_netbsd) + } + else if (bsd_type =3D=3D target_netbsd) { + syscall_flags =3D syscall_nr & (TARGET_NETBSD_SYSCALL_G7RF= LAG | + TARGET_NETBSD_SYSCALL_G5RFLA= G | + TARGET_NETBSD_SYSCALL_G2RFLA= G); + syscall_nr &=3D ~(TARGET_NETBSD_SYSCALL_G7RFLAG | + TARGET_NETBSD_SYSCALL_G5RFLAG | + TARGET_NETBSD_SYSCALL_G2RFLAG); ret =3D 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 =3D=3D target_openbsd) -#if defined(TARGET_SPARC64) - syscall_nr &=3D ~(TARGET_OPENBSD_SYSCALL_G7RFLAG | - TARGET_OPENBSD_SYSCALL_G2RFLAG); -#endif + syscall_flags =3D syscall_nr & (TARGET_OPENBSD_SYSCALL_G2R= FLAG | + TARGET_OPENBSD_SYSCALL_G7RFL= AG); + syscall_nr &=3D ~(TARGET_OPENBSD_SYSCALL_G2RFLAG | + TARGET_OPENBSD_SYSCALL_G7RFLAG); ret =3D 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] =3D ret; /* next instruction */ -#if defined(TARGET_SPARC64) - if (bsd_type =3D=3D target_openbsd && - env->gregs[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG) { - env->pc =3D env->gregs[2]; - env->npc =3D env->pc + 4; - } else if (bsd_type =3D=3D target_openbsd && - env->gregs[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG) { - env->pc =3D env->gregs[7]; - env->npc =3D env->pc + 4; - } else { + if (bsd_type =3D=3D target_openbsd) { + switch (syscall_flags) { + case 0: + env->pc =3D env->npc; + break; + case TARGET_OPENBSD_SYSCALL_G7RFLAG: + env->pc =3D env->gregs[7]; + break; + default: /* G2 or G2|G7 */ + env->pc =3D env->gregs[2]; + break; + } + } + else if (bsd_type =3D=3D target_netbsd) { + switch (syscall_flags) { + case 0: + env->pc =3D env->npc; + break; + case TARGET_NETBSD_SYSCALL_G7RFLAG: + env->pc =3D env->gregs[7]; + break; + case TARGET_NETBSD_SYSCALL_G5RFLAG: + env->pc =3D env->gregs[5]; + break; + case TARGET_NETBSD_SYSCALL_G2RFLAG: + env->pc =3D env->gregs[2]; + break; + } + } + else { env->pc =3D env->npc; - env->npc =3D env->npc + 4; } -#else - env->pc =3D env->npc; - env->npc =3D env->npc + 4; -#endif + env->npc =3D 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 PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * 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, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * 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 r= ather than npc */ +#define TARGET_NETBSD_SYSCALL_G7RFLAG 0x800 /* use %g7 as above (deprecate= d) */ +#define TARGET_NETBSD_SYSCALL_G5RFLAG 0xc00 /* use %g5 as above (only ABI = compatible way) */ --=20 2.24.1