home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / CERRINST.ASM < prev    next >
Assembly Source File  |  1997-07-05  |  3KB  |  103 lines

  1. ;  +++Date last modified: 05-Jul-1997
  2.  
  3.         PAGE ,132
  4.  
  5. ;  Install an Interrupt 24 (DOS critical error exception) handler
  6. ;
  7. ;  Public domain by Bob Stout
  8. ;
  9. ;  Requires MASM 5.1 or later or equivalent
  10. ;
  11. ;  Assemble with:       MASM /Mx /z ...
  12. ;                       TASM /jMASM /mx /z ...
  13.  
  14. %       .MODEL  memodel,C               ;Add model support via command
  15.                                         ;line macros, e.g.
  16.                                         ;MASM /Dmemodel=LARGE
  17.  
  18.         .DATA?
  19.  
  20.         PUBLIC cedevdvr, cetype, ceerror, cereturn
  21. _origvec        dd      ?
  22. _newvec         dd      ?
  23. cedevdvr        dd      ?
  24. cetype          dw      ?
  25. ceerror         dw      ?
  26. cereturn        db      ?
  27.  
  28.         .CODE
  29.  
  30. ;
  31. ;  This is our actual ISR
  32. ;
  33. myint24:
  34.         push    ds                      ;save registers which may be
  35.         push    es                      ;required in case "Retry" is
  36.         push    bx                      ;selected
  37.         push    cx
  38.         push    dx
  39.         push    si
  40.         push    di
  41.         push    bp
  42.         mov     word PTR cedevdvr,si    ;save device driver header address
  43.         mov     word PTR cedevdvr+2,bp
  44.         mov     cetype,ax               ;save error type information
  45.         mov     ceerror,di              ;save error code information
  46.         call    far PTR _newvec         ;call our handler
  47.         mov     al,cereturn             ;set up return code (abort, retry...)
  48.         pop     bp                      ;restore necessary registers
  49.         pop     di
  50.         pop     si
  51.         pop     dx
  52.         pop     cx
  53.         pop     bx
  54.         pop     es
  55.         pop     ds
  56.         iret
  57.  
  58. ;
  59. ;  Call this to install  our ISR
  60. ;
  61. ;  void (_far *)() ins24(unsigned short segm, unsigned short offs);
  62. ;  void (_far *)() ins24((void _far *handler)());
  63. ;
  64. ;  Paramters (option 1) - 1 : Segment of handler
  65. ;                         2 : Offset of handler
  66. ;
  67. ;  Paramters (option 2) - 1 : Address of handler
  68. ;
  69. ;  Returns pointer to old handler
  70. ;
  71. ins24   PROC    USES AX BX DS ES, segm:WORD, offs:WORD
  72.         mov     ax,3524h                ;get old vector...
  73.         int     21h
  74.         mov     word PTR _origvec,bx
  75.         mov     word PTR _origvec+2,es  ;...and save it
  76.         mov     ax,offs                 ;load handler offset...
  77.         mov     word PTR _newvec,ax
  78.         mov     ax,segm                 ; & segment into _newvec
  79.         mov     word PTR _newvec+2,ax
  80.         push    cs                      ;get myint24 segment in DS
  81.         pop     ds
  82.         mov     dx, OFFSET myint24      ;install myint24 in int 24h
  83.         mov     ax,2524h                ;  into Interrupt 24h
  84.         int     21h
  85.         mov     ax,word PTR _origvec
  86.         mov     dx,word PTR _origvec+2
  87. ins24   ENDP
  88.  
  89. ;
  90. ;  Call this to uninstall our ISR
  91. ;
  92. ;  void redo24(void);
  93. ;
  94. redo24  PROC    USES AX BX DS
  95.         mov     dx, word PTR _origvec   ;restore original vector
  96.         mov     ds, word PTR _origvec+2
  97.         mov     ax,2524h
  98.         int     21h
  99.         ret
  100. redo24  ENDP
  101.  
  102.         end
  103.