16 June 2019, 16:23 | #1 |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Misaligned stack
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 bsr.b .x addq.l #1,sp .x rts 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. Last edited by ross; 16 June 2019 at 17:36. Reason: typos.. |
16 June 2019, 16:49 | #2 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,216
|
There is no crash on a real machine in this case, either. The 68K family always aligns its stack, so "subq.l #1,a7" does not quite do what you expect it to do. The same holds for "move.b d0,-(a7)" or similar instructions.
|
16 June 2019, 16:57 | #3 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
And also some tools (like Easy68k) are wrong about an Address Error on RTS execution. Last edited by ross; 16 June 2019 at 17:37. Reason: added image |
|
16 June 2019, 17:09 | #4 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
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). |
16 June 2019, 17:11 | #5 | |
Registered User
Join Date: Mar 2019
Location: Poland
Posts: 59
|
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. |
|
16 June 2019, 17:13 | #6 | ||
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
Quote:
The "famous" stack auto-align on byte operations. I use it for the usual tricks. So the culprit is elsewhere |
||
16 June 2019, 17:17 | #7 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
Quote:
So probably Toni will give us an explanation. |
|
16 June 2019, 17:23 | #8 | |
Defendit numerus
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
|
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 ... Last edited by ross; 16 June 2019 at 17:39. Reason: welcome |
|
16 June 2019, 17:51 | #9 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
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. |
16 June 2019, 19:12 | #10 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,507
|
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 Last edited by Toni Wilen; 16 June 2019 at 20:32. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Hot swapping internal floppy drive/checking for misaligned heads | TTSAddict | support.Hardware | 12 | 13 April 2018 20:23 |
Stack up (Zeppelin '91) | PopoCop | support.Games | 0 | 05 March 2015 17:38 |
Stack available | mritter0 | Coders. General | 4 | 03 August 2014 18:31 |
Best Stack Program? | dannyp1 | support.Other | 2 | 01 January 2012 19:43 |
Stack Up | Galaxy | request.Old Rare Games | 5 | 08 September 2004 03:06 |
|
|