home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK7 / SOURCE / STARTUP / WIN / FATAL.AS$ / FATAL
Encoding:
Text File  |  1991-11-06  |  3.5 KB  |  151 lines

  1.     page    ,132
  2.     title     fatal - Fatal error handler (Windows)
  3. ;***
  4. ;fatal.asm - Fatal error handler (Windows)
  5. ;
  6. ;    Copyright (c) 1989-1992, Microsoft Corporation.  All rights reserved.
  7. ;
  8. ;Purpose:
  9. ;    This source contains code that handles fatal C runtime errors
  10. ;    in the Windows models.
  11. ;
  12. ;    NOTE: In the non-windows libs, this code appears in startup.  It
  13. ;    is moved out of win crt0.asm for granularity purposes (Win DLL
  14. ;    users are particularly sensitive to this).
  15. ;
  16. ;*******************************************************************************
  17.  
  18. ?DF=    1            ; this is special for c startup
  19. .xlist
  20. include version.inc
  21. ?PLM = 1
  22. include cmacros.inc
  23. include defsegs.inc
  24. include rterr.inc
  25. .list
  26.  
  27. CrtDefSegs <code, data>
  28. CrtDefSegs <nmsg>
  29.  
  30.  
  31. externFP    <FATALAPPEXIT>    ; Fatal windows exit (term app)
  32. externFP    <FATALEXIT>     ; Fatal windows exit (term all of windows)
  33.  
  34. externP    <__FF_MSGBANNER>    ; Write out standard error header
  35. externP    <__NMSG_WRITE>    ; Write out an error message
  36. externP    <__NMSG_TEXT>    ; Get error text
  37.  
  38. ifdef    SS_NEQ_DGROUP
  39. externP    <__GetDGROUP>    ; Function to recover DGROUP
  40. endif    ;_WINDLL
  41.  
  42.  
  43. sBegin    code
  44. assumes cs,code
  45. assumes ds,data
  46.  
  47. page
  48. ;***
  49. ; _amsg_exit - Fatal error handler
  50. ;
  51. ;Purpose:
  52. ;
  53. ;    _amsg_exit = general runtime error handler
  54. ;    _cintDIV   = integer divide by 0 trap
  55. ;
  56. ;    NOTE:  In windows, this code is tightly tied to how nmsghdr.asm
  57. ;    works.    If you change one, you should look at the other, too.
  58. ;
  59. ;Entry:
  60. ;    _amsg_exit = ax = fatal error number
  61. ;
  62. ;Exit:
  63. ;    Fatal error -- never returns to caller
  64. ;
  65. ;Uses:
  66. ;
  67. ;Exceptions:
  68. ;
  69. ;*******************************************************************************
  70.  
  71. labelNP <PUBLIC,__cintDIV>
  72.  
  73. ifndef    SS_NEQ_DGROUP
  74.     push    ss
  75.     pop    ds            ;set DS = DGROUP
  76. else    ;SS_NEQ_DGROUP
  77.     call    __GetDGROUP
  78.     mov    ds,ax            ;set DS = DGROUP
  79. endif    ;SS_NEQ_DGROUP
  80.  
  81.     ; *** should we flush stream buffers, etc. here?
  82.  
  83.     mov    ax,_RT_INTDIV
  84.     ;jmp     short __amsg_exit    ; <fall thru>
  85.  
  86.  
  87. labelNP <PUBLIC,__amsg_exit>
  88.  
  89. ;
  90. ; write error message to debug screen and get pointer
  91. ; to text for FATALAPPEXIT
  92. ;
  93.     ; <pascal calling convention>
  94.     push    ax            ; for __NMSG_TEXT
  95.     push    ax            ; for __NMST_WRITE
  96.     callcrt __FF_MSGBANNER        ; run-time error message banner
  97.     callcrt __NMSG_WRITE        ; write out error message
  98.     callcrt __NMSG_TEXT        ; ax = * msg or NULL
  99.  
  100.     ; make sure all fatal msgs are short enough for FATALAPPEXIT
  101.     .ERRE    (_RT_MAXTXTLEN LE 35)
  102.  
  103.  ;
  104.  ; Set up the message for FATALAPPEXIT
  105.  ;
  106.  
  107.     xor    bx,bx            ; bx = 0
  108.     or    ax,ax            ; is ptr 0?
  109.     jz    killapp         ; jump, if so
  110.  
  111.     mov    di,ax            ; di = ptr to start of string
  112.     mov    ax,_RT_STANDARD_STRING    ; assume "R6???" message
  113.     cmp    byte ptr [di],_RT_MATH_STARTCHAR ; message start with "M" ??
  114.     jne    @F            ; jump, if not
  115.     mov    ax,_RT_MATH_STRING    ; "M6???" message
  116. @@:
  117.     add    di,ax            ; step over "?6???" portion of msg
  118.     push    di            ; save ptr to start of string
  119.  
  120.     push    ds
  121.     pop    es            ; es:di = *message
  122.     mov    al,_RT_STANDARD_ENDCHAR ; al = char after string
  123.     mov    cx,_RT_MAXTXTLEN    ; max length of a fatal string
  124.     repne    scasb            ; find end of string
  125.     ; don't worry about cx=0 case
  126.     mov    [di-1],bl        ; store a final null
  127.     pop    ax            ; ax = ptr to string
  128.  
  129. ;
  130. ; kill the app
  131. ; ax = ptr to string (or 0)
  132. ; bx = 0
  133. ;
  134.  
  135. killapp:
  136.     push    bx            ; action code = 0
  137.     push    ds
  138.     push    ax            ; ds:ax = * fatal message
  139.     call    FATALAPPEXIT        ; term app
  140.     ;*** NORMALLY DOESN'T RETURN ***
  141.  
  142.     mov    ax,255
  143.     push    ax            ; error code
  144.     call    FATALEXIT        ; term windows
  145.     ;*** NEVER RETURNS ***
  146.  
  147.  
  148. sEnd    code
  149.  
  150.     end
  151.