[PATCH 4/7] opcodes: microblaze: annotate mbar sleep modes

Samuel Price thesamprice@gmail.com
Mon Nov 9 04:08:08 GMT 2026


An mbar other than sleep, hibernate and suspend can still enter a sleep
mode.  In UG984's pseudocode for mbar, IMM & 24 selects the mode, and
IMM & 1 and IMM & 2 skip the instruction-side and data-side waits.
Print that as a comment, in the "// " form already used for branch
targets:

	mbar	17		// sleep, without the instruction-side wait
	mbar	31		// suspend, without either wait

An mbar that enters no sleep mode prints as before.  The pseudocode does
not use IMM & 4, so mbar 20 gets a plain "// sleep"; I have not checked
what hardware does with that bit.

opcodes/
	* microblaze-dis.c (print_insn_microblaze) <INST_TYPE_IMM5>: Name
	the sleep mode and the skipped waits of an mbar that enters one.

Signed-off-by: Sam Price <thesamprice@gmail.com>
Assisted-by: Claude (Anthropic)
---
 opcodes/microblaze-dis.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
index c4fa6e2e493..6e0957c029f 100644
--- a/opcodes/microblaze-dis.c
+++ b/opcodes/microblaze-dis.c
@@ -439,6 +439,28 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
 	  /* For mbar insn.  */
 	case INST_TYPE_IMM5:
 	  print_func (stream, "\t%s", get_field_imm5_mbar (&buf, inst));
+	  {
+	    /* When IMM & 24 is nonzero, mbar enters a sleep mode (UG984,
+	       mbar): 16 is sleep, 8 hibernate and 24 suspend.  mbar 16, 8
+	       and 24 themselves match the sleep, hibernate and suspend
+	       pseudo-instructions, which come earlier in microblaze_opcodes,
+	       so an IMM with those bits set that gets here also has some of
+	       its low bits set.  Name the mode, and say which waits the low
+	       bits skip: IMM & 1 skips the wait for instruction-side
+	       accesses, and IMM & 2 the wait for data-side accesses.  */
+	    static const char *const mode[] = {
+	      NULL, "hibernate", "sleep", "suspend"
+	    };
+	    static const char *const skips[] = {
+	      "", ", without the instruction-side wait",
+	      ", without the data-side wait", ", without either wait"
+	    };
+	    unsigned int imm = (inst & IMM5_MBAR_MASK) >> IMM_MBAR;
+
+	    if ((imm & 0x18) != 0)
+	      print_func (stream, "\t\t// %s%s", mode[(imm >> 3) & 3],
+			  skips[imm & 3]);
+	  }
 	  break;
 	  /* For mbar 16 or sleep insn.  */
 	case INST_TYPE_NONE:
-- 
2.39.5 (Apple Git-154)



More information about the Binutils mailing list