/*static char *SCCSID = "@(#)ptrace.h   6.3 91/11/14";*/
/***    PTRACE.H - PTrace structures and definitions
 *
 *      SCCSID = @(#)ptrace.h   6.3 91/11/14
 *
 *      THIS IS AN OS/2 VERSION 2.x SPECIFIC FILE
 *
 *       IBM/Microsoft Confidential
 *
 *       Copyright (c) IBM Corporation 1987, 1989
 *       Copyright (c) Microsoft Corporation 1987, 1989
 *
 *       All Rights Reserved
 *
 *      This file contains the API interface structures and definitions
 *      for the DosPTrace function.
 *
 *      This will enable any 16-bit PTrace calls to be used on OS/2 2.0,
 *      and use the enhanced API calls of DosDebug.
 *
 *****************************************************************************
 *  Change                                                               Chg *
 *  Activity      Date    BY   Reason                                    Num *
 *  --------      ----    ---  -------                                   --- *
 *  DCR 1372    10/19/91  ARJ  Added for DOSPTRACE Support NEW           NEW *
 *  DEF 58487   12/09/92  ARJ  Added Floating Point Support for 16 bit   001 *
 *****************************************************************************
 ****************************************************************************/
/****************************************************************************
 *      This is the User PTrace buffer structure, passed to/from the user   *
 *      via the kPTB_s structure fields kPTB_uPTBOff and kPTB_uPTBSel. This *
 *      structure will contain the necessary information to control the     *
 *      DosPtrace function, and pass on to the DosDebug API the control     *
 *      information.                                                        *
 ****************************************************************************/
struct  uPTB_s  {
        USHORT PID;          /* Process ID of program being debugged */
        USHORT TID;          /* Thread ID of program being debugged ID */
        USHORT Cmd;          /* Request type / Result code (returned) */
        USHORT Value;        /* Input data / Error code (returned) */
        USHORT OffV;         /* Far address */
        USHORT SegV;
        USHORT MTE;          /* Module Table Entry */
        USHORT rAX;          /* Registers of program being debugged */
        USHORT rBX;
        USHORT rCX;
        USHORT rDX;
        USHORT rSI;
        USHORT rDI;
        USHORT rBP;
        USHORT rDS;
        USHORT rES;
        USHORT rIP;
        USHORT rCS;
        USHORT rF;           /* flags */
        USHORT rSP;
        USHORT rSS;
};

typedef struct uPTB_s uPTB_t;

/*******************************************************
*       Possible PTRACE Error Return Values            *
********************************************************/

#define trace_bad_command         1
#define trace_child_not_found     2
#define trace_child_untraceable   5

/*******************************************************
*       Possible PTRACE Thread Status Return Codes     *
********************************************************/

/*      DbgState values    */

#define TRC_C_Thawed    0
#define TRC_C_Frozen    1

/*      TState values      */

#define TRC_C_Runnable  0
#define TRC_C_Suspended 1
#define TRC_C_Blocked   2
#define TRC_C_CritSec   3
#define TRC_C_StateERR  -1      /*invalid state, internal error use only */

/*******************************************************
*       Possible Ptrace Commands                       *
********************************************************/

#define TRC_C_Null              0      /* Invalid command                  */
#define TRC_C_ReadMem_I         1      /* Read memory I-space              */
#define TRC_C_ReadMem_D         2      /* Read memory D-space              */
#define TRC_C_ReadMem           TRC_C_ReadMem_I
#define TRC_C_ReadReg           3      /* Read registers                   */
#define TRC_C_WriteMem_I        4      /* Write memory I-space             */
#define TRC_C_WriteMem_D        5      /* Write memory D-space             */
#define TRC_C_WriteMem          TRC_C_WriteMem_I
#define TRC_C_WriteReg          6      /* Write registers                  */
#define TRC_C_Go                7      /* Go (w/ signal)                   */
#define TRC_C_Term              8      /* Terminate child                  */
#define TRC_C_SStep             9      /* Single Step                      */
#define TRC_C_Stop              10     /* Stop child    (first command)    */
#define TRC_C_Freeze            11     /* freeze a child (threads)         */
#define TRC_C_Resume            12     /* resume a child (threads)         */
#define TRC_C_NumtoSel          13     /* Convert seg number to selector   */
#define TRC_C_GetFPRegs         14     /* Get Floating point registers     */
                                       /* contains 94 byte                 */
                                       /* buffer to place the floating ptr */
                                       /* registers                        */
#define TRC_C_SetFPRegs         15     /* Set Floating point registers     */
                                       /* Trace_B.tbSeg,tbOff has a 94 byte*/
                                       /* buffer to be used to set the     */
                                       /* floating pointer registers       */
#define TRC_C_GetLibName        16     /* Get library module name          */
                                       /* Trace_B.tbValue contains handle of */
                                       /* library module, Trace_B.tbSeg,tbOff*/
                                       /* contains buffer to return name of  */
                                       /* library module                   */
#define TRC_C_ThrdStat          17     /* Thread status command.           */
#define TRC_C_MapROAlias        18     /* Read-Only alias                  */
#define TRC_C_MapRWAlias        19     /* Read-Write alias                 */
#define TRC_C_UnMapAlias        20     /* unmap alias                      */

#define TRC_C_MAXCMD    TRC_C_UnMapAlias /* highest command number         */

/*******************************************************
*       Possible Ptrace Notifications (return codes)   *
********************************************************/

#define TRC_C_SUC_ret   0       /*  Success return code                     */
#define TRC_C_ERR_ret   -1      /*  TRCHandler error, code in .Tdata        */
#define TRC_C_SIG_ret   -2      /*  user about to recieve signal            */
#define TRC_C_TBT_ret   -3      /*  user hit T_Bit interrupt                */
#define TRC_C_BPT_ret   -4      /*  user hit breakpoint                     */
#define TRC_C_NMI_ret   -5      /*  got a parity error                      */
#define TRC_C_KIL_ret   -6      /*  user in process of dying                */
#define TRC_C_GPF_ret   -7      /*  General protection fault occured        */
                                /*  type in Trace_B.tbValue,                */
                                /*  Trace_B.tbSeg and tbOff contain         */
                                /*  refecence that generated fault.         */
#define TRC_C_LIB_ret   -8      /*  Library module has just been loaded     */
                                /*  Trace_B.tbValue has library module      */
                                /*  handle                                  */
#define TRC_C_FPE_ret   -9      /*  Process has not used the 287 yet        */
#define TRC_C_THD_ret   -10     /*  Thread termination                      */
#define TRC_C_STP_ret   -11     /*  Async. Stop.                            */
#define TRC_C_NEW_ret   -12     /*  New Process                             */
#define TRC_C_AFR_ret   -13     /*  Alias being freed.                      */

/****************************************************************************
* kPDB - Kernel Debug Buffer structure                                      *
*        A pointer to a kDB is the sole parameter to DosDebug.  It          *
*        contains all the information required for each DosDebug            *
*        command.                                                           *
*****************************************************************************/

struct _kPDB {                          /* kPDB                         */
        unsigned long   wPid;           /* Debuggee Process id          */
        unsigned long   wTid;           /* Debuggee Thread id           */
        long            wCmd;           /* Command or Notification      */
        long            wValue;         /* Generic Data Value           */
        unsigned long   wAddr;          /* Debuggee Address             */
        unsigned long   wBuffer;        /* Debugger Buffer Address      */
        unsigned long   wLen;           /* Length of Range              */
        unsigned long   wIndex;         /* Generic Identifier Index     */
        unsigned long   wMTE;           /* Module Table Entry Handle    */
        unsigned long   wEAX;           /* Register Set                 */
        unsigned long   wECX;
        unsigned long   wEDX;
        unsigned long   wEBX;
        unsigned long   wESP;
        unsigned long   wEBP;
        unsigned long   wESI;
        unsigned long   wEDI;
        unsigned long   wEFlags;
        unsigned long   wEIP;
        unsigned long   wCSLim;
        unsigned long   wCSBase;
        unsigned char   wCSAcc;
        unsigned char   wCSAtr;
        unsigned short  wCS;
        unsigned long   wDSLim;
        unsigned long   wDSBase;
        unsigned char   wDSAcc;
        unsigned char   wDSAtr;
        unsigned short  wDS;
        unsigned long   wESLim;
        unsigned long   wESBase;
        unsigned char   wESAcc;
        unsigned char   wESAtr;
        unsigned short  wES;
        unsigned long   wFSLim;
        unsigned long   wFSBase;
        unsigned char   wFSAcc;
        unsigned char   wFSAtr;
        unsigned short  wFS;
        unsigned long   wGSLim;
        unsigned long   wGSBase;
        unsigned char   wGSAcc;
        unsigned char   wGSAtr;
        unsigned short  wGS;
        unsigned long   wSSLim;
        unsigned long   wSSBase;
        unsigned char   wSSAcc;
        unsigned char   wSSAtr;
        unsigned short  wSS;
};

typedef struct _kPDB  kPDB_t;

/****************************************************************************
* kPTB - Kernel PTrace Buffer structure                                     *
*        This is the PTrace Control Block, used to control the interface    *
*        between the DosPTrace function and the DosDebug API Calls.         *
*****************************************************************************/

struct kPTB_s {
        ULONG   uPTBOff;        /* offset of user's PTB                     */
        ULONG   uPTBSel;        /* selector of user's PTB                   */
        ULONG   ulPTBAddr;      /* Linear Address of user's PTB             */
        ULONG   ulAddrIO;       /* Saved Linear Addr of Input Output buffer */
        ULONG   uHoldL;         /* Hold LONG  area can be used for anything */
        USHORT  uHoldS;         /* Hold SHORT area can be used for anything */
        USHORT  command;        /* command from uPTB                        */
        kPDB_t  wrkPDB;         /* copy of kPDB_t to modify and pass to on  */
};

typedef struct kPTB_s  kPTB;

