home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / msdos / programm / 8582 < prev    next >
Encoding:
Text File  |  1992-08-17  |  2.3 KB  |  53 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!cs.utexas.edu!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
  3. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  4. Subject: Re: Why can't I hook INT 21h???
  5. Message-ID: <dmurdoch.46.714083466@mast.queensu.ca>
  6. Lines: 41
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University
  9. References: <14339@mindlink.bc.ca> <eoq.25.0@vthnw.cvm.msu.edu>
  10. Date: Mon, 17 Aug 1992 20:31:06 GMT
  11.  
  12. In article <eoq.25.0@vthnw.cvm.msu.edu> eoq@vthnw.cvm.msu.edu (Edward Quillen) writes:
  13. >In article <14339@mindlink.bc.ca> Charlie_Hutchins@mindlink.bc.ca (Charlie Hutchins) writes:
  14. >>Okay, maybe someone could help me here.  I am trying to write a TSR
  15. >>that hooks interrupt 21h but whenever I try and hook that vector I
  16. >>get an invalid command.com error and my system crashes.  
  17.  
  18. >>void interrupt new21handler(void)
  19. >>{
  20. >>        (old21handler)();
  21. >>}
  22. >>
  23. >Please post replies to this ? because I've always wanted to hook INT 21h
  24. >but have never been able to. Thanks!!!
  25.  
  26. This is the wrong way to intercept a service interrupt.  Service interrupts 
  27. take arguments in the registers (and sometimes on the stack, but no INT 
  28. 21h interrupts do this) and return results in the registers (and sometimes 
  29. on the stack).  
  30.  
  31. The new21handler above probably changes the values in several registers
  32. before the call, so it'll pass the wrong request to the old handler.  It 
  33. restores the old register values from the stack when it returns; this wipes 
  34. out the result from the service.
  35.  
  36. Intercepting service interrupts is tricky.  I've no idea how to do it in C, 
  37. but the basic idea is the following:
  38.  
  39.   1.  On entry, save the registers, and do any preprocessing.
  40.   2.  Restore the registers; if necessary, restore the stack; call the
  41.       old handler.  Note that if parameters are being passed on the stack,
  42.       you need to do some fiddling here to do the call without messing
  43.       up the stack frame.
  44.   3.  When the old handler returns, save the registers, and do any
  45.       postprocessing.
  46.   4.  Restore the returned register values, and return to the original 
  47.       caller.  You have to handle this return carefully:  use RETF 2, not
  48.       IRET.  Otherwise, you'll lose any status information being returned
  49.       in the flags.  
  50.  
  51. Duncan Murdoch
  52. dmurdoch@mast.queensu.ca
  53.