From nobody Mon May 15 15:59:04 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QKkZX337kz4BmK2; Mon, 15 May 2023 15:59:16 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QKkZX2Qdyz3Nrl; Mon, 15 May 2023 15:59:16 +0000 (UTC) (envelope-from kevans@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684166356; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ADpi1FnQmCY4tBNRXkOGaMIIxYvBLpG0ecYLj2SzOzg=; b=Athpoy+1p9TFtlXlG02VYueKUL4HATuG08ajYL4HJ+Up6f/b1qYikNV9T6fTRtuOY9a5aJ Tpi55VjVStM4CRRsjSokVoO3Min1NAxfo64rfa6ixGWZ23Tp65Uag868qb9/uiLTDhkQVs UDu5wo13S+A5DuaKuHznOref6AmzZrodcIBtyYl5yKjg1TfWwWaoynR6B0XDFbKkzIpTRm 8i+wvecIBJhE3b2M7nHaF+9K3CJln0n7tzWFr9Ax96nsfOcz8Py212SYntQpQaPcIGinjZ E7qq0LrzRSbugcHMOG2IBTxPECyRl2RUPmnwnr2wbpfSVK/13RueYiSQoPxzDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684166356; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ADpi1FnQmCY4tBNRXkOGaMIIxYvBLpG0ecYLj2SzOzg=; b=Dd/5WdIPs89kopaGdHfhkDmM/7UinREg0kC9GOKRO+x4G1osS5GZ6EvMVyQXt5iVvd9MvH iEdnciBEwqyWghxPmlVixiAY38J5ZcZ8ClL44LKccdakYD8fAfjvDrjwIAGuv8QKzrmRON 8EQpG5Nssp90PFipR8oz6qRCKWTnfAVZpcpF8uHQyO0Kj7EYBi77wt84EMhjy01lP63wmh P5yGUHk5hf4X4FUsrV9734pbkzYzNY4+R0uWLdEVk08S3uX9wp8USmVljEvbONwo+yLhaE pavWYoO2UNZB4VN34bwllgKCLP5JaRUmySOOqYl7BL6LQyNJAN753Ir/GMSVhQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684166356; a=rsa-sha256; cv=none; b=l2U0vWQ7R6MvW+7XsV/Tb3u6BQSNfKJ+sk/Og7/nljy9JMG1sR/ILY+YvwSyEkvyriZVLK uCAam5vcGR4sgYL3LnDlO2vAfsZOD+ANYIFsnItH6uHqwAEaogNllsDlyajOjv237r6J4d NKDBCkhzMF3N4EW2DkX+lGRcZsynSsAEwWCAGUHRTlbF+ybtjVnNCnnWmR8Mx9y6m7IE+3 NGu8JN0BjtXdXEbbIjPgJLtse5mrUQHrXz7jZHPITsnhXRD6MMN3FoKr44ODwIezN2q2r1 M7a1lWNw22w42sZlFc7ccwm7L3DqxTYYMVLuwI9Cp9OYOd09pEBzH6R2uLccWg== Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) (Authenticated sender: kevans) by smtp.freebsd.org (Postfix) with ESMTPSA id 4QKkZX1Ls2z12ND; Mon, 15 May 2023 15:59:16 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-759219bed84so190528985a.0; Mon, 15 May 2023 08:59:16 -0700 (PDT) X-Gm-Message-State: AC+VfDygAaddE1tHe0pkQWW0UUK89CbdaL/da0w7mcoucLVoxLoLD9p6 Nwvc5aNBa7fVIqmxo31Z3hfWIxBXY4x5jlrN/6Q= X-Google-Smtp-Source: ACHHUZ6V+CRoWkt7k6A0rehvpMpEnYnthsUMhmegZsIXt5YVgxAGJ6qCKFgVbKYjKCVd1QWrcwV4kfTadfsapH7o8gA= X-Received: by 2002:a05:6214:1305:b0:61b:7884:4351 with SMTP id pn5-20020a056214130500b0061b78844351mr65561123qvb.32.1684166355561; Mon, 15 May 2023 08:59:15 -0700 (PDT) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 References: <202305151542.34FFgN7D071754@gitrepo.freebsd.org> In-Reply-To: From: Kyle Evans Date: Mon, 15 May 2023 10:59:04 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: git: 4b500174dd2d - main - arm64: emulate swp/swpb instructions To: Jessica Clarke Cc: Kyle Evans , "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-ThisMailContainsUnwantedMimeParts: N On Mon, May 15, 2023 at 10:49=E2=80=AFAM Jessica Clarke wrote: > > On 15 May 2023, at 16:42, Kyle Evans wrote: > > > > The branch main has been updated by kevans: > > > > URL: https://cgit.FreeBSD.org/src/commit/?id=3D4b500174dd2d1e16dcb87c22= 364f724472c82edc > > > > commit 4b500174dd2d1e16dcb87c22364f724472c82edc > > Author: Kyle Evans > > AuthorDate: 2023-05-15 15:42:10 +0000 > > Commit: Kyle Evans > > CommitDate: 2023-05-15 15:42:10 +0000 > > > > arm64: emulate swp/swpb instructions > > > > Add another undefined instruction handler for compat32 and watch out= for > > SWP/SWPB instructions. > > > > SWP/SWPB were deprecated in ARMv6 and declared obsolete in ARMv7, bu= t > > this implementation is motivated by some proprietary software that s= till > > uses SWP/SWPB. Because it's deprecated, emulation is pushed back beh= ind > > a sysctl that defaults to OFF in GENERIC so that it doesn't potentia= lly > > adversely affect package builds; it's unknown whether software may t= est > > for a functional swp/swpb instruction with the desire of using it la= ter, > > so we err on the side of caution to ensure we don't end up with swp/= swpb > > use in freebsd/arm packages (which are built on aarch64). > > > > The EMUL_SWP config option may be used to enable emulation by defaul= t in > > environments where emulation is desired and won't really be turned o= ff. > > > > Reviewed by: andrew, mmel (both earlier version) > > Sponsored by: Stormshield > > Sponsored by: Klara, Inc. > > Differential Revision: https://reviews.freebsd.org/D39667 > > --- > > sys/arm64/arm64/freebsd32_machdep.c | 4 + > > sys/arm64/arm64/undefined.c | 162 +++++++++++++++++++++++++++++= +++++++ > > sys/conf/options.arm64 | 2 + > > 3 files changed, 168 insertions(+) > > > > diff --git a/sys/arm64/arm64/freebsd32_machdep.c b/sys/arm64/arm64/free= bsd32_machdep.c > > index 5fadef74df87..44f35f1b2abf 100644 > > --- a/sys/arm64/arm64/freebsd32_machdep.c > > +++ b/sys/arm64/arm64/freebsd32_machdep.c > > @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -55,6 +56,9 @@ _Static_assert(sizeof(struct siginfo32) =3D=3D 64, "s= truct siginfo32 size incorrect" > > > > extern void freebsd32_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t = *mask); > > > > +SYSCTL_NODE(_compat, OID_AUTO, arm, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, > > + "32-bit mode"); > > + > > /* > > * The first two fields of a ucontext_t are the signal mask and the mac= hine > > * context. The next field is uc_link; we want to avoid destroying the= link > > diff --git a/sys/arm64/arm64/undefined.c b/sys/arm64/arm64/undefined.c > > index 1feb242db060..7f436aaef6e5 100644 > > --- a/sys/arm64/arm64/undefined.c > > +++ b/sys/arm64/arm64/undefined.c > > @@ -39,14 +39,47 @@ __FBSDID("$FreeBSD$"); > > #include > > #include > > #include > > +#include > > #include > > > > +#include > > #include > > +#define _MD_WANT_SWAPWORD > > +#include > > +#include > > #include > > #include > > > > +#include > > +#include > > + > > +/* Low bit masked off */ > > +#define INSN_COND(insn) ((insn >> 28) & ~0x1) > > +#define INSN_COND_INVERTED(insn) ((insn >> 28) & 0x1) > > +#define INSN_COND_EQ 0x00 /* NE */ > > +#define INSN_COND_CS 0x02 /* CC */ > > +#define INSN_COND_MI 0x04 /* PL */ > > +#define INSN_COND_VS 0x06 /* VC */ > > +#define INSN_COND_HI 0x08 /* LS */ > > +#define INSN_COND_GE 0x0a /* LT */ > > +#define INSN_COND_GT 0x0c /* LE */ > > +#define INSN_COND_AL 0x0e /* Always */ > > + > > MALLOC_DEFINE(M_UNDEF, "undefhandler", "Undefined instruction handler d= ata"); > > > > +#ifdef COMPAT_FREEBSD32 > > +#ifndef EMUL_SWP > > +#define EMUL_SWP 0 > > +#endif > > + > > +SYSCTL_DECL(_compat_arm); > > + > > +static bool compat32_emul_swp =3D EMUL_SWP; > > +SYSCTL_BOOL(_compat_arm, OID_AUTO, emul_swp, > > + CTLFLAG_RWTUN | CTLFLAG_MPSAFE, &compat32_emul_swp, 0, > > + "Enable SWP/SWPB emulation"); > > +#endif > > + > > struct undef_handler { > > LIST_ENTRY(undef_handler) uh_link; > > undef_handler_t uh_handler; > > @@ -88,6 +121,54 @@ id_aa64mmfr2_handler(vm_offset_t va, uint32_t insn,= struct trapframe *frame, > > return (0); > > } > > > > +static bool > > +arm_cond_match(uint32_t insn, struct trapframe *frame) > > +{ > > + uint64_t spsr; > > + uint32_t cond; > > + bool invert; > > + bool match; > > + > > + /* > > + * Generally based on the function of the same name in NetBSD, though > > + * condition bits left in their original position rather than shifting > > + * over the low bit that indicates inversion for quicker sanity checki= ng > > + * against spec. > > + */ > > + spsr =3D frame->tf_spsr; > > + cond =3D INSN_COND(insn); > > + invert =3D INSN_COND_INVERTED(insn); > > + > > + switch (cond) { > > + case INSN_COND_EQ: > > + match =3D (spsr & PSR_Z) !=3D 0; > > + break; > > + case INSN_COND_CS: > > + match =3D (spsr & PSR_C) !=3D 0; > > + break; > > + case INSN_COND_MI: > > + match =3D (spsr & PSR_N) !=3D 0; > > + break; > > + case INSN_COND_VS: > > + match =3D (spsr & PSR_V) !=3D 0; > > + break; > > + case INSN_COND_HI: > > + match =3D (spsr & (PSR_C | PSR_Z)) =3D=3D PSR_C; > > + break; > > + case INSN_COND_GE: > > + match =3D (!(spsr & PSR_N) =3D=3D !(spsr & PSR_V)); > > + break; > > + case INSN_COND_GT: > > + match =3D !(spsr & PSR_Z) && (!(spsr & PSR_N) =3D=3D !(spsr & PSR_V))= ; > > + break; > > + case INSN_COND_AL: > > + match =3D true; > > + break; > > + } > > + > > + return (!match !=3D !invert); > > This is equivalent to match !=3D invert? > Good shout, fixed in b68588618b43, thanks. Clear lack of consideration on my part, and I'm guessing they were ints in an earlier version of NetBSD's implementation. > Jess