/*      SCCSID = @(#)dc1mmph.h	6.3 92/03/04
/****************************************************************************/
/*                                                                          */
/*                       IBM/Microsoft Confidential                         */
/*                                                                          */
/*                 Copyright (c) IBM Corporation  1987, 1990                */
/*                 Copyright (c) Microsoft Corp.  1987, 1990                */
/*                           All Rights Reserved                            */
/*                                                                          */
/****************************************************************************/
/*                                        */
/*  MMPH DOSCALL1.DLL macro include file  */
/*                                        */
/*  GDW  3/03/92 PTR AA04704  DosLogRegister MMIOPH TRAPS when MMIOAddr field */
/*                            in GlobalInfo Segment is accessed. This is      */
/*                            because that field is for 32bit callers ONLY.   */

#include <perfhook.h>

#define FP_SEG(fp) (*((unsigned *)&(fp) + 1))
#define FP_OFF(fp) (*((unsigned *)&(fp)))

/***
 *  Public variable used by the doscall1's performance hook macros. This
 *  declaration must reside in this file. Public definition is in INITDC1.ASM
 */
extern unsigned short       globalIS;

/***
 *  Local variable used by the doscall1's performance hook macros. Again these
 *  declaration must be here.
 */
static struct InfoSegGDT *  ISptr;
static unsigned char *      RMT;
static USHORT FAR *         mmio_addr;  /* Addr. of memory mapped I/O buffer */

/***
 *  The following macro is used by all doscall1 performance macros to set
 *  both the "ISptr" pointer to the infoseg structure and the local variable
 *  "RMT" to the major_error_code (mec) table.
 */
#define SETUP_PTRS(infosegp)        \
        if (infosegp==NULL){        \
        FP_SEG(infosegp)=globalIS;  \
        FP_OFF(infosegp)=0;}        \
        RMT = &(infosegp->SIS_mec_table [0]);


/****************************************************************************/
/*                                                                          */
/*      MISCELLANEOUS SERVICES: External Interface  -  Major Code 1Ch       */
/*                                                                          */
/****************************************************************************/

#if defined(MMIOPH)
                                                        /* c16\logcalls.c  */
#define MMPHPreDOSLogRead()                       \
        SETUP_PTRS(ISptr)                         \
        if (TEST_TRACING(RMT,0x1C)){              \
          FP_SEG(mmio_addr)=ISptr->SIS_MMIOBase;  \
          FP_OFF(mmio_addr)=4;                    \
          *mmio_addr = 0x1c07;                    \
        }
/*      SET_DEKKO_ADDRESS2(ISptr)   \ */                /* AA04704         */
/*      WRITE_MAJMNR_CODES (0x1C07) \ */                /* AA04704         */
                                                        /* c16\logcalls.c  */
#define MMPHPreDOSLogRegister()                   \
        SETUP_PTRS(ISptr)                         \
        if (TEST_TRACING(RMT,0x1C)){              \
          FP_SEG(mmio_addr)=ISptr->SIS_MMIOBase;  \
          FP_OFF(mmio_addr)=4;                    \
          *mmio_addr = 0x1c08;                    \
        }
/*      SET_DEKKO_ADDRESS2(ISptr)   \ */                /* AA04704         */
/*      WRITE_MAJMNR_CODES (0x1C08) \ */                /* AA04704         */
                                                        /* except32\apis.c */

#define MMPHPreDOSRaiseException()      PreDOSRaiseException();
#define MMPHPreDOSSetExceptHandler()    PreDOSSetExceptHandler(pHandler);
#define MMPHPreDOSUnsetExceptHandler()  PreDOSUnsetExceptHandler(pHandler);
#define MMPHPreDOSUnwindExceptHandler() PreDOSUnwindExceptHandler(pHandler);

                                                        /* c16\logcalls.c  */
#define MMPHPostDOSLogRead()        \
        if (TEST_TRACING(RMT,0x1C)){\
          *mmio_addr = 0x1c87;      \
        }
/*      SETUP_PTRS(ISptr)           \                   /* AA04704         */
/*      SET_DEKKO_ADDRESS2(ISptr)   \                   /* AA04704         */
/*      WRITE_MAJMNR_CODES (0x1C87) \                   /* AA04704         */
                                                        /* c16\logcalls.c  */
#define MMPHPostDOSLogRegister()    \
        if (TEST_TRACING(RMT,0x1C)){\
          *mmio_addr = 0x1c88;      \
        }
/*      SETUP_PTRS(ISptr)           \ */                /* AA04704         */
/*      SET_DEKKO_ADDRESS2(ISptr)   \ */                /* AA04704         */
/*      WRITE_MAJMNR_CODES (0x1C88) \ */                /* AA04704         */
                                                        /* except32\apis.c */

#define MMPHPostDOSRaiseException()      PostDOSRaiseException(rc);
#define MMPHPostDOSSetExceptHandler()    PostDOSSetExceptHandler();
#define MMPHPostDOSUnsetExceptHandler()  PostDOSUnsetExceptHandler(rc);
#define MMPHPostDOSUnwindExceptHandler() PostDOSUnwindExceptHandler(rc);

#else                                          /* define the null macros for */
                                               /*   non-performance builds   */
#define MMPHPreDOSLogRead()
#define MMPHPostDOSLogRead()

#define MMPHPreDOSLogRegister()
#define MMPHPostDOSLogRegister()

#define MMPHPreDOSRaiseException()
#define MMPHPostDOSRaiseException()

#define MMPHPreDOSSetExceptHandler()
#define MMPHPostDOSSetExceptHandler()

#define MMPHPreDOSUnsetExceptHandler()
#define MMPHPostDOSUnsetExceptHandler()

#define MMPHPreDOSUnwindExceptHandler()
#define MMPHPostDOSUnwindExceptHandler()

#endif

/****************************************************************************/
/*                                                                          */
/*      VIRTUAL MEMORY MGNT: External Interface  -  Major Code 24h          */
/*                                                                          */
/*  The hooks defined in this major type are calls to 32-bit assembly       */
/*  routines. These routines can be found at \drv6\src\doscall1\mmphdc1.asm */
/*                                                                          */
/****************************************************************************/

#if defined(MMIOPH)
                                                        /* c32\msp32.c     */

#define MMPHPreDOS32SubAlloc()      PreDOS32SubAlloc(pHdr,nSize);
#define MMPHPreDOS32SubFree()       PreDOS32SubFree(pHdr,pBlock,nSize);
#define MMPHPreDOS32SubSet()        PreDOS32SubSet(pHdr,fFlags,nSize);
#define MMPHPreDOS32SubUnSet()      PreDOS32SubUnSet();

#define MMPHPostDOS32SubAlloc()     PostDOS32SubAlloc(*ppBlock,rc);
#define MMPHPostDOS32SubFree()      PostDOS32SubFree(rc);
#define MMPHPostDOS32SubSet()       PostDOS32SubSet(rc);
#define MMPHPostDOS32SubUnSet()     PostDOS32SubUnSet();

#else                                          /* define the null macros for */
                                               /*   non-performance builds   */
#define MMPHPreDOS32SubAlloc()
#define MMPHPostDOS32SubAlloc()

#define MMPHPreDOS32SubFree()
#define MMPHPostDOS32SubFree()

#define MMPHPreDOS32SubSet()
#define MMPHPostDOS32SubSet()

#define MMPHPreDOS32SubUnSet()
#define MMPHPostDOS32SubUnSet()

#endif

