Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cyVJD-000080-AH for mharc-grub-devel@gnu.org; Wed, 12 Apr 2017 23:20:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyVJB-00007u-5y for grub-devel@gnu.org; Wed, 12 Apr 2017 23:20:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyVJ7-00081I-7j for grub-devel@gnu.org; Wed, 12 Apr 2017 23:20:33 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:35408) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyVJ6-000811-Uv for grub-devel@gnu.org; Wed, 12 Apr 2017 23:20:29 -0400 Received: by mail-lf0-x241.google.com with SMTP id i3so5224537lfh.2 for ; Wed, 12 Apr 2017 20:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=e4kc+EHuNrUOvefY7HvHOnBQpAEHNcrwEjB1SY/8kFo=; b=Hy72+xYC/apJ0m04VjcMXX5IquUIVOQwa0OlSfgdRpkm+OPSRcutii6jh0FKS4S57A iQVPnl5cDXMePvpjtmXjhoN6zuqCms/bW4i6eNHHPNjdv5lkmAQELAhoF17faPkNAnOE z2Ie9Hs8VArIfYxd07PYCiq2mzkVlYI1odQ2rlIx103NbprhsViVd2hBpe5Xi1MRN+KG 3bCAbP0CUlUYM2GJ6R5+0+1Zxhx7eWRMdNemdtPF21AVL4CKlNgaClxigtXMN0J56b04 L4Vq34bxBccRDBtK8i3uutMLAN3Q7wEPQ6fFDpxfuQUK8e4FUeWSU4h65C2OevQ6PAxF OXYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=e4kc+EHuNrUOvefY7HvHOnBQpAEHNcrwEjB1SY/8kFo=; b=WSFCyO5O4GGyL1vApMckCsTeh7ttr1VIwqNljsekSRhEvB4VxeW2SHH2WNrxYfweIO yhRVl5gipiLq6pfoIaUzPcNtNw8Ri5b0g+Qc3Kkr9Hc5LZM1MQCnK2zWqgs/IBPwaTjw um0K2C2Z5OBZ01PKpePC4y/V43haFC+4Yq3J3zInbH3uajWn5vEhY184pyaME8w8G/Si 49RjtFMihIfaiykyQsy9d/+m6KoCmM2fSKUw2Oe+CLMqVWkkq7zMJG2el80uyA72F81e AEXRMfG+SIQsW7bd8KdfTaWhPDJyzHgV5couM6hAzEQ+qnpbE1bnypDLojfZcfcFWLhx VE3A== X-Gm-Message-State: AN3rC/7ZOE3xk2nRSs0cZb689b0WozQJEefGRNSqzVnvy/BrhyJdxGZD vYmAMQCoVOFAiC1R X-Received: by 10.25.190.2 with SMTP id o2mr291906lff.80.1492053626180; Wed, 12 Apr 2017 20:20:26 -0700 (PDT) Received: from [192.168.1.5] (ppp109-252-90-38.pppoe.spdop.ru. [109.252.90.38]) by smtp.gmail.com with ESMTPSA id 2sm4471594ljp.36.2017.04.12.20.20.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 20:20:25 -0700 (PDT) Subject: Re: [RFC][PATCH] cmd: test: Add bitwise AND, document the feature To: The development of GNU GRUB References: <20170412181025.15643-1-brad.mouring@ni.com> Cc: Brad Mouring From: Andrei Borzenkov Message-ID: <1fa967c5-e4ef-f911-9d67-8190cc5951b9@gmail.com> Date: Thu, 13 Apr 2017 06:20:24 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170412181025.15643-1-brad.mouring@ni.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::241 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Apr 2017 03:20:34 -0000 12.04.2017 21:10, Brad Mouring пишет: > Currently, there is not a good way to control script flow based on > bitwise values. This initially led to NI adding the ability to read > a specific bit from a port-mapped register to control bootflow. > > Here, we add a more generic ability to test the bitwise AND of a > value available to the grub scripting environment. This obviates the > need for the inbit command (which is currently OOT). > See recent discussion about arithmetic operations. This could also be if $((a&b)); then ... fi I think it is more generic than single specific test. > Signed-off-by: Brad Mouring > --- > docs/grub.texi | 2 ++ > grub-core/commands/test.c | 10 ++++++++++ > 2 files changed, 12 insertions(+) > > diff --git a/docs/grub.texi b/docs/grub.texi > index 82f6fa4..f28063e 100644 > --- a/docs/grub.texi > +++ b/docs/grub.texi > @@ -5019,6 +5019,8 @@ the strings are not equal > @var{integer1} is less than @var{integer2} > @item @var{integer1} @code{-ne} @var{integer2} > @var{integer1} is not equal to @var{integer2} > +@item @var{integer1} @code{-bwa} @var{integer2} > +Performs a bitwise AND between @var{integer1} and @var{integer2} > @item @var{prefix}@var{integer1} @code{-pgt} @var{prefix}@var{integer2} > @var{integer1} is greater than @var{integer2} after stripping off common non-numeric @var{prefix}. > @item @var{prefix}@var{integer1} @code{-plt} @var{prefix}@var{integer2} > diff --git a/grub-core/commands/test.c b/grub-core/commands/test.c > index 5f06642..af4fad7 100644 > --- a/grub-core/commands/test.c > +++ b/grub-core/commands/test.c > @@ -290,6 +290,16 @@ test_parse (char **args, int *argn, int argc) > continue; > } > > + /* GRUB extension: bitwise AND */ > + if (grub_strcmp (args[*argn + 1], "-bwa") == 0) > + { > + update_val (grub_strtoul (args[*argn], 0, 0) > + & grub_strtoul (args[*argn + 2], 0, 0), &ctx); > + (*argn) += 3; > + continue; > + } > + > + > /* -nt and -ot tests. GRUB extension: when doing -?t bias > will be added to the first mtime. */ > if (grub_memcmp (args[*argn + 1], "-nt", 3) == 0 >