You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a language spec for the SC/MP processor for giggles. This processor is of mid-to late 70s vintage, and the instruction set has some interesting quirks.
The XMPP instruction is used for call, jump and return, and the decompiler can't seem to figure out which is which.
Additionally the decompiler can't seem to figure out the value of pointer registers on function return, though this might be related to the other two.
The processor has 4 pointer registers; PC, P1, P2 and P3, all of which are effectively divided into 4 MSB of "page" and 12 LSB of "address". When e.g. PC is incremented, only the first 12 bits increment, but the top 4 bits are unchanged. The same happens with indexed and auto-indexed adressing. The KITBUG monitor program I've been looking at uses this wraparound to its advantage, by referencing globals and stack in RAM by wrapping up to 0x0FFF from the zero page with PC-relative addressing.
This means that every increment of e.g. P2 (often used as stack pointer) becomes something like P2 = (P2 & 0xF000) | ((P2 + 1) & 0x0FFF), which then bleeds through to the decompiled code. I wonder if using a segmentop user-defined PCode will help with this?
The other problem is the XMPP instruction, which exchanges PC with another pointer register. This is used both to call functions and to return from functions, and apparently it's even used as a jump. The decompiler can't seem to figure out which case applies when, which makes a total hash of non-leaf functions.
Even after I fix the XPPC P3 instruction flows by hand (to CALL, in this case), the decompiler seems unable to infer the value of the P3 register on return, so I get hash like this:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm writing a language spec for the SC/MP processor for giggles. This processor is of mid-to late 70s vintage, and the instruction set has some interesting quirks.
There are two issues that make the decompilation awful at the moment:
Additionally the decompiler can't seem to figure out the value of pointer registers on function return, though this might be related to the other two.
The processor has 4 pointer registers; PC, P1, P2 and P3, all of which are effectively divided into 4 MSB of "page" and 12 LSB of "address". When e.g. PC is incremented, only the first 12 bits increment, but the top 4 bits are unchanged. The same happens with indexed and auto-indexed adressing. The KITBUG monitor program I've been looking at uses this wraparound to its advantage, by referencing globals and stack in RAM by wrapping up to 0x0FFF from the zero page with PC-relative addressing.
This means that every increment of e.g. P2 (often used as stack pointer) becomes something like
P2 = (P2 & 0xF000) | ((P2 + 1) & 0x0FFF)
, which then bleeds through to the decompiled code. I wonder if using asegmentop
user-defined PCode will help with this?The other problem is the
XMPP
instruction, which exchangesPC
with another pointer register. This is used both to call functions and to return from functions, and apparently it's even used as a jump. The decompiler can't seem to figure out which case applies when, which makes a total hash of non-leaf functions.Even after I fix the
XPPC P3
instruction flows by hand (to CALL, in this case), the decompiler seems unable to infer the value of theP3
register on return, so I get hash like this:from assembly like this:
I've tried to mess with the .cspec to try and explain to the decompiler that P3 is always an output from each function,
but so far no joy.
Any ideas for how I can improve this, or what I'm doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions