2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 Desc: Supervisor() - Execute some code in a privileged environment.
8 /*****************************************************************************
11 #include <proto/exec.h>
13 AROS_LH1(ULONG, Supervisor,
16 AROS_LHA(ULONG_FUNC, userFunction, A5),
19 struct ExecBase *, SysBase, 5, Exec)
22 Supervisor will allow a short privileged instruction sequence to
23 be called from user mode. This has very few uses, and it is probably
24 better to use any system supplied method to do anything.
26 The function supplied will be called as if it was a system interrupt,
27 notably this means that you must *NOT* make any system calls or
28 use any system data structures, and on certain systems you must
29 use special methods to leave the code.
31 The code will not be passed any parameters.
34 userFunc - The address of the code you want called in supervisor
38 The code will be called.
41 This function has completely different effects on different
42 processors and architectures.
44 Currently defined effects are:
47 -------------------------------------------------------------------
48 m68k (native) Runs the process in supervisor mode.
49 The process must end with an RTE
50 instruction. It should save any
51 registers which is uses.
56 You can very easily make the system unusable with this function.
57 In fact it is recommended that you do not use it at all.
60 SuperState(), UserState()
63 You can do what you want with this function, even ignoring it if
64 you don't think it makes any sense. But it could be quite useful
65 to make it run something under different protection levels.
67 You should trust that the programmer know what they are doing :-)
69 ******************************************************************************/
70 /* If this fails (called via user mode), then the trap code below
71 * will get called to finish the job. Regardless, we can't use
72 * anything on the stack, since if we *did* switch from User
73 * to Supervisor, our stack swapped!
75 #include "aros/m68k/asm.h"
79 .globl AROS_SLIB_ENTRY(Supervisor,Exec,5)
80 .type AROS_SLIB_ENTRY(Supervisor,Exec,5),@function
81 AROS_SLIB_ENTRY(Supervisor,Exec,5):
82 /* CRITICAL SECTION - DO NOT USE THE STACK */
83 Exec_Supervisor_Entry:
84 or.w #0x2000, %sr // Caused exception on 68000
86 /* If we're here, we need to fake a stack frame,
87 * because we were already supervisor.
89 btst #0, %a6@(AttnFlags+1) // If 68010, push frame id
91 move.w #0x0020,%sp@- // push the 68010/20 frame id
93 pea Exec_Supervisor_Exit
94 move.w %sr,%sp@- // Fix up return mode & flags
97 /* END CRITICAL SECTION - CALLER'S STACK */
100 /* 68000 privilege violation stack frame:
104 * 68010 privilege violation stack frame:
109 /* Special case - if we were trying to do the
110 * Supervisor() call, then give it permission.
112 * Both the asmcall and stackcall interface
113 * should work with this code.
118 .globl Exec_Supervisor_Trap
119 Exec_Supervisor_Trap:
120 cmp.l #Exec_Supervisor_Entry, %sp@(2)
123 /* No need to wait - we're supervisor,
124 * we have the right frame, all we need
125 * now is to fix up the return address
126 * and jump to the user's function in A5
128 2: move.l #Exec_Supervisor_Exit, %sp@(2)
130 /* Jump to standard exception handler */
131 1: jmp M68KTrapHelper_10
133 .globl Exec_Supervisor_Trap_00
134 Exec_Supervisor_Trap_00:
136 cmp.l #Exec_Supervisor_Entry, %sp@(2)
138 jmp M68KFaultTable_00+8*4