COMMENT #
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*                                                                             *
* MODULE NAME     : INDEDES                                                   *
*                                                                             *
*                                                                             *
*                    5669-196 (C) COPYRIGHT 1988 Microsoft		      *
*                                                                             *
* DESCRIPTIVE NAME: Macros for setting up 80386 descriptors                   *
*                                                                             *
* STATUS (LEVEL)  : Version (0) Level (1.0)                                   *
*                                                                             *
* FUNCTION        : DESCR_DEF  - Define storage for a descriptor              *
*                   DESCR_INIT - Initialize a descriptor that has already     *
*                                been defined                                 *
*                                                                             *
* MODULE TYPE     : MAC                                                       *
*                                                                             *
* REGISTER USAGE  : 80286 Standard                                            *
*                                                                             *
* CHANGE ACTIVITY :                                                           *
*                                                                             *
* $MAC(INDEDES) COMP(LOAD) PROD(3270PC) :                                     *
*                                                                             *
* $D0=D0004700 410 870604 D : NEW FOR RELEASE 1.1                             *
* $P1=P0000311 410 870804 D : RENAME MODULE'S LIBRARY FILE TYPE TO "MAC"      *
*                                                                             *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#

; DESCR_DEF:  Define a descriptor in-line using DWs and DBs.
;
; Input:      For Segment descriptors, TYPE = SEG.
;             For Gate descriptors, TYPE = GATE.
;             Other parameters are as described by comments below.
;
; Output:     DWs (define words) and DBs (define bytes) using the passed
;             values.  Useful for copying descriptors directly out of the code
;             space, as when their values are forever static.
;
; Example:    DESCR_DEF  SEG, TSS0_LEN, TSS0_LOC, 0, CPL0_DATA_ACCESS
;
;             This defines a segment format (limit/base/access) descriptor
;             based on the parameters, which are usually equated values.  Note
;             that the low word of the address is TSS0_LOC and the high byte
;             is 0.


DESCR_DEF       MACRO   TYPE,PARM1,PARM2,PARM3,ARB

     IFIDN   <&TYPE>,<SEG>
;
;       Segment descriptor definition
;
        DW      &PARM1        ; Segment limit
        DW      &PARM2        ; Segment base address - low word
        DB      &PARM3        ; Segment base address - high byte
        DB      &ARB          ; Access rights byte
        DW      0             ; Intel reserved

     ENDIF

     IFIDN   <&TYPE>,<GATE>
;
;       Gate descriptor definition
;
        DW      &PARM1        ; Destination offset
        DW      &PARM2        ; Destination segment selector
        DB      &PARM3        ; Word count for stack-to-stack copy
                              ;   (only for call gates when PL changes)
        DB      &ARB          ; Access rights byte
        DW      0             ; Intel reserved

     ENDIF

                ENDM

PAGE

; DESCR_INIT: Initialize a descriptor dynamically.
;
;             NOTE:   ES must already point to the BASE of table
;                     where you want the descriptor to go.
;
;
; Input:      For Segment descriptors, TYPE = SEG.
;             For 4K granularity Segment descriptors, TYPE = BSEG.
;             For Gate descriptors, TYPE = GATE.
;             If the FIELD parameter is supplied, a MOV DI,FIELD is generated.
;             Otherwise, its current value is used.  Other parameters are as
;             described by comments below.
;
;
; Output:     DI ends up as DI + 8 (i.e.  pointing at next descriptor.  This
;             is useful if you are initializing several consecutive
;             descriptors).
;
;             The passed data is stored at ES:DI using string store.  This
;             macro would be used when creating descriptors dynamically, as
;             when allocating virtual machines.
;
; Example:    DESCR_INIT  GATE,INT13_PTR,INT13_IP,INT13_CS,0,TRAP_GATE_ACCESS
;
;             This stores the parameters in gate format (offset/ selector/word
;             count/access) through ES:DI, where DI is first loaded with
;             INT13_PTR.


DESCR_INIT      MACRO   TYPE,FIELD,PARM1,PARM2,PARM3,ARB

        PUSH    AX            ; Save the utility register

     IFNB    <&FIELD>

        MOV     DI,&FIELD     ; Set up index value to proper descriptor
        ADD     DI,GDT_LOC

     ENDIF


     IFIDN   <&TYPE>,<SEG>
;
;       Segment descriptor initialization
;
        MOV     AX,&PARM1       ; PARM1 = Segment Limit; load into AX
        STOSW                   ;   and store
        MOV     AX,&PARM2       ; PARM2 = BASE_LO_W; load into AX
        STOSW                   ;   and store
        MOV     AL,&PARM3       ; PARM3 = BASE_HI_B; load into AL, and
        MOV     AH,&ARB         ;   ARB = Access Rights Byte; load into AH
        STOSW                   ;     and store both
        MOV     AX,0            ; Make sure the Intel
        STOSW                   ;   reserved word is zero

     ENDIF


     IFIDN   <&TYPE>,<BSEG>
;
;       Big (4k granularity) segment descriptor initialization
;
        MOV     AX,&PARM1       ; PARM1 = Segment Limit; load into AX
        STOSW                   ;   and store
        MOV     AX,&PARM2       ; PARM2 = BASE_LO_W; load into AX
        STOSW                   ;   and store
        MOV     AL,&PARM3       ; PARM3 = BASE_HI_B; load into AL, and
        MOV     AH,&ARB         ;   ARB = Access Rights Byte; load into AH
        STOSW                   ;     and store both
        MOV     AX,0080H        ; 4k granularity bit
        STOSW

     ENDIF


     IFIDN   <&TYPE>,<GATE>
;
;       Gate descriptor initialization
;
        MOV     AX,&PARM1       ; PARM1 = Destination offset; load into AX
        STOSW                   ;   and store
        MOV     AX,&PARM2       ; PARM2 = Destination Selector;load into AX
        STOSW                   ;   and store
        MOV     AL,&PARM3       ; PARM3 = Word Count; load into AL, and
        MOV     AH,&ARB         ;   ARB = Access Rights Byte; load into AH
        STOSW                   ;     and store both
        MOV     AX,0            ; Make sure the Intel
        STOSW                   ;   reserved word is zero

     ENDIF

        POP     AX              ; Restore AX

        ENDM
