home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 5.ddi / CLIBSRC2.ZIP / CHAININT.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  2.9 KB  |  83 lines

  1. ;[]-----------------------------------------------------------------[]
  2. ;|      chainint.asm                                                 |
  3. ;[]-----------------------------------------------------------------[]
  4.  
  5. ;
  6. ;       C/C++ Run Time Library - Version 5.0
  7. ;       Copyright (c) 1991, 1992 by Borland International
  8. ;       All Rights Reserved.
  9.  
  10.         INCLUDE rules.asi
  11.  
  12. ; Name          _chain_intr - chain to another interrupt handler
  13. ;
  14. ; Usage         void _chain_intr (void interrupt (far *target)());
  15. ;
  16. ; Description   _chain_intr passes control from one interrupt
  17. ;               handler to another.  The current register set
  18. ;               is NOT passed to the new handler.  Instead,
  19. ;               the new handler receives the registers that
  20. ;               were stacked (and possibly modified in the stack)
  21. ;               by the old handler.  The new handler can simply
  22. ;               return, as if it were the original handler.
  23. ;               The old handler is not entered again.
  24. ;
  25. ; Return value  This function does not return.
  26. ;
  27. ; This function is always called by a C interrupt function, so the
  28. ; stack now looks like this (high address at top, low at bottom):
  29. ;
  30. ;       FLAGS
  31. ;       CS
  32. ;       IP
  33. ;       AX
  34. ;       BX
  35. ;       CX
  36. ;       DX
  37. ;       ES
  38. ;       DS
  39. ;       SI
  40. ;       DI
  41. ; BP->  BP
  42. ;       target (low word)
  43. ;       target (high word)
  44. ;       return address (low word)
  45. ; SP->  return address (high word -- only present in large code models)
  46. ;
  47. ; To chain to "target" (the new interrupt handler), we poke the target
  48. ; address into the stack where AX and BX were saved (after loading
  49. ; AX and BX directly from the stack).  Then we pop all registers up
  50. ; to where "target" was poked in, and execute a far return.  This
  51. ; causes execution to start at "target" with only the CS, IP, and flags
  52. ; on the stack, exactly as if an interrupt had just occurred.
  53.  
  54.                 Code_Seg@
  55.  
  56. PubProc@        _chain_intr, __CDECL__
  57.  
  58.                 pop     ax              ; discard return address
  59. IF LPROG
  60.                 pop     ax              ; discard high word of return address
  61. ENDIF
  62.                 mov     bx,[bp+14]      ; restore stacked BX
  63.                 mov     ax,[bp+16]      ; restore stacked AX
  64.                 pop     [bp+14]         ; pop target address into stack
  65.                 pop     [bp+16]         ;  in place of stacked AX:BX
  66.                 mov     sp,bp           ; point SP at stacked registers
  67.                 pop     bp              ; restore all other stacked registers
  68.                 pop     di
  69.                 pop     si
  70.                 pop     ds
  71.                 pop     es
  72.                 pop     dx
  73.                 pop     cx
  74.                 cli                     ; disable interrupts
  75.                 retf                    ; "return" to target
  76.  
  77. EndProc@        _chain_intr, __CDECL__
  78.  
  79.                 Code_EndS@
  80.                 END
  81.