lab313ru / ghidra_psx_ldr

Sony Playstation PSX executables loader for GHIDRA
231 stars 31 forks source link

Coprocessor 2 (GTE) instructions use incorrect registers #31

Closed Zinfidel closed 2 years ago

Zinfidel commented 4 years ago

There are 6 store/load instructions for the GTE (LWC2, SWC2, MTC2, MFC2, CTC2, and CFC2) that come in 3 forms:

LWC2 gd, imm(base)
MTC2 rt, gd
CTC2 rt, gc

where gd is a GTE data register (0-31) and gc is a GTE control register (0-31). Using the plugin, Ghidra disassembles these instructions interpreting the first operands as either CPU registers or constant values, however. This leads to disassembly that looks like: javaw_c6A9IPEDDT Notice that MTC2's second operand is listed as 0x0, where it should be the data register gd0, which happens to be the VXY0 register. For the LWC2 command, the gd operand is interpreted as CPU register 1 (at) instead of GTE data register 1 (VZ0).

The decompiled code is similarly affected: javaw_1i4TDPIGxb Here, iVar1 and iVar8 just happen to be associated with CPU registers 0 and 1, and so they get placed in the function call incorrectly.

Just a disclaimer, I'm a real novice with Ghidra so I'm not sure if this is a problem with the plugin, Ghidra itself, or just me!

MrSapps commented 4 years ago

another nice enhancement would also be to decompile these to gte macros...

altro50 commented 4 years ago

another nice enhancement would also be to decompile these to gte macros...

Definitely! I'm currently in the middle of a disassembly for the purpose of recompiling and I wouldn't need to reference the PSYQ headers constantly if it just resolved them in the decompiler.

lab313ru commented 3 years ago

I don't even understand how would I implement this.

lab313ru commented 3 years ago

In result I must provide my own mips processor implementation copy just to implement psx coprocessor specific functionality.

lab313ru commented 2 years ago

Implemented since: https://github.com/lab313ru/ghidra_psx_ldr/releases/tag/v6.0.