English Amiga Board

Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

Thread Tools
Old 17 July 2017, 15:56   #1
Registered User

Join Date: Jul 2015
Location: The Netherlands
Posts: 262
Moving supervisor stack

I'm looking for a safe way to move the supervisor stack to an address of my choosing.

Now, I could do this by simply running the whole program from in supervisor mode and never returning to user mode. But that's not what I want, what I really want is to move both stacks to addresses of my choice for a test program without any OS left running.

However, while I'm reasonably sure how to safely do this for the user stack, I'm not so sure how to safely do so for the supervisor stack, given that I want to be able to RTE after moving the stack and not blow up the system.

Does anyone here know how to do so?
roondar is offline  
AdSense AdSense  
Old 17 July 2017, 18:39   #2
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 718
push the return address onto the stack before executing RTE, or exit supervisor mode by writing to the status register (don't remember if that's possible).
hooverphonique is offline  
Old 17 July 2017, 19:05   #3
son of 68k
meynaf's Avatar
Join Date: Nov 2007
Location: Lyon / France
Age: 44
Posts: 2,496
Pushing return address for RTE is unsafe - supervisor stack frame may differ from one cpu to another.
But it's safe to exit supervisor mode by writing to the status register, provided there's nothing left in the supervisor stack.
meynaf is online now  
Old 17 July 2017, 23:38   #4

Join Date: Jul 2008
Location: Sweden
Posts: 2,044
It's generally not safe to move the stacks at run-time because you may end up with dangling pointers, but if you don't have any pointers onto the stack: make a copy, set the new SSP, and RTE.
Leffmann is offline  
Old 17 July 2017, 23:48   #5
Registered User
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 169
Let's say that you start out in user mode. In this mode, a7 will alias onto the user stack pointer register (USP), and the supervisor stack pointer register (SSP) is inaccessible to you.

You can move the usermode stack when you are in usermode to somewhere else by doing move.l #imm,a7. This may upset the OS, so you should make sure that you do not have the OS task switching active when you have moved the USP. I'm not sure if you also need to disable interrupts when doing this.

If you enter supervisor mode, for example by calling Supervisor(), then the act of entering Supervisor mode will have resulted in the CPU creating some form of exception stack frame on the supervisor stack. The "clean" method for going back to user mode is to ensure that the SSP points to the same place where it was at the start of supervisor execution, and issue an RTE instruction.

Once you are in supervisor mode, a7 is an alias for SSP, and you can access the USP register via movec usp,rn / movec rn,usp. You can point them elsewhere with no impact.

If you want to permanently relocate your supervisor and usermode stacks and discard all OS compatibility you could do as follows:
  1. Disable all interrupts
  2. Switch to supervisor mode
  3. Force SSP and USP to point to the ends of your own stack buffers
  4. Replace interrupt handlers with your own
  5. Ensure there is still a mechanism for you to switch to supervisor if needed (example: set up a trap #0 handler that acts like Supervisor())
  6. Disable S bit in SP to switch back to usermode

I haven't tried disabling the S bit in SR in practice but like meynaf I'm pretty sure it'll work.
Kalms is offline  
Old 18 July 2017, 00:06   #6
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 718
I've used this method in the past. It's from my small trackmo 'OS' called BOSS. It clears the S bit to exit supervisor mode. It seems it also sets the interrupt stack pointer on bigger cpu's.
Man,I don't remember any details about this sort of stuff anymore :-/

Last edited by hooverphonique; 18 July 2017 at 00:15.
hooverphonique is offline  
Old 18 July 2017, 18:13   #7
Registered User

Join Date: Jul 2015
Location: The Netherlands
Posts: 262
The idea is to use this for a self booting trackloader program running on a 512KB system (without OS). Naturally, compatibility with other systems is also desired - this is why I asked how to do this safely across processors.

So thanks all for the tips, I'll be trying them for sure
roondar is offline  
AdSense AdSense  

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving Amiga's.... Steve T support.Hardware 26 05 September 2015 02:13
Moving HDD from Pc to Amiga Hockmiester support.Hardware 2 25 March 2013 18:37
Moving Files Etc Washac support.Hardware 1 09 February 2010 17:50
moving OS3.9 to different HD lopos2000 support.Apps 2 09 August 2005 13:56
It's moving..it's alive, it's moving.. IT'S ALLIIIIIIIIIIVE!!!!!!!!!1 alkis21 Retrogaming General Discussion 23 22 August 2002 11:51

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 21:00.

Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Page generated in 0.20686 seconds with 14 queries