BigEd wrote:
But branches have two possible successor PCs. Is there a tricky case with the byte following a taken branch? If the branch is never taken, that might be data, already speculatively copied because of indexing. But it might be code, if the branch will later not to be taken, and yet it's now non-zero so it won't be trapped.
Yes, every 'exit' from an emulated/pre-JIT instruction must be checked. If a branch is followed by data, that would prevent the branch instruction from ever being JITted. Ah, but it also needs to un-JIT existing code paths leading into that instruction, a point that I missed. So the 6502 hypervisor needs to track all instruction flow as well, so it can un-JIT any instruction that might lead to that location.
Quote:
Is there another tricky case with an RTS that uses pushed constants? You'll capture the first case you see, but later cases with different constants could miss the trap, for the same reason: the destination was speculatively copied because there's nearby data accessed with an index mode.
RTS, RTI, and JMP (ind) would always be emulated, because their next address of execution is dynamic. It's checked every time. It would be a "dangerous" optimization to allow RTS and RTI to be JITted, but would be expected to work in the common case.
Quote:
(There's another trick people use, but I don't think it causes any trouble: a JSR which is followed by constant data, read by pulling the PC and adjusting it.)
Yeah, no problem there.
Dangit, I don't have the time to start a new project, but this one is very tempting. It all seems to check out, and isn't super complex. It's very RAM-heavy, though.