NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
51.62k stars 5.87k forks source link

Sleigh: Duplicate Symbol Name? #6874

Open pjsoberoi opened 2 months ago

pjsoberoi commented 2 months ago

I would like to support an instruction similar to the following:

:add a0, a0 is opcode_00_16=0b1111111111 & a0
{}

The instruction is 16-bits. It references register a0 twice. This fails in the Sleigh compiler with:

ERROR MyProc.slaspec:123: Duplicate symbol name: a0 (previously defined at MyProc.slaspec:123) (SleighCompile)  

I am unable to use attach variables (take my word for it, I admit I'm doing weird stuff). I don't want to define the entire instruction as a mnemonic. I need a0 to be a register. Basically I need it to work like this:

:add a0, a1 is opcode_00_16=0b1111111111 & a0 & a1
{}

But with a0 twice. As the first instruction is a valid instruction there has to be a way right? Thanks in advance.

GhidorahRex commented 2 months ago

The fact that you say you can't use attach values for it is interesting, but it's a solvable problem. One way to duplicate the register name in the operands would be to use a string, which would work fine as long as it was always a0, and not possibly some other register:

:add a0, "a0" is opcode_00_16=0b1111111111 & a0 {}

Another way would be to use a sub-constructor:

a0_: a0 is a0 { export a0; }
:add a0, a0_ is opcode_00_16=0b1111111111 & a0 & a0_ {}

A third way is to not worry about the correctness of the display and just use a single a0:

:add a0 is opcode_00_16=0b1111111111 & a0 {}
pjsoberoi commented 2 months ago

@GhidorahRex : Thank you for the quick response. The sub-constructor is the closest to what I want, I'll attempt to use that.

Taking a step back, I would consider this a bug in SLEIGH. The above instruction is a valid instruction and should be able to be represented in SLEIGH. We should be allowed to have duplicate register names IMHO.