/*static char *SCCSID = "@(#)vdmmasrt.c 6.1 90/11/17";*/

#define SCCSID "@(#)vdmmasrt.c 13.5 90/07/29"

/*
 *      IBM/Microsoft Confidential
 *
 *      Copyright (c) IBM Corporation 1987, 1989
 *      Copyright (c) Microsoft Corporation 1987, 1989
 *
 *      All Rights Reserved
 *
 *  Author:
 *      Sudeep Bharati
 *      (c) 1988,1989
 *      Microsoft Corporation
 *
 *  Exported Routines:
 *      VDHAssertInitOnly
 *      VDHAssertTask
 *      VDHAssertVDMTask
 *      VDHAssertTaskOnly
 *      VDHAssertVDMTaskOnly
 *      VDHCheckHVDM
 *
 *  Imported Routines:
 *
 *  Important:
 *      These assertions are used as follows:
 *
 *      CALLING CONTEXT                   ASSERTION NEEDED
 *
 *  1.  INIT ONLY                         VDHAssertInitOnly
 *  2.  VDM TASK (Excluding INIT time)    VDHAssertVDMOnly
 *  3.  VDM TASK (Including INIT time)    VDHAssertVDM
 *  4.  ANY TASK (Excluding INIT time)    VDHAssertTaskOnly
 *  5.  ANY TASK (Including INIT time)    VDHAssertTask
 *  6.  INTERRUPT TIME                    None
 */
#define FNO_NUM  FNO_VDMMASRT_C
#include <fnomvdm.h>

#define VDDSTRICT
#define INCL_NONE
#define INCL_VDH

#include <vdmvdh.h>


extern LONG     InterruptLevel;      // Interrupt level
extern BOOL     fIsInitTime;

extern ULONG            vdmid_VDMSIG;   // HVDM signature

// #pragma BEGIN_MVDM_GLOBAL_CODE
//tw
#pragma BEGIN_MVDM_SWAP_CODE

/***LP+ VDHAssertInitOnly - check if it is mvdm init time
 *
 *  ENTRY   None
 *  EXIT    SUCCESS None
 *          FAILURE Panics if not init time
 *
 */

VOID PRIVENTRY VDHAssertInitOnly()
/*end*/
{

if(fIsInitTime == FALSE)
    Panic(("Init Time Only"));
else
    return;
}

/***LP+ VDHAssertTask - check if it is task time
 *
 *  ENTRY   None
 *  EXIT    SUCCESS None
 *          FAILURE Panics if not task time
 */

VOID PRIVENTRY VDHAssertTask()
/*end*/
{

if(InterruptLevel == -1 || fIsInitTime == TRUE)
    return;
else
    Panic(("Task Time"));
}

/***LP+ VDHAssertVDMTask - check if it is vdm task time
 *
 *  ENTRY   None
 *  EXIT    SUCCESS None
 *          FAILURE Panics if not vdm task time
 */

VOID PRIVENTRY VDHAssertVDMTask()
/*end*/
{

if(fIsInitTime == TRUE || (InterruptLevel == -1 &&
                     pPTDACur->ptda_infoseg.LIS_ProcType == LIS_PT_REALMODE))
    return;
else
    Panic(("VDM Task Time"));
}

/***LP+ VDHAssertTaskOnly - check if it is task time
 *
 *  ENTRY   None
 *  EXIT    SUCCESS None
 *          FAILURE Panics if not task time
 */

VOID PRIVENTRY VDHAssertTaskOnly()
/*end*/
{

if(InterruptLevel != -1)
    Panic(("Task Time Only"));
else
    return;
}

/***LP+ VDHAssertVDMTaskOnly - check if it is vdm task time
 *
 *  ENTRY   None
 *  EXIT    SUCCESS None
 *          FAILURE Panics if not vdm task time
 */

VOID PRIVENTRY VDHAssertVDMTaskOnly()
/*end*/
{

if(InterruptLevel == -1 &&
                  pPTDACur->ptda_infoseg.LIS_ProcType == LIS_PT_REALMODE)
    return;
else
    Panic(("VDM Task Time Only"));
}

/***LP+ VDHCheckHVDM - check if vdm handle is valid
 *
 *  ENTRY   hvdm - hvdm to validate
 *
 *  EXIT    SUCCESS None
 *          FAILURE Panics if hvdm is invalid
 *
 *  NOTE
 *          Instead of panicking with an informative message,
 *          we may instead encounter a page fault when we attempt
 *          to access vdmid_VDMSIG.
 *
 */

VOID PRIVENTRY VDHCheckHVDM(hvdm)
HVDM    hvdm;
/*end*/
{
if(hvdm == 0 && (pPTDACur->ptda_infoseg.LIS_ProcType != LIS_PT_REALMODE))
    Panic(("HVDM Passed 0 in Non VDM context"));

// IF YOU GET A PANIC ON THIS LINE SYAING PAGE FAULT OR SOMETHING
// LIKE THAT DONT PANIC. INSTEAD OF PUTTING UP A MESSAGE AND THEN
// SHUTTING DOWN THE SYSTEM WE HAVE LEFT IT TO PANIC AS IT IS. IT
// CHECKS AN INVALID HVDM USING THAT HVDM ITSELF.

else if (REFHVDM(hvdm,ULONG,vdmid_VDMSIG) != HVDM_SIGNATURE)
    Panic(("Invalid HVDM"));

return;
}

// #pragma END_MVDM_GLOBAL_CODE
// tw
