home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / util / heartbeat-1.0.lha / HeartBeat-1.0 / func.s < prev    next >
Encoding:
Text File  |  1994-05-12  |  4.0 KB  |  133 lines

  1. *********************************************************************************
  2. * HeartBeat Assembler Modules
  3. * ---------------------------
  4. * Written by Laurence Vanhelsuwé © April 1992
  5. *
  6. * This files contains the generic "patches" that are attached to selected system
  7. * calls via their library vectors.
  8. *
  9. * Every patch has a little structure in front of the routine that enables 'C'
  10. * to make a copy of the routine and patch selected pointers to create a unqique
  11. * patch for every system call.
  12. *********************************************************************************
  13.  
  14.         include    std
  15.  
  16. ;-------------------------------------------------------------------------
  17.         RSRESET    Context    (same as 'C' version !!)
  18. ctxt_regvals    RS.L    16            ; 16 LONGS for D0-D7/A0-A7
  19. ctxt_regmasks    RS.L    16            ; 16 MASKS for above
  20. ctxt_freeze    RS.W    1            ; should we freeze ?
  21. ctxt_frozen    RS.W    1            ; we're frozen !
  22. ctxt_sizeof    rs.w    0
  23. ;-------------------------------------------------------------------------
  24.  
  25.         XREF    _SNOOP_TASK        ;struct Task *
  26.         XDEF    _WEDGE
  27.  
  28. XXXXXXXX    equ    $ABCDEF86        ; a dummy long absolute
  29.  
  30. ;-------------------------------------------------------------------------
  31. ; This is the generic system call wedge.
  32. ; First it increments the call counter (conditionally if SNOOP_TASK is set)
  33. ; Then it does a match check on the input registers and incr a second counter
  34. ; if there is a match.
  35. ;-------------------------------------------------------------------------
  36.  
  37.         dc.w    (global_tracking+2-_WEDGE)>>1    ; CTXT PTR
  38.         dc.w    (inc_global+2-_WEDGE)>>1    ; CALL  CNT
  39.         dc.w    (inc2+2-_WEDGE)>>1        ; MATCH CNT
  40.         dc.w    (chain_jmp+2-_WEDGE)>>1        ; CHAIN PTR
  41.         dc.w    (_NEXT_PATCH-_WEDGE)>>1        ; LENGTH
  42.  
  43. _WEDGE:        movem.l    d0-d7/a0-a7,-(SP)    ;SP-> D0..D7, A0..A7 in that order
  44.  
  45.     IFD dumpA0
  46.         moveq    #$80-1,d7    ;
  47.         lea    $100,a1        ;
  48. dump_a0        move.b    (a0)+,(a1)+    ;
  49.         dbra    d7,dump_a0    ;
  50.     ENDC
  51.  
  52.         sf    d7            ;assume not Task specific
  53.         move.l    _SNOOP_TASK,d0        ;do we have to check ONE Task?
  54.         beq    inc_global        ;yes,
  55.  
  56.         move.l    4.w,a6            ;check whether caller is Task.
  57.         cmp.l    ThisTask(a6),d0        ;is it ?
  58.         bne    global_tracking
  59.         st    d7            ;Task is target task.
  60.  
  61. inc_global    addq.l    #1,XXXXXXXX        ;INCREMENT CALL COUNTER
  62.  
  63. global_tracking    lea    XXXXXXXX,a5        ;GET PRIVATE CALL CONTEXT
  64.         lea    (sp),a1            ;point to saved registers
  65.         jsr    match_regs        ;check match (shared re-entrant)
  66.         bne    no_match
  67.  
  68. inc2        addq.l    #1,XXXXXXXX        ;INCREMENT MATCH COUNTER
  69.  
  70. no_match    movem.l    (SP)+,d0-d7/a0-a7
  71. chain_jmp    jmp    XXXXXXXX        ;CHAIN TO STANDARD ROUTINE
  72.  
  73. ;-------------------------------------------------------------------------
  74. _NEXT_PATCH:
  75.  
  76. ******************************************************************************
  77. ** Re-entrant routine to determine template registers match.
  78. ** (this is common to all wedges to keep wedges small)
  79. **
  80. ** A1 -> D0, D1, D2... A5, A6, A7
  81. ** A5 -> Context struct
  82. ** D7 = TRUE/FALSE Task is SNOOP_TASK
  83. **
  84. ** RETURN EQ for match
  85. **      NE for no match
  86. ******************************************************************************
  87.  
  88. match_regs    lea    ctxt_regvals(a5),a2    ;-> 16 register values
  89.         lea    ctxt_regmasks(a5),a3    ;-> 16 register don't care masks
  90.  
  91.         moveq    #16-1,d0        ;check all 16 680x0 regs
  92.  
  93. check_register    move.l    (a3)+,d1        ;get register mask
  94.         and.l    (a1)+,d1        ;mask out don't care bits
  95.         cmp.l    (a2)+,d1        ;did register match template ?
  96.  
  97.         dbne    d0,check_register    ;exit as soon as match fails
  98.         bne    didnt_match
  99. ;---------------
  100.         tst.b    ctxt_freeze(a5)        ;should we freeze SNOOP_TASK
  101.         beq    did_match        ;on match ?
  102.  
  103.         tst.b    d7            ;ok, but are we sure caller is
  104.         beq    did_match        ;SNOOP_TASK ?
  105.  
  106.         move.l    4.w,a6            ;yep, get signal to Wait() on
  107.         moveq    #24,d0
  108.         EXEC    AllocSignal
  109.         tst.l    d0
  110.         bmi    did_match
  111.  
  112.     ; avoid nasty race conditions
  113.  
  114.     FORBID
  115.         st    ctxt_frozen(a5)        ;tell main we're frozen
  116.         
  117.         move.l    #1<<24,d0        ;yes, freeze until HeartBeat
  118.         EXEC    Wait            ;wakes us up (signal 24)
  119.  
  120.         sf    ctxt_frozen(a5)        ;we're not frozen any more...
  121.     PERMIT
  122.  
  123.         moveq    #24,d0
  124.         EXEC    FreeSignal        ;leave SNOOP_TASK's signal free
  125.  
  126. did_match    moveq    #0,d0            ;return EQ for match
  127.         rts
  128.  
  129. didnt_match    moveq    #-1,d0            ;return NE for no match
  130.         rts
  131. ;-------------------------------------------------------------------------
  132.         END
  133.