dont try to convert the pixfmt while calculating the "shade"
[AROS.git] / arch / m68k-all / exec / supervisor.S
blobfd9ef1f145e1a4437f9f9c132f67a0c80656926d
1 /*
2     Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3     $Id$
5     Desc: Supervisor() - Execute some code in a privileged environment.
6     Lang: english
7 */
8 /*****************************************************************************
10     NAME
11 #include <proto/exec.h>
13         AROS_LH1(ULONG, Supervisor,
15     SYNOPSIS
16         AROS_LHA(ULONG_FUNC, userFunction, A5),
18     LOCATION
19         struct ExecBase *, SysBase, 5, Exec)
21     FUNCTION
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.
33     INPUTS
34         userFunc    -   The address of the code you want called in supervisor
35                         mode.
37     RESULT
38         The code will be called.
40     NOTES
41         This function has completely different effects on different
42         processors and architectures.
44         Currently defined effects are:
46         Kernel                      Effect
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.
53     EXAMPLE
55     BUGS
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.
59     SEE ALSO
60         SuperState(), UserState()
62     INTERNALS
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!
74      */
75         #include "aros/m68k/asm.h"
77         .text
78         .balign 4
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.
88          */
89         btst    #0, %a6@(AttnFlags+1)   // If 68010, push frame id
90         beq.s   0f
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
95         jmp     (%a5)
96 Exec_Supervisor_Exit:
97         /* END CRITICAL SECTION - CALLER'S STACK */
98         rts
100         /* 68000 privilege violation stack frame:
101          *   ULONG PC
102          *   UWORD STATUS
103          *
104          * 68010 privilege violation stack frame:
105          *   UWORD 0x0020
106          *   ULONG PC
107          *   UWORD STATUS
108          */
109         /* Special case - if we were trying to do the
110          * Supervisor() call, then give it permission.
111          *
112          * Both the asmcall and stackcall interface
113          * should work with this code.
114          */
115         .text
116         .align 4
117         /* 68010+ version */
118         .globl Exec_Supervisor_Trap
119 Exec_Supervisor_Trap:
120         cmp.l   #Exec_Supervisor_Entry, %sp@(2)
121         bne.s   1f
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
127          */
128 2:      move.l  #Exec_Supervisor_Exit, %sp@(2)
129         jmp     (%a5)
130         /* Jump to standard exception handler */
131 1:      jmp M68KTrapHelper_10
133         .globl Exec_Supervisor_Trap_00
134 Exec_Supervisor_Trap_00:
135         /* 68000 version */
136         cmp.l   #Exec_Supervisor_Entry, %sp@(2)
137         beq.s   2b
138         jmp M68KFaultTable_00+8*4