Skip to content

Movi.n instruction causes error when patching #16

@wilco375

Description

@wilco375

Although I know this is integrated in Ghidra now, only collaborators can submit issues there, and since the implementation is based on your code @yath, I thought you might know how to solve this bug.

When patching an instruction to movi.n, an "invalid instruction and/or prefix" error is caused.

To Reproduce
Steps to reproduce the behavior:

  1. Open an ESP32 firmware image
  2. Go to a two-byte instruction
  3. Right click -> Patch instruction (or Ctrl+Shift+G)
  4. Enter movi.n a2,0x0
  5. While typing, the instruction/parameters are even suggested for auto-completion, but entering the full instruction yields an "invalid instruction and or prefix" error. It seems the error originates from Ghidra's AssemblyDualTextField.java#924, where the following error is generated: Could not solve two-sided OR (Solution to tmp : 761 in 0 = (((([opval:n_s3_4_6 exp [ins(4,6), bytes 0-0, shift=4]] & 0x7) << 0x4) | ([opval:n_s4_12_15 exp [ins(12,15), signed, bytes 1-1, shift=4]] & 0xf)) | (((([opval:n_s3_4_6 exp [ins(4,6), bytes 0-0, shift=4]] >> 0x2) & 0x1) & (([opval:n_s3_4_6 exp [ins(4,6), bytes 0-0, shift=4]] >> 0x1) & 0x1)) << 0x7)))
    My suspicion is that this has to do with the definition of the movi.n instruction in xtensaInstructions.sinc, but I don't know how to fix it, and AI isn't being of much help either...

Expected behavior
Ghidra finds the instruction and updates the bytecode with the correct bytes (0c 02 in case of movi.n a2,0x0).

Screenshots
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions