From 9cf7e5687f823a1009d25cb25ff653ee8372e517 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 16 Aug 2018 16:14:12 +0930 Subject: Use operand->extract to provide defaults for optional PowerPC operands Most optional operands to powerpc instructions use a default value of zero, but there are a few exceptions. Those have been handled by PPC_OPERAND_OPTIONAL_VALUE and an entry in the powerpc_operands table for the default value, smuggled in the shift field. This patch changes that to using the operand extract function to provide non-zero defaults. I've also moved the code determining whether optional operands are provided or omitted, to the point the first optional operand is seen, and allowed for the possibility of optional base register operands in a future patch. The patch does change the error you get on invalid assembly like ld 3,4 You'll now see "missing operand" rather than "syntax error; end of line, expected `('". gas/ * config/tc-ppc.c (md_assemble): Delay counting of optional operands until one is encountered. Allow for the possibility of optional base regs, ie. PPC_OPERAND_PARENS. Call ppc_optional_operand_value with extra args. include/ * opcode/ppc.h (struct powerpc_operand): Correct "insert" comment. Mention use of "extract" function to provide default value. (PPC_OPERAND_OPTIONAL_VALUE): Delete. (ppc_optional_operand_value): Rewrite to use extract function. opcodes/ * ppc-dis.c (operand_value_powerpc): Init "invalid". (skip_optional_operands): Count optional operands, and update ppc_optional_operand_value call. * ppc-opc.c (extract_dxdn): Remove ATTRIBUTE_UNUSED from used arg. (extract_vlensi): Likewise. (extract_fxm): Return default value for missing optional operand. (extract_ls, extract_raq, extract_tbr): Likewise. (insert_sxl, extract_sxl): New functions. (insert_esync, extract_esync): Remove Power9 handling and simplify. (powerpc_operands ): Delete PPC_OPERAND_OPTIONAL_VALUE flag and extra entry. (powerpc_operands ): Likewise, and use insert_sxl and extract_sxl. --- include/ChangeLog | 7 +++++++ include/opcode/ppc.h | 40 ++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/include/ChangeLog b/include/ChangeLog index 37edc38..f0dca58 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,10 @@ +2018-08-21 Alan Modra + + * opcode/ppc.h (struct powerpc_operand): Correct "insert" comment. + Mention use of "extract" function to provide default value. + (PPC_OPERAND_OPTIONAL_VALUE): Delete. + (ppc_optional_operand_value): Rewrite to use extract function. + 2018-08-18 John Darrington * opcode/s12z.h: New file. diff --git a/include/opcode/ppc.h b/include/opcode/ppc.h index cfabcbd..2b7f51e 100644 --- a/include/opcode/ppc.h +++ b/include/opcode/ppc.h @@ -280,11 +280,10 @@ struct powerpc_operand If this field is not NULL, then simply call it with the instruction and the operand value. It will return the new value - of the instruction. If the ERRMSG argument is not NULL, then if - the operand value is illegal, *ERRMSG will be set to a warning - string (the operand will be inserted in any case). If the - operand value is legal, *ERRMSG will be unchanged (most operands - can accept any value). */ + of the instruction. If the operand value is illegal, *ERRMSG + will be set to a warning string (the operand will be inserted in + any case). If the operand value is legal, *ERRMSG will be + unchanged (most operands can accept any value). */ uint64_t (*insert) (uint64_t instruction, int64_t op, ppc_cpu_t dialect, const char **errmsg); @@ -302,11 +301,18 @@ struct powerpc_operand is the result). If this field is not NULL, then simply call it with the - instruction value. It will return the value of the operand. If - the INVALID argument is not NULL, *INVALID will be set to - non-zero if this operand type can not actually be extracted from - this operand (i.e., the instruction does not match). If the - operand is valid, *INVALID will not be changed. */ + instruction value. It will return the value of the operand. + *INVALID will be set to one by the extraction function if this + operand type can not be extracted from this operand (i.e., the + instruction does not match). If the operand is valid, *INVALID + will not be changed. *INVALID will always be non-negative when + used to extract a field from an instruction. + + The extraction function is also called by both the assembler and + disassembler if an operand is optional, in which case the + function should return the default value of the operand. + *INVALID is negative in this case, and is the negative count of + omitted optional operands up to and including this operand. */ int64_t (*extract) (uint64_t instruction, ppc_cpu_t dialect, int *invalid); /* One bit syntax flags. */ @@ -421,11 +427,6 @@ extern const unsigned int num_powerpc_operands; out regardless of the PPC_OPERAND_OPTIONAL field. */ #define PPC_OPERAND_NEXT (0x100000) -/* This flag is only used with PPC_OPERAND_OPTIONAL. If this operand - is omitted, then the value it should use for the operand is stored - in the SHIFT field of the immediatly following operand field. */ -#define PPC_OPERAND_OPTIONAL_VALUE (0x200000) - /* This flag is only used with PPC_OPERAND_OPTIONAL. The operand is only optional when generating 32-bit code. */ #define PPC_OPERAND_OPTIONAL32 (0x400000) @@ -464,10 +465,13 @@ extern const int powerpc_num_macros; extern ppc_cpu_t ppc_parse_cpu (ppc_cpu_t, ppc_cpu_t *, const char *); static inline int64_t -ppc_optional_operand_value (const struct powerpc_operand *operand) +ppc_optional_operand_value (const struct powerpc_operand *operand, + uint64_t insn, + ppc_cpu_t dialect, + int num_optional) { - if ((operand->flags & PPC_OPERAND_OPTIONAL_VALUE) != 0) - return (operand+1)->shift; + if (operand->extract) + return (*operand->extract) (insn, dialect, &num_optional); return 0; } -- cgit v1.1