Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HCS12] fix memory mapping local -> physical #7261

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

esaulenka
Copy link
Contributor

There are a few commits to improve HSC12 decompilation.

  • first one is just cosmetic changes, removed a few spaces to align similar lines into one column. If you want, I can remove this commitit (as I know, such 'useless' changes are not much appreciated)

  • Local addresses 0..0x3fff had a reference to flash page 3D, which is wrong.
    AN3784 "Understanding the Memory Scheme in the S12(X) Architecture" (as well as datasheets for particular MC9S12xxxx chips) says that the first quarter of the local memory should point to the IO area, RAM and EEPROM.

  • there is the issue with reading data relative to PC register. In particular I found that JMP [D,PC] reads the jump address from some weird location, while typically these addresses located immediately after it. I'm not sure about the other PC-related operands, but perhaps it also broken.

The first quarter of the local space should be used to access IO / RAM / EEPROM,
FLASH should be mapped only to the 0x4000..0xffff
JMP [D,PC] instruction that is the 'core' for switch/case statement should use physical address, not logical to fetch branch table.
PC register (inst_next in terms of Ghidra) is already contains physical address, so there is no need to extend it.
@esaulenka
Copy link
Contributor Author

To reproduse you can use this binary. It's a old vehicle dashboard, based on MC9S12HZ256.
Specification: https://www.nxp.com/docs/en/data-sheet/MC9S12HZ256V2.pdf

Flash image should be loaded at 0x0c0000.
Good place to test is FUN_0d805d(), it's not very complicated but contains switch/case (don't forget to set PPAGE = 0x36 here).

flash 9s12.bin.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Processor/HCS12 Status: Triage Information is being gathered
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants