home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 013 / bugslay.zip / EXCEPTIO.PAS < prev    next >
Pascal/Delphi Source File  |  1994-09-29  |  3KB  |  114 lines

  1.  
  2.  
  3. {Exception trap for BugSlay (TM). Traps processor exceptions to give
  4. detailed error reports.
  5.  
  6. Must be seperate from the other functions as the code segment attributes
  7. are different. Handler must be installed by InterruptRegister at startup
  8. and removed with InterruptUnRegister at termination.
  9.  
  10. Rex K. Perkins, 10th February, 1994.
  11.  
  12. ⌐ Copyright Apsley-Bolton Computers, Inc.}
  13.  
  14.  
  15. Unit ExceptionHandler;
  16.  
  17. {$C Fixed Preload Permanent}
  18. {$S-}  {Don't bother to check the stack. We couldn't do anything about it anyway}
  19. {$W-}  {BugSlay does not support Windows stack frames, so turn them off}
  20. {$IfDef VER70}
  21.   {$K-}  {Turn off Smart Callbacks in BP7[.00]}
  22. {$EndIf}
  23.  
  24. Interface
  25.  
  26.   Procedure ExceptionCallback; Export;
  27.     {Exception handler. Install using InterruptRegister}
  28.  
  29. Implementation
  30.  
  31. Uses BugSlayImports;
  32.  
  33. {$IfDef Ver15}  {Local in TPW1.5, default in BPW7}
  34.   {$G+}  {Enable 286 instructions}
  35. {$EndIf}
  36.  
  37.  
  38.   Procedure ExceptionCallback; Assembler;
  39.  
  40.   {Exception handler. Install using InterruptRegister}
  41.  
  42.   Const IntNumOffset=8; {Stack frame adds two bytes to the stack, so sp+6=bp+8}
  43.         SSOffset=$14;
  44.         SPOffset=$12;
  45.         CSOffset=$0E;
  46.         IPOffset=$0C;
  47.  
  48.   Asm
  49.     db $66;pusha    {32 bit prefix=pushad}
  50.  
  51.     push es
  52.  
  53.     mov ax,[bp+IntNumOffset]  {Get the Exception number}
  54.  
  55.     cmp ax,$0100    {Don't process Ctrl-Alt-SysReq interrupts (IntNum=$0100)}
  56.     jz @DoNotProcess
  57.     cmp ax,$01  {Breakpoint. Don't process}
  58.     jz @DoNotProcess
  59.     cmp ax,$03  {Breakpoint. Don't process}
  60.     jz @DoNotProcess
  61.  
  62.     mov bx,ss
  63.       {If a low-stack error occured, the MSb of ax will be set, the
  64.        SS on error is at [bp+SSOffset] and SS will be one supplied by
  65.        the DPMI host [Windows]}
  66.     cmp ah,$80  {SS parameter present?}
  67.     jnz @NoStackParam
  68.     mov bx,[bp+SSOffset]
  69.    @NoStackParam:    {We now have the SS on error in BX, regardless of a stack switch}
  70.  
  71.     mov cx,ds
  72.     cmp bx,cx        {Was/Is our task running?}
  73.     jnz @DoNotProcess  {No, OldSS<>DS so don't process exception}
  74.  
  75.                {Set up the stack for a call to the Pascal handler}
  76.     push ax    {Param: ErrorNumber}
  77.     mov bx,[bp+CSOffset]    {this is a selector. Is it valid?}
  78.     lsl cx,bx
  79.     jnz @SelectorNotValid
  80.     push bx     {Param: FaultCS; yes}
  81.     jmp @GotCS
  82.  
  83.   @SelectorNotValid:    {The CS is not valid, so push a nil selector}
  84.     push 0      {Param: FaultCS}
  85.  
  86.   @GotCS:
  87.     mov bx,[bp+IPOffset]
  88.     push bx     {Param: FaultIP}
  89.  
  90.     mov bx,[bp]  {Get stack frame when error occured. Pushed on this stack by the prolog code}
  91.     push bx   {Param BP}
  92.     and ax,$8000    {If high bit is set, SS and SP are present on the stack frame}
  93.     jnz @HasStackInfo
  94.     push SS      {Param: FaultSS; no stack info. Push SS...}
  95.     push SP      {Param: FaultSP; ...and SP}
  96.     jmp @StackSetup
  97.  
  98.   @HasStackInfo:    {This is a stack low fault. Get the stack details}
  99.     mov ax,[bp+SSOffset]
  100.     push ax     {Param: FaultSS}
  101.     mov ax,[bp+SPOffset]
  102.     push ax     {Param: FaultSP}
  103.   @StackSetup:
  104.  
  105.     push HeapList  {Param: AppHeapList}
  106.     Call BugSlayImports.HandleException
  107.  
  108.   @DoNotProcess:
  109.     pop es
  110.     db $66;popa    {32 bit prefix=popad}
  111.   End;
  112.  
  113. End.
  114.