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

CLR opcode workaround #7

Open
SamuraiCrow opened this issue Sep 5, 2023 · 5 comments
Open

CLR opcode workaround #7

SamuraiCrow opened this issue Sep 5, 2023 · 5 comments

Comments

@SamuraiCrow
Copy link

When generating code for the CLR opcode using a data register operand, there is a microcode bug in the 68000 CPU that can crash the system. If it hasn't been fixed already, the CLR.W D0 opcode should be implemented as EOR.W D0,D0. It's a drop-in substitute for all sizes.

@dmcoles
Copy link
Owner

dmcoles commented Sep 5, 2023

interesting, do you have any further details on this bug? I am only aware of the issues that could potentially be caused by clr with hardware registers (for example) that cannot be read - which in this case EOR.W D0,D0 would not be a useful substitute.

@SamuraiCrow
Copy link
Author

The bug only affects data register operands. Memory-direct operands generate the intended effect with CLR already.

I think this bug fix would only make a difference in the assembler opcode and the 32 bit unsigned division operation because the remainder is in the high word and the quotient is in the low word (or the other way around).

@dmcoles
Copy link
Owner

dmcoles commented Sep 5, 2023

the multiply, divide and rnd functions all use clr.w. do you have any links where i can read up on this?

@SamuraiCrow
Copy link
Author

I'm afraid not but I gave the same advice to the Scorpion Engine developer on EAB when he was getting unexplained crashes with his modulo operation and said the EOR workaround worked. It only affects the stock 68000, not 68020+ and probably not 68010 AFAIK.

@SamuraiCrow
Copy link
Author

SamuraiCrow commented Sep 5, 2023

I did a little more reading on a long, insult-ridden EAB thread and the problem is that CLR was incorrectly classified as using read-modify-write addressing.

That means that if it was used on chip RAM the system could crash because of bus timing issues. If it was used on a data register, it would write a zero to whatever memory was recently accessed (determined by whatever the last contents of the address bus latch was set at). Either way it was unsafe on Amiga.

The standard workaround was to use MOVEQ #0,D0 but that would clear the whole register. EOR.L D0,D0 would also, but at least would set the condition code registers correctly. For clearing the bottom half of a data register, EOR.W D0,D0 is functionally equivalent to the 68020 version of CLR.W D0 in both opcode size, results and processor flags. Not bad for a substitution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants