home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / msc7.zip / EXCEPTIO.H < prev    next >
C/C++ Source or Header  |  1992-02-13  |  2KB  |  73 lines

  1. //
  2. // (c) Copyright 1992, Qualitas, Inc. All Rights Reserved
  3. //
  4. // exception.h - header for ExceptionHandler class 
  5. //
  6. // The ExceptionHandler class allows easy creation of handlers for
  7. // processor exceptions under DPMI.  The exception frame structure,
  8. // excFrame, is passed in as an argument, and its fields may be
  9. // modified by the handler.  In addition, a structure containing the 
  10. // register state at time of the exception is passed in as an argument, 
  11. // and its fields may be read and modified, except for the fields
  12. // which correspond to fields in the exception frame (namely cs, ip, 
  13. // ss, sp, and flags).
  14. //
  15. // The constructor hooks the requested exception and maintains the
  16. // previous value of the exception vector.  The destructor unhooks
  17. // the vector, restoring it to the previous value.
  18. //
  19. // The class library provides exception dispatching so that DS==SS when
  20. // the handler executes.
  21. //
  22. // Do not declare static ExceptionHandlers, because the processor
  23. // is not running in protected mode at start up time.  It is recommended
  24. // to declare a static ExceptionHandler*, and initialize it by dynamically
  25. // creating an ExceptionHandler with the new operator.
  26. //
  27. // Example:
  28. //
  29. //    #include "dpmihost.h"
  30. //    #include "exception.h"
  31. //        
  32. //    . . .
  33. //
  34. //    ExceptionHandler* pGP;
  35. //
  36. //    void myGPhandler(dpmiRegs_t dRegs, excFrame ef)
  37. //    {
  38. //
  39. //        cout << hex << "General protection fault at " << ef.excCS 
  40. //             << ":" << ef.excIP "\n";
  41. //
  42. //        . . . body of handler . . .
  43. //
  44. //    }
  45. //
  46. //    void main(void)
  47. //    {
  48. //        . . . normal enter protected mode calls . . .
  49. //            
  50. //        pGP = new ExceptionHandler(0xD, myGPhandler);
  51. //
  52. //        . . .
  53. //            
  54. //        delete pGP;
  55. //    }
  56. //
  57.  
  58. #include "dpmi.h"
  59.  
  60. class ExceptionHandler 
  61. {
  62. public:
  63.     ExceptionHandler(uChar ord, void (*handler)(dpmiRegs_t, excFrame));
  64.     ~ExceptionHandler(void);
  65.  
  66.     void callPrevious(dpmiRegs_t&, excFrame&);
  67.  
  68. protected:
  69.     uChar ordinal;
  70.     void far* previousVector;
  71.     void (*prevDispatch)(dpmiRegs_t, excFrame);
  72. };
  73.