home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / internal / m68k / m68k-native / switch.s < prev   
Encoding:
Text File  |  1996-07-16  |  2.1 KB  |  100 lines

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