;       SCCSID = @(#)stubload.inc	6.1 90/11/17
;       SCCSID = @(#)stubload.inc	6.2 90/01/24
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************
;     This file contains definitions and redefinitions of loadrr constants.
;
;   Modification History
;
;       09/08/86 (billme)   add "VERSION200" and "DISPLAY_STRING" equates
;
;       23-Sep-86 (billme) for FIDRQQinc, change CD34 - 9BD8 to 34CD - D89B
;
;       19-Mar-87   IDB    Added localvars ex_start/next_segno for huge
;                          segment support (PTM 2888).
;
; @@    26-Jun-87 (giacomoa) added equates: WRITE_FILE, DOLLAR_SIGN,
; @@                         STDERR.
;
;       05-Apr-88 (robertc) added local vars for iterated data load
;
;       Loader local stack equated variables
;       Old EXE Header format

;oh_s    STRUC
;oh_signature    dw      ?               ; Must contain 4D5A
;oh_len_mod_512  dw      ?               ; Low 9 bits of length
;oh_pages        dw      ?               ; Number of 512 byte pages
;oh_rle_count    dw      ?               ; Count of reloc entries
;oh_par_dir      dw      ?               ; # of paras before image
;oh_min_BSS      dw      ?               ; Min # of paras of BSS
;oh_max_BSS      dw      ?               ; Max # of paras of BSS
;oh_SS           dw      ?               ; SS of image
;oh_SP           dw      ?               ; SP of image
;oh_chksum       dw      ?               ; Ignored checksum of file
;oh_IP           dw      ?               ; IP of image
;oh_CS           dw      ?               ; CS of image
;oh_rle_table    dw      ?               ; Byte offset to reloc table
;oh_iov          dw      ?               ; Overlay number( 0 for root )
;oh_sym_tab      dd      ?               ; offset of symbol table in file
;oh_40_BB        dw      ?               ; DOS 4.0 behavior bits
;oh_win_BB       dw      ?               ; Windows behavior bits
;oh_oem_ID       dw      ?               ; Reserved for OEM's
;oh_oem_info     dw      ?               ; Reserved for OEM's
;oh_res          dw      10 DUP (?)      ; Reserved for future use
;oh_nhdr_offset  dd      ?               ; offset to new EXE header
;oh_s    ENDS

EXE_VALID_SIGNATURE     EQU     "ZM"
EXE_VALID_OLDSIGNATURE  EQU     "MZ"

;       Relocation Data Item format

IFNDEF  ri_s
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
ENDIF   ;ri_s

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

SOURCE_MASK     EQU     07h
SEG_ADR         EQU     02h
FAR_ADR         EQU     03h
OFF_ADR         EQU     05h
LOBYTE          EQU     00h             ; SteveSa P3687

TARGET_MASK     EQU     03h
INTERNALREF     EQU     00h
IMPORTORDINAL   EQU     01h
IMPORTNAME      EQU     02h
OSFIXUP         EQU     03h
ADDITIVE        EQU     04h

MOVABLE_ENTRY   EQU     0FFh

;       ex_func, a stack variable set by the exec.asm to EXEC_TRACE
;       if the program is to be debugged

EXEC_TRACE      EQU     14

?frame          =       0

localvar        ex_lib_name,DWORD
localvar        ex_func,BYTE
localvar        ex_mode,BYTE
localvar        ex_fh,WORD
localvar        ex_mte,WORD
localvar        ex_seghndl,WORD
localvar        ex_seg_alias,WORD
localvar        ex_environ,WORD
localvar        ex_cmdoff,WORD
localvar        ex_filetype,WORD

BASE_VAR_LEN    =       ?frame
?temp           =       ?frame

localvar        ex_ibb,WORD
localvar        ex_ohdr,<SIZE oh_s>
localvar        ex_dma,WORD
localvar        ex_size,WORD
localvar        ex_load_block,WORD
localvar        ex_rel_fac,WORD
localvar        ex_res_len_para,WORD
localvar        ex_envstr,DWORD
localvar        ex_argstr,DWORD
localvar        ex_relbuf,32

OEXE_VAR_LEN    =       ((?frame + 1) AND 0FFFEh)
                                        ; overlay oldheader structure with
?frame          =       ?temp           ; newheader structure

localvar        ex_ste,WORD
localvar        ex_start_segno,WORD
localvar        ex_next_segno,WORD
localvar        ex_segno,WORD
localvar        ex_mte_sel,WORD
localvar        ex_tgtmte_sel,WORD
localvar        ex_dslen,WORD           ; length of DS, 0 = 64K
localvar        ex_envlen,WORD          ; length of environment segment
localvar        ex_reloc_item,<SIZE ri_s>

localvar        lid_avail_size,DWORD   ; space available in segment
localvar        lid_avail_offset,WORD  ; offset to available space in segment
localvar        lid_rem_filedata,WORD  ; remaining data to be read from file
localvar        lid_seg_alias,WORD     ; alias selector to segment



NEXE_VAR_LEN    =       ((?frame + 1) AND 0FFFEh)

ex_ss_sp        EQU (dword ptr ex_ste)
ex_cs_ip        EQU (dword ptr ex_reloc_item)
ex_ds           EQU (word ptr ex_tgtmte_sel)


;       buffer to save module name or procedure name

        buf_length      equ     64


;       loader temporary descriptor index values

LD_MTESEL       equ     0
LD_ENVSEL       equ     LD_MTESEL
LD_TMPSEL       equ     2
LD_RMPSEL       equ     4
GC_MTESEL       equ     LD_MTESEL
GC_TMPSEL       equ     LD_TMPSEL

LD_SELCOUNT     equ     3       ; number of decsriptors to allocate


rparm struc
rp_handle       dw      ?               ; handle to segment
rp_selector     dw      ?               ; GDT selector to use
rparm ends






;   OSFIXUP Types and values ... See EXE spec for details
    ;
    ;   OSFIXUP types 0-3 are of the form "FWAIT,SegOver,ESCn" where n can vary
    ;   from  0 - 7.  We replace this with "INT,3C,ESCn | (SegOverMask)".
    ;   SegOverMask encodes the two segment register id bits into the high two
    ;   bits of the  ESC instruction
    ;

FP_TYPE_0        EQU     01h
    FIARQQ       EQU        03CCDh      ; byte reversed "INT,3C"
    FJARQQ_MASK  EQU        03Fh        ; SegOverMask for ES

FP_TYPE_1        EQU     02h
    FISRQQ       EQU        03CCDh      ; byte reversed "INT,3C"
    FJSRQQ_MASK  EQU        05Fh        ; SegOverMask for CS

FP_TYPE_2        EQU     03h
    FICRQQ       EQU        03CCDh      ; byte reversed "INT,3C"
    FJCRQQ_MASK  EQU        09Fh        ; SegOverMask for SS

; special dummy mask for cases 3 and 5

    FDUMMY_MASK EQU     0FFh

;   Case 3 is a special case.  ESCn | (DSOverMask) == ESCn, So we don't need to
;   do the masking at all.
FP_TYPE_3        EQU     04h
    FIERQQ       EQU        03CCDh      ; byte reversed "INT,3C"
                                        ; SegOverMask for DS is not needed
    ;
    ;   OSFIXUP type 4 is of the form "FWAIT,ESCn". We replace this with
    ;   "INT,34+n".  An artifact of the instruction set of the 80286/8287 lets
    ;   us accomplish this by simply adding a constant <FIDRQQinc> to the existing
    ;   instruction.
    ;
FP_TYPE_4        EQU     05h
    FIDRQQinc    EQU        034CDh - 0D89Bh     ; "(INT,34) - (FWAIT,ESC0)"

    ;   OSFIXUP type 5 is of the form "NOP,FWAIT".  We replace this with
    ;   "INT,3D" a simple store operation.
FP_TYPE_5        EQU     06h
    FIWRQQinc    EQU        03DCDh - 09B90h     ; "(INT,3D) - (NOP,FWAIT)"

; ###   FIWRQQ       EQU        03DCDh      ; byte reversed "INT,3D"


COMMANDPID      EQU     02
VERSION200      EQU     0200h
VERSION300      EQU     0300h

;;  Various sizes of Constant objects

EXTENTsizeB     EQU     5                       ; <".exe",0>
MAXCMDLINEB     EQU     128
MAXENVsizeB     EQU     0EFFFh                  ; 32k
MAXPATHsizeB    EQU     64
PARAsizeB       EQU     10h
;SEGTBLsizeB     EQU     4 * WORDsizeB
STACKsizeB      EQU     512
STACKsizeP      EQU     STACKsizeB / PARAsizeB
TRANSsizeB      EQU     7530h                   ; ptm 3395
TRANSsizeP      EQU     TRANSsizeB / PARAsizeB
WORDsizeB       EQU     2

SEGTBLsizeB     EQU     4 * WORDsizeB           ; we break alphabetic ordering
STACKsizeW      EQU     STACKsizeB / WORDsizeB  ; because MASM causes PHASE
                                                ; errors if Forward Ref CONSTs
                                                ; are used.
;;  DOS 2.x,3.x INT equates

DISPLAY_STRING  EQU     09h
ALLOCATE_BLOCK  EQU     48h
CLOSE_HANDLE    EQU     3Eh
FREE_BLOCK      EQU     49h
GET_CURR_DIR    EQU     47h
GET_VERSION     EQU     30h
LSEEK           EQU     42h
OPEN_FILE       EQU     3Dh
READ            EQU     3Fh
SET_BLOCK       EQU     4Ah
TERMINATE_PROC  EQU     4Ch
WRITE_FILE      EQU     40h     ; @@ write to file or device

DOLLAR_SIGN     EQU     24h     ; @@ append '$' to msg to display string
STDERR          EQU     02h     ; @@ display error message to stderr
D_PRES          equ     080h            ; present in memory

NAME_SIZE       equ     8
EXT_SIZE        equ     3
