SEL_512MEG	EQU	20000000H          
SEL_128K	EQU	20000H             
SEL_64K	EQU	10000H             
SEL_LADDR_SHIFT	EQU	13                   
SEL_LADDR_MASK	EQU	1fff0000H          
SEL_IPG_SHIFT	EQU	1                    
SEL_IPG_MASK	EQU	1fff0H             
SEL_LDTBIT	EQU	4H                  
SEL_RPLDPL_SHIFT	EQU	5H                 
SEL_RPL0	EQU	0H                  
SEL_RPL1	EQU	1H                  
SEL_RPL2	EQU	2H                  
SEL_RPL3	EQU	3H                  
SEL_RPLMASK	EQU	SEL_RPL3            
SEL_RPLCLR	EQU	0fffcH               
SELECTOR_MASK	EQU	0fff8H          
SEL_LOW_MASK	EQU	0f8H            
SEL_SHIFT	EQU	3H              
SEL_INCR	EQU	(1H   SHL  SEL_SHIFT)  
HUGESHIFT	EQU	SEL_SHIFT
HUGEINCR	EQU	SEL_INCR
SEL_MAXDESC	EQU	(SEL_64K  SHR  SEL_SHIFT) 
USERLDTSEL	EQU	7                

seldesc_s	STRUC
desc_cb	DD	?
desc_laddr	DD	?
desc_acc	DB	?
desc_attr	DB	?
seldesc_s	ENDS

desc_sel	EQU	      desc_laddr    
desc_off	EQU	desc_cb             
desc_cparm	EQU	desc_attr           
SEL_TASKINFOLADDR	EQU	(1c000000H  - 10000H )
SEL_TASKINFOSEG	EQU	(((SEL_TASKINFOLADDR  AND  SEL_LADDR_MASK)  SHR  SEL_LADDR_SHIFT)  OR  SEL_LDTBIT)
SEL_SYSINFOLADDR	EQU	(SEL_TASKINFOLADDR - 10000H )
SEL_SYSINFOSEG	EQU	(((SEL_SYSINFOLADDR  AND  SEL_LADDR_MASK)  SHR  SEL_LADDR_SHIFT)  OR  SEL_LDTBIT)
R3THKDS	EQU	(68H   OR  SEL_RPL3)
SELAL_GRAN4K	EQU	8000H  
SELAL_32BIT	EQU	4000H  
SELAL_GDTRPL0	EQU	2000H  
SELAL_UVIRT	EQU	1000H  
SELAL_ALLOCATED	EQU	0800H  
SELAL_SELMAP	EQU	0400H  
SELAL_BASEALL	EQU	0200H  
SELAL_DISCSEG	EQU	0100H  
SELAL_PRELOAD	EQU	0001H  
SELAL_CODE	EQU	0008H  
SELAL_EXPDN	EQU	0004H  
SELAL_CONFORM	EQU	0004H  
SELAL_W	EQU	0002H  
SELAL_R	EQU	0002H  
SELAL_PRIVSHIFT	EQU	SEL_RPLDPL_SHIFT
SELAL_PRIVMASK	EQU	60H    
SELSD_ALL	EQU	00000H        
SELSD_LIMIT	EQU	10000H        
SELSD_GATE	EQU	20000H        
SELSD_SHARED	EQU	1000H 
SELSD_ALIAS	EQU	0001H 
SELSD_CSALIAS	EQU	SELSD_ALIAS
SELSD_BASEALL	EQU	0004H       
SELFT_FREELDT	EQU	0        
SELFT_SHRINKLDT	EQU	1        
SELCA_W	EQU	1H          
SELCA_U	EQU	(SEL_RPL3  SHL  SEL_RPLDPL_SHIFT)
SELCA_IOPL	EQU	(SEL_RPL2  SHL  SEL_RPLDPL_SHIFT)
SELCA_PRIVMASK	EQU	(SEL_RPLMASK  SHL  SEL_RPLDPL_SHIFT) 
SEL_IFSLDT	EQU	0001H       
SEL_IFSGDT	EQU	0000H       
SEL_IFSSWAP	EQU	0002H       
SEL_IFSFIXED	EQU	0000H       
SEL_IFSNONCONTIG	EQU	0004H      
SEL_IFSRING0	EQU	0000H       
SEL_IFSRING1	EQU	2000H       
SEL_IFSRING2	EQU	4000H       
SEL_IFSRING3	EQU	6000H       
SEL_IFSRINGMASK	EQU	6000H       
SEL_IFSRINGSHFT	EQU	0008H       
SEL_IFSFLAGS	EQU	(SEL_IFSRINGMASK  OR  SEL_IFSLDT  OR  SEL_IFSSWAP                OR  SEL_IFSNONCONTIG)
SEL_GS_HOBPTDA	EQU	0001H       
SEL_FREE_KHB_OVERRIDE	EQU	1 
    
    
    
    
    
    
    LaToSelTiled MACRO laddr
        LOCAL   ?lts1

ifdef SELSTRICT
        cmp     laddr, SEL_512MEG
        jb      short ?lts1

        Panic   <'LaToSel'>
    ?lts1:
endif

        IFDIFI <eax>, <laddr>
            mov   eax, laddr
        ENDIF
        and   eax, SEL_LADDR_MASK
        shr   eax, SEL_LADDR_SHIFT
        or    eax, SEL_LDTBIT
    ENDM


    
    
    
    
    
    
    SelToLaTiled    MACRO    sel
        LOCAL   ?stl1

ifdef SELSTRICT
        test    sel, SEL_LDTBIT
        jnz     short ?stl1

        Panic   <'SelToLa'>

    ?stl1:
endif

        IFDIFI <ax>, <sel>
            mov     ax, sel
        ENDIF
        shl     eax, SEL_LADDR_SHIFT
        and     eax, SEL_LADDR_MASK
    ENDM


    
    
    
    
    
    
    IpgToSelTiled MACRO ipg
        LOCAL   ?its1

ifdef SELSTRICT

        cmp     ipg, SEL_128K
        jb      short ?its1

        Panic   <'IpgToSel'>

    ?its1:
endif
        IFDIFI <eax>, <ipg>
            mov   eax, ipg
        ENDIF
        and   eax, SEL_IPG_MASK
        shr   eax, SEL_IPG_SHIFT
        or    eax, SEL_LDTBIT
    ENDM


    
    
    
    
    
    
    SelToIpgTiled   MACRO    sel
        LOCAL   ?sti1

ifdef SELSTRICT

        test    sel, SEL_LDTBIT
        jnz     short ?sti1

        Panic   <'SelToIpg'>
    ?sti1:
endif
        IFDIFI <ax>, <sel>
            mov     ax, sel
        ENDIF
        shl     eax, SEL_IPG_SHIFT
        and     eax, SEL_IPG_MASK
    ENDM


    
    
    SELRplStamp MACRO   sel, acc
        
        

        IFDIFI  <sel>, <ax>
            mov     ax, sel
        ENDIF
        IFDIFI  <acc>, <cl>
            mov     cl, acc
        ENDIF
        and     cl, D_PRIV
        shr     cl, SEL_RPLDPL_SHIFT
        and     ax, SEL_RPLCLR
        or      al, cl
    ENDM
 

selswitchvdm_s	STRUC
ssv_ldthandle	DW	?
ssv_ldtpgmap	DW	?
ssv_ldtaddr	DD	?
selswitchvdm_s	ENDS

