TK_UM_FATAL_SRC	EQU	1H              
TK_UM_FATAL_DST	EQU	2H              
TK_UM_FATAL	EQU	(TK_UM_FATAL_SRC  OR  TK_UM_FATAL_DST)
TK_UM_SRCE	EQU	10H             
TK_UM_DEST	EQU	20H             
TK_UM_READ	EQU	TK_UM_SRCE      
TK_UM_WRITE	EQU	TK_UM_DEST      
TK_UM_SELPROBE	EQU	40H             
TK_UM_USER	EQU	80H             
TK_FF_BUF	EQU	00000001H       
TK_FF_EXIT	EQU	00000002H       
TK_FF_CRITSEC	EQU	00000004H       
TK_FF_ICE	EQU	00000008H       
TK_FF_NPX	EQU	00000010H       
TK_FF_TIB	EQU	00000020H       
TK_FF_TRC	EQU	00000040H       
TK_FF_SIG	EQU	00000080H       
TK_FF_CTXH	EQU	00000100H       
TK_FF_STIH	EQU	00000200H       
TK_FF_VDMBP	EQU	00000400H       
TK_FF_RTRY	EQU	00000800H       
TK_FF_PIB	EQU	00001000H       
TK_FF_SCH	EQU	00002000H       
TK_FF_TFBIT	EQU	00004000H       
TK_FF_TIBPRI	EQU	00008000H       
TK_IEF_PFCLI	EQU	0                
TK_IEF_TRC	EQU	1                
TK_EF_PFCLI	EQU	(1   SHL  TK_IEF_PFCLI)
TK_EF_TRC	EQU	(1   SHL  TK_IEF_TRC)
TK_WF_INTERRUPTED	EQU	01H     
TK_WF_TIMEEXP	EQU	02H     
TK_WF_INTPENDING	EQU	04H     
TK_WF_SINGLEWAKEUP	EQU	08H     
TK_WF_INTERRUPTIBLE	EQU	10H     
TK_WF_TIMEOUT	EQU	20H     
TK_WF_SLEEPING	EQU	40H     
TK_WF_PMPOSTED	EQU	80H     
TK_TG_CSUB	EQU	0H              
TK_TG_ONE	EQU	1H              
TK_TG_TREE	EQU	2H              
TK_TG_SCRN	EQU	3H              
TK_TG_ALL	EQU	4H              
TK_SF_WORKER	EQU	0100H           
TK_SF_WRETCODE	EQU	0200H           
TK_SF_EXEC	EQU	0400H           
TK_SF_DYING	EQU	0800H           
TKCPTDAMAX	EQU	4096             
TKCTCBMAX	EQU	4096             
TCBNEWFILES	EQU	1Q 
TCBKNOWEAS	EQU	2Q 
TCBREPORTPOSN	EQU	4Q 
TK_RP_ALLOCATED	EQU	01H 
TK_RP_INUSE	EQU	02H 
ifdef MEMSTAT

memstat_s	STRUC
ms_idletime	DD	?
ms_cputime	DD	?
ms_ws	DD	?
ms_pad	DD	?
ms_swapin	DD	?
ms_demandload	DD	?
ms_reclaimswap	DD	?
ms_reclaimdiscard	DD	?
ms_swapoutdirty	DD	?
ms_swapoutclean	DD	?
ms_discard	DD	?
ms_bitmapdf	DD	?
ms_stealdirtydf	DD	?
ms_steallastdf	DD	?
ms_stealcleandf	DD	?
memstat_s	ENDS

endif
ifdef CONTIGSTAT

contigstat_s	STRUC
cs_seglock	DD	?
cs_dhvmlock	DD	?
cs_kvmlock	DD	?
cs_alloc	DD	?
cs_uvirtsel	DD	?
cs_onepage	DD	?
cs_contig	DD	?
cs_existing	DD	?
cs_block	DD	?
cs_cblocks	DD	?
contigstat_s	ENDS

endif

fakelock_s	STRUC
fl_dummy	DB	12 DUP (?)
fakelock_s	ENDS

toe_worker_t struc
	dd ?
toe_worker_t ends


toe_s	STRUC
toe_ptoeNext	DD	?
toe_ptoePrev	DD	?
toe_cmsec	DD	?
toe_mscount	DD	?
toe_worker	DD	?
toe_s	ENDS

toe_t struc
db size toe_s dup(?)
toe_t ends

ifndef INCL_DIRENT
INCL_TKEXPORT	EQU	1


