/*static char *SCCSID = "@(#)exmg.h     6.5 92/01/23";*/

/*
 *      Exceptions - Kernel Thread Exception Routines
 *
 *      This is an OS/2 2.x specific file
 *      IBM/Microsoft Confidential
 *
 *      Copyright (c) Microsoft Corporation 1987, 1989
 *      Copyright (c) IBM Corporation 1987, 1989
 *
 *      All Rights Reserved
 *
 *      Re-Created: April 1990 - Kyle Peltonen
 *
 *      This file provides contains local kernel/dispatcher definitions.
 */

/*
 * Local types
 */

struct _FPENV {
   ULONG   fpenv_Control;       /* Control Word */
   ULONG   fpenv_Status;        /* Status Word */
   ULONG   fpenv_Tag;           /* Tag Word */
   ULONG   fpenv_EIP;           /* Instruction Offset */
   USHORT  fpenv_OpCode;        /* Instruction OpCode */
   USHORT  fpenv_CS;            /* Instruction CS     */
   ULONG   fpenv_DataOffset;    /* Data Offset */
   ULONG   fpenv_DataSel;       /* Data selector */
};

typedef struct _FPENV FPENV;
typedef struct _FPENV *PFPENV;

struct _FPSTATE {
   FPENV   fpstate_env;
   FPREG   fpstate_stack[8];
};
typedef struct _FPSTATE FPSTATE;
typedef struct _FPSTATE *PFPSTATE;

/*
 * Ring 3 stack image.
 */
#define LOCALVARSPACE 128

struct _R3XcptStackImage {             /* top of R3 stack               */
   VOID * ReturnAddr;                  /* return address (place holder) */
   ULONG TrapNumber;                   /* Trap Number                   */
   PEXCEPTIONREPORTRECORD pERepRec;    /* Exception Dispatcher Argument */
   PCONTEXTRECORD pContext;            /* Exception Dispatcher Argument */
   EXCEPTIONREPORTRECORD ERepRec;      /* Exception Report Record       */
   CONTEXTRECORD Context;              /* Context Record                */
};
typedef struct _R3XcptStackImage R3XCPTSTACK;

/*
 * Procedure definitions
 */

/* XLATOFF */
extern ULONG XCPTCheckExceptionHandler(PTCB ptcb);

extern ULONG xcptExceptionCallBack(ULONG ulTrapNumber,
                           PEXCEPTIONREPORTRECORD pERepRec,
                           PCONTEXTRECORD pContext,
                           PEXCEPTIONREPORTRECORD pR0ERepRec,
                           PCONTEXTRECORD pR0Context,
                           ULONG ulDisposition);

extern ULONG xcptCopyinXcptStruct(PEXCEPTIONREPORTRECORD pERepRec,
                           PCONTEXTRECORD pContext,
                           PEXCEPTIONREPORTRECORD pR0RepRec,
                           PCONTEXTRECORD pR0Context);

extern ULONG xcptDefaultAction(ULONG ulTrapNumber,
                       PEXCEPTIONREPORTRECORD pERepRec,
                       PCONTEXTRECORD pContext,
                       PEXCEPTIONREPORTRECORD pR0ERepRec,
                       PCONTEXTRECORD pR0Context);

extern VOID xcptFormatAndSendHardErr(ULONG, PEXCEPTIONREPORTRECORD, PCONTEXTRECORD);

extern VOID xcptStackOverRun(ULONG, PEXCEPTIONREPORTRECORD, PCONTEXTRECORD);

extern VOID xcptFatalDispatchError(ULONG, PEXCEPTIONREPORTRECORD, PCONTEXTRECORD);

extern VOID xcptRestoreXcptContext( PCONTEXTRECORD pContext);

extern ULONG xcptQueryFPState(PFPSTATE);

extern VOID xcptRestoreFPState(PFPSTATE pFPEnv);

extern VOID xcptProcessFatalFault(ULONG, PULONG);

extern ULONG xcpt2Trap(ULONG, PULONG);

#define xcptAssert(_p1)     _assert(_p1)

/* XLATON */

/*
 * The following flags correspond to bits in the 387 status word.
 */

#define XCPT_FP_STACK_FAULT     0x0040
#define XCPT_FP_PRECISION       0x0020
#define XCPT_FP_UNDERFLOW       0x0010
#define XCPT_FP_OVERFLOW        0x0008
#define XCPT_FP_ZERO_DIVIDE     0x0004
#define XCPT_FP_DENORMAL        0x0002
#define XCPT_FP_INVALID_OP      0x0001

/*
 * This is a special code passed to Dos32ExceptionCallback to indicate
 * the end of an exit unwind. *Note* It is also defined in Except32\R3Except.H
 */
#define EXIT_UNWIND         0x65796C4B

#define NXCPT               (XCPT_SIGNAL & ~XCPT_SEVERITY_CODE)
                        /* number of defined fatal system exceptions    */
