/*static char *SCCSID = "@(#)ldrvars.h  6.19 92/03/29";*/
/*      SCCSID = @(#)ldrvars.h  6.19 92/03/29 */
/*
 *      IBM/Microsoft Confidential
 *
 *      Copyright (c) IBM Corporation 1987, 1989
 *      Copyright (c) Microsoft Corporation 1987, 1989
 *
 *      All Rights Reserved
 */
/* INT32 */

/***ET+ ldrmte_t - MTE */

struct ldrmte_s
{
    //Warning!!! The debug kernel expects to have mte_flags as the first
    //           element of the resident MTE.
    ushort_t          mte_flags2;     /* Module flags 2 */
    ushort_t          mte_handle;     /* the handle for this mte */
    struct ldrsmte_s *mte_swapmte;    /* link to swappable mte */
    struct ldrmte_s  *mte_link;       /* link to next mte */
    ulong_t           mte_flags1;     /* Module flags 1 */

    ulong_t           mte_impmodcnt;  /* Num of entries in Imp Mod Name Tbl */
    ushort_t          mte_sfn;        /* file system number for open file */
    ushort_t          mte_usecnt;     /* .EXE only - use count */
    char              mte_modname[8]; /* resident module name (zero extended)*/

};
typedef struct ldrmte_s ldrmte_t;      /* Swappable Module table entry */

struct ldrsmte_s
{

    ulong_t  smte_mpages;      /* Module # pages */
    ulong_t  smte_startobj;    /* Object # for instruction pointer */
    ulong_t  smte_eip;         /* Extended instruction pointer */
    ulong_t  smte_stackobj;    /* Object # for stack pointer */

    ulong_t  smte_esp;         /* Extended stack pointer */
    ulong_t  smte_pageshift;
    ulong_t  smte_fixupsize;   /* Fixup section size */
    ulong_t  smte_objtab;      /* Object table offset */

    ulong_t  smte_objcnt;      /* Number of objects in module */
    ulong_t  smte_objmap;      /* Object page map offset */
    ulong_t  smte_itermap;     /* Object iterated data map offset */
    ulong_t  smte_rsrctab;     /* Offset of Resource Table */

    ulong_t  smte_rsrccnt;     /* Number of resource entries */
    ulong_t  smte_restab;      /* Offset of resident name table */
    ulong_t  smte_enttab;      /* Offset of Entry Table */
    ulong_t  smte_fpagetab;    /* Offset of Fixup Page Table */

    ulong_t  smte_frectab;     /* Offset of Fixup Record Table */
    ulong_t  smte_impmod;      /* Offset of Import Module Name Table */
    ulong_t  smte_impproc;     /* Offset of Imp Procedure Name Tab */
    ulong_t  smte_datapage;    /* Offset of Enumerated Data Pages */

    ulong_t  smte_nrestab;     /* Offset of Non-resident Names Table */
    ulong_t  smte_cbnrestab;   /* Size of Non-resident Name Table */
    ulong_t  smte_autods;      /* Object # for automatic data object */
    ulong_t  smte_debuginfo;   /* Offset of the debugging info */

    ulong_t  smte_debuglen;    /* The len of the debug info in bytes */
    ulong_t  smte_heapsize;    /* use for converted 16-bit modules */
    ulong_t  smte_path;        /* full pathname */
    ushort_t smte_semcount;    /* Count of threads waiting on MTE semaphore. 0 => semaphore is free */
    ushort_t smte_semowner;    /* Slot number of the owner of MTE semahore */

    ulong_t  smte_pfilecache;  /* Pointer to file cache for Dos32CacheModule */
    ulong_t  smte_stacksize;   /* Thread 1 Stack size from the exe header */
    ushort_t smte_alignshift;  /* use for converted 16-bit modules */
    ushort_t smte_NEexpver;    /* expver from NE header */
    ushort_t smte_pathlen;     /* length of full pathname */
    ushort_t smte_NEexetype;   /* exetype from NE header */

    ushort_t smte_csegpack;    /* count of segs to pack */
    uchar_t  smte_major_os;    /* major os version to lie about */ /* 161596 */
    uchar_t  smte_minor_os;    /* minor os version to lie about */ /* 161596 */

};
typedef struct  ldrsmte_s ldrsmte_t;    /* Swappable Module table entry */

#define smte_ssegpack   smte_frectab    /* size of object for seg pack */
#define smte_spaddr     smte_itermap    /* virtual address of packed object */



/***LK+ Definitions for mte_flags1
 *
 *      USED and INGRAPH are used by the graph traversl routines.  If
 *      the loader semaphore is clear, these bits must both be clear.
 *      See traversal routines for more.
 *
 *      MTE_INTNL_MASK is the set of bits which are used by the kernel.
 *      These bits are cleared when a module is finished loading.
 *
 *      LDRINVALID and MTEVALID are overloaded.  Once an mte is linked
 *      into the chain, this bit is used to indicate (if set) that the
 *      mte contains valid information that demand loaders (who are not
 *      excluded by the loader semaphore) may examine.
 *
 */

#define NOAUTODS        0x00000000      /* No Auto DS exists */
#define SOLO            0x00000001      /* Auto DS is shared */
#define INSTANCEDS      0x00000002      /* Auto DS is not shared */
#define INSTLIBINIT     0x00000004      /* Per-instance Libinit */
#define GINISETUP       0x00000008      /* Global Init has been setup */
#define NOINTERNFIXUPS  0x00000010      /* internal fixups in .EXE-.DLL applied */
#define NOEXTERNFIXUPS  0x00000020      /* external fixups in .EXE-.DLL applied */
#define CLASS_PROGRAM   0x00000040      /* Program class */
#define CLASS_GLOBAL    0x00000080      /* Global class */
#define CLASS_SPECIFIC  0x000000C0      /* Specific class, as against global */
#define CLASS_ALL       0x00000000      /* nonspecific class - all modules */
#define CLASS_MASK      0x000000C0
#define MTEPROCESSED    0x00000100      /* MTE being loaded */
#define USED            0x00000200      /* MTE is referenced - see ldrgc.c */
#define DOSLIB          0x00000400      /* set if DOSCALL1 */
#define DOSMOD          0x00000800      /* set if DOSCALLS */
#define MTE_MEDIAFIXED  0x00001000      /* File Media permits discarding */
#define LDRINVALID      0x00002000      /* module not loadable */
#define PROGRAMMOD      0x00000000      /* program module */
#define DEVDRVMOD       0x00004000      /* device driver module */
#define LIBRARYMOD      0x00008000      /* DLL module */
#define VDDMOD          0x00010000      /* VDD module */
#define MVDMMOD         0x00020000      /* Set if VDD Helper MTE (MVDM.DLL) */
#define INGRAPH         0x00040000      /* In Module Graph - see ldrgc.c */
#define GINIDONE        0x00080000      /* Global Init has finished */
#define MTEADDRALLOCED  0x00100000      /* Allocate specific or not */
#define FSDMOD          0x00200000      /* FSD MTE */
#define FSHMOD          0x00400000      /* FS helper MTE */
#define MTELONGNAMES    0x00800000      /* Module supports long-names */
#define MTE_MEDIACONTIG 0x01000000      /* File Media contiguous memory req */
#define MTE_MEDIA16M    0x02000000      /* File Media requires mem below 16M */
//REMOVED #define MTEIOPLALLOWED  0x04000000      /* Module has IOPL privilege */
#define MTESWAPONLOAD   0x04000000      /* make code pages swap on load */
#define MTEPORTHOLE     0x08000000      /* porthole module */
#define MTEMODPROT      0x10000000      /* Module has shared memory protected */
#define MTENEWMOD       0x20000000      /* Newly added module */
#define MTEDLLTERM      0x40000000      /* Gets instance termination */
#define MTESYMLOADED    0x80000000      /* Set if debugger symbols loaded */

/* The following bits are overloaded or aliased. */

#define MTEVALID     (LDRINVALID)
#define AUTODS_MASK  (NOAUTODS|SOLO|INSTANCEDS)

/* The following bits are cleared after each successful module load. */

#define MTE_INTNL_MASK  (DOSLIB|DOSMOD|MTEVALID|MTEPROCESSED| \
                        GINISETUP|GINIDONE|USED|INGRAPH|MTENEWMOD)

/*
 * The following define which modules are "ring 0" for the purpose of
 * indirect fixups.
 */
#define MTE_RING0       (DEVDRVMOD | VDDMOD | MVDMMOD | FSDMOD | FSHMOD)

#define SEARCH_BY_PATH  1               /* FindModule class parameter */


/***LK+ Definitions for mte_flags2
 *
 */
#define MTEFORMATMASK   0x0003       /* Module format mask */
#define MTEFORMATR1     0x0000       /* Module format reserved */
#define MTEFORMATNE     0x0001       /* Module format NE */
#define MTEFORMATLX     0x0002       /* Module format LX */
#define MTEFORMATR2     0x0003       /* Module format reserved */

#define MTESYSTEMDLL    0x0004       /* DLL exists in system list */
#define MTELOADORATTACH 0x0008       /* Module under load or attach - for init */
#define MTECIRCLEREF    0x0010       /* Module circular reference detection */
#define MTEFREEFIXUPS   0x0020       /* Free system mte's fixup flag d#98488 */
//REMOVED #define MTEFATALCIRCLE  0x0020       /* Module circular reference detection */
#define MTEPRELOADED    0x0040       /* MTE Preload completed */
#define MTEGETMTEDONE   0x0080       /* GetMTE already resolved */
#define MTEPACKSEGDONE  0x0100       /* Segment packed memory allocated */
#define MTE20LIELIST    0x0200       /* Name present in version20 lie list */
#define MTESYSPROCESSED 0x0400       /* System DLL already processed */
/* #define MTEDLLONEXTLST  0x1000        DLL has term routine on exit list #74177 removed - 75809 */

/*end*/

/***ET+ ldrote_s - Object Table entry */

struct _oteres_s
{
    ushort_t        _ote_selector;  /* store selector used by loader only */
    ushort_t        _ote_handle;    /* store handle used by loader only */
};

/*
 * Since H2INC will not work correctly with unions to get SIZE of ldrote_t
 * to return the correct size remove the ulong_t from the assembler declare
 */

/* XLATOFF */
union _oteres_u
{
    struct _oteres_s _ote_res;
    ulong_t _ote_vddaddr;           /* store vdd address */
};
/* XLATON */

/* ASM
_oteres_u       STRUC
 _ote_res       DB      SIZE _oteres_s DUP (?)
_oteres_u       ENDS
*/

struct ldrote_s                         /* Flat .EXE object table entry */
{
    ulong_t          ote_size;       /* Object virtual size */
    ulong_t          ote_base;       /* Object base virtual address */
    ulong_t          ote_flags;      /* Attribute flags */
    ulong_t          ote_pagemap;    /* Object page map index */
    ulong_t          ote_mapsize;    /* Num of entries in obj page map */
    union _oteres_u _ote_resu;
};
typedef struct ldrote_s ldrote_t;       /* Object table entry */

#define ote_handle      _ote_resu._ote_res._ote_handle
#define ote_selector    _ote_resu._ote_res._ote_selector

/* XLATOFF */
#define ote_vddaddr     _ote_resu._ote_vddaddr
/* XLATON */

/* ASM
ote_vddaddr     equ     <dword ptr _ote_resu>
*/

// Made private support rewritten by Dave Medina. Paul.
// #define OBJMADEPRIV     0x40000000L  /* Object is made private for debug */

// Warning - OBJALLOC flag : this flag is set when an object is allocated. It
// is not necessarily reset when the object is freed. To know whether or not it
// really has been freed, you need to look at the object type, the alloc flag,
// and the hob field. Paul.
#define OBJALLOC        0x80000000L     /* Object is allocated used by loader */

/* XLATOFF */
/***ET+ ldrote_t - Object Table entry */

#define LGS_FSDMOD      8L              /* for ldrGetSelector */
#define LGS_FSDMODSHF   18L             /* for ldrGetSelector */
#define LGS_VDDMOD      4L              /* for ldrGetSelector */
#define LGS_VDDMODSHF   14L             /* for ldrGetSelector */
#define LGS_DEVDRVMOD   4L              /* for ldrGetSelector */
#define LGS_DEVDRVSHF   12L             /* for ldrGetSeletor */
#define LGS_OBJEXECSHF  2L              /* for ldrGetSelector */
#define LGS_OBJIOPLSHF  14L             /* for ldrGetSelector */
#define LGS_OBJEXEC     1L              /* for ldrGetSelector */
#define LGS_OBJIOPL     2L              /* for ldrGetSelector */

#if ((LGS_VDDMOD << LGS_VDDMODSHF) != VDDMOD)
  error ldrvars.h include file changed  /* create compile error */
#endif

#if ((LGS_OBJEXEC << LGS_OBJEXECSHF) != OBJEXEC)
  error exe386.h include file changed   /* create compile error */
#endif

#if ((LGS_OBJIOPL << LGS_OBJIOPLSHF) != OBJIOPL)
  error exe386.h include file changed   /* create compile error */
#endif

/***ET+ ldropm_t - Object Page Map */

typedef struct  o32_map ldropm_t;       /* Object Page Map */

/* XLATON */

/***ET+ ldrste_t - Segment Table entry */

struct  ldrste_s
{
    ushort_t        ste_offset;     /* file offset to segment data */
    ushort_t        ste_size;       /* file data size */
    ushort_t        ste_flags;      /* type and attribute flags */
    ushort_t        ste_minsiz;     /* minimum allocation size */
    ushort_t        ste_seghdl;     /* segment handle */
    ushort_t        ste_selector;   /* segment selector */
    ulong_t         ste_fixups;     /* fixup record storage */
};
typedef struct  ldrste_s ldrste_t;     /* Segment table entry */

/* ste_flags bit definitions */

#define STE_TYPE_MASK           0x0001 /* segment type field */
#define STE_CODE                0x0000 /* code segment type */
#define STE_DATA                0x0001 /* data segment type */

#define STE_PACKED              0x0002 /* segment is packed */
#define STE_SEMAPHORE           0x0004 /* segment semaphore */
#define STE_ITERATED            0x0008 /* segment data is iterated */
#define STE_WAITING             0x0010 /* segment is waiting on semephore */
#define STE_SHARED              0x0020 /* segment can be shared */

// Made private support rewritten by Dave Medina. Paul.
// #define STE_MADEPRIV            0x0040 /* debug made private -OVERLOAD ! */

#define STE_PRELOAD             0x0040 /* segment is preload */

#define STE_ERONLY              0x0080 /* excute only if code segment */
                                       /* read only if data segment */
#define STE_RELOCINFO           0x0100 /* set if segment has reloc records */

#define STE_CONFORM             0x0200 /* segment is conforming */
#define STE_RING_2              0x0800 /* ring 2 selector */
#define STE_RING_3              0x0C00 /* ring 3 selector */
#define STE_SEGDPL              0x0C00 /* I/O privilege level */

#define STE_HUGE                0x1000 /* huge segment */
#define STE_PAGEABLE            0x2000 /* just a page can be faulted in */
#define STE_PRESENT             0x2000 /* packed segment already loaded */
#define STE_SELALLOC            0x4000 /* used to indicate sel allocated */
#define STE_GDTSEG              0x8000 /* used to indicate GTD sel alloc */

#define STE_HUGE_MASK  ( STE_TYPE_MASK|STE_SHARED|STE_SEGDPL )
#define STE_RSRC_HUGE  ( STE_HUGE_MASK & ((NOT STE_TYPE_MASK)|STE_PRELOAD) )

#define ISRSRC                  1      /* flag to indicate we have a rsrc seg */

/*
 * The sfr_s is used to store segment fixup information so we can
 * page segments.
 *
 * If sfr_fchained, then sfr_soff holds the count of chain records
 * immediately following the fixup data bytes (sfr_bytes). If records
 * are not chained, then sfr_soff holds the page offset for the fixup
 * data.
 *
 */

#define SFR_DATALEN     4
struct sfr_s                    // Segment fixup record
{
    unsigned short sfr_fchained:1;  // Flag: Is it chained
    unsigned short sfr_fixsize:3;   // Number of bytes in fixup
    unsigned short sfr_soff:12;     // Page offset or count of fixups
    unsigned char sfr_bytes[SFR_DATALEN];   // Fixup data bytes
};

typedef struct sfr_s sfr_t;

#define SFR_HEADSIZE (sizeof(sfr_t)-SFR_DATALEN)

#define PAGESPERSEGMENT         16

/*
 * segfix iterated record
 */
struct sfir_s
{
    ulong_t         sfir_doffset;   // Offset into data file
    ushort_t        sfir_soffset;   // Offset into segment
    ushort_t        sfir_cbdata;    // Number of bytes in record
    ushort_t        sfir_count;     // Number of iterations
};

typedef struct sfir_s sfir_t;

/* XLATOFF */


/***EC+ B16 - 16-bit bundle types */

#define B16EMPTY        EMPTY           /* empty bundle */
#define B16ABSOLUTE     0xFE            /* absolute entry bundle */
#define B16MOVABLE      0xFF            /* movable entry bundle */
/*end*/


/***ET+ ldrcte_t - Loader call thunk entry for 16-bit entry table */

struct  ldrcte_s
{
    uchar_t         cte_flags;      /* entry flags */
    ushort_t        cte_sel;        /* space for callgate selector */
    uchar_t         cte_obj;        /* object index */
    ushort_t        cte_off;        /* offset of routine entry point */
};

typedef struct ldrcte_s ldrcte_t;       /* Loader call thunk entry */
/*end*/


/***ET+ ldrent_t - Loader Exported entry for 16-bit entry table */

struct  ldrent_s
{
    uchar_t         ent_flags;      /* entry flags */
    ushort_t        ent_off;        /* offset of routine entry point */
};

typedef struct ldrent_s ldrent_t;       /* Loader exported entry */
/*end*/


typedef struct b32_bundle ldret_t;      /* General entry table type */
typedef struct e32_entry ldr32et_t;     /* 32-bit entry table */


/* XLATON  */
/***ET+ ldrempty_t unused entry */

struct  ldrempty_s
{
    uchar_t         empty_count;    /* count of empty entries */
    uchar_t         emtpy_type;     /* type 0 for empty */
};

typedef struct  ldrempty_s ldrempty_t;
/*end*/

/* XLATOFF */

/***ET+ ldret16_t 32-bit entry table 16-bit offset entry */

struct  ldret16_s
{
    uchar_t         et16_flags;     /* entry flags */
    ushort_t        et16_off;       /* offset in object */
};

typedef struct ldret16_s ldret16_t;     /* 32-bit entry table 16-bit offset */
/*end*/


/***ET+ ldret16iopl_t 32-bit entry table 16-bit IOPL */

struct  ldret16iopl_s
{
    uchar_t         et16iopl_flags; /* entry flags */
    ushort_t        et16iopl_off;   /* offset in object */
    ushort_t        et16iopl_call;  /* callgate selector */
};

/* 32-bit entry table 16-bit callgate */
typedef struct ldret16iopl_s ldret16iopl_t;
/*end*/


/***ET+ ldret32_t 32-bit entry table 32-bit offset entry */

struct  ldret32_s
{
    uchar_t         et32_flags;     /* entry flags */
    ulong_t         et32_off;       /* offset in object */
};

typedef struct ldret32_s ldret32_t;     /* 32-bit entry table 32-bit offset */
/*end*/

/***ET+ ldrfwd_t forwarder entry table entry */
struct ldrfwd_s
{
    uchar_t         fwd_flags;      /* entry flags */
    ushort_t        fwd_modord;     /* module ordinal */
    ulong_t         fwd_value;      /* offset in table, or ordinal */
};

typedef struct ldrfwd_s ldrfwd_t;
/*end*/

/***ET+ ldrfrt_t 32-bit fixup page table */

#define fr_stype        nr_stype
#define fr_flags        nr_flags

typedef struct r32_rlc ldrfrt_t;
/*end*/


struct  ldrefrt_s                       /* expanded fixup record */
{
    ulong_t         efr_tgt;        /* 32-bit target field */
    ulong_t         efr_add;        /* addtive value */
    ushort_t        efr_srcoff;     /* source offset */
    ushort_t        efr_tobj;       /* target object or ordinal */
    uchar_t         efr_stype;      /* source type */
    uchar_t         efr_flags;      /* flags */
    uchar_t         efr_cchain;     /* count for chained records */
};

typedef struct ldrefrt_s ldrefrt_t;

struct objmem_s
{
    ulong_t         flobj;          /* allocation flags needed */
};

/*
 * Warning this structure must match the structure defined in the ASM
 * part at the end of this file
 */

struct taddr_s
{
    ulong_t  toff;
    ushort_t tsel;
    uchar_t tflags;
    /*
     * For use by ldrGetFwdEnt():
     */
    uchar_t     fflags;             /* forwarder flags */
    ushort_t    cgsel;              /* callgate selector */
};

/* The structure of a non-resident name table is as follows: */

struct nonres_s
{
    struct nonres_s *nr_link;       /* link to next non-resident table */
    ushort_t nr_mte;                /* mte handle to which names belong */
    uchar_t nr_names;               /* nonresident nametable from file */
};

#define NT_TYPEINFO 0x80


struct  hit_s
{
        ulong_t offset;                 /* offset of field in mte */
        ulong_t cnt;                    /* count of bytes to copy */
};

struct  his_s
{
        ulong_t offset;                 /* offset of field in ste */
        ulong_t cnt;                    /* count of bytes to copy */
};

struct  etmt_s
{
        ushort_t offset;                /* offset of field in linker exe image */
};

struct  zmt_s
{
        ushort_t offset;                /* offset of field in swappable MTE */
        uchar_t size;                   /* size of field */
        uchar_t zero;                   /* flag to zero or not */
};

struct objflags_s
{
        ulong_t flobj;                  /* object's flags */
        ulong_t flVM;                   /* required allocation flags */
};

struct selflags_s
{
        ulong_t         flobj;          /*object's flags */
        ushort_t        fsSEL;          /* required allocation flags */
};

struct pgstatechg_s
{
        ulong_t         flpage;         /* allocation flags needed */
};

#define et_count        b32_cnt
#define et_type         b32_type
#define et_obj          b32_obj
#define et_flags        e32_flags
#define et_16off        e32_variant.e32_offset.offset16
#define et_cgoff        e32_variant.e32_callgate.offset
#define et_cgsel        e32_variant.e32_callgate.callgate
#define et_32off        e32_variant.e32_offset.offset32
#define et_modord       e32_variant.e32_fwd.modord
#define et_value        e32_variant.e32_fwd.value


/* XLATON */

/***ET+ ldrlv_t - Loader local variables */

struct  ldrlv_s
{
    ldrmte_t        *lv_pmte;       /* pointer to mte */
    ulong_t         lv_lbufaddr;    /* linear addr of alloc buf from PG */
    ulong_t         lv_sbufaddr;    /* segment addr of alloc buf from PG */
    ulong_t         lv_lrecbufaddr; /* linear addr of fixup buf from PG */
    ulong_t         lv_srecbufaddr; /* segment addr of fixup buf from PG */
    ulong_t         lv_new_exe_off; /* offset relative begin of new exe */
    ushort_t        lv_sfn;         /* current system file number */
    ushort_t        lv_hobmte;      /* handle of current mte */
    ulong_t         lv_objnum;      /* object number */
    ulong_t         lv_csmte;       /* size of swappable mte */
    ushort_t        lv_class;       /* module class */
    uchar_t         lv_type;        /* module type */
};

typedef struct ldrlv_s  ldrlv_t;        /* Loader local variables */

/*end*/

/***ET+ ldrrsrc16_t 16-bit Resource structure */

struct  ldrrsrc16_s
{
        ushort_t        ldrrsrc16_type;
        ushort_t        ldrrsrc16_name;
};

typedef struct  ldrrsrc16_s     ldrrsrc16_t;
/*end*/


/***ET+ ldrrsrc32_t 32-bit Resource structure */

struct  ldrrsrc32_s
{
        ushort_t        ldrrsrc32_type;         /* Resource type */
        ushort_t        ldrrsrc32_name;         /* Resource name */
        ulong_t         ldrrsrc32_cb;           /* Resource size */
        ushort_t        ldrrsrc32_obj;          /* Object number resoucre is found in */
        ulong_t         ldrrsrc32_off;          /* Offset within object */
};

typedef struct  ldrrsrc32_s     ldrrsrc32_t;
/*end*/


/***ET+ Resource segment structure, kept in BMP segment */

struct ldrrsrc_s
{
        ulong_t         rsrc_typeid;    /* resource type id */
        ulong_t         rsrc_nameid;    /* resource name id */
        ushort_t        rsrc_mte;       /* owner */
        ushort_t        rsrc_refcount;  /* local reference count */
        ushort_t        rsrc_localptr;  /* local PTDA chain */
        ushort_t        rsrc_globalptr; /* global chain */
};

typedef struct  ldrrsrc_s       ldrrsrc_t;
/*end*/


/***ET+ ldrrrsrc_t Return Resource structure */

struct  ldrrrsrc_s
{
        ptr_t   ldrrrsrc_ptr;
        int     ldrrrsrc_type;
};

typedef struct  ldrrrsrc_s      ldrrrsrc_t;


/***ET+ ldrwhois_t who is sructure */

struct  ldrwhois_s
{
        ushort_t        whois_ssegnum;
        ushort_t        whois_hmte;
        uchar_t         whois_achname[256];
};

typedef struct  ldrwhois_s      ldrwhois_t;
/*end*/

#define DOSCALL1STRING          "DOSCALL1"
#define SIZEDOSCALL1STR         8
#define MAX_DEMAND_READ         8       /* current we can only read 8 pages */
#ifdef  RANGE
#define RANGEINVALID            (INVALID | RANGE)
#define RANGEZEROED             (ZEROED | RANGE)
#endif

#define LOAD_PAGE               0       /* return value for LDRGetPGInfo */
#define LOAD_SEGMENT            1       /* return value for LDRGetPGInfo */
#define ALIGNMENT_SHIFT         512     /* logical sector alignment shift */
#define ENDMTETBL               0xDEAD  /* mark end of validatetbl */
#define SKIPCOPY                -1

#define MAX_NAME_LEN            8
#define MAX_PROC_LEN            256     /* Max proc name length incl. NUL */

#define EXT_PROGRAM             0       /* program */
#define EXT_LIBRARY             1       /* library */
#define EXT_DEVICE              2       /* device driver */
#define EXT_FSD                 3       /* installable file system */
#define EXT_VDD                 4       /* VDD */

#define CHECK_ALL               1       /* Use full set off invalid chars */
#define CHECK_WILDCARDS         2       /* Use wild card char set */
#define MIN_CHAR_VALUE          0x20    /* space */

/*
 * Sub-function code for DosQueryHeaderInfo
 */
#define HEADER_EXEINFO          1       /* return fields values from EXE hdr */
#define HEADER_READRSRCTBL      2       /* return pointer of rsrc table */
#define HEADER_READSECTOR       3       /* read resource table */
#define HEADER_LIBPATHLEN       4       /* return length of LIBPATH */
#define HEADER_LIBPATH          5       /* return LIBPATH string */
#define HEADER_FIXENTRY         6       /* fix a value in entry table */
#define HEADER_STE              7       /* return segment table info */
#define HEADER_MAPSEL           8       /* map selector to segment number */

/* XLATOFF */

/***LT+ ldrdld_t - Loader Demand Load Data.
 *
 *      Each process (PTDA) has a chain of ldrdld records, managed
 *      by the loader, allocated from the kernel heap, to keep track
 *      of the runtime attachments to a process.
 *
 *      The ldrdld records are created on the initial attachment
 *      to a module via a DOSLOADMODULE call, setting ldrdld_cRef
 *      to 1.  Subsequent DOSLOADMODULE calls increment ldrdld_cRef
 *      for the appropriate record.  ldrdld_cRef is decremented when
 *      the program calls DOSFREEMODULE, and the record is removed
 *      if ldrdld_cRef goes to Zero.   The entire chain of ldrdld
 *      records is freed when the process dies, in LDRFreeTask.
 */

struct  ldrdld_s
{
        struct ldrdld_s *ldrdld_pldrdldNext;
        ushort_t         ldrdld_hmte;
        ushort_t         ldrdld_cRef;
};

typedef struct  ldrdld_s        ldrdld_t;


/***LT  ldrpip_t - page count packet
 *      used by ldrMakeIDCache32, getpages and ldrProcessObjects
 */
struct ldrpip_s
{
        ulong_t         pip_pbuf;       /* Pointer to load buffer */
        int             pip_spbf;       /* Starting page in load buffer */
        int             pip_cpbf;       /* Count of pages in load buffer */
        int             pip_maxp;       /* Max. page to read */
};
typedef struct  ldrpip_s        ldrpip_t;

/**LT   ldrmodhdr - return structure for MTE info
 *      used to return info from the MTE.
 */
