added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / m68k-native / exec / switch.s
blob1d54933cf49fceb479d93ab79c0c25ad84e81a37
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*****************************************************************************
8 NAME
10 AROS_LH0(void, Switch,
12 LOCATION
13 struct ExecBase *, SysBase, 6, Exec)
15 FUNCTION
16 Tries to switch to the first task in the ready list. This
17 function works almost like Dispatch() with the slight difference
18 that it may be called at any time and as often as you want and
19 that it does not lose the current task if it is of type TS_RUN.
21 INPUTS
23 RESULT
25 NOTES
26 This function is CPU dependant.
28 This function is for internal use by exec only.
30 This function preserves all registers.
32 EXAMPLE
34 BUGS
36 SEE ALSO
37 Dispatch()
39 INTERNALS
41 HISTORY
43 ******************************************************************************/
45 #include "machine.i"
47 .text
48 .balign 4
49 .globl AROS_SLIB_ENTRY(Switch,Exec)
50 .type AROS_SLIB_ENTRY(Switch,Exec),@function
51 AROS_SLIB_ENTRY(Switch,Exec):
52 /* call switch in supervisor mode
53 this is necessary to determine if the current context is user or
54 supervisor mode */
55 move.l a5,-(sp)
56 move.l #switch,a5
57 jsr Supervisor(a6)
58 move.l (sp)+,a5
59 rts
61 switch:
62 /* test if called from supervisor mode
63 (supervisor bit is bit 8+5 of sr when calling Switch() ) */
64 btst #5,(sp)
65 beq nosup
67 /* called from supervisor mode (grrrr)
68 since I can only Dispatch() when falling down to user mode I
69 must do it later - set the delayed dispatch flag and return */
70 bset #7,AttnResched(a6)
71 end: rte
73 /* Called from user mode
74 Always disable interrupts when testing task lists */
75 nosup: move.w #0x2700,sr
77 /* Preserve scratch registers */
78 movem.l d0/d1/a0/a1,-(sp)
80 /* If not in state TS_RUN the current task is part of one of the
81 task lists. */
82 move.l ThisTask(a6),a1
83 cmp.b #TS_RUN,tc_State(a1)
84 bne disp
86 /* If TB_EXCEPT is not set... */
87 btst #TB_EXCEPT,tc_Flags(a1)
88 bne disp
90 /* ...Move task to the ready list */
91 move.b #TS_READY,tc_State(a1)
92 lea.l TaskReady(a6),a0
93 jsr Enqueue(a6)
95 /* dispatch */
96 disp: movem.l (sp)+,d0/d1/a0/a1
97 jmp Dispatch(a6)