home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / ISDETECT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-13  |  4.0 KB  |  125 lines

  1. /**
  2. *
  3. * Name        isdetect -- Detect an installed interrupt service routine
  4. *
  5. * Synopsis    result = isdetect(intype,pident,pprev_ads,ppsp_seg);
  6. *
  7. *        int result      Result code:    0 if found, 1 if not found,
  8. *                  2 if intype is outside of 0-255 range.
  9. *        int intype      Interrupt type number
  10. *        char *pident      Pointer to array of 16 bytes of
  11. *                  identifying information
  12. *        ADS *pprev_ads      Pointer to ADS structure in which
  13. *                  to return the value of the interrupt
  14. *                  vector which existed before the ISR
  15. *                  was installed
  16. *        unsigned *ppsp_seg
  17. *                  Pointer to variable in which to put
  18. *                  the segment address of the PSP of the
  19. *                  program containing the ISR.
  20. *
  21. * Description    This function examines the contents of memory pointed to
  22. *        by an interrupt vector to see whether it contains a
  23. *        particular C TOOLS PLUS ISR control block.  If so, the
  24. *        function returns two pieces of information:
  25. *
  26. *            (1) the previous value of the interrupt vector
  27. *            (useful for disabling the ISR); and
  28. *            (2) the segment address of the program segment
  29. *            prefix (PSP) of the program containing the ISR
  30. *            (useful for removing the program if it has
  31. *            terminated but stayed resident).
  32. *
  33. *        This version does NOT trace chains of "cascaded" ISRs.
  34. *        That is, if the ISR pointed to by the interrupt vector
  35. *        is not the desired ISR but merely passes control to the
  36. *        desired ISR, the desired ISR will not be found.
  37. *
  38. *  Returns    ercode          The return code is 0 if the vector is
  39. *                  is successfully set; other values are:
  40. *                  1 - Not found
  41. *                  2 - Interrupt type out of range
  42. *
  43. *  Version    3.0  (C)Copyright Blaise Computing Inc.  1986
  44. *
  45. * Version    3.02 March 24, 1987
  46. *        Removed two strong typing warnings (no change in object
  47. *            code).
  48. *
  49. **/
  50.  
  51. #include <bisr.h>
  52.  
  53. #if LAT300
  54. #include <stdlib.h>
  55. #endif
  56. #if MSC300
  57. #include <memory.h>
  58. #endif
  59.  
  60. #define  FOUND          0           /* Return codes              */
  61. #define  NOT_FOUND    1
  62. #define  BAD_INTYPE   2
  63.  
  64. int isdetect(intype,pident,pprev_ads,ppsp_seg)
  65. int     intype;
  66. char     *pident;
  67. ADS     *pprev_ads;
  68. unsigned *ppsp_seg;
  69. {
  70.     ADS  vector;              /* Pointer to various parts of  */
  71.                       /* possible ISRCTRL structure.  */
  72.     char scratch[16];              /* Local copy of pieces of the  */
  73.                       /* structure.              */
  74.     ADS  scratch_ads;              /* Physical address of scratch[]*/
  75.                       /* or of *pprev_ads or *ppsp_seg*/
  76.     unsigned signature;
  77.  
  78.     if (isretvec(intype,&vector))
  79.     return BAD_INTYPE;
  80.  
  81.     /* If this vector points to a C TOOLS PLUS Interrupt Service      */
  82.     /* Routine, then the actual item pointed to is at offset          */
  83.     /* ISR_ENTRY_OFFSET in an ISRCTRL structure.              */
  84.  
  85.     /* Check for signature word in ISRCTRL structure.              */
  86.  
  87.     vector.r += ICB_SGN_OFFSET - ICB_ENTRY_OFFSET;
  88.     utabsptr(scratch,&scratch_ads);
  89.     utslmove(&vector,&scratch_ads,2);
  90.     signature = ICB_SIGNATURE;
  91.     if (memcmp(scratch,(char *) &signature,sizeof(signature)))
  92.     return NOT_FOUND;
  93.  
  94.     /* Confirm signature by checking its two's-complement.            */
  95.  
  96.     vector.r += ICB_S2_OFFSET - ICB_SGN_OFFSET;
  97.     utslmove(&vector,&scratch_ads,2);
  98.     signature = ~signature;
  99.     if (memcmp(scratch,(char *) &signature,sizeof(signature)))
  100.     return NOT_FOUND;
  101.  
  102.     /* Check identifying "string".                                    */
  103.  
  104.     vector.r += ICB_IDENT_OFFSET - ICB_S2_OFFSET;
  105.     utslmove(&vector,&scratch_ads,16);
  106.     if (memcmp(scratch,pident,16))
  107.     return NOT_FOUND;
  108.  
  109.     /* Fall through:  all tests passed, this is the desired ISR.      */
  110.  
  111.     /* Extract previous vector contents.                  */
  112.  
  113.     vector.r += (unsigned) (ICB_PREV_OFFSET - ICB_IDENT_OFFSET);
  114.     utabsptr((char *) pprev_ads,&scratch_ads);
  115.     utslmove(&vector,&scratch_ads,sizeof(*pprev_ads));
  116.  
  117.     /* Extract PSP of program containing ISR.                  */
  118.  
  119.     vector.r += (unsigned) (ICB_PSP_OFFSET - ICB_PREV_OFFSET);
  120.     utabsptr((char *) ppsp_seg,&scratch_ads);
  121.     utslmove(&vector,&scratch_ads,sizeof(*ppsp_seg));
  122.  
  123.     return FOUND;
  124. }
  125.