home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name isdetect -- Detect an installed interrupt service routine
- *
- * Synopsis result = isdetect(intype,pident,pprev_ads,ppsp_seg);
- *
- * int result Result code: 0 if found, 1 if not found,
- * 2 if intype is outside of 0-255 range.
- * int intype Interrupt type number
- * char *pident Pointer to array of 16 bytes of
- * identifying information
- * ADS *pprev_ads Pointer to ADS structure in which
- * to return the value of the interrupt
- * vector which existed before the ISR
- * was installed
- * unsigned *ppsp_seg
- * Pointer to variable in which to put
- * the segment address of the PSP of the
- * program containing the ISR.
- *
- * Description This function examines the contents of memory pointed to
- * by an interrupt vector to see whether it contains a
- * particular C TOOLS PLUS ISR control block. If so, the
- * function returns two pieces of information:
- *
- * (1) the previous value of the interrupt vector
- * (useful for disabling the ISR); and
- * (2) the segment address of the program segment
- * prefix (PSP) of the program containing the ISR
- * (useful for removing the program if it has
- * terminated but stayed resident).
- *
- * This version does NOT trace chains of "cascaded" ISRs.
- * That is, if the ISR pointed to by the interrupt vector
- * is not the desired ISR but merely passes control to the
- * desired ISR, the desired ISR will not be found.
- *
- * Returns ercode The return code is 0 if the vector is
- * is successfully set; other values are:
- * 1 - Not found
- * 2 - Interrupt type out of range
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- * Version 3.02 March 24, 1987
- * Removed two strong typing warnings (no change in object
- * code).
- *
- **/
-
- #include <bisr.h>
-
- #if LAT300
- #include <stdlib.h>
- #endif
- #if MSC300
- #include <memory.h>
- #endif
-
- #define FOUND 0 /* Return codes */
- #define NOT_FOUND 1
- #define BAD_INTYPE 2
-
- int isdetect(intype,pident,pprev_ads,ppsp_seg)
- int intype;
- char *pident;
- ADS *pprev_ads;
- unsigned *ppsp_seg;
- {
- ADS vector; /* Pointer to various parts of */
- /* possible ISRCTRL structure. */
- char scratch[16]; /* Local copy of pieces of the */
- /* structure. */
- ADS scratch_ads; /* Physical address of scratch[]*/
- /* or of *pprev_ads or *ppsp_seg*/
- unsigned signature;
-
- if (isretvec(intype,&vector))
- return BAD_INTYPE;
-
- /* If this vector points to a C TOOLS PLUS Interrupt Service */
- /* Routine, then the actual item pointed to is at offset */
- /* ISR_ENTRY_OFFSET in an ISRCTRL structure. */
-
- /* Check for signature word in ISRCTRL structure. */
-
- vector.r += ICB_SGN_OFFSET - ICB_ENTRY_OFFSET;
- utabsptr(scratch,&scratch_ads);
- utslmove(&vector,&scratch_ads,2);
- signature = ICB_SIGNATURE;
- if (memcmp(scratch,(char *) &signature,sizeof(signature)))
- return NOT_FOUND;
-
- /* Confirm signature by checking its two's-complement. */
-
- vector.r += ICB_S2_OFFSET - ICB_SGN_OFFSET;
- utslmove(&vector,&scratch_ads,2);
- signature = ~signature;
- if (memcmp(scratch,(char *) &signature,sizeof(signature)))
- return NOT_FOUND;
-
- /* Check identifying "string". */
-
- vector.r += ICB_IDENT_OFFSET - ICB_S2_OFFSET;
- utslmove(&vector,&scratch_ads,16);
- if (memcmp(scratch,pident,16))
- return NOT_FOUND;
-
- /* Fall through: all tests passed, this is the desired ISR. */
-
- /* Extract previous vector contents. */
-
- vector.r += (unsigned) (ICB_PREV_OFFSET - ICB_IDENT_OFFSET);
- utabsptr((char *) pprev_ads,&scratch_ads);
- utslmove(&vector,&scratch_ads,sizeof(*pprev_ads));
-
- /* Extract PSP of program containing ISR. */
-
- vector.r += (unsigned) (ICB_PSP_OFFSET - ICB_PREV_OFFSET);
- utabsptr((char *) ppsp_seg,&scratch_ads);
- utslmove(&vector,&scratch_ads,sizeof(*ppsp_seg));
-
- return FOUND;
- }