home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / BIN / TESTTERM.C < prev    next >
C/C++ Source or Header  |  1996-06-17  |  2KB  |  83 lines

  1. // TESTTERM.C
  2. // Demonstrates new API functions UserErrTerm and SetDump
  3. // Requires _MAYDAY.C support module
  4. // Compile as register-based, stack-checking turned off for _MAYDAY.C
  5. // Link via: WLINK system causeway file testterm,_mayday
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <i86.h>
  10.  
  11. struct InfoListStruct {
  12.     unsigned int ebp;
  13.     unsigned int edi;
  14.     unsigned int esi;
  15.     unsigned int edx;
  16.     unsigned int ecx;
  17.     unsigned int ebx;
  18.     unsigned int eax;
  19.     short unsigned int gs;
  20.     short unsigned int fs;
  21.     short unsigned int es;
  22.     short unsigned int ds;
  23.     unsigned int eip;
  24.     short unsigned int cs;
  25.     short unsigned int reserved1;
  26.     unsigned int eflags;
  27.     unsigned int esp;
  28.     short unsigned int ss;
  29.     short unsigned int reserved2;
  30.     short unsigned int tr;
  31.     unsigned int cr0;
  32.     unsigned int cr1;
  33.     unsigned int cr2;
  34.     unsigned int    cr3;
  35.     unsigned int csAddr;
  36.     unsigned int dsAddr;
  37.     unsigned int esAddr;
  38.     unsigned int fsAddr;
  39.     unsigned int gsAddr;
  40.     unsigned int ssAddr;
  41.     short unsigned int Exception;
  42.     unsigned int Code;
  43. };
  44.  
  45. extern struct InfoListStruct InfoList;
  46.  
  47. void far __loadds Mayday(void);
  48.  
  49. int main(void)
  50. {
  51.     setup();
  52.     croaker();
  53.     return(0);
  54. }
  55.  
  56. // setup the vector to Mayday() routine when croaker() faults
  57. void setup(void)
  58. {
  59.     struct SREGS sregs;
  60.     union REGS regs;
  61.  
  62.     segread(&sregs);
  63.     sregs.ds=FP_SEG(Mayday);    // vector address
  64.     regs.x.esi=FP_OFF(Mayday);
  65.     sregs.es=FP_SEG(&InfoList);    // info dump address
  66.     regs.x.edi=FP_OFF(&InfoList);
  67.     regs.h.cl=1;    // 32-bit routine
  68.     regs.w.ax=0xff31;    // UserErrTerm
  69.     int386x(0x31,®s,®s,&sregs);
  70.     regs.w.ax=0xff30;    // SetDump
  71.     regs.h.cl=0;
  72.     int386(0x31,®s,®s);
  73. }
  74.  
  75. void croaker(void)
  76. {
  77.     int i,peekaboo=0x12345678;
  78.  
  79.     printf("%d ",*(int *)peekaboo);     // if this one doesn't fault,
  80.     peekaboo=0x87654321;                // then
  81.     printf("%d\n",*(int *)peekaboo);    // this one will
  82. }
  83.