/***************************************************************************
 *  These are the coprocessor environment and state structures             *
 *  for use in the TRC_C_GetFPRegs and TRC_C_SetFPRegs Calls.              *
 ***************************************************************************/

struct _TRC_FPCONTROL {
    ULONG   Control;    /* Control Word (lower word)*/
    ULONG   Status;     /* Status Word  (lower word)*/
    ULONG   fpTag;      /* Tag Word     (lower word)*/
    ULONG   fpEIP;      /* Instruction Offset       */
    USHORT  fpCS;       /* CS Selector              */
    USHORT  OpCode;     /* Instruction OpCode (upper 5 bits reserved) */
    ULONG   DataOffset; /* Data Operand Offset (lower word) */
    ULONG   DataSel;    /* Data Operand selector    */
};

typedef struct _TRC_FPCONTROL TRC_FPENV;
typedef struct _TRC_FPCONTROL *PTRC_FPENV;

struct _TRC_FPREG {     /* coprocessor stack register element */
   ULONG    losig;
   ULONG    hisig;
   USHORT   sign_exp;
};

typedef    struct _TRC_FPREG TRC_FPREG;

struct _TRC_FPSTATE {
   TRC_FPENV   fpstate_env;
   TRC_FPREG   fpstate_stack[8];
};

typedef struct _TRC_FPSTATE FPSTATE;
typedef struct _TRC_FPSTATE *PFPSTATE;

/***************************************************************************
 *  These are the coprocessor environment and state structures       A001  *
 *  for the orginal DosPtrace Code from 1.3. This code is used       A001  *
 *  by the TRC_C_GetFPRegs and TRC_C_SetFPRegs Calls ONLY to map     A001  *
 *  the USERs INPUT buffer.                                          A001  *
 ***************************************************************************/

struct _TRC_13CONTROL {
    USHORT  Control_13;                       /* Control Word          A001*/
    USHORT  Status_13;                        /* Status Word           A001*/
    USHORT  Tag_13;                           /* Tag Word              A001*/
    USHORT  EIP_13;                           /* Instruction Offset    A001*/
    USHORT  CS_13;                            /* CS Selector           A001*/
    USHORT  DataOffset_13;                    /* Data Operand Offset   A001*/
    USHORT  DataSel_13;                       /* Data Operand selector A001*/
};

typedef struct _TRC_13CONTROL TRC_13_FPENV;   /*                       A001*/
typedef struct _TRC_13CONTROL *PTRC_13_FPENV; /*                       A001*/

struct _TRC_13FPREG {           /* coprocessor stack register element  A001*/
   ULONG    losig_13;                         /*                       A001*/
   ULONG    hisig_13;                         /*                       A001*/
   USHORT   sign_exp_13;                      /*                       A001*/
};                                            /*                       A001*/

typedef    struct _TRC_13FPREG TRC_13_FPREG;  /*                       A001*/

struct _TRC_13FPSTATE {                       /*                       A001*/
   TRC_13_FPENV   fpstate_13_env;             /*                       A001*/
   TRC_13_FPREG   fpstate_13_stack[8];        /*                       A001*/
};

typedef struct _TRC_13FPSTATE FP13STATE;      /*                       A001*/
typedef struct _TRC_13FPSTATE *PFP13STATE;    /*                       A001*/

/****************************************************************************
*       Ptrace Work Area - Amount of storage required for Structures        *
*****************************************************************************/

#define kPTB_size     sizeof (kPTB)    /* Kernal PTrace Buffer              */
#define FP387_size    sizeof (FPSTATE) /* 387 Floating Point Buffer         */
#define PTres_size    24               /* this is reserved storage          */
#define PTWrkArea     kPTB_size + FP387_size + PTres_size /* Total Size     */

#define uPTB_size     sizeof (uPTB_t)  /* USERs  PTrace Buffer              */

#ifdef PTSTRICT
/*
 *      These are flags used to display information about DosPtrace
 *
 *   0x00000000  -  Do Not Display any DeBug information (initial setting)
 *   PTCVTo      -  Display Output buffer setup to be passed to user
 *   PTCVTi      -  Display Input Buffer setup from user to DosDebug
 *   PTCVTr      -  Display conversion routine Flow
 *   PTCVTar     -  Display Alias conversion routine Flow
 *   PTRACEc     -  Display Input and output return codes only
 *   PTCHECKc    -  Display processing of notifications from DosDebug
 *   PTCVTfp     -  Display Floating Point Information
 *   PTallinfo   -  Display ALL Debug Information
 */

#define PTCVTo          0x01000000
#define PTCVTi          0x02000000
#define PTCVTr          0x04000000
#define PTCVTar         0x08000000
#define PTRACEc         0x10000000
#define PTCHECKc        0x20000000
#define PTCVTfp         0x00000001
#define PTallinfo       0xffffffff

/*end*/
#endif

//XLATOFF
int PTPidToPTDA (ulong_t pid, PPTDA *pPTDA);                         //d57053
//XLATON
