home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / EXAMPLES / MSC / CRITHAND.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-01-08  |  2.8 KB  |  124 lines

  1. ;    crithand.asm - Critical error handler
  2. ;
  3. ;************************************************************************/
  4. ;*    Copyright (C) 1986-1993 Phar Lap Software, Inc.            */
  5. ;*    Unpublished - rights reserved under the Copyright Laws of the    */
  6. ;*    United States.  Use, duplication, or disclosure by the         */
  7. ;*    Government is subject to restrictions as set forth in         */
  8. ;*    subparagraph (c)(1)(ii) of the Rights in Technical Data and     */
  9. ;*    Computer Software clause at 252.227-7013.            */
  10. ;*    Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138    */
  11. ;************************************************************************/
  12.  
  13. .twocase
  14. include dosx.ah
  15.  
  16. _TEXT segment public byte use32 'CODE'
  17.     extrn    _ProcessCritErr:near
  18. _TEXT ends
  19.  
  20. _DATA segment public dword 'DATA'
  21.     extrn    _DSReg:word,_ESReg:word,_FSReg:word,_GSReg:word
  22. ;
  23. ; 8K stack for use by critical error handler
  24. ;
  25.     align    4
  26.     db    2000h dup (?)    
  27. ProtTopOfStack label dword
  28.  
  29. _DATA ends
  30.  
  31.     assume    cs:_TEXT,ds:nothing
  32. _TEXT segment
  33. ;
  34. ; void CritErrHand()
  35. ;
  36. ; Sets up a valid C stack, and calls a C routine to process the critical
  37. ; error.
  38. ;
  39.     public    _CritErrHand
  40. _CritErrHand proc    far
  41. ;
  42. ; Stack frame
  43. ;
  44. #EAX    equ    (dword ptr [ebp-4])    ; Original EAX value
  45.  
  46.     sti                ; enable interrupts
  47.     push    ebp            ; set up frame pointer
  48.     mov    ebp,esp                ;
  49.     push    eax            ; save all regs
  50.     push    ebx                ;
  51.     push    ecx                ;
  52.     push    edx                ;
  53.     push    esi                ;
  54.     push    edi                ;
  55.     push    ds                ;
  56.     push    es                ;
  57.     push    fs                ;
  58.     push    gs                ;
  59.  
  60. ;
  61. ; Set seg regs to our protected mode values
  62. ; We'll use the fact that CS and DS are aliases when loading DS.
  63. ;
  64.     mov    ds,cs:_DSReg
  65.     assume    ds:_DATA
  66.     mov    es,_ESReg
  67.     mov    ax,_FSReg
  68.     mov    fs,ax
  69.     mov    ax,_GSReg
  70.     mov    gs,ax
  71.  
  72. ;
  73. ; Make sure Direction Flag is clear for C code
  74. ;
  75.     cld
  76.  
  77. ;
  78. ; Switch stacks, and call our C critical error handler.  We just use
  79. ; a hardcoded stack buffer here, which makes this handler non-reentrant.
  80. ; That's OK, because a critical error handler isn't allowed to call any
  81. ; DOS functions that could cause a second critical error.
  82. ;
  83. ; The C handler returns the desired action code in EAX
  84. ;
  85.     mov    ecx,esp            ; save current stack & interrupt stack
  86.     mov    dx,ss                ; frame
  87.     mov    esi,ebp                ;
  88.     add    esi,4                ;
  89.     mov    ax,ds            ; switch to new stack
  90.     lea    ebx,ProtTopOfStack        ;
  91.     mov    ss,ax                ;
  92.     mov    esp,ebx                ;
  93.     push    edx            ; save old stack pointer
  94.     push    ecx                ;
  95.     push    edx            ; call C critical error handler
  96.     push    esi                ;
  97.     call    _ProcessCritErr            ;
  98.     add    esp,8                ;
  99.     lss    esp,[esp]        ; switch back to old stack
  100.     mov    byte ptr #EAX,al    ; return action code in AL
  101.  
  102. #exit:
  103. ;
  104. ; Restore regs and return
  105. ;
  106.     pop    gs            ; restore regs 
  107.     pop    fs                ;
  108.     pop    es                ;
  109.     pop    ds                ;
  110.     pop    edi                ;
  111.     pop    esi                ;
  112.     pop    edx                ;
  113.     pop    ecx                ;
  114.     pop    ebx                ;
  115.     pop    eax                ;
  116.     mov    esp,ebp            ; restore stack frame & exit
  117.     pop    ebp                ;
  118.     iretd                    ;
  119. _CritErrHand endp
  120.  
  121. _TEXT ends
  122.  
  123. end
  124.