home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / config / m68k-native / switch.s < prev    next >
Encoding:
Text File  |  1996-12-06  |  2.1 KB  |  101 lines

  1. /*
  2.      (C) 1995-96 AROS - The Amiga Replacement OS
  3.      $Id: switch.s,v 1.7 1996/12/06 03:56:18 aros Exp $
  4.  
  5.      Desc:
  6.      Lang:
  7. */
  8.  
  9. /*****************************************************************************
  10.  
  11.     NAME
  12.  
  13.      AROS_LH0(void, Switch,
  14.  
  15.     LOCATION
  16.      struct ExecBase *, SysBase, 6, Exec)
  17.  
  18.     FUNCTION
  19.      Tries to switch to the first task in the ready list. This
  20.      function works almost like Dispatch() with the slight difference
  21.      that it may be called at any time and as often as you want and
  22.      that it does not lose the current task if it is of type TS_RUN.
  23.  
  24.     INPUTS
  25.  
  26.     RESULT
  27.  
  28.     NOTES
  29.      This function is CPU dependant.
  30.  
  31.      This function is for internal use by exec only.
  32.  
  33.      This function preserves all registers.
  34.  
  35.     EXAMPLE
  36.  
  37.     BUGS
  38.  
  39.     SEE ALSO
  40.      Dispatch()
  41.  
  42.     INTERNALS
  43.  
  44.     HISTORY
  45.  
  46. ******************************************************************************/
  47.  
  48.     #include "machine.i"
  49.  
  50.     .text
  51.     .balign 16
  52.     .globl    AROS_SLIB_ENTRY(Switch,Exec)
  53.     .type    AROS_SLIB_ENTRY(Switch,Exec),@function
  54. AROS_SLIB_ENTRY(Switch,Exec):
  55.     /* call switch in supervisor mode
  56.        this is necessary to determine if the current context is user or
  57.        supervisor mode */
  58.     move.l    a5,-(sp)
  59.     move.l    #switch,a5
  60.     jsr    Supervisor(a6)
  61.     move.l    (sp)+,a5
  62.     rts
  63.  
  64. switch:
  65.     /* test if called from supervisor mode
  66.        (supervisor bit is bit 8+5 of sr when calling Switch() ) */
  67.     btst    #5,(sp)
  68.     beq    nosup
  69.  
  70.     /* called from supervisor mode (grrrr)
  71.        since I can only Dispatch() when falling down to user mode I
  72.        must do it later - set the delayed dispatch flag and return */
  73.     bset    #7,AttnResched(a6)
  74. end:    rte
  75.  
  76.     /* Called from user mode
  77.        Always disable interrupts when testing task lists */
  78. nosup:    move.w    #0x2700,sr
  79.  
  80.     /* Preserve scratch registers */
  81.     movem.l    d0/d1/a0/a1,-(sp)
  82.  
  83.     /* If not in state TS_RUN the current task is part of one of the
  84.        task lists. */
  85.     move.l    ThisTask(a6),a1
  86.     cmp.b    #TS_RUN,tc_State(a1)
  87.     bne    disp
  88.  
  89.     /* If TB_EXCEPT is not set... */
  90.     btst    #TB_EXCEPT,tc_Flags(a1)
  91.     bne    disp
  92.  
  93.     /* ...Move task to the ready list */
  94.     move.b    #TS_READY,tc_State(a1)
  95.     lea.l    TaskReady(a6),a0
  96.     jsr    Enqueue(a6)
  97.  
  98.     /* dispatch */
  99. disp:    movem.l    (sp)+,d0/d1/a0/a1
  100.     jmp    Dispatch(a6)
  101.