Struggling with MED17 Tricore decompilation in Ghidra

Disassembly, Reassembly, Tools and devleopment. Going deep with Hardware and Software.
User avatar
Gatecrasher
Posts: 435
Joined: Fri Apr 24, 2020 8:09 pm

Struggling with MED17 Tricore decompilation in Ghidra

Post by Gatecrasher »

Got a weird problem here. I'm working on comparing two MED17x bins from the same manufacturer and approximate timeframe. They're both defined as tc179x. The bin on the left doesn't use the global A0 and A1 registers for setting up address references, so everything decompiles fine. It builds the address references in real time on every function.

The bin on the right does use the global regs. Some addresses decompile correctly, but most don't. The addresses DO show up correctly in the disassembly listing window, so Ghidra is doing the calculation correctly. It's just not making it to the decompiler.
MED17_TriCore.jpg
I'm currently on Ghidra 11.0. I haven't found anything in my searches to indicate this was fixed in a newer version. Does anyone know of a fix or workaround for this?
You do not have the required permissions to view the files attached to this post.
User avatar
Gatecrasher
Posts: 435
Joined: Fri Apr 24, 2020 8:09 pm

Re: Struggling with MED17 Tricore decompilation in Ghidra

Post by Gatecrasher »

I fixed it.
MED17_TriCore_fixed.png
Go to your Ghidra install path and then drill down to Ghidra\Processors\tricore\data\languages. Edit the 'unaffected' section in tricore.cspec. We're adding a0, a1, a8, a9, p0 and p8. For some odd reason, it has to be in this order. I tried putting them in alphanumerical order and it didn't work.

Code: Select all

      <unaffected>
	<register name="a0"/>
	<register name="a1"/>
	<register name="a8"/>
	<register name="a9"/>
	<register name="p0"/>
	<register name="p8"/>
	<register name="d8"/>
	<register name="d9"/>
	<register name="d10"/>
	<register name="d11"/>
	<register name="d12"/>
	<register name="d13"/>
	<register name="d14"/>
	<register name="d15"/>
	<register name="a10"/>
	<register name="a11"/>
	<register name="a12"/>
	<register name="a13"/>
	<register name="a14"/>
	<register name="a15"/>
      </unaffected>
You do not have the required permissions to view the files attached to this post.