All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] cmd: test: Add bitwise AND, document the feature
@ 2017-04-12 18:10 Brad Mouring
  2017-04-13  3:20 ` Andrei Borzenkov
  0 siblings, 1 reply; 3+ messages in thread
From: Brad Mouring @ 2017-04-12 18:10 UTC (permalink / raw)
  To: grub-devel; +Cc: 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).

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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-17 20:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-12 18:10 [RFC][PATCH] cmd: test: Add bitwise AND, document the feature Brad Mouring
2017-04-13  3:20 ` Andrei Borzenkov
2017-04-17 20:42   ` Brad Mouring

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.