dir_entry	STRUC
dir_name	DB	11 DUP (?)
dir_attr	DB	?
dir_pad	DB	8 DUP (?)
dir_EAhandle	DW	?
dir_time	DW	?
dir_date	DW	?
dir_firstfile	DW	?
dir_size_l	DW	?
dir_size_h	DW	?
dir_entry	ENDS

DIRENT_DELETED	EQU	0E5H             
DIRENT_NOFEALIST	EQU	0               
attr_read_only	EQU	1H 
attr_hidden	EQU	2H 
attr_system	EQU	4H 
attr_volume_id	EQU	8H 
attr_directory	EQU	10H 
attr_archive	EQU	20H 
attr_device	EQU	40H                 
attr_newfiles	EQU	40H               
attr_not_norm	EQU	80H               
attr_all	EQU	attr_hidden+attr_system+attr_directory
attr_ignore	EQU	attr_read_only+attr_archive+attr_device
attr_changeable	EQU	attr_read_only+attr_hidden+attr_system+attr_archive
attr_used	EQU	attr_read_only OR attr_hidden OR attr_system OR attr_volume_id OR attr_directory OR attr_archive OR attr_newfiles
attr_not_3xbox	EQU	attr_not_norm+attr_newfiles
INV_3XBOX_SRCH_ATTRS	EQU	attr_newfiles   
must_have_attr_read_only	EQU	(attr_read_only  SHL  8 )
must_have_attr_hidden	EQU	(attr_hidden  SHL  8 )
must_have_attr_system	EQU	(attr_system  SHL  8 )
must_have_attr_directory	EQU	(attr_directory  SHL  8 )
must_have_attr_archive	EQU	(attr_archive  SHL  8 )
may_have_all	EQU	attr_read_only OR attr_hidden OR attr_system OR attr_directory OR attr_archive
must_have_all	EQU	must_have_attr_read_only OR must_have_attr_hidden OR must_have_attr_system OR must_have_attr_directory OR must_have_attr_archive
ignore_attr	EQU	10000H 
endif      
SetBP_CurrTCB macro

        push    bp
        mov     bp,TASKAREA:[CurrTCB]
   ENDM

UnSetBP_CurrTCB macro
        pop     bp
   ENDM

TIDANY	EQU	0                
TIDINVALID	EQU	-1               
TLMA_MAX_VARS	EQU	32        
TLMA_MAX_ALLOC_SIZE	EQU	8        
TLMA_BITS_PER_BM_ENTRY	EQU	8         
TLMA_MAX_BME	EQU	(TLMA_MAX_VARS / TLMA_BITS_PER_BM_ENTRY)
TLMA_LEN	EQU	(4  * TLMA_MAX_VARS) 

tcb_s	STRUC
TCBOrdinal	DW	?
TCBNumber	DW	?
TCBForcedActions	DD	?
TCBpPTDA	DD	?
TCBpTSD	DD	?
TCBptib	DD	?
TCBpTCBNext	DD	?
TCBcbStackMax	DD	?
TCBcbStackCur	DD	?
TCBpStack	DD	?
TCBpStack16Lo	DD	?
TCBpStack16Hi	DD	?
TCBpLibiHead	DD	?
TCBpLibiCurr	DD	?
TCBpLibiFree	DD	?
TCB_pcriFrameType	DD	?
TCB_pFrameBase	DD	?
TCB_hookheadLocal	DD	2 DUP (?)
TCB_phookOwnerHead	DD	?
TCBpteKStackTCB0	DD	?
TCBpteKStackTCB1	DD	?
TCBpteKStackTSD	DD	?
TCBpteKStackPTDA0	DD	?
TCBpteKStackPTDA1	DD	?
TCBpteKStackPTDA2	DD	?
TCBCurrTCB	DD	?
TCBCurrTSD	DD	?
TCBBiasTCB	DD	?
TCBBiasTSD	DD	?
TCBpDHRetAddr	DD	?
TCBTLMA	DD	TLMA_MAX_VARS DUP (?)
TCBDMAAdd	DD	?
TCBSecPos	DD	?
TCBThisSFT	DD	?
TCBValSec	DD	?
TCBpRTCB	DD	?
TCBProc_ID	DW	?
TCBUser_ID	DW	?
TCBfSharing	DB	?
TCBSrvAttrib	DB	?
TCBJfnFlag	DB	?
TCBAllowed	DB	?
TCBOpCookie	DD	?
TCBOpFlags	DW	?
TCBCurBuf	DD	?
TCBThishVPB	DW	?
TCBNextAdd	DW	?
TCBBytSecPos	DW	?
TCBClusNum	DW	?
TCBLastPos	DW	?
TCBBytCnt1	DW	?
TCBBytCnt2	DW	?
TCBSecCnt	DW	?
TCBSecClusPos	DB	?
TCBNoSetDir	DB	?
TCBJoins	DB	?
TCBPad	DB	?
TCBDevFCB	DB	?
TCB_direntry	DB	SIZE dir_entry DUP (?)
TCBName1	DB	12 DUP (?)
TCBName2	DB	13 DUP (?)
TCBDESTSTART	DW	?
        DB      ((SIZE dir_entry) - ($ - TCBName1)) DUP (0)