struct  ldrmhdr_s
{
    ushort_t    mhdr_flags;             /* ne_flags */
    ushort_t    mhdr_flagsothers;       /* ne_flagsothers */
    ushort_t    mhdr_exetyp;            /* ne_exetyp */
    ushort_t    mhdr_expver;            /* ne_expver */
    ulong_t     mhdr_rsrctab;           /* mte_rsrctab */
    ulong_t     mhdr_restab;            /* mte_restab */
    ushort_t    mhdr_sfn;               /* sfn */
};
typedef struct  ldrmhdr_s       ldrmhdr_t;

#ifdef  KM_REG_DS
/***LT  dllterm_t - DLL termination data buffer
 *
 *      This buffer contains the registers of the caller of
 *      DosFreeModule as well as all the handles of all the
 *      modules requiring termination notification.
 */

struct dllterm_s
{
    struct dllterm_s *dllt_pdlltnext;   /* Next record in chain */
    struct kmreg_s dllt_regs;           /* User registers */
    ushort_t dllt_chmod;                /* # of module handles left to call */
    VMHOB dllt_ahmod[1];                /* Array of handles (variable length) */
};
typedef struct dllterm_s dllterm_t;
#endif


/**LT   ldrnewseg - return structure for STE info
 *      used to return info from the STE
 */
struct  newseg                          /* Segment Table entry info */
{
    USHORT      ns_sector;              /* file sector of start of segment */
    USHORT      ns_cbseg;               /* number of bytes in file */
    USHORT      ns_flags;               /* attribute flags */
    USHORT      ns_minalloc;            /* minimum alloc in bytes */
};
typedef struct  ldrnewseg_s     ldrnewseg_t;

struct SysTblEnt_s
{
    char         *SysDll;
    ldrmte_t *    pMTE;
    unsigned char NamLen;
};
typedef struct  SysTblEnt_s     SysTblEnt_t;

 //Defect 80218 Need private version of kernel to use old DLL's
#ifdef NODLLMERGE
   #define NUMSYSTBLENT 11
#else
   #define NUMSYSTBLENT 8
#endif

#define ldrNumToSte(pmte, objnum) ((ldrste_t *) ldrNumToOte(pmte, objnum))

#define ldrIsLX(pmte) ( (((pmte)->mte_flags2) & MTEFORMATMASK) == MTEFORMATLX )
#define ldrIsNE(pmte) ( (((pmte)->mte_flags2) & MTEFORMATMASK) == MTEFORMATNE )

#define LEMAGIC         (('E' << 8) | 'L')
#define LXMAGIC         ((E32MAGIC2 << 8) | (E32MAGIC1))
#define MAX_PRELOAD     10

#define RESIZE64K(cb)   (cb? (ulong_t) cb : (ulong_t) 64*1024)
#define TCYIELD_CNT     31
#define RSRC32TYPEID    0xffffffff
#define LDRMAXHEAPCACHE 2048            /* Max. size of cache to put on heap */
#define _5K             5*1024

// #define MINSEGPACKCNT   ldrMINSEGPACKCNT
// #define MINPGPACKSIZE   ldrMINPGPACKSIZE
// #define MAXSEGPACKSIZE  ldrMAXSEGPACKSIZE
#define MINSEGPACKCNT   3
#define MINPGPACKSIZE   4000                /* 4k-96 */
#define MAXSEGPACKSIZE  32768               /* 32K */

/*
 * Loader Data
 */

extern  ldrdld_t            *pldrdldHeadKernel;  /* kernel demand load  */
                                                 /* reference list head */

extern  ushort_t             R0CS;               /* Ring 0 CS */
extern  ushort_t             R0DS;               /* Ring 0 DS */

extern  ldrmte_t             DosModMte;          /* Kernel MTE */
extern  ldrsmte_t            DosModMteSwappable; /* Swappable Kernel MTE */
extern  ldrmte_t             VDDModMte;          /* VDD MTE */
extern  ldrmte_t             FSHModMte;          /* FSD MTE */

extern  ulong_t              ldrcDLLDetach;  /* Count of detaching DLLs */
extern  ulong_t              cDLLTerm;       /* count of DLLs getting termination */

extern  ldrmte_t            *mte_h;        /* head of linked mte list */
extern  ldrmte_t            *program_h;    /* head of list of program modules */
extern  ldrmte_t            *program_l;    /* tail of list of program modules */
extern  ldrmte_t            *global_h;     /* head of list of global modules */
extern  ldrmte_t            *global_l;     /* tail of list of global modules */
extern  ldrmte_t            *specific_h;   /* head of list of specific modules */
extern  ldrmte_t            *specific_l;   /* tail of list of specific modules */

extern  VMHOB                DosModHdl;      /* Handle to DOSCALLS */
extern  ldrmte_t            *pmteDoscall1;   /* pmte pointer to DOSCALL1 */
extern  VMHOB                hMteDoscall1;   /* Handle to DOSCALL1 */

extern  ushort_t             mptbl[];           /* expantion table */
extern  ushort_t             validatetbl[];     /* validation table */
extern  struct hit_s         HeaderInfoTbl[];   /* DosQueryHeaderInfo fun 1 */
extern  struct his_s         HeaderInfoSTE[];   /* DosQueryHeaderInfo fun 4 */
extern  struct etmt_s        ExeToResMTETbl[];  /* Reduce EXE image to MTE */
extern  struct etmt_s        ExeToSwapMTETbl[]; /* Reduced EXE image to MTE */
extern  struct objflags_s    objflags[];     /* object flags table */
extern  struct selflags_s    selflags[];     /* selector flags table */
extern  struct objmem_s      objmem[];       /* memory type flags table */
extern  struct  pgstatechg_s pgstatechg[];   /* set type table */
extern  int                  swapping;       /* swapping enabled flag */
extern  char                 *pheaderbuf;    /* temp buf to read mte header */
extern  struct nonres_s      *pNonResNamTbl; /* pointer to Resident table */
extern  int                  cNonResNamTbl;  /* count of Resident table */
extern  uchar_t              ldrDoGCollect;  /* Garbage collection flag */
extern  char                 DOSCALL1[];
extern  ulong_t              ldrMINSEGPACKCNT;
extern  ulong_t              ldrMINPGPACKSIZE;
extern  ulong_t              ldrMAXSEGPACKSIZE;

/*
 * Module Loading
 */

// WARNING - this structure is passed on the stack as a single unsigned
//           long. It MUST therefore be packed as 4 contig bytes !!

struct GetModParms_s
{
    ushort_t gm_cchModname;
    uchar_t  gm_chLdrtype;
    uchar_t  gm_class;
};
typedef struct GetModParms_s GetModParms_t;

extern int ldrGetModule( uchar_t *pachModname,
                         ulong_t GetModParms,     // Packed GetModParms_t
                         ldrmte_t **ppmte );

extern int ldrAllocSegments( ldrlv_t *plv );

extern int ldrAllocSegment( ldrmte_t *pmte,
                            ldrste_t *pste,
                            ulong_t iseg,
                            ulong_t fLoadRsrc );

extern int ldrAllocObjects( ldrlv_t *plv );

extern int ldrAllocObject( ldrmte_t *pmte,
                           ldrote_t *pote,
                           uchar_t type,
                           PPTDA pptda,
                           ulong_t lobjnum );

