Supervisor mode in C [AHCC]

C and PASCAL (or any other high-level languages) in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
iceman
Captain Atari
Captain Atari
Posts: 178
Joined: Sat Mar 02, 2013 11:03 pm

Supervisor mode in C [AHCC]

Postby iceman » Sun Nov 01, 2015 4:57 pm

Hi all,

Really easy question here (for someone who knows what they are doing that is). I'm trying to enter Supervisor mode in C by using the Super() function prototyped in tos.h.

In assembly, the supervisor mode is called and the old stack pointer is saved (by you). When you want to drop out, pass the old sp and run Super() again. Job done, no mess, no fuss.

The function in C returns a long and requires a void pointer as a parameter. I would have thought that the return value would have been the old stack pointer, but it can't be if it's a long, can it?

My question is:

What is the correct way to enter Supervisor Mode? How would I then leave it later?
Atarian since 1989. Atari 1040STFM, 4MB 520STe with UltraSatan and Unitor N, A dodgy 1 MBSTe that bombs out after a few minutes, and a 14MB 48MHz Falcon 030 with NetUSBee and Soundpool 8 channel DAC. Plus my new MiST!

User avatar
iceman
Captain Atari
Captain Atari
Posts: 178
Joined: Sat Mar 02, 2013 11:03 pm

Re: Supervisor mode in C [AHCC]

Postby iceman » Sun Nov 01, 2015 6:45 pm

After finding some source on Exxos's Floppyshop mirror, I can answer my own question. I'll leave it here in case it's any use to anyone.


Code: Select all

register long ssp;
ssp = Super(0L);         /* enter supervisor mode */
Super(ssp);            /* return to user mode */
Atarian since 1989. Atari 1040STFM, 4MB 520STe with UltraSatan and Unitor N, A dodgy 1 MBSTe that bombs out after a few minutes, and a 14MB 48MHz Falcon 030 with NetUSBee and Soundpool 8 channel DAC. Plus my new MiST!

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 4859
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Supervisor mode in C [AHCC]

Postby simonsunnyboy » Sun Nov 01, 2015 6:58 pm

I personally prefer to use Supexec() instead. With gcc, I simply modified the startup code to call main through SUpexec(). Instant supervisor mode for those oldschool hardware banging apps without having to care :)

The method above is identical to what I used for years from GFABASIC. It is important to have going to supervisor and returning in the same stack scope (function). I remember atleast GFA crashed if the stack depth was not correct.
Simon Sunnyboy/Paradize - http://paradize.atari.org/ - STOT: http://www.npoi.de/stot/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Jabber: simonsunnyboy@atari-jabber.org

User avatar
iceman
Captain Atari
Captain Atari
Posts: 178
Joined: Sat Mar 02, 2013 11:03 pm

Re: Supervisor mode in C [AHCC]

Postby iceman » Sun Nov 01, 2015 7:05 pm

Ah, I see. I was being a bit prissy about only using Supervisor mode for functions that need it. I guess it's just going to cause overhead.
Atarian since 1989. Atari 1040STFM, 4MB 520STe with UltraSatan and Unitor N, A dodgy 1 MBSTe that bombs out after a few minutes, and a 14MB 48MHz Falcon 030 with NetUSBee and Soundpool 8 channel DAC. Plus my new MiST!

User avatar
Mikefulton
Captain Atari
Captain Atari
Posts: 169
Joined: Sun Nov 29, 2015 10:27 am

Re: Supervisor mode in C [AHCC]

Postby Mikefulton » Wed Jan 13, 2016 12:15 am

iceman wrote:The function in C returns a long and requires a void pointer as a parameter. I would have thought that the return value would have been the old stack pointer, but it can't be if it's a long, can it?


Both the return value and the parameter should have been listed as void pointers, but it was fairly common back in those days to say "long" for pointer values. Just cast it as needed, as shown in the other message.


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 1 guest