Misaligned stack
1 Attachment(s)
Target: bare 68k.
I was writing code using the stack to store some temporary data and by mistake I made the stack odd aligned and called a subroutine. I'm expecting a crash, but to my surprise nothing.. So investigated and there is no crash in WinUAE for this cases! A little snippet, reducing the code to the minimum: Code:
sq subq.l #1,sp Yes, wrong section if is a WinUAE oddity, but I'm not sure so.. Maybe I miss something obvious (no, stack not auto-align on subq, and no, impossible for a prefetch behavior). And yes, WinUAE debugger displays the right return code in a misaligned location. Cheers. |
Quote:
|
1 Attachment(s)
Quote:
And also some tools (like Easy68k) are wrong about an Address Error on RTS execution. http://eab.abime.net/attachment.php?...1&d=1560697344 |
Winuae does not detect 100% cases of address errors.
You can get misaligned stack on 68000, if you move.b it will still do 2 bytes but stay misaligned. Any access should trigger error. On 68020+ you can have misaligned nearly everything including stack, in fact even misaligned vbr will work (only code must remain aligned). |
Quote:
or Predecrement Register Indirect addressing modes. Subq.l should decrement a7 by 1 but the move.b d0, -(a7) will decrement by 2. Bsr does decrement stack while pushing return address on it (similar to -(a7)) , so it also aligns stack to word address. |
Quote:
Quote:
The "famous" stack auto-align on byte operations. I use it for the usual tricks. So the culprit is elsewhere ;) |
Quote:
So probably Toni will give us an explanation. |
Quote:
A WinUAE wrong display? Noticed now that is your first forum post, so welcome :) -- I apologize for the multipost but they were all close answers and in the meantime I was answering ... |
68k never auto aligns, so you can try whatever you want in matter of alignment. Even push/pop of bytes don't align, they just do +/- 2 instead of +/- 1 on the stack pointer without more care.
However if an access isn't allowed, you get the address error trap. The only mystery is in which cases winuae does not actually detect it ; i remember having read something about this. |
I guess I forgot bsr/jsr when I added 68000/010 exception odd stack checks.
Yes, there is no "true" "auto align", and 68020+, as usual, does not care (unless PC becomes odd) EDIT: fixed :) |
All times are GMT +2. The time now is 14:02. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.