TCBBufHE	DB	?
TCBactBufHE	DB	?
TCBfIOLock	DB	?
TCBLockHndl	DB	SIZE fakelock_s DUP (?)
TCBThisCDS	DD	?
TCBThisFSC	DD	?
TCBpTmpCDS	DD	?
TCBpOpenBuf	DW	?
TCBpSearchBuf	DW	?
TCBFailErr	DW	?
TCBShareRetriesLeft	DW	?
TCBRetryCount	DW	?
TCBRetryLoop	DW	?
TCB_pSrchBuf	DW	?
TCB_pOpenBuf	DW	?
TCBAttrib	DW	?
TCBExtFCB	DB	?
TCBPad2	DB	?
TCBWFP_Start	DW	?
TCBRen_WFP	DW	?
TCBWFP_Path_End	DW	?
TCBCurr_Dir_End	DW	?
TCBDTAddr	DD	?
TCBVolID	DB	?
TCBSpaceFlag	DB	?
TCBCreating	DB	?
TCBDelAll	DB	?
TCBFoundDel	DB	?
TCBFound_dev	DB	?
TCBfSplice	DB	?
TCBClusFac	DB	?
TCBcMeta	DB	?
TCBPathNameType	DB	?
TCBDevPt	DD	?
TCBDirSec	DD	?
TCBDirStart	DW	?
TCBNxtClusNum	DW	?
TCBEntFree	DW	?
TCBEntLast	DW	?
TCBLastEnt	DW	?
TCBSattrib	DW	?
TCB_SemInfo	DD	?
TCB_SemDebugAddr	DD	?
TCB_NPX_Buffer	DD	?
TCBpTCBWaitNext	DD	?
TCBpTCBWaitList	DD	?
TCBQState	DB	?
TCBState	DB	?
TCBWakeFlags	DB	?
TCBcWindowBoost	DB	?
TCBPriClass	DB	?
TCBPriLevel	DB	?
TCBPriClassMod	DB	?
TCBSchFlags	DB	?
TCBPriority	DW	?
TCBPriorityMin	DW	?
TCBcBoostLock	DD	?
TCBpTCBPriNextQ	DD	?
TCBpTCBPriPrevQ	DD	?
TCBpTCBPriHigher	DD	?
TCBpTCBPriLower	DD	?
TCBpTCBPriNext	DD	?
TCBpTCBPriPrev	DD	?
TCBpTCBWakeup	DD	?
TCBSleepID	DD	?
TCBtoe	DB	SIZE toe_t DUP (?)
TCBCheckedSig	DB	?
TCBfSwapping	DB	?
TCBVolIONest	DB	?
TCBReqPktFlg	DB	?
TCBReqPkt	DD	?
ifdef MEMSTAT
TCBpMemStatCur	DD	?
TCBMemStat	DB	SIZE memstat_s DUP (?)
endif
TCBSysTime	DD	?
TCBUserTime	DD	?
TCB_pPVDBThd	DD	?
TCB_flDbg	DD	?
TCBCpl2_ESP	DD	?
TCBCpl2_SS	DW	?
TCBNewFlags	DB	?
TCBEntryActions	DB	?
TCBSig_pend	DW	?
TCBSig_holding	DW	?
TCBSig_cur	DW	?
TCBXcptRepRec	DD	?
TCBSig_termtid	DW	?
TCBSecbits	DB	?
TCBSecFlags	DB	?
TCB_ulSRIndex	DD	?
TCBMiscFlags	DB	?
TCBModeFlags	DW	?
TCBSpareFlags	DB	?
TCBLibiFlags	DB	?
TCBFiller	DB	?
TCB_ProcNameBuf	DD	?
TCB_ObjNameBuf	DD	?
TCB_TmpNameBuf	DD	?
TCB_SrcModNameBuf	DD	?
TCB_FaultBuf	DD	?
TCB_ObjNameBufL	DW	?
TCB_TmpNameBufL	DW	?
TCB_SrcModNameBufL	DW	?
TCB_FaultBufL	DW	?
TCBSecchild	DD	?
tcb_s	ENDS

tcb_t struc
db size tcb_s dup(?)
tcb_t ends

TCB struc
db size tcb_s dup(?)
TCB ends

PTCB struc
	dd ?
PTCB ends

TCB_TgtModNameBuf	EQU	TCB_TmpNameBuf  
TCB_TgtModNameBufL	EQU	TCB_TmpNameBufL 
TCBIOCopyStart	EQU	TCBDMAAdd       
TCBIOCopySize   EQU     (TCB_SemInfo - TCBDMAAdd)
TCBIOCopySizeX  EQU     (TCBIOCopySize - SIZE TCB_TmpNameBufL)
fOPENDASD	EQU	01H             
fLOCKDRV	EQU	02H             
BufHE_Percolate	EQU	1H              
BufHE_CurBufFreed	EQU	2H            
SM_TCB_SWAPPING	EQU	01H             
SM_TCB_RESIZING	EQU	02H             
TMF_CMapFailed	EQU	(01H )          
TMF_IGNORE_HE	EQU	(02H )          
TMF_MULT_XCPT	EQU	(04H )          
TMF_NoFwd	EQU	(08H )          
TMF_EXIT_TERM	EQU	(10H )          
TMF_NO_EXCEPT	EQU	(20H )          
TMF_XCPT_HE	EQU	(40H )          
TCBForce_Flg    EQU     BYTE PTR TCBForcedActions
TCBCpl2_SP      EQU     WORD PTR TCBCpl2_ESP

        .errnz          ((SIZE tcb_s) AND 3)
        .errnz          (TCBIOCopyStart AND 3)
        .errnz          (TCBIOCopySize  AND 3)

INIT_ROUTINE_FAILED	EQU	(01H )   
ifdef  VMSTRICT
TSDStackSize	EQU	1994                
else
TSDStackSize	EQU	1996                
endif

tsd_s	STRUC
ifdef MISCSTRICT
TSDpad	DB	4096 DUP (?)
endif
TSDUserStack	DW	TSDStackSize DUP (?)
TSDUserESP	DD	?
TSDUserSS	DW	?
TSDUserSSPad	DW	?
TSDKernelESP	DD	?
TSDKernelEBP	DD	?
TSDpTCB	DD	?
TSDpfnFault	DD	?
TSDTrapNum	DD	?
TSDerrcFault	DD	?
TSDpljmp	DD	?
TSDselFault	DW	?
TSDCpl2_SSSize	DW	?
TSDdescLDT	DD	2 DUP (?)
TSDdescKStackSS	DD	2 DUP (?)
TSDdescFPEM	DD	2 DUP (?)
TSDdescTIB	DD	2 DUP (?)
TSDulExitCode	DD	?
TSDerridFault	DD	?
TSDPFErr	DD	?
TSDlDbgRangeStart	DD	?
TSDlDbgRangeEnd	DD	?
TSDlDbgLastAddr	DD	?
TSDpPCB	DD	?
TSDpDLLTerm	DD	?
ifdef VMSTRICT
TSDcObjSem	DD	?
endif
tsd_s	ENDS

tsd_t struc
db size tsd_s dup(?)
tsd_t ends

TSDdescTaskCopy	EQU	TSDdescLDT
TSDdescThreadCopy	EQU	TSDdescKStackSS
ifdef   MISCSTRICT
        .errnz  SIZE tsd_s - 4096*2
else
        .errnz  SIZE tsd_s - 4096
endif

TSDPMStack	EQU	TSDKernelESP    
TSDRMStack	EQU	TSDUserESP      
TSDSTART         equ     TSDUserStack
TSDCBCOMMIT      equ     (SIZE tsd_s - TSDSTART)

ljmp_s	STRUC
ljmp_lEBX	DD	?
ljmp_lESI	DD	?
ljmp_lEDI	DD	?
ljmp_lEBP	DD	?
ljmp_lESP	DD	?
ljmp_lEIP	DD	?
ljmp_pfnFault	DD	?
ljmp_pljmp	DD	?
ljmp_s	ENDS

ljmp_t struc
db size ljmp_s dup(?)
ljmp_t ends


dostimer_s	STRUC
tmr_tom	DB	SIZE toe_t DUP (?)
tmr_hsem	DD	?
tmr_mstime	DD	?
tmr_pptda	DD	?
tmr_htimer	DW	?
tmr_fl	DW	?
tmr_prev	DD	?
tmr_next	DD	?
tmr_fired	DD	?
dostimer_s	ENDS

