English Amiga Board


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

 
 
Thread Tools
Old 17 July 2017, 14:56   #1
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,409
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  
Old 17 July 2017, 17:39   #2
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
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 online now  
Old 17 July 2017, 18:05   #3
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
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 offline  
Old 17 July 2017, 22:38   #4
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
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, 22:48   #5
Kalms
Registered User
 
Join Date: Nov 2006
Location: Stockholm, Sweden
Posts: 237
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 17 July 2017, 23:06   #6
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
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; 17 July 2017 at 23:15.
hooverphonique is online now  
Old 18 July 2017, 17:13   #7
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,409
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  
 


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 01:13
Moving HDD from Pc to Amiga Hockmiester support.Hardware 2 25 March 2013 17:37
Moving Files Etc Washac support.Hardware 1 09 February 2010 16:50
moving OS3.9 to different HD lopos2000 support.Apps 2 09 August 2005 12:56
It's moving..it's alive, it's moving.. IT'S ALLIIIIIIIIIIVE!!!!!!!!!1 alkis21 Retrogaming General Discussion 23 22 August 2002 10: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 09:58.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.30420 seconds with 13 queries