Commit Graph

6 Commits

Author SHA1 Message Date
Alan Modra
dd39dcae88 PR30793, kvx_reassemble_bundle index 8 out of bounds
While the patch already committed for pr30793 prevents the asan error,
there is a problem: Now the last element of bundle_words never gets
written.  That's very likely wrong, or KVXMAXBUNDLEWORDS is too big.
So this patch rearranges things a little to support writing of all of
bundle_words and does the parallel bit checking only when filling
bundle_words.  In the normal case, kvx_reassemble_bundle will see
bundle_words[word_count-1] with the parallel bit clear and all other
words having it set.  In the error case where all words in
bundle_words have the parallel bit set, kvx_reassemble_bundle will be
passed a wordcount of KVXMAXBUNDLEWORDS + 1.  I've also made
kvx_reassemble_bundle return true for success rather than zero, and
removed the unnecessary check for zero wordcount.

	PR 30793
	* kvx-dis.c (kvx_reassemble_bundle): Return bool, true on success.
	Fail if wordcount is too large.  Don't check for wordcount zero.
	Don't check kvx_has_parallel_bit.
	(print_insn_kvx): Rewrite code reading bundle_words as a for loop.
	Don't stop reading at KVXMAXBUNDLEWORDS - 1.
	(decode_prologue_epilogue_bundle): Similarly.
2023-09-08 07:49:09 +09:30
Paul Iannetta
f1917fc631 kvx: fix kvx_reassemble_bundle index 8 out of bounds
opcodes/
	* kvx-dis.c (print_insn_kvx): Change the loop condition so that
	wordcount is always less than KVXMAXBUNDLEWORDS.
	(decode_prologue_epilogue_bundle): Likewise.
2023-08-24 20:03:23 +09:30
Alan Modra
81656b43f1 kvx: workaround gcc-4.5 bug
kvx-dis.c:1078:10: error: missing initializer
kvx-dis.c:1078:10: error: (near initialization for 'dec.nb_ops')

	* kvx-dis.c (print_insn_kvx): Init dec with memset.
	(decode_prologue_epilogue_bundle): Likewise.
2023-08-24 15:54:39 +09:30
Paul Iannetta
af6242628a kvx: use {u,}int32_t and {u,}int64_t
gas/
	* config/kvx-parse.c (promote_token): Use {u,}int32_t and
	{u,}int64_t.
	(get_token_class): Likewise.
	* config/tc-kvx.c (insert_operand): Likewise.
	* config/tc-kvx.h (struct token_s): Likewise.
	(struct token_list): Likewise.

opcodes/
	* kvx-dis.c (struct decoded_insn): Use {u,}int32_t and
	{u,}int64_t.
	(decode_insn): Likewise.
	(print_insn_kvx): Likewise.
	(decode_prologue_epilogue_bundle): Likewise.
	* kvx-dis.h (struct kvx_prologue_epilogue_insn): Likewise.
2023-08-24 12:36:25 +09:30
Alan Modra
5bf26ab7cb kvx_dis_init
kvx_dis_init currently always returns true, but error conditions do so
by "return -1" which converts to true.  The return status is ignored
anyway, and it doesn't make much sense to error on unexpected arch or
mach:  If print_insn_kvx is called then the atch is known to be kvx,
and it's better to choose some default for a user passing an unknown
mach value rather than segfaulting in decode_insn when env.opc_table
is NULL.

I've chosen the default mach to be bfd_mach_kv3_1, the default in
bfd/cpu-kvx.c, not that it matters very much.  In normal objdump/gdb
usage, info->mach won't be an unexpected value.

	* kvx-dis.c (kvx_dis_init): Return void.  Don't error on
	unexpected arch or mach.  Default to bfd_mach_kv3_1 for
	unknown mach.  Don't clear info->disassembler_options.
2023-08-22 09:35:55 +09:30
Paul Iannetta
6e712424f5 kvx: New port. 2023-08-16 14:22:54 +01:00