extern int ldrLoadSegment( ldrste_t *pste,
                           ldrlv_t *plv,
                           ulong_t cbSegHack );

extern int ldrSegFixCloseRec( ldrste_t * );

extern int ldrSegFixOpenRec( ldrste_t * );

extern int ldrSegFixFixupPage( ldrste_t *pste,
                               ulong_t ulPage,
                               uchar_t *pchPage );

extern int ldrSegFixLoadIterated( ldrste_t *pste,
                                  ldrlv_t *plv,
                                  ulong_t ulPage,
                                  uchar_t *pchPage );


extern  void    ldrSetLoaded( void );

extern  int     ldrIsPath( char *pachname );

extern  int     ldrGetFileName( char *pchname,
                                char **ppchname,
                                char **ppchext );

extern  void    ldrLinkMTE( ldrmte_t *pmte );

extern  void    ldrUnlinkMTE( ldrmte_t *pmte );

extern  int     ldrProcessObjects( ldrmte_t *pmte );

/*
 * Fixups
 */

#define LDREACHOBJWPARMS ldret_t *pet, ulong_t *pentry, ldrmte_t *pmte, ldrlv_t *plv

extern  int     ldrEachObjEntry(ulong_t objnum,
                                 ldrmte_t *pmte,
                                 int (*pwork)(LDREACHOBJWPARMS),
                                 ldrlv_t *plv);

extern  int     ldrGetCallGate(ldret_t *pet, ulong_t *pentry,
                                 ldrmte_t *pmte, ldrlv_t *plv);

extern  int     ldrInitEntry(ldret_t *pet, ulong_t *pentry,
                                 ldrmte_t *pmte, ldrlv_t *plv);

extern  ulong_t ldrNextEntry(ldrmte_t *pmte, ldret_t *pet);

extern  int     ldrAllocCallGate(ldret_t *pet, ulong_t *pentry,
                                 ldrmte_t *pmte);

extern  ldrote_t *ldrNumToOte(ldrmte_t *pmte, ulong_t objnum);

extern  ulong_t ldrSkipEnts( uchar_t fNE, uchar_t type, uchar_t count );

extern  int     ldrEnum32bitRelRecs(ldrmte_t *pmte, ulong_t objnum, ulong_t cphyspg,
                            ulong_t psrcaddr, ulong_t psrcobj, ptda_t *pptda);

extern  void    ldrExpandRecord(ldrfrt_t *pfrt, ldrefrt_t *pefrt,
                                uchar_t **pfix);

extern  int     ldrGet32TgtAddr(ldrmte_t *pmte, ulong_t objnum,
                                ldrefrt_t *pefrt, struct taddr_s *ptaddr,
                                ptda_t *pptda );

extern  int     ldrApply32Fixups(ulong_t lsrcaddr, struct taddr_s *ptaddr,
                         ldrefrt_t *pefrt, uchar_t **p,  ulong_t lsrcobj);

extern  int     ldrIsInternalFixup(uchar_t *rec, ulong_t *len);

extern  int     ldrGetTgtMte(ushort_t modord, ldrmte_t *pmte,
                             ldrmte_t **ptgtmte);

extern  int     ldrGetOrdNum(ldrmte_t *pmte, uchar_t *pprocnam,
                        ushort_t *pentord);

extern  int     ldrGetOrdNumSub(uchar_t *pnt, uchar_t *pprocnam,
                        ushort_t *pentord);

extern  int     ldrGetEntAddr(ushort_t entord, ldrmte_t *pmte,
                        struct taddr_s *ptaddr, ulong_t flags,
                        ldrmte_t *psrcmte, ptda_t *pptda);

extern  SEL     ldrGetSelector(ldrmte_t *pmte, ulong_t lflags);

extern  ushort_t        ldrMapOrdinal(ushort_t ord);

extern int      ldrFindModule(char *pachModname, ushort_t cchModname,
                                ushort_t class, ldrmte_t **ppmte);

/*
 * Module Freeing
 */

extern  void    ldrGarbageCollect(void);

extern  void    LDRFreeTask(ptda_t *pptda);

extern  void    ldrLibDetach(void);

extern  ulong_t ldrLibDetachSub(ldrmte_t *pmte);

extern  void    ldrFreeMTE(ldrmte_t *pmte);

extern  ulong_t ldrGetGate(ldret_t *pet, ulong_t *pentry,
                                 ldrmte_t *pmte, ushort_t *psel);

extern  ulong_t ldrFreeCallGate(ldret_t *pet, ulong_t *pentry,
                                 ldrmte_t *pmte, ldrlv_t *plv);

extern  ulong_t ldrFreeLDTGate(ldret_t *pet, ulong_t *pentry,
                                 ldrmte_t *pmte, ldrlv_t *plv);

/* Graph Traversal
 */

extern  ulong_t ldrMarkTaskInGraph(ptda_t *pptda, void *pvoid);

extern  void    ldrMarkInGraph(VMHOB hmte);

extern  ulong_t ldrFindDetach(VMHOB hmte, ptda_t *pptda, ULONG flExitList);

extern  ulong_t ldrFindAttached(ptda_t *pptda);

extern  void    ldrFindGraph(ulong_t fAttached);

extern  ulong_t ldrRunGraph(ulong_t fClear,
                            ulong_t fInGraphUsed,
                            ulong_t (*pwork)(ldrmte_t *pmte));

extern  void    ldrClearGraph(void);

/*
 * Runtime Load Management
 */

extern  ulong_t ldrIncDLDRecord(VMHOB hmte, ptda_t *pptda);

extern  ulong_t ldrDecDLDRecord(VMHOB hmte, ptda_t *pptda, int funlink);

extern  ulong_t ldrWasLoadModuled(VMHOB hmte, ptda_t *pptda, ulong_t *pcref);

extern  void    ldrBlastDLDRecord (ptda_t *pptda);

/*
 * Loader to File System Interfaces
 */

extern  int     ldrRead( ushort_t SFN,
                         ulong_t lSeek,
                         uchar_t * plchBuf,
                         ulong_t pschBuf,
                         ulong_t cchBuf,
                         ldrmte_t * pmte );

extern  int     ldrOpen( ushort_t *pSFN,
                         uchar_t *pchModName,
                         ulong_t *pflMediaType );

extern  int     ldrTransPath( uchar_t *pchModName );

extern  int     ldrClose( ushort_t SFN );

extern  int     ldrNextLibPath( ulong_t *pichLibPath,
                                char *pchBuf,
                                int cchBuf,
                                char *pchModName,
                                ushort_t cchModName );
extern int      ldrFindChar(char *temp_ptr, unsigned int separator_char);
/*
 * Error handling
 */

extern  void    load_error( int errcode, ldrmte_t * pmte );

extern  int     ldrWriteErrTxt( int errcode, ldrmte_t *pmte );

/*
 * Misc.
 */

extern  ulong_t ldrAscToOrd( char *pachstring, int cchstring );

extern  void    ldrStrCpyB( char *pDst, char *pSrc, int Cnt );

extern  int     ldrMatchStringsN( char *pchUpper, char *pchMixed, int cchMixed);

// Validate and convert hMTE to pMTE
extern  ldrmte_t *ldrValidateMteHandle(VMHOB hobmte);

// Fast conversion of hMTE to pMTE, but no checking.
#define ldrpMTEFromHandle(hMTE) ( (ldrmte_t *) (VMPseudoHandleMap(hMTE)) )

