home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / ISINSTAL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.9 KB  |  126 lines

  1. /**
  2. *
  3. * Name        isinstal -- Install interrupt service routine
  4. *
  5. * Synopsis    ercode = isinstal(intype,pfunc,pident,pisrblk,pstack,
  6. *                  stksize,stknum);
  7. *
  8. *        int ercode      Error return code:
  9. *                  0 if okay;
  10. *                  1 if intype is outside of 0-255 range
  11. *        int intype      Interrupt type number
  12. *        void cdecl (*pfunc)(ALLREG *,ISRCTRL *,ISRMSG *)
  13. *                  Pointer to interrupt service routine
  14. *        const char *pident
  15. *                  Address of array of 16 bytes of
  16. *                  identifying information
  17. *        ISRCTRL *pisrblk  Pointer to ISR control block
  18. *                  (already allocated)
  19. *        char *pstack      Address of beginning of memory block
  20. *                  to be used for the stack(s) for this ISR
  21. *                  (already allocated)
  22. *        int stksize      Size (in bytes) of one ISR stack
  23. *                  (must be at least 64 bytes).
  24. *        int stknum      Maximum depth of nested invocations of
  25. *                  this ISR (must be at least 1)
  26. *
  27. * Description    ISINSTAL installs an interrupt service routine (ISR) in
  28. *        the interrupt vector of the specified type.  This
  29. *        includes (1) completing all the values in the ISR
  30. *        control block; and (2) storing the address of the ISR
  31. *        control block in the interrupt vector.
  32. *
  33. *        The ISR is in effect (and may be invoked) as soon as
  34. *        operation (2) is complete, i.e., even before ISINSTAL
  35. *        returns to its caller.
  36. *
  37. *        The calling function must allocate space for the ISR
  38. *        control block and pass its address as pisrblk.    This
  39. *        space must be static during the time that the ISR is in
  40. *        use.
  41. *
  42. *        The calling function must also allocate space to be used
  43. *        for the ISR's stack(s).  The address of this space must
  44. *        be passed as pstack.  The space must be at least
  45. *        (stksize*stknum) bytes long.  This space must be static
  46. *        during the time that the ISR is in use.
  47. *
  48. *        The sixteen bytes of identifying information are stored
  49. *        in the ISR control block so that other programs may
  50. *        examine the interrupt vector and detect the presence of
  51. *        this ISR.  (See ISSENSE for an example of this.)
  52. *
  53. * Example    The following code fragment illustrates one way to
  54. *        declare the arguments to ISINSTAL and how to use
  55. *        ISPUTVEC to restore the contents of the interrupt vector
  56. *        when the ISR is no longer in use.
  57. *
  58. *            #include <stdlib.h>
  59. *            #include <bintrupt.h>
  60. *
  61. *            #define MY_INTYPE        0x60
  62. *            #define MY_STK_SIZE     2000
  63. *            #define MY_NUM_STKS        5
  64. *
  65. *            void       my_isr(ALLREG *,ISRCTRL *,ISRMSG *);
  66. *            static ISRCTRL isrblk;
  67. *            char       *pstacks;
  68. *
  69. *            if (NIL == (pstacks = malloc(MY_STK_SIZE*MY_NUM_STKS)))
  70. *            exit(3);
  71. *            isinstal(MY_INTYPE,my_isr,"THIS IS MY ISR.",
  72. *                 &isrblk,pstacks,MY_STK_SIZE,MY_NUM_STKS);
  73. *
  74. *             .......    (Use the ISR.)
  75. *
  76. *            isputvec(intype,isrblk.prev_vec);
  77. *            free(pstacks);
  78. *
  79. * Returns    ercode          The return code is 0 if the vector is
  80. *                  is successfully set; other values are:
  81. *                  1 - Interrupt type out of range
  82. *
  83. * Version    6.00 (C)Copyright Blaise Computing Inc.  1986, 1987, 1989
  84. *
  85. **/
  86.  
  87. #include <dos.h>              /* For getvect(), setvect().    */
  88.  
  89. #include <bintrupt.h>
  90.  
  91. #define  NO_ERROR    0
  92. #define  BAD_INTYPE    1
  93.  
  94. typedef char CHAR16[16];          /* Aid for using utcopy          */
  95.  
  96. int isinstal(intype,pfunc,pident,pisrblk,pstack,stksize,stknum)
  97. int    intype;
  98. void    (*pfunc)(ALLREG *,ISRCTRL *,ISRMSG *);
  99. const char *pident;
  100. ISRCTRL *pisrblk;
  101. char    *pstack;
  102. int    stksize,stknum;
  103. {
  104.     int ints_were_on;
  105.  
  106.     if (utrange(intype,0,255))
  107.     return BAD_INTYPE;
  108.  
  109.     isprep(pfunc,pident,pisrblk,pstack,stksize,stknum);
  110.  
  111.     /* Now load the interrupt vector with the segment and offset      */
  112.     /* address of the ISR control block.                  */
  113.  
  114.     ints_were_on = utintflg(UT_INTOFF);
  115.  
  116.     pisrblk->prev_vec = isgetvec(intype);
  117.     isputvec(intype,((char far *) pisrblk) + ICB_ENTRY_OFFSET);
  118.                       /* Setting the vector completes */
  119.                       /* the installation.          */
  120.  
  121.     if (ints_were_on)
  122.     utintflg(UT_INTON);
  123.  
  124.     return NO_ERROR;
  125. }
  126.