WAKEUP_SINGLE	EQU	01H     
WAKEUP_SINGLE_ALL	EQU	02H     
WAKEUP_BOOST	EQU	04H     

krnlsemshr_s	STRUC
ifdef  MISCSTRICT
ks_Signature	DD	?
endif
ks_bFlags	DB	?
ks_bType	DB	?
ks_Owner	DW	?
ks_cusPendingWriters	DW	?
ks_cusNest	DW	?
ks_cusReaders	DW	?
ks_cusPendingReaders	DW	?
krnlsemshr_s	ENDS

KSEMSHR struc
db size krnlsemshr_s dup(?)
KSEMSHR ends

PKSEMSHR struc
	dd ?
PKSEMSHR ends


krnlsemmtx_s	STRUC
ifdef  MISCSTRICT
ksm_Signature	DD	?
endif
ksm_bFlags	DB	?
ksm_bType	DB	?
ksm_Owner	DW	?
ksm_cusPendingWriters	DW	?
ksm_cusNest	DW	?
krnlsemmtx_s	ENDS

KSEMMTX struc
db size krnlsemmtx_s dup(?)
KSEMMTX ends

PKSEMMTX struc
	dd ?
PKSEMMTX ends


krnlsemevt_s	STRUC
ifdef  MISCSTRICT
kse_Signature	DD	?
endif
kse_bFlags	DB	?
kse_bType	DB	?
kse_Owner	DW	?
kse_cusPendingWriters	DW	?
krnlsemevt_s	ENDS

KSEMEVT struc
db size krnlsemevt_s dup(?)
KSEMEVT ends

PKSEMEVT struc
	dd ?
PKSEMEVT ends

KSEM_SIGNATURE	EQU	4D45534BH               
KSEM_NOINTERRUPT	EQU	1H              
KSEM_WRITER	EQU	2H 
KSEM_DISPLAYID	EQU	4H              
KSEM_NOBLOCK	EQU	8H 
KRNL_EVENTSEM	EQU	0 
KRNL_MUTEXSEM	EQU	1 
KRNL_SHARESEM	EQU	2 
KRNL_MAXSEMTYPE	EQU	3 
        
        .errnz  KRNL_EVENTSEM - 0
        .errnz  KRNL_MUTEXSEM - 1
        .errnz  KRNL_SHARESEM - 2

HKSEM struc
	dd ?
HKSEM ends

PHKSEM struc
	dd ?
PHKSEM ends


KSemState_s	STRUC
kss_semtype	DB	?
kss_fOwned	DB	?
kss_fWaiter	DW	?
kss_cRequest	DW	?
kss_tid	DW	?
KSemState_s	ENDS

KSEMSTATE struc
db size KSemState_s dup(?)
KSEMSTATE ends

PKSEMSTATE struc
	dd ?
PKSEMSTATE ends

ifdef   MISCSTRICT
        .errnz          ks_Signature - ksm_Signature
        .errnz          ks_Signature - kse_Signature
endif
        .errnz          ks_bFlags - ksm_bFlags
        .errnz          ks_bFlags - kse_bFlags
        .errnz          ks_bType - ksm_bType
        .errnz          ks_bType - kse_bType
        .errnz          ks_Owner - ksm_Owner
        .errnz          ks_Owner - kse_Owner
        .errnz          ks_cusPendingWriters - ksm_cusPendingWriters
        .errnz          ks_cusPendingWriters - kse_cusPendingWriters
        .errnz          ks_cusNest - ksm_cusNest

TKEnterInversion macro tcbreg
        inc     [tcbreg].TCBcBoostLock
        endm

TKTakeKernelSem macro
ifndef  _KSEMRequestMutex
        EXTRN32 _KSEMRequestMutex
endif
ifndef  _pPTDACur
        ReferFlat _pPTDACur,DWORD
endif
        mov     eax,[_pPTDACur]
        lea     eax,[eax].ptda_ptdasem
        CCALL32 _KSEMRequestMutex,<eax, -1>
        endm


TKClearKernelSem macro
ifndef  _KSEMReleaseMutex
        EXTRN32 _KSEMReleaseMutex
endif
ifndef  _pPTDACur
        ReferFlat _pPTDACur,DWORD
endif
        mov     eax,[_pPTDACur]
        lea     eax,[eax].ptda_ptdasem
        CCALL32 _KSEMReleaseMutex,<eax>
        endm


