home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 387b.lha / dice_v2.02 / lib / amiga / lwp.a < prev    next >
Encoding:
Text File  |  1990-05-30  |  2.2 KB  |  90 lines

  1.  
  2.         ;   LWP.A
  3.         ;
  4.         ;   Light Weight Process Support
  5.  
  6.         section text,code
  7.  
  8.         ;   start a new LWP process.  D0.W = bytes of args
  9.         ;                  D1.W = bytes of local vars
  10.         ;
  11.         ;   push args.    Return address (start pc) already pushed
  12.         ;   by calling process.
  13. __LWPStart
  14.         ext.l    D0
  15.         ext.l    D1
  16.         move.l    D1,-(sp)
  17.         move.l    D0,-(sp)
  18.         jsr    __CLWPStart(pc) ; sets up independant context
  19.         lea    8+4(sp),sp      ; args, skip local ret addr
  20.         moveq.l #0,D0
  21.         rts            ; return from calling procedure
  22.  
  23.         ;   JMP'd to at end of LWP subroutine.
  24.  
  25. __LWPReturn:
  26.         move.l    D0,-(sp)        ; return code
  27.         move.l    (A5),-(sp)      ; LWP descriptor
  28.         jsr    __CLWPReturn(pc); sets up new context and
  29.         addq.l    #8,sp
  30.         move.l    D0,A0        ; returns it
  31.  
  32.         ;   D0,D2-D7,PC,A2,A3,A5,A6
  33.         ;   (D0 usually holds a return address)
  34.  
  35.         movem.l (A0),D0/D2-D7/A1/A2/A3/A5/A6
  36.         jmp    (A1)
  37.  
  38.         ;   Called by user. LWPGetEvent().  First do a context
  39.         ;   switch if feasible.
  40.  
  41. _LWPGetEvent:
  42.         move.l    (A5),A0         ; LWP descriptor (circular doubly
  43.         tst.l    8(A0)           ; event ready ?
  44.         bne    lge10
  45.                     ; no, unlink from rdy
  46.         move.l    4(A0),A1        ; A1 = prev
  47.         move.l    (A0),(A1)       ; this->next -> prev->next
  48.         move.l    (A0),A1         ; A1 = next
  49.         move.l    4(A0),4(A1)     ; this->prev -> next->prev
  50.         move.l    A1,D1        ; next ready context
  51.  
  52. lgeout        lea    lge50(pc),A1    ; restore pc (when event ready)
  53.         move.l    (sp)+,D0        ; return address
  54.         movem.l D0/D2-D7/A1/A2/A3/A5/A6,12(A0)  ; save ctx
  55.         move.l    D1,A1
  56.         movem.l 12(A1),D0/D2-D7/A1/A2/A3/A5/A6  ; restore ctx
  57.         jmp    (A1)                            ; go
  58.  
  59.         ;   lge50, restore from wait state, check event,
  60.         ;   relink if event found, else go back to wait state.
  61.  
  62. lge50        move.l    (A5),A0         ; get A0 back
  63.         move.l    D0,-(sp)        ; push ret addr again
  64.  
  65.         move.l    __LWPRdyBase(A4),D1
  66.         move.l    8(A0),D0
  67.         beq    lgeout
  68.  
  69.         ;   event in D0.  first relink
  70.  
  71.         move.l    __LWPRdyBase(A4),A1 ; insert after item
  72.  
  73.         move.l    (A1),(A0)       ; item->next -> this->next
  74.         move.l    A1,4(A0)        ; item       -> this->prev
  75.         move.l    A0,(A1)         ; this -> item->next
  76.         move.l    (A0),A1         ; (A1 = nextitem)
  77.         move.l    A0,4(A1)        ; nextitem->prev = this
  78.  
  79.         ;   unlink event
  80.  
  81.         move.l    D0,A1
  82.         move.l    (A1),8(A0)
  83.  
  84.         ;   return event
  85.  
  86.         rts
  87.  
  88.         END
  89.  
  90.