;       SCCSID = @(#)initmac.inc        6.1 90/11/17
;      SCCSID = @(#)initmac.inc 1.7 90/09/17
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************

        ReferGDT        GDT_MSSTACK,WORD

        extrn           MSSTACKSIZE:ABS

;includes for inisifs.asm and fshelper.asm


RM      macro   SPsavereg,SSsavereg
        mov     SSsavereg,SS    ;switch stacks
        mov     SPsavereg,SP
;;      cli                     ;disable interrupts during stack switch
        push    GSEL GDT_MSSTACK        ; switch to mode switch stack
        pop     SS
        mov     sp,MSSTACKSIZE          ; SS:SP -> top of mode switch stack
        pushf
        push    eax
        push    ecx
        push    edx
        push    ds
        FlatContext     ds,ax,NOASSUME
        CALL32  _TKSetSSBase,nocheck
        pop     ds
        pop     edx
        pop     ecx
        pop     eax
        popf
        push    SSsavereg       ;save ss:sp for return to PM
        push    SPsavereg
        call    RealModeIC      ;switch to real mode
        endm

PM      macro   tempreg
        call    ProtModeIC
        pop     tempreg         ;restore ss:sp
;;      cli                     ;disable interrupts during stack switch
        pop     SS
        mov     SP,tempreg
        pushf
        push    eax
        push    ecx
        push    edx
        push    ds
        FlatContext     ds,ax,NOASSUME
        CALL32  _TKSetSSBase,nocheck
        pop     ds
        pop     edx
        pop     ecx
        pop     eax
        popf
        endm

