yath / ghidra-xtensa

Tensilica Xtensa processor module for Ghidra
MIT License
102 stars 34 forks source link

Implement CALL/CALLX/ENTRY/RETW/RETW.N windowed instructions. #12

Closed marcushall42 closed 7 months ago

marcushall42 commented 1 year ago

This implementation is not hardware faithful, but it does produce acceptable pcodeop for the decompiler to grok things. It is sufficient for working on an xtensa binary that uses CALL8 calls. It does confuse the function argument/return guessing of the decompiler, but that is a manageable deficiency.

Rather than fully implementing a register stack, the CALLX instructions (X!=0) creates pcodeop temporary variables and saves the rotated out registers there and shifts the re-used registers down, and restores things after the pcodeop call. The real hardware performs the register rotation in the ENTRY and RETW instructions. In this implementation, the ENTRY instruction only performs stack allocation and the RETW is just a pcodeop RETURN. The stack pointer is restored by the un-shifting and restore from temporaries done in the CALLX pcodeops.

kitor commented 1 year ago

FYI: Check this fork: https://github.com/austinc3030/ghidra-xtensa. This repo seems to be not maintained for years. Fork above contains Ebiroll updates and a lot of merges from other people forks - it is the most complete Xtensa implementation for now.