From: Milica Matic <milicamatic05@gmail.com>
To: gdb-patches@sourceware.org
Cc: milica.matic@htecgroup.com, simark@simark.ca, cfu@wavecomp.com,
aburgess@redhat.com, kevinb@redhat.com, macro@orcam.me.uk,
djordje.todorovic@htecgroup.com,
Simon Dardis <simon.dardis@imgtec.com>,
Faraz Shahbazker <fshahbazker@wavecomp.com>
Subject: [PATCH 08/21] Disassembler fix.
Date: Fri, 13 Dec 2024 16:53:15 +0100 [thread overview]
Message-ID: <20241213155328.406003-10-milica.matic@htecgroup.com> (raw)
In-Reply-To: <20241213155328.406003-1-milica.matic@htecgroup.com>
From: Simon Dardis <simon.dardis@imgtec.com>
Mask off lowest bit when disassembling compressed code.
It fixes a bug in the MIPS disassembler by ensuring that the
disassembler for compressed instructions (MIPS16 and microMIPS)
does not start disassembling from odd addresses. These instructions
require at least 2-byte alignment. The fix adjusts the disassembly
logic by masking off the least significant bit of the input memory
address. MIPS16 and microMIPS instructions must be aligned to at
least 2 bytes. By removing the least significant bit, correct
alignment is ensured during disassembly. The disassembler always
aligns the memory address before continuing, ensuring accuracy when
disassembling MIPS16 and microMIPS instructions.
Cherry-picked e497794
from https://github.com/MIPS/binutils-gdb
Signed-off-by: Simon Dardis <simon.dardis@imgtec.com>
Signed-off-by: Faraz Shahbazker <fshahbazker@wavecomp.com>
Signed-off-by: Milica Matic <milica.matic@htecgroup.com>
opcodes/
* mips-dis.c (print_insn_mips16, print_insn_micromips): Don't
disassemble from odd addresses.
---
opcodes/mips-dis.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/opcodes/mips-dis.c b/opcodes/mips-dis.c
index 612f694f442..80c447e854d 100644
--- a/opcodes/mips-dis.c
+++ b/opcodes/mips-dis.c
@@ -2278,7 +2278,7 @@ enum match_kind
/* Disassemble mips16 instructions. */
static int
-print_insn_mips16 (bfd_vma memaddr, struct disassemble_info *info)
+print_insn_mips16 (bfd_vma memaddr_base, struct disassemble_info *info)
{
const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
int status;
@@ -2292,6 +2292,10 @@ print_insn_mips16 (bfd_vma memaddr, struct disassemble_info *info)
unsigned int first;
unsigned int full;
+ /* Some users of bfd may supply an address with the MIPS16 flag set,
+ e.g. objdump. MIPS16 instructions must be at least 2 byte aligned. */
+ bfd_vma memaddr = memaddr_base & ~1;
+
info->bytes_per_chunk = 2;
info->display_endian = info->endian;
info->insn_info_valid = 1;
@@ -2506,7 +2510,7 @@ print_insn_mips16 (bfd_vma memaddr, struct disassemble_info *info)
/* Disassemble microMIPS instructions. */
static int
-print_insn_micromips (bfd_vma memaddr, struct disassemble_info *info)
+print_insn_micromips (bfd_vma memaddr_base, struct disassemble_info *info)
{
const fprintf_styled_ftype infprintf = info->fprintf_styled_func;
const struct mips_opcode *op, *opend;
@@ -2517,6 +2521,10 @@ print_insn_micromips (bfd_vma memaddr, struct disassemble_info *info)
int status;
unsigned int insn;
+ /* Some users of bfd may supply an address with the micromips flag set,
+ e.g. objdump. microMIPS instructions must be at least 2 byte aligned. */
+ bfd_vma memaddr = memaddr_base & ~1;
+
info->bytes_per_chunk = 2;
info->display_endian = info->endian;
info->insn_info_valid = 1;
--
2.34.1
next prev parent reply other threads:[~2024-12-13 15:59 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 15:53 [PATCH 0/21] Integrate MIPS-Specific Support into Official binutils-gdb Milica Matic
2024-12-13 15:53 ` [PATCH 00/21] " Milica Matic
2024-12-13 15:53 ` [PATCH 01/21] Don't adjust microMIPS HI/LO rel section-relative Milica Matic
2024-12-13 15:53 ` [PATCH 02/21] Add new relocations for microMIPSR6 Milica Matic
2024-12-13 15:53 ` [PATCH 03/21] Improve WARN for $0 constraint on MIPSR6 branches Milica Matic
2024-12-13 15:53 ` [PATCH 04/21] Instruction mapping support (pre-R6 to R6) Milica Matic
2024-12-13 15:53 ` [PATCH 05/21] Add microMIPSR6 support Milica Matic
2024-12-13 15:53 ` [PATCH 06/21] Update branch relaxation Milica Matic
2024-12-13 15:53 ` [PATCH 07/21] Add --user-defined-sdata-sections Milica Matic
2024-12-13 15:53 ` Milica Matic [this message]
2024-12-13 15:53 ` [PATCH 09/21] MIPS: Add CRYPTO ASE support Milica Matic
2024-12-13 15:53 ` [PATCH 10/21] Add the m6201 architecture Milica Matic
2024-12-13 15:53 ` [PATCH 11/21] Add GINV(+VIRT) ASE for MIPSr6/microMIPS6 Milica Matic
2024-12-13 15:53 ` [PATCH 12/21] Implement the XBurst MXU extensions Milica Matic
2024-12-13 15:53 ` [PATCH 13/21] MIPS: Update encoding of d16mule MXU instruction Milica Matic
2024-12-13 15:53 ` [PATCH 14/21] Re-arrange MXU code blocks and add comments Milica Matic
2024-12-13 15:53 ` [PATCH 15/21] Accept MCU mapped string operands as constants Milica Matic
2024-12-13 15:53 ` [PATCH 16/21] Fix addr2line mapping - garbage collected modules Milica Matic
2024-12-13 15:53 ` [PATCH 17/21] Extend trap macros to handle immediate zero Milica Matic
2024-12-13 15:53 ` [PATCH 18/21] Fix failing test cases for linux and 64-bit target Milica Matic
2024-12-13 15:53 ` [PATCH 19/21] Remove exec permission tc-mips.c Milica Matic
2024-12-13 15:53 ` [PATCH 20/21] Workaround for line info in compressed MIPS func Milica Matic
2024-12-13 15:53 ` [PATCH 21/21] Fix gold linker build issues for mingw Milica Matic
2025-01-07 21:18 ` [PATCH 0/21] Integrate MIPS-Specific Support into Official binutils-gdb Kevin Buettner
2025-01-09 1:11 ` [EXTERNAL]Re: " Chao-ying Fu
2025-01-07 21:31 ` Kevin Buettner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241213155328.406003-10-milica.matic@htecgroup.com \
--to=milicamatic05@gmail.com \
--cc=aburgess@redhat.com \
--cc=cfu@wavecomp.com \
--cc=djordje.todorovic@htecgroup.com \
--cc=fshahbazker@wavecomp.com \
--cc=gdb-patches@sourceware.org \
--cc=kevinb@redhat.com \
--cc=macro@orcam.me.uk \
--cc=milica.matic@htecgroup.com \
--cc=simark@simark.ca \
--cc=simon.dardis@imgtec.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox