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

* Re: [RFC][PATCH] cmd: test: Add bitwise AND, document the feature
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Andrei Borzenkov @ 2017-04-13  3:20 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Brad Mouring

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 <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
> 



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

* Re: [RFC][PATCH] cmd: test: Add bitwise AND, document the feature
  2017-04-13  3:20 ` Andrei Borzenkov
@ 2017-04-17 20:42   ` Brad Mouring
  0 siblings, 0 replies; 3+ messages in thread
From: Brad Mouring @ 2017-04-17 20:42 UTC (permalink / raw)
  To: Andrei Borzenkov; +Cc: The development of GNU GRUB

On Thu, Apr 13, 2017 at 06:20:24AM +0300, Andrei Borzenkov wrote:
> 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.

I can appreciate the sentiment, but are you asking me to implement
some/all of the functionality of the double-paren arith expansion,
partially duplicating the functionality of the test/[ command, simply
because (( a & b )) is more bash-ful than [ a -bwa b ]?

I'm not trying to bake-in any sort of assumption here, in fact, I'm
just trying to get clarification.

Thanks,
Brad


^ permalink raw reply	[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.