Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cyMj3-0005N9-Tx for mharc-grub-devel@gnu.org; Wed, 12 Apr 2017 14:10:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyMj1-0005LY-Kq for grub-devel@gnu.org; Wed, 12 Apr 2017 14:10:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyMiw-0005xJ-Kx for grub-devel@gnu.org; Wed, 12 Apr 2017 14:10:39 -0400 Received: from mx0a-00010702.pphosted.com ([148.163.156.75]:48999 helo=mx0b-00010702.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cyMiw-0005wv-C6 for grub-devel@gnu.org; Wed, 12 Apr 2017 14:10:34 -0400 Received: from pps.filterd (m0098780.ppops.net [127.0.0.1]) by mx0a-00010702.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3CHuC5s014838 for ; Wed, 12 Apr 2017 13:10:32 -0500 Received: from ni.com (skprod2.natinst.com [130.164.80.23]) by mx0a-00010702.pphosted.com with ESMTP id 29sh9m4vy0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 12 Apr 2017 13:10:32 -0500 Received: from us-aus-exch1.ni.corp.natinst.com (us-aus-exch1.ni.corp.natinst.com [130.164.68.11]) by us-aus-skprod2.natinst.com (8.16.0.17/8.16.0.17) with ESMTPS id v3CIAV4X011350 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 12 Apr 2017 13:10:31 -0500 Received: from us-aus-exhub1.ni.corp.natinst.com (130.164.68.41) by us-aus-exch1.ni.corp.natinst.com (130.164.68.11) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Wed, 12 Apr 2017 13:10:29 -0500 Received: from ni.com (130.164.49.7) by us-aus-exhub1.ni.corp.natinst.com (130.164.68.41) with Microsoft SMTP Server id 15.0.1156.6 via Frontend Transport; Wed, 12 Apr 2017 13:10:30 -0500 Received: by ni.com (sSMTP sendmail emulation); Wed, 12 Apr 2017 13:10:29 -0500 From: Brad Mouring To: CC: Brad Mouring Subject: [RFC][PATCH] cmd: test: Add bitwise AND, document the feature Date: Wed, 12 Apr 2017 13:10:25 -0500 Message-ID: <20170412181025.15643-1-brad.mouring@ni.com> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703280066 X-Proofpoint-Virus-Version: vendor=nai engine=5600 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-12_14:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_policy_notspam policy=outbound_policy score=30 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=30 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704120148 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.75 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: Wed, 12 Apr 2017 18:10:40 -0000 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). 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 -- 2.9.0