-
Notifications
You must be signed in to change notification settings - Fork 6.1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Emulation of MOV instructions in M16C architecture do not get affected by preceding INDEX instructions. #7468
Comments
I would like to reproduce the issue. Can you share the bytes for the pair of instructions? |
I am also not sure if worth mentioning, however the stack variables applied here are also displayed incorrect, and are off by 4 bytes. Though the actual executed instructions reference memory correctly, as evidenced by the printed sleigh debug output. Basically local_f is supposed to be local_B. But it's just a visual error. The execution of INDEXBS.B correctly sets byteIndexOffset to the expected value, but MOV.B:G never uses it, it only ever references the immediate value 003200. |
the I also see
There should probably be a |
It does not work for me even after the suggested change. And yes byteIndexOffset is set, but just never used. I am using GhidraEmu and had to significantly modify it to emulate the behaviour of INDEXBS and only in single stepping mode (emuhelper.step()). No matter what the src value is of INDEXBS it is never added to the immediate value in the MOV, always resulting in LOADS from the base immediate value. So if the base is 003200 then all reads are that base address instead of 003200 + byteIndexOffset and that is what is stored in the stack. Otherwise, I do see it. In this case, byteIndexOffset = 0x8d. Added to 0x003200 = 0x00328D, which has the value 0x5d but the actual value loaded is from base 0x003200 where its 0x63. |
In your screenshot, you can see the pcode that should be adding byteIndexOffset which is the register at 0x3009 in the sleigh file. So the issue seems to be possibly in the GhidraEmu? I've never used that. |
I wonder if the usage of the writeRegister apis before the actual emuhelper.step() is somehow overwriting part of the context/clearing the opcodes? Or perhaps it's this
|
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
The INDEXB,INDEXBS etc instruction modify the src operand of the next LOAD type instruction such as MOV. However when emulated, despite the INDEX instruction having correct semantics implemented, they do not actually affect the mov.
I have narrowed down the problem in my specific example to
and the corresponding two patterns in M16C/80 slaspec are
While byteIndexOffset is actually set, and useSrcByteIndexOffset is also globalset for the next instruction(the MOV), it seems like byteIndexOffset is not evaluated.
I have used the DebuGSleighInstructionParse plugin and produced this output
From which we see that byteIndexOffset is not added to the imm24_dat token, despite the correct pattern being selected.
The text was updated successfully, but these errors were encountered: