[PATCH] target/hexagon: Fix disassembly of extended GP-relative accesses

Brian Cain posted 1 patch 4 days, 12 hours ago
target/hexagon/gen_printinsn.py | 7 +++++++
1 file changed, 7 insertions(+)
[PATCH] target/hexagon: Fix disassembly of extended GP-relative accesses
Posted by Brian Cain 4 days, 12 hours ago
A GP-relative load or store with a constant extender is an absolute
access: the semantics read GP as 0 when insn->extension_valid is set,
and the extended immediate is the full address.  The printed form kept
the "gp+" base, so for example

    R0 = memw(gp+##0x48c30)

was shown for an instruction that accesses 0x48c30 and does not use GP.

Only print the "gp+" base when there is no extender.

Link: https://lore.kernel.org/qemu-devel/20261118144441.27680-1-anjo@rev.ng/
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
---
 target/hexagon/gen_printinsn.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/target/hexagon/gen_printinsn.py b/target/hexagon/gen_printinsn.py
index cf1a12adbc1..1eb98a1a432 100755
--- a/target/hexagon/gen_printinsn.py
+++ b/target/hexagon/gen_printinsn.py
@@ -125,6 +125,10 @@ def main():
             beh = hex_common.absimmre.sub(r"#%s0x%x", beh)
             beh = hex_common.relimmre.sub(r"PC+%s%d", beh)
             beh = spacify(beh)
+
+            gp_relative = "(gp+" in beh
+            if gp_relative:
+                beh = beh.replace("(gp+", "(%s")
             # Print out a literal "%s" at the end, used to match empty string
             # so C won't complain at us
             if "A_VECX" in hex_common.attribdict[tag]:
@@ -158,6 +162,9 @@ def main():
                         ri += 1
                 else:
                     # immediate
+                    if gp_relative:
+                        f.write(', insn->extension_valid ? "" : "gp+"')
+                        gp_relative = False
                     if immlett.isupper():
                         if extendable_upper_imm:
                             if immlett in "rR":
-- 
2.34.1

Re: [PATCH] target/hexagon: Fix disassembly of extended GP-relative accesses
Posted by Anton Johansson via qemu development 4 days, 9 hours ago
On 18/11/26, Brian Cain wrote:
> A GP-relative load or store with a constant extender is an absolute
> access: the semantics read GP as 0 when insn->extension_valid is set,
> and the extended immediate is the full address.  The printed form kept
> the "gp+" base, so for example
> 
>     R0 = memw(gp+##0x48c30)
> 
> was shown for an instruction that accesses 0x48c30 and does not use GP.
> 
> Only print the "gp+" base when there is no extender.
> 
> Link: https://lore.kernel.org/qemu-devel/20261118144441.27680-1-anjo@rev.ng/
> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
> ---
>  target/hexagon/gen_printinsn.py | 7 +++++++
>  1 file changed, 7 insertions(+)

Reviewed-by: Anton Johansson <anjo@rev.ng>
Re: [PATCH] target/hexagon: Fix disassembly of extended GP-relative accesses
Posted by Pierrick Bouvier 4 days, 10 hours ago
On 11/18/2026 7:57 AM, Brian Cain wrote:
> A GP-relative load or store with a constant extender is an absolute
> access: the semantics read GP as 0 when insn->extension_valid is set,
> and the extended immediate is the full address.  The printed form kept
> the "gp+" base, so for example
> 
>     R0 = memw(gp+##0x48c30)
> 
> was shown for an instruction that accesses 0x48c30 and does not use GP.
> 
> Only print the "gp+" base when there is no extender.
> 
> Link: https://lore.kernel.org/qemu-devel/20261118144441.27680-1-anjo@rev.ng/
> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
> ---
>  target/hexagon/gen_printinsn.py | 7 +++++++
>  1 file changed, 7 insertions(+)
> 

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>