grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC][PATCH] cmd: test: Add bitwise AND, document the feature


From: Andrei Borzenkov
Subject: Re: [RFC][PATCH] cmd: test: Add bitwise AND, document the feature
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

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 <address@hidden>
> ---
>  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}
> address@hidden @var{integer1} @code{-bwa} @var{integer2}
> +Performs a bitwise AND between @var{integer1} and @var{integer2}
>  @item @address@hidden @code{-pgt} @address@hidden
>  @var{integer1} is greater than @var{integer2} after stripping off common 
> non-numeric @var{prefix}.
>  @item @address@hidden @code{-plt} @address@hidden
> 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
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]