Teaching expression() to treat some operations specially

Dmitry Selyutin ghostmansd@gmail.com
Mon Jul 11 14:28:35 GMT 2022


On Mon, Jul 11, 2022 at 6:08 AM Alan Modra <amodra@gmail.com> wrote:
> On Mon, Jul 11, 2022 at 03:33:55AM +0100, lkcl wrote:
> > please read then use contents of register r3 as the predicate mask, invert all its bits before passing it on".
>
> OK, then you'll want ppc_parse_name to continue to create O_register
> values.

There is another difficulty with statements like "r3" or "~r3" in
macros. As such, PPC does not support register names in macros, at
all.

    .set REG, %r0
    extsw REG, 2

This code leads to "junk at end of line, first unrecognized character
is `r'" error. Also, using "r0" instead of "%r0" also fails due to
unknown relocation.
>From the code around it looks that we could define a simple
md_operand() routine. This _almost_ works, but now I hit checks at
tc-ppc.c:3484.

I think we're being bitten by some discrepancies between these checks
and symbol expansion.
Alan, could you, please, help me with understanding these checks? I
understand it's been 5 years ago...

P.S. I've inlined the patch for a simple md_operand routine here.

diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
index ac61cd8f12..c04bde0d00 100644
--- a/gas/config/tc-ppc.c
+++ b/gas/config/tc-ppc.c
@@ -3275,8 +3275,14 @@ parse_tls_arg (char **str, const expressionS
*exp, struct ppc_fixup *tls_fix)
}
#endif

-/* This routine is called for each instruction to be assembled.  */
+void
+md_operand (expressionS *exp)
+{
+  if (!register_name (exp))
+    expression (exp);
+}

+/* This routine is called for each instruction to be assembled.  */
void
md_assemble (char *str)
{
diff --git a/gas/config/tc-ppc.h b/gas/config/tc-ppc.h
index ed06a29638..a65e51c875 100644
--- a/gas/config/tc-ppc.h
+++ b/gas/config/tc-ppc.h
@@ -328,8 +328,6 @@ extern int ppc_parse_name (const char *, struct
expressionS *);
#define md_optimize_expr(left, op, right) ppc_optimize_expr (left, op, right)
extern int ppc_optimize_expr (expressionS *, operatorT, expressionS *);

-#define md_operand(x)
-
#define md_cleanup() ppc_cleanup ()
extern void ppc_cleanup (void);

-- 
Best regards,
Dmitry Selyutin


More information about the Binutils mailing list