extern  int     ldrGetRsrcSel(ulong_t typeid, ulong_t nameid, VMHOB hob,
                               ldrmte_t *pmte, ulong_t rsrc, ptr_t *paddr);

extern  int     ldrGet32Rsrc(VMHOB hob, ldrmte_t *pmte, ulong_t lobj,
                             ptr_t *paddr);

extern  int     ldrCheckForResource(ulong_t objnum, ldrmte_t *pmte,
                                    long prsrc, ptda_t *pptda, ulong_t lflags);

extern  int     ldrRsrcFindGlobal(ulong_t objnum, ldrmte_t *pmte, ulong_t prsrc);

extern  void    ldrFreeHuge(ulong_t objnum, ldrmte_t *pmte);

extern  int     ldrIsIFS(void);

extern  void    ldrGetMedia(void);

extern  int     ldrIncRefCount(ulong_t typeid, ulong_t nameid, VMHOB hobmte,
                       ldrmte_t *pmte);

extern int ldrSegment( ldrste_t *pste, ldrlf_t *plf, ldrlv_t *plv );

extern  ldrmte_t *pPortHoleMte; /* PortHole MTE */

extern  char    pPHMtePath[];

extern  char    pPHMteResNam[];

extern  ldrote_t pPHMteObjTab;

extern  void    ldrUCaseString(PCHAR pchstring, ulong_t cbstring);

extern  int     ldrPreloadLDT( ldrmte_t *pmte );

/*
 * Kernel Debugger support
 */

#ifdef PMDEBUG
extern  void    DebugLoadSymMTE(ldrmte_t *pmte, VMHOB hmte);
extern  void    DebugUnLinkSymMTE(ldrmte_t *pmte, VMHOB hmte);
#endif

/***LP  ldrAssert - cause internal error if assertion fails
 *
 *      Given a boolean, this procedure causes an internal error if
 *      the boolean is false.  Typically, the value of this boolean is
 *      derived from some test expression.
 *
 *      ldrAssert (e)
 *
 *      ENTRY   e               - boolean value (int)
 *      RETURN  NONE
 *
 *      CALLS   panicfmt
 *
 *      WARNING This procedure is implemented as a macro.
 *
 *      EFFECTS NONE
 */
#ifdef  LDRSTRICT
#       define ldrAssert(e) _assert(e)
#else
#       define ldrAssert(e)
#endif


/***LP  ldrStop - stop in kernel debugger
 *
 *      If the global ldrErr is TRUE and the mte pointer is not doscalls
 *      or is null, this routine transfers control to the kernel debugger.
 *
 *      ldrStop (id, pmte)
 *
 *      ENTRY   id              - identifier of caller (ignored)
 *              pmte            - mte pointer or NULL
 *      RETURN  NONE
 *
 *      CALLS   Debug_BreakDM
 *
 *      EFFECTS NONE
 */
#ifdef  LDRSTRICT
    extern      void _cdecl ldrStop(int id, void *pmte);
#else
#   define      ldrStop(id, pmte)
#endif

/*
 * Forwarder declarations
 */
extern int ldrGetFwdEnt(ldr32et_t *pent, ldrmte_t *pmte, ptda_t *pptda );
extern int ldrSelToFwdFlg(ushort_t);
extern int ldrGetImport(ldrmte_t *, long, ushort_t, int, ldrmte_t **, ushort_t *);
/*
 * Values for forwarder flags after processing:
 */
#define FWD_ALIAS16     0x01    /* Target object requires 16:16 alias */
#define FWD_SPECIAL     0x02    /* DOSMOD, FSHMOD, MVDMMOD */
#define FWD_PROCESSED   0x04    /* Forwarder has been processed */
#define FWD_SHIFT       3       /* Flat target selector field is 0x38 */
#define FWD_GATE16      0x40    /* 286 call gate */
#define FWD_IOPL        0x80    /* Target object has I/O privilege */

/*
 * Other forwarder constants.
 */
#define ERROR_LDR_FWD     -1    /* Return code indicating forwarder */
#define LDRFWDMAX       1024    /* Max length of forwarder chain */
#define SMALLFWDMAX     3       /* Max length of chain to fix up in memory */

/***LP  ldrSetupSrcErrTxt - Sets up source module name in error text buffer
 ***LP  ldrInvSrcErrTxt   - Invalidates source module in error text buffer
 *
 *      This procedure is implemented as a macro.
 *
 *      ENTRY   pachmodname             - ModuleName/FullPathName string
 *              cchmodname              - length of string
 *
 *      EXIT    none                    - TCB_SrcModNameBuf[L] is setup
 *
 */
#define ldrSetupSrcErrTxt(pachmodname, cchmodname)      \
                pTCBCur->TCB_SrcModNameBuf  = pachmodname;        \
                pTCBCur->TCB_SrcModNameBufL = cchmodname

#define ldrInvSrcErrTxt()       \
                pTCBCur->TCB_SrcModNameBufL = 0;

/***LP  ldrSetupTgtErrTxt - Sets up target module name in error text buffer
 ***LP  ldrInvTgtErrTxt   - Invalidates target module in error text buffer
 *
 *      This procedure is implemented as a macro.
 *
 *      ENTRY   pachmodname             - ModuleName/FullPathName string
 *              cchmodname              - length of string
 *
 *      EXIT    none                    - TCB_TgtModNameBuf[L] is setup
 *
 */
#define ldrSetupTgtErrTxt(pachmodname, cchmodname)      \
                pTCBCur->TCB_TgtModNameBuf  = pachmodname;        \
                pTCBCur->TCB_TgtModNameBufL = cchmodname

#define ldrInvTgtErrTxt()       \
                pTCBCur->TCB_TgtModNameBufL = 0;

/* XLATON */


/* Loader private debug */

#ifdef LDRSTRICT

extern ulong_t ldrDebugFlags;

#define LDR_DEBUG_OFF            0x00000000
#define LDR_INT3_BAD_GETPAGE     0x00000001
#define LDR_PRINT_BAD_GETPAGE    0x00000002
#define LDR_PRINT_ALL_GETPAGE    0x00000004
#define LDR_PRINT_ALL_DLM        0x00000008
#define LDR_PRINT_DLM_SEM        0x00000018
#define LDR_SETUP_DLL_INIT       0x00000020
#define LDR_EXTRA_GC_PANICS      0x00000040
#define LDR_PRINT_IMPORTS        0x00000080
#define LDR_PRINT_BROKEN_BASING  0x00000100
/* Skipping so that TREE_WALKING and ALL_DLM are easier to remember */
/* OK to use bits in between                                        */
#define LDR_PRINT_TREE_WALKING   0x00000800
#define LDR_DEBUG_ON             0xFFFFFFFF

#endif



