;[]-----------------------------------------------------------------[]
;|      STACK.ASM -- stack overflow handler                          |
;[]-----------------------------------------------------------------[]

;
;       C/C++ Run Time Library - Version 6.0
; 
;       Copyright (c) 1987, 1993 by Borland International
;       All Rights Reserved.
; 

; calls to this routine are generated by the compiler when
; stack overflow is detected.

        INCLUDE RULES.ASI

_TEXT   SEGMENT BYTE PUBLIC 'CODE'
        ASSUME  CS:_TEXT

extrn   __exit:near

        public  F_OVERFLOW@
        public  N_OVERFLOW@
        public  OVERFLOW@

message db      'Stack overflow!',13,10,'$'
N_OVERFLOW@:
F_OVERFLOW@:
OVERFLOW@:
        mov     bx,ds                   ; save DS
        mov     ax,cs
        mov     ds,ax                   ; Print the message.
        mov     dx,offset message
        mov     ah,9
        int     21h
        mov     ds,bx                   ; restore DS
;
; We can't just terminate the program here because it might die owning
; interrupt vectors that startup took for the signals and divide by zero.
; The clean way out is through _exit() who puts all that stuff back.
;
; Hopefully the program hasn't gone so berserk so that _exit() restores
; invalid stuff.  We have a real "lose-lose" situation here....
; In the case of a 'nice' stack overrun we're doing the right thing though.
;
        jmp    __exit                   ; This is a one-way trip!
_TEXT   ENDS
        END

