(****************************************
*                                       *
*     CPUMode  (definition)             *
*     ******************************    *
*                                       *
*      Implementation for ATARI ST      *
*                                       *
*      To switch you from user mode     *
*      into supervisor mode with a      *
*      choice of stack (USP/SSP).       *
*                                       *
*     Version 1.0 of 27.4.86            *
*                                       *
*     Stichting MODULA Nederland        *
*     Bakkersteeg 9 A                   *
*     2311 RH LEIDEN                    *
*                                       *
*+++++++++++++++++++++++++++++++++++++++*
*                                       *
*  Author: R.J. van der Kamp            *
****************************************)
  
DEFINITION  MODULE CPUMode;
 (* in the manuals of GEMDOS there is no mention of function number 
   32 ( 20h ). This function brings you into or out of supervisor 
   mode. See the expanation in the definition module.
 *)

FROM SYSTEM IMPORT ADDRESS;
EXPORT QUALIFIED Mode ;


PROCEDURE Mode ( stack : ADDRESS ) : ADDRESS ;
(* We use TRAP #1 , function number 20h     *)
(* 'stack' can be:
   -1=0FFFFFFFFh = proc returns 1 for super mode, 0 for user mode
    0= supervisor stack will be same as user stack when going from
       user to super mode. Then old value of systemstack pointer
       will be returned, so you can (and have) to reset this system
       stack pointer. The call toggles you between super and user mode.
  /***********************************************/
  MODULE TEST; (* Demo: how to use this all *)
  FROM SYSTEM IMPORT ADDRESS;
  FROM CPUMode IMPORT Mode;
  VAR savedssp,dummy : ADDRESS;
  BEGIN /* now doing user mode actions */
  savedssp := Mode(0);
   /* now super mode, using user stack as system stack */
   /* do here the super things */
   dummy := Mode(savedssp);
   /* now back in user mode, stack ok. */
  END TEST.
  /************************************************/
*)
END CPUMode.