/* ASM
;***LP  ldrSetupSrcErrTxt - Sets up source module name in error text buffer
;
;       This is implemented as a macro.
;
;       ENTRY:  pmtereg         register with pointer to swappable MTE
;
;       EXIT:   TCB_SrcModNameBuf and TCB_SrcModNameBufL setup
;
;       USES:   EAX, ECX, EDX
ldrSetupSrcErrTxt       macro   pmtereg
        mov     edx,_pTCBCur
        mov     ecx,[pmtereg].smte_restab
        movzx   eax, byte ptr [ecx]
        mov     [edx].TCB_SrcModNameBufL,ax
        inc     ecx
        mov     [edx].TCB_SrcModNameBuf,ecx
        endm

;***LP  ldrInvSrcErrTxt   - Invalidates source module in error text buffer
;
;       This is implemented as a macro.
;
;       ENTRY   NONE
;
;       EXIT    TCB_SrcModNameBufL is set to 0
;
;       USES    EDX
ldrInvSrcErrTxt macro   currtcbreg
        ifb <currtcbreg>
                mov     edx,_pTCBCur
                mov     [edx].TCB_SrcModNameBufL,0
        else
                mov     [currtcbreg].TCB_SrcModNameBufL,0
        endif
        endm

;***LP  ldrSetupTgtErrTxt - Sets up target module name in error text buffer
;
;       This is implemented as a macro.
;
;       ENTRY:  pmtereg         register with pointer to swappable MTE
;
;       EXIT:   TCB_TgtModNameBuf and TCB_TgtModNameBufL setup
;
;       USES:   EAX, ECX, EDX
ldrSetupTgtErrTxt       macro   pmtereg
        mov     edx,_pTCBCur
        mov     ecx,[pmtereg].smte_restab
        movzx   eax, byte ptr [ecx]
        mov     [edx].TCB_TgtModNameBufL,ax
        inc     ecx
        mov     [edx].TCB_TgtModNameBuf,ecx
        endm

;***LP  ldrInvTgtErrTxt   - Invalidates target module in error text buffer
;
;       This is implemented as a macro.
;
;       ENTRY   NONE
;
;       EXIT    TCB_TgtModNameBufL is set to 0
;
;       USES    EDX
ldrInvTgtErrTxt macro   currtcbreg
        ifb <currtcbreg>
                mov     edx,_pTCBCur
                mov     [edx].TCB_TgtModNameBufL,0
        else
                mov     [currtcbreg].TCB_TgtModNameBufL,0
        endif
        endm


;***LP  ldrInvErrTxt - Invalidate source and target Global Module name
;
;       This is implemented as a macro.
;
;       ENTRY   NONE
;
;       EXIT    TCB_TgtModNameBufL and TCB_SrcModNameBufL is set to 0
;
;       USES    EDX
ldrInvErrTxt    macro   currtcbreg
        ifb <currtcbreg>
                mov     edx,_pTCBCur
                mov     [edx].TCB_SrcModNameBufL,0
                mov     [edx].TCB_TgtModNameBufL,0
        else
                mov     [currtcbreg].TCB_SrcModNameBufL,0
                mov     [currtcbreg].TCB_TgtModNameBufL,0
        endif
        endm


;***LP  taddr_s - return info from ldrGetEntAddr
;       WARNING this struc must match in size the C structure taddr_s found
;       above
;
taddr_s         STRUC
taddr_toffl     dw      ?
taddr_toffh     dw      ?
taddr_tsel      dw      ?
taddr_tflags    db      ?
taddr_fflags    db      ?
taddr_cgsel     dw      ?
taddr_s         ENDS


dld_s           STRUC
dld_ptda        dw      ?
dld_mte         dw      ?
dld_cnt         db      ?
dld_s           ENDS
;       Relocation Data Item format

ri_s    STRUC
ri_stype        db      ?               ; relocation source type
ri_flags        db      ?               ; relocation target type
ri_source       dw      ?               ; relocation source offset
ri_target_seg   dw      ?               ; internal target segment index
ri_target_off   dw      ?               ; internal target entry offset index
ri_s    ENDS

ri_target_modnam EQU    ri_target_seg   ; import module name offset
ri_target_impnam EQU    ri_target_off   ; imoprt procedure name offset

SOURCE_MASK     EQU     07h
BYTE_ADR        EQU     00h             ; Byte source location
SEG_ADR         EQU     02h             ; Base source location
FAR_ADR         EQU     03h             ; Pointer source location
OFF_ADR         EQU     05h             ; Offset source location
TARGET_MASK     EQU     03h
INTERNALREF     EQU     00h
IMPORTORDINAL   EQU     01h
IMPORTNAME      EQU     02h
ADDITIVE        EQU     04h

RELOCSPERBUF    EQU     8
RELOCBUFLEN     EQU     ((SIZE ri_s)*RELOCSPERBUF)

;       Call Thunk Entry format

cte_s   STRUC
cte_flags       db      ?               ;
cte_inst        db      2 DUP(?)        ; space for INT or JMP instructions
cte_seg         db      ?               ; file segment table index
cte_off         dw      ?               ; offset of routine entry point
cte_s   ENDS

cte_sel         EQU (word ptr cte_inst) ; selector for ring 2 callgates

;       cte_flags bit definitions

EF_EXPORT       EQU     01h             ; entry is exported
EF_GDATA        EQU     02h             ; entry uses global shared data

BUF_LENGTH      EQU     64

;       Exported Entry format

ent_s   STRUC
ent_flags       db      ?               ;
ent_off         dw      ?               ; offset of routine entry point
ent_s   ENDS

;       get_module ex_type definitions

;       ste_flags bit definitions

TYPE_MASK       EQU     0003h           ; segment type field
CODE_TYPE       EQU     0000h           ; code segment type
DATA_TYPE       EQU     0001h           ; data segment type
ITERATED        EQU     0008h           ; segment data is iterated
MOVABLE         EQU     0010h           ; segment is not fixed
SHARED          EQU     0020h           ; segment is shared
PRELOAD         EQU     0040h           ; segment is not demand loaded
ERONLY          EQU     0080h           ; execute only (code segment)
RELOCINFO       EQU     0100h           ; segment has relocation records
CONFORMING      EQU     0200h           ; conforming code segment
SEGDPL          EQU     0C00h           ; reserved for 286 DPL bits
RING_2          EQU     0800h           ; Privilege level 2
RING_3          EQU     0c00h           ; privilege level 3
DISCARD         EQU     1000h           ; discardable
;;;;;;;         EQU     2000h           ; unused bit (used to be for resources)
SELALLOC        EQU     4000h           ; indicates selector allocated
OBJIOPL         EQU     8000h           ; object I/O privilege level
OBJCONFORM      EQU     4000h           ; object is conforming
NRALIAS         EQU     10h

;       BUGBUG: duplicate definition from bios/loader.c

OBJTILE         equ     OBJPRELOAD
OBJNOFLAT       equ     OBJIOPL
OBJHIMEM        equ     OBJDISCARD

;       BUGBUG: duplicate definition from exe386.h

OBJREAD         equ     00000001h       ; Readable Object
OBJWRITE        equ     00000002h       ; Writeable Object
OBJEXEC         equ     00000004h       ; Executable Object
OBJRSRC         equ     00000008h       ; Resource Object
OBJDISCARD      equ     00000010h       ; Object is Discardable
OBJSHARED       equ     00000020h       ; Object is Shared
OBJPRELOAD      equ     00000040h       ; Object has preload pages
OBJINVALID      equ     00000080h       ; Object has invalid pages
OBJZEROFIL      equ     00000100h       ; Object has zero-filled pages
OBJRESIDENT     equ     00000200h       ; Object is resident
OBJALIAS16      equ     00001000h       ; 16:16 alias required
OBJBIGDEF       equ     00002000h       ; Big/Default bit setting
OBJCONFORM      equ     00004000h       ; Object is conforming for code
OBJIOPL         equ     00008000h       ; Object I/O privilege level

*/
