home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DSKCACHE / EVALCACH.ZIP / SNOOP.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-10-26  |  5.1 KB  |  123 lines

  1. ; ******************************************************************
  2. ; SNOOP.ASM                      Created 6/24/1989 by L. Brett Glass
  3. ; ******************************************************************
  4. ; This TSR logs disk all hard disk reads and writes that pass through
  5. ; the IBM PC BIOS on the way to the first hard disk to a RAM buffer.
  6. ; The sector, cylinder, head, drive, operation, and number of sectors
  7. ; are recorded.
  8. ;
  9. ; Copyright (C) 1989 by L. Brett Glass, Systems Consultant
  10. ;
  11. ; Usenet: apple!well!rogue
  12. ; ARPANET: well!rogue@APPLE.COM
  13. ; BIX: glass
  14. ; CompuServe: [72267,3673] (Also reachable from MCIMail)
  15. ;
  16. ; This program may be freely redistributed for non-commercial purposes
  17. ; only. It may not be made part of any hardware or software product
  18. ; without the express written consent of the copyright owner. This
  19. ; program is supplied on an "as-is" basis. The author assumes no
  20. ; responsibility for its correctness or its fitness for a given
  21. ; purpose, nor for consequential damages which may arise from its use.
  22. ;
  23. ; ******************************************************************
  24. ;
  25. DISKINT   equ 13h ; Disk I/O Interrupt number
  26. DOS       equ 21h ; Interrupt number for: DOS function
  27. TSR       equ 27h ;                       Terminate/stay resident
  28. GETVEC    equ 35h ; DOS Function numbers: Get interrupt vector
  29. SETVEC    equ 25h ;                       Set interrupt vector
  30. PRINTMSG  equ 9   ;                       Print message
  31. HARD      equ 80h ; Mask to test for hard disk #
  32. DISKREAD  equ 2   ; BIOS functions: Read
  33. DISKWRITE equ 3   ;                 Write
  34. GETBUFADDR equ 99AAh ; Special Int 13h request for snoop buffer address
  35. BADCMD    equ 1   ; Bad command result code for BIOS call
  36. SENTINEL  equ 4321h ; Sentinel value to signal that SNOOP is present
  37.  
  38. MAXTRANSACTIONS equ 8 * 1024       ; Log 8K disk transactions
  39. BUFFERSIZE equ 6 * MAXTRANSACTIONS ; Each transaction is 6 bytes
  40.  
  41. Code       segment
  42.            assume cs:Code,ds:Nothing
  43.            org 100h
  44. Entry:     jmp near ptr Init ; Jump to transient portion of program
  45. ;
  46. ; Store the original vector here
  47. ;
  48. DiskIO     label   dword   ; Make a label for the whole vector
  49. DiskIOOfs  dw 0 ; Now make labels for segment and offset
  50. DiskIOSeg  dw 0
  51. ;
  52. ; Define constants that indicate where buffer starts and ends
  53. ;
  54. BufferStart equ (offset NextLoc) + 2
  55. BufferEnd  equ   (offset NextLoc) + 2 + BUFFERSIZE
  56. ;
  57. Snoop      proc far
  58.            cmp dl,80h  ; Is it a call to the first hard disk?
  59.            jnz Chain   ; Nope, let it through
  60.            cmp ah,DISKREAD ; Is it a read request?
  61.            je Log      ; If so, log it
  62.            cmp ah,DISKWRITE ; Is it a write request?
  63.            je Log
  64.            cmp ax,GETBUFADDR ; Is it a buffer address request?
  65.            jne Chain   ; If not read or write or addr request, pass on
  66. GetAddr:   mov  ax,cs  ; Get address
  67.            mov  es,ax
  68.            mov  bx,offset WrapFlag
  69.            mov  dx,SENTINEL ; Tell program SNOOP is present on the sly
  70.            mov  ah,BADCMD ; Look like bad command
  71.            stc         ; Generate apparent error
  72.            sti         ; And enable interrupts
  73.            ret 2       ; Do not restore original flags when returning
  74. Log:       push di     ; Use di as a pointer into the buffer
  75.            mov  di,cs:NextLoc ; Get the next position to be written
  76.            mov  cs:[di],dx ; Store DX
  77.            add  di,2
  78.            mov  cs:[di],cx ; Then CX
  79.            add  di,2
  80.            mov  cs:[di],ax ; Then AX
  81.            add  di,2
  82.            cmp  di,BufferEnd ; End of buffer?
  83.            jb   @F
  84.            mov  di,BufferStart ; If so, wrap to beginning
  85.            mov  cs:WrapFlag,1 ; And set a flag so we know we've wrapped
  86. @@:        mov  cs:NextLoc,di
  87.            pop  di
  88. Chain:     jmp cs:[DiskIO]  ; Jump to disk BIOS
  89. Snoop      endp
  90. ;
  91. ; Labels used by TSR portion of program
  92. ;
  93. WrapFlag   db   0 ; Flag to indicate buffer has wrapped at least once
  94. NextLoc    label word ; Next location to store disk info
  95. ;
  96. ;          "Transient" area (also used for logging transactions) begins here
  97. ;
  98. Message    db 'Hard Disk Log Utility'
  99.            db 0Dh,0Ah,'Copyright (C) 1989 by L. Brett Glass'
  100.            db 0Dh,0Ah,'Reboot to remove this TSR.'
  101.            db 0Dh,0Ah,'$'
  102. ;
  103. ;          assume cs:Code,ds:Code
  104. ;
  105. Init       proc near       ; This code executed on entry
  106.            mov ax,(GETVEC shl 8) + DISKINT  ; Get interrupt vector from DOS
  107.            int DOS         ; DOS call
  108.            mov [DiskIOOfs],bx ; Save the old vector
  109.            mov [DiskIOSeg],es
  110.            mov dx,offset Snoop ; Get ready to add our own routine
  111.            mov ah,SETVEC   ; Set interrupt vector thru DOS
  112.            int DOS         ; DOS call
  113.            mov dx,offset Message ; Prepare to print message
  114.            mov ah,PRINTMSG ; Print message through DOS
  115.            int DOS         ; DOS call
  116.            mov NextLoc,BufferStart ; Start from beginning of buffer
  117.            mov dx,BufferEnd ; Reserve space for buffer
  118.            int TSR         ; Terminate and stay resident
  119. Init       endp
  120. Code       ends
  121.            end     Entry
  122.  
  123.