All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brad Mouring <brad.mouring@ni.com>
To: <grub-devel@gnu.org>
Cc: Brad Mouring <brad.mouring@ni.com>
Subject: [RFC][PATCH] cmd: test: Add bitwise AND, document the feature
Date: Wed, 12 Apr 2017 13:10:25 -0500	[thread overview]
Message-ID: <20170412181025.15643-1-brad.mouring@ni.com> (raw)

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 <brad.mouring@ni.com>
---
 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> bias
 	     will be added to the first mtime. */
 	  if (grub_memcmp (args[*argn + 1], "-nt", 3) == 0
-- 
2.9.0



             reply	other threads:[~2017-04-12 18:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-12 18:10 Brad Mouring [this message]
2017-04-13  3:20 ` [RFC][PATCH] cmd: test: Add bitwise AND, document the feature Andrei Borzenkov
2017-04-17 20:42   ` Brad Mouring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170412181025.15643-1-brad.mouring@ni.com \
    --to=brad.mouring@ni.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.