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

/***    DEBDEF.H
 *
 *      This file contains the debugger's general/global defines.
 *
 *      SCCSID = @(#)debdef.h   13.3 90/03/09
 */

#define FALSE                   0
#define TRUE                    -1
#define NULL                    0

#define CTRLC                   3
#define CTRLQ                   17
#define CTRLS                   19
#define BEL                     7
#define BS                      8
#define TABCHR                  9
#define CR                      13
#define LF                      10
#define ESCCHR                  27
#define DEL                     127

#define BUFLEN                  80      /* Length of "list" buffer */
//136682 #define CMDLINELEN              80      /* Maximum length of cmd line buffer */
#define CMDLINELEN              160     /* Maximum length of cmd line buffer */
#define OPBUFLEN                200     /* Length of unassemble line buffer */
#define MAXADDRSTR              25      /* Maximum address string buffer */

/* Expression type codes */

#define EXPR_TYPE_SEGSEL        0x01    /* segment or selector class */
#define EXPR_TYPE_LINPHY        0x02    /* linear or physical class */
#define EXPR_TYPE_DEF           0x04    /* default address type */

#define EXPR_TYPE_DATA          0       /* data type */
#define EXPR_TYPE_SEG           0x01    /* address type segment:offset */
#define EXPR_TYPE_SEL           0x09    /* address type selector:offset */
#define EXPR_TYPE_LIN           0x02    /* address type linear */
#define EXPR_TYPE_PHY           0x0A    /* address type physical */

/* Expression size codes */

#define EXPR_SIZE_BYTE          1       /* byte size (1 byte) */
#define EXPR_SIZE_WORD          2       /* word size (2 bytes) */
#define EXPR_SIZE_DWORD         4       /* dword size (4 bytes) */

/* Flag bit definitions */

#define F_OVERFLOW              0x0800
#define F_DIRECTION             0x0400
#define F_INTERRUPT             0x0200
#define F_TRACE                 0x0100
#define F_SIGN                  0x0080
#define F_ZERO                  0x0040
#define F_AUX                   0x0010
#define F_PARITY                0x0004
#define F_CARRY                 0x0001

/* Some codes for TrapNumber */

#define SINGLE_STEP_TRAP        1
#define NMI_TRAP                2
#define BREAK_POINT_TRAP        3
#define INVALID_OPCODE_TRAP     6

/* Debugger call out routine codes */

#define DEB_CALLOUT_INIT_COM    0
#define DEB_CALLOUT_OUTPUT_CHAR 1
#define DEB_CALLOUT_SCAN_CHAR   2
#define DEB_CALLOUT_ENABLE_NMI  3
#define DEB_CALLOUT_ENABLE_A20  4
#define DEB_CALLOUT_RESTORE_A20 5
#define DEB_CALLOUT_EXTCMD      6
#define DEB_CALLOUT_DEBENTRY    7
#define DEB_CALLOUT_DEBEXIT     8
#define DEB_CALLOUT_DEBINIT     9
#define DEB_CALLOUT_DEBEND      10
#define DEB_CALLOUT_GETCURRTASK 11
#define DEB_CALLOUT_GETDESCINFO 12
#define DEB_CALLOUT_BREAK       13
#define DEB_CALLOUT_BEEP        14
#define DEB_CALLOUT_DRALLOC     15
#define DEB_CALLOUT_DRFREE      16
#define DEB_CALLOUT_GETPDE      17
#define DEB_CALLOUT_GETFRAME    18

/* Memory get/put error codes */

#define DEBERR_INVALID_SELECTOR         1
#define DEBERR_SELECTOR_NOT_PRESENT     2
#define DEBERR_OFFSET_PAST_LIMIT        3
#define DEBERR_INVALID_TASK_NUMBER      4
#define DEBERR_INVALID_ADDR_TYPE        5
#define DEBERR_PAGE_TABLE_NOT_PRESENT   6
#define DEBERR_PAGE_NOT_PRESENT         7
#define DEBERR_INVALID_ADDRESS          8
#define DEBERR_CODE_MAX                 8

/* getsymbuf() flags */

#define MAP_GETMAPNAME          0x01    /* prefix with map name */
#define MAP_GETGROUP            0x02    /* prefix with group name */
#define MAP_NEAR_PREV           0x04    /* find nearest previous */
#define MAP_NEAR_NEXT           0x08    /* find nearest next */
#define MAP_BRACKET             0x10    /* PrintNearSym only */

/* fmtaddr() flags */

#define FMT_ADDR_32ENV          0x0001          /* format as 32 bit offset */
#define FMT_ADDR_SEG            0x0002          /* format segment/selector */
#define FMT_ADDR_TYPE           0x0004          /* internal use only */
#define FMT_ADDR_TASK           0x0008          /* internal use only */
#define FMT_ADDR_LINPHY         0x0010          /* internal use only */

/* LDT/GDT table bit */

#define TABLE_MASK              0x0004

typedef int bool;
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;

/*
 *  Expression value structures, both ExprS and AddrS are unions
 *  of each other. ExprS is used by the Expr routine. AddrS is used
 *  by the routines that take addresses as parameters.
 */

typedef struct
{
    dword ExprData;
    word  ExprSeg;
    byte  ExprType;
    byte  ExprSize;
    word  ExprTask;
} ExprS;

typedef struct
{
    dword AddrOff;
    word AddrSeg;
    byte AddrType;
    byte AddrSize;
    word AddrTask;
} AddrS;

/*  Descriptor structure */

typedef struct
{
    word DescLimit;                 /* limit (size - 1) */
    word DescBaseLow;               /* bits 0-15 of base address */
    byte DescBaseHigh;              /* bits 16-23 of base address */
    byte DescAccess;                /* access byte */
    byte DescAttr;                  /* attributes/extended limit */
    byte DescBaseExt;               /* bits 24-31 of base address */
} Desc;

/*  Gate structure */

typedef struct
{
    word GateOffset;                /* gate offset */
    word GateSelector;              /* gate selector */
    byte GateWordCount;             /* word count for call gate */
    byte GateAccess;                /* access byte */
    word GateExtOffset;             /* extended target offset */
} Gate;

/*  Load/store gdt/idt register instruction buffer structure */

typedef struct
{
    word DTRLimit;                  /* limit of gdt/idt register */
    word DTRBaseLow;                /* bits 0-15 of base address */
    byte DTRBaseHigh;               /* bits 16-23 of base address */
    byte DTRBaseExt;                /* bits 24-31 of base address */
} DTR;

/*
 *  User register save structure
 */

struct RegSA_struc
{
    dword EAXsav;
    dword EBXsav;
    dword ECXsav;
    dword EDXsav;
    dword ESPsav;
    dword EBPsav;
    dword ESIsav;
    dword EDIsav;
    word ESsav;
    word SSsav;
    word DSsav;
    word FSsav;
    word GSsav;
    AddrS CSIPsav;
    dword EFsav;
    dword CR0sav;
    DTR GDTsav;
    word RS_Pad1;
    DTR IDTsav;
    word RS_Pad2;
    word LDTsav;
    word TRsav;
    dword CR2sav;
    dword CR3sav;
    dword CR4sav;                                                               // 148688
    dword DR0sav;
    dword DR1sav;
    dword DR2sav;
    dword DR3sav;
    dword DR6sav;
    dword DR7sav;
    dword DR7sav2;
    dword TR6sav;
    dword TR7sav;
};


/*
 *  Debugger initialization packet (DebData)
 */

struct DebugInit
{
    word CSseg;                     /* Real mode code segment */
    word DSseg;                     /* Real mode data segment */
    word CSsel;                     /* Prot mode code selector */
    word DSsel;                     /* Prot mode data selector */
    word GDTalias;                  /* Prot mode GDT r/w alias */
    DTR GDTaddr;                    /* GDT Base & Limit */
    word DI_Pad1;
    DTR ProtIDTaddr;                /* Prot mode IDT base & limit */
    word DI_Pad2;
    DTR RealIDTaddr;                /* Real mode IDT base & limit */
    word DI_Pad3;
    word InitFlag;                  /* Initialization flags */
    byte BreakChar;                 /* Init break character */
    byte DI_Pad4;
    word ProtTicInt;                /* Prot mode tic timer int number */
    word RealTicInt;                /* Real mode tic timer int number */
    word RealVectorSet;             /* Real mode int vec set by debugger */
    word ProtVectorSet;             /* Prot mode int vec set by debugger */
    word ProtVectorHard;            /* Prot vecs to be intercepted at R0 */
    word DebCallOutPtr;             /* Debugger callout routines near ptr */
    dword DebPageDir;               /* Linear address of page directory */
    dword DebSpareLin;              /* Paging enabled linear alias */
};

/* These are the "InitFlag" definitions */

#define INIT_NOBRKFLAG  0x0001          /* don't break into debugger */
#define INIT_REALFLAG   0x0002          /* initialize for real mode */
#define INIT_PROTFLAG   0x0004          /* initialize for protected */
#define INIT_CTRLCFLAG  0x0008          /* init ctrl-c to debugger */
#define INIT_CPU386     0x0010          /* CPU is a 386 */
#define INIT_NOVECSET   0x0020          /* don't set the int vectors */
#define INIT_ENV386     0x0040          /* environment is 386 (v1.3) */
#define INIT_DISLWR     0x0080          /* disassembly in lower case */
#define INIT_NOREGTERSE 0x0100          /* dump full register set */

/* JWE start */
typedef struct
{
  word  hMTE;    /* MTE handle of module containing page */
  word  filler;
  dword page;    /* Address of page                      */
} PageinStruct;
#define PAGEINMAX 256
/* JWE end */

