
dd_s	STRUC
dd_dd	DD	?
dd_s	ENDS

DWRD struc
db size dd_s dup(?)
DWRD ends

.errnz (SIZE DWRD - DWORD)      

PVW_CAL_POWEROF2	EQU	8 
PVW_CAL_ITERATIONS	EQU	(1   SHL  PVW_CAL_POWEROF2) 
PVW_FL_MT_LOCK	EQU	0001H   
PVW_FL_KRNL_PERS_INIT	EQU	0002H   
PVW_FL_KRNL_TRAN_INIT	EQU	0004H   
PVW_FL_KRNL_PERS_HOOKS	EQU	0008H   
PVW_FL_KRNL_TRAN_HOOKS	EQU	0010H   
PVW_FL_MSGQ	EQU	0020H   
PVW_FL_MSGQOF	EQU	0040H   
PVW_FLM_KRNL_INIT	EQU	(PVW_FL_KRNL_PERS_INIT  OR  PVW_FL_KRNL_TRAN_INIT)
PVW_FLM_KRNL_HOOKS	EQU	(PVW_FL_KRNL_PERS_HOOKS  OR  PVW_FL_KRNL_TRAN_HOOKS)
PVW_MSGQ_SIZE	EQU	(16  * PAGESIZE) 
PVW_MSGQ_TIMEOUT	EQU	1000             
MIN_PVMRT_INDEX	EQU	0        
MAX_PVMRT_INDEX	EQU	255 
ifdef PERFSTRICT                       
LAST_PVMRT_INDEX	EQU	(39 +80 )  
else
LAST_PVMRT_INDEX	EQU	39       
endif
PVMRT_SIZE	EQU	((LAST_PVMRT_INDEX+1 ) * SIZE   DWRD )
MAX_PVMRT_SIZE	EQU	((MAX_PVMRT_INDEX+1 ) * SIZE   DWRD )
RPC_MAX_DESC	EQU	(TKCTCBMAX + TKCPTDAMAX + MAXSFN)

ked_s	STRUC
ked_flFlags	DD	?
ked_pbDataBlk	DD	?
ked_cbDataSize	DD	?
ked_cbDataBlks	DD	?
ked_pbTextBlk	DD	?
ked_s	ENDS

ked_t struc
db size ked_s dup(?)
ked_t ends


ked_pers_s	STRUC
pers_cpu	DB	SIZE ked_t DUP (?)
pers_mem	DB	SIZE ked_t DUP (?)
pers_fbc	DB	SIZE ked_t DUP (?)
pers_spr	DB	SIZE ked_t DUP (?)
pers_cal	DB	SIZE ked_t DUP (?)
ked_pers_s	ENDS

ked_pers_t struc
db size ked_pers_s dup(?)
ked_pers_t ends


ked_tran_s	STRUC
tran_fil	DB	SIZE ked_t DUP (?)
tran_thd	DB	SIZE ked_t DUP (?)
ked_tran_s	ENDS

ked_tran_t struc
db size ked_tran_s dup(?)
ked_tran_t ends

PVW_NUM_ENT_KRNL_PERS	EQU	SIZE   ked_pers_t /SIZE   ked_t 
PVW_NUM_ENT_KRNL_TRAN	EQU	SIZE   ked_tran_t /SIZE   ked_t 
PVW_MAX_BLKS_KRNL_PERS	EQU	1        
PVW_MAX_BLKS_KRNL_TRAN	EQU	20       

pvpff_s	STRUC
pvpff_edx	DD	?
pvpff_ecx	DD	?
pvpff_eax	DD	?
pvpff_ulEI	DD	?
pvpff_eip	DD	?
pvpff_s	ENDS

pvpff_t struc
db size pvpff_s dup(?)
pvpff_t ends

ppvpff_t struc
	dd ?
ppvpff_t ends































PvwMtRoutEntry macro ctrtype, entname, ctrname, instance, init, dist
GenPublic PVWMI_&ctrtype&_&entname&_&ctrname&_&instance
        PVWMI_&ctrtype&_&entname&_&ctrname&_&instance equ ($-_PvwMtRouterTable)/(DWORD)
    IFIDNI <dist>,<far32>
        IFB <init>
        dd      OFFSET FLAT:g_pvwMt_&ctrtype&_&entname&_&ctrname&_&instance
        ELSE 
        dd      OFFSET FLAT:g_pvwMt_Init_&ctrtype&_&entname&_&ctrname&_&instance
        ENDIF 
    ELSE
        IFB <init>
        dd      OFFSET FLAT:pvwMt_&ctrtype&_&entname&_&ctrname&_&instance
        ELSE 
        dd      OFFSET FLAT:pvwMt_Init_&ctrtype&_&entname&_&ctrname&_&instance
        ENDIF 
    ENDIF
endm





























PvwPatchFn macro ctrtype, entname, ctrname, instance
GenPublic _PvwPatch_&ctrtype&_&entname&_&ctrname&_&instance
_PvwPatch_&ctrtype&_&entname&_&ctrname&_&instance:
IFDEF PERFSTRICT
        push    DWORD PTR PVWMI_&ctrtype&_&entname&_&ctrname&_&instance
ELSE  
        push    BYTE PTR PVWMI_&ctrtype&_&entname&_&ctrname&_&instance
ENDIF 
        jmp     pvwPatchHookA
endm























































pvwMtSetup      macro   hooktype,regopts
        ?fbOpts = 0
        IRP opt,<regopts>
            IFIDNI <opt>,<savreg>
                ?fbOpts = ?fbOpts OR 1
                IRP ht,<ST,ET,EQ,LQ,CtST,SmTm,SmET>
                    IFIDN <hooktype>,<ht>
                        ?fbOpts = ?fbOpts OR 2
                    ENDIF
                ENDM
            ELSEIFIDNI <opt>,<loaddses>
                ?fbOpts = ?fbOpts OR 4
            ELSE
                IF2
                    %out Bad register option opt
                ENDIF
                .err
            ENDIF
        ENDM
        IF ?fbOpts AND 1
            pushfd
            push    ecx
        ENDIF
        IF ?fbOpts AND 2
            push    eax
            push    edx
        ENDIF
        IF ?fbOpts AND 4
            push    ds
            push    es
            FlatContext <ds,es>,ecx
        ENDIF
        endm

pvwMtCleanup    macro
        IF ?fbOpts AND 4
            pop     es
            pop     ds
        ENDIF
        IF ?fbOpts AND 2
            pop     edx
            pop     eax
        ENDIF
        IF ?fbOpts AND 1
            pop     ecx
            popfd
        ENDIF
        RETC
        endm













PvwMtDataBlkPtr macro   enttype,entname,dstreg,entptr

        IFIDN      <enttype>,<pers>
                IFNB  <entptr>
                        %OUT Variable (&entptr&) ignored.
                ENDIF 
                mov     &dstreg&,_ked_&enttype&.&enttype&_&entname&.ked_pbDataBlk
        ELSEIFIDN  <enttype>,<tran>
                IFIDN <entname>,<fil>           
                        IFNB <entptr>
                                mov     &dstreg&,&entptr
                        ELSE  
                                push    es
                                push    ebx
                                mov     &dstreg&,_pTCBCur
                                les     bx,[&dstreg&].TCBThisSFT
                                mov     &dstreg&,es:[bx].sf_fsi.pPVDBFil  
                                pop     ebx
                                pop     es
                        ENDIF 




                ELSEIFIDN <entname>,<prc>       
                        IFNB <entptr>
                                mov     &dstreg&,&entptr
                        ELSE  
                                mov     &dstreg&,_pPTDACur
                        ENDIF 
                        mov     &dstreg&,[&dstreg&].ptda_pPVDBPrc
                ELSEIFIDN <entname>,<thd>       
                        IFNB <entptr>
                                mov     &dstreg&,&entptr
                        ELSE  
                                mov     &dstreg&,_pTCBCur
                        ENDIF 
                        mov     &dstreg&,[&dstreg&].TCB_pPVDBThd



                ELSEIFIDN <entname>,<sem>

                        DosContext <ds>                                
                        mov     &dstreg&,ds:[bx].SysSempPvwBlk         
                        FlatContext <ds>                               




                ELSEIF2   
                        %OUT Unknown transient entity name (&entname&).
                        .ERR
                ENDIF     
        ELSEIF2    
                %OUT Unknown entity type (&enttype&).
                .ERR
        ENDIF      
endm





































PvwMtCt macro enttype, entname, ctrname, instance, regopts, dist
local exit
Procedure pvwMt_Ct_&entname&_&ctrname&_&instance,<dist>
        pvwMtSetup Ct,<regopts>
        PvwMtDataBlkPtr <enttype>,<entname>,ecx,
        jecxz   exit
        inc     [ecx].&entname&_ct&ctrname
exit:   pvwMtCleanup
EndProc pvwMt_Ct_&entname&_&ctrname&_&instance
endm


PvwMtST macro enttype, entname, ctrname, instance, regopts, dist
local exit
Procedure pvwMt_ST_&entname&_&ctrname&_&instance,<dist>
        pvwMtSetup ST,<regopts>
        PvwMtDataBlkPtr <enttype>,<entname>,ecx
        jecxz   exit
        inc     [ecx].&entname&_hdr.dbh_ulSem 
        add     ecx,&entname&_tm&ctrname
        CCALL32 TMR32SubTime
exit:   pvwMtCleanup
EndProc pvwMt_ST_&entname&_&ctrname&_&instance
endm

PvwMtET macro enttype, entname, ctrname, instance, regopts, dist
local exit
Procedure pvwMt_ET_&entname&_&ctrname&_&instance,<dist>
        pvwMtSetup ET,<regopts>
        PvwMtDataBlkPtr <enttype>,<entname>,ecx
        jecxz   exit
        inc     [ecx].&entname&_hdr.dbh_ulSem 
        add     ecx,&entname&_tm&ctrname
        CCALL32 TMR32AddTime
exit:   pvwMtCleanup
EndProc pvwMt_ET_&entname&_&ctrname&_&instance
endm


PvwMtEQ macro enttype, entname, ctrname, instance, regopts, dist
local exit
Procedure pvwMt_EQ_&entname&_&ctrname&_&instance,<dist>
        pvwMtSetup EQ,<regopts>
        PvwMtDataBlkPtr <enttype>,<entname>,ecx
        jecxz   exit
        inc     [ecx].&entname&_hdr.dbh_ulSem 
        add     ecx,&entname&_ql&ctrname
        inc     [ecx].ql_ct
        add     ecx,ql_tm               
        CCALL32 TMR32SubTime
exit:   pvwMtCleanup
EndProc pvwMt_EQ_&entname&_&ctrname&_&instance
endm

PvwMtLQ macro enttype, entname, ctrname, instance, regopts, dist
local exit
Procedure pvwMt_LQ_&entname&_&ctrname&_&instance,<dist>
        pvwMtSetup LQ,<regopts>
        PvwMtDataBlkPtr <enttype>,<entname>,ecx
        jecxz   exit
        inc     [ecx].&entname&_hdr.dbh_ulSem 
        add     ecx,&entname&_ql&ctrname
        dec     [ecx].ql_ct
        add     ecx,ql_tm               
        CCALL32 TMR32AddTime
exit:   pvwMtCleanup
EndProc pvwMt_LQ_&entname&_&ctrname&_&instance
endm

PvwMtCtST macro enttype, entname, ctrname, instance, regopts, dist
local exit
Procedure pvwMt_CtST_&entname&_&ctrname&_&instance,<dist>
        pvwMtSetup CtST,<regopts>
        PvwMtDataBlkPtr <enttype>,<entname>,ecx
        jecxz   exit
        inc     [ecx].&entname&_hdr.dbh_ulSem 
        inc     [ecx].&entname&_ct&ctrname
        add     ecx,&entname&_tm&ctrname
        CCALL32 TMR32SubTime
exit:   pvwMtCleanup
EndProc pvwMt_CtST_&entname&_&ctrname&_&instance
endm












































PvwMtRoutEntrySpares macro ctrname
        PvwMtRoutEntry ET, spr, <ctrname>, 0, ,
        PvwMtRoutEntry ST, spr, <ctrname>, 0, ,
        PvwMtRoutEntry CtST, spr, <ctrname>, 0, ,
        PvwMtRoutEntry Ct, spr, <ctrname>, 0, ,

        PvwMtRoutEntry ET, spr, <ctrname>, 1, , far32
        PvwMtRoutEntry ST, spr, <ctrname>, 1, , far32
        PvwMtRoutEntry CtST, spr, <ctrname>, 1, , far32
        PvwMtRoutEntry Ct, spr, <ctrname>, 1, , far32
endm















PvwMtSpare macro ctrname

PvwMtET         pers, spr, <ctrname>, 0, savreg,
PvwMtST         pers, spr, <ctrname>, 0, savreg,
PvwMtCtST       pers, spr, <ctrname>, 0, savreg,
PvwMtCt         pers, spr, <ctrname>, 0, savreg,


_TEXT   SEGMENT

PvwMtET         pers, spr, <ctrname>, 1, <savreg,loaddses>, far32
PvwMtST         pers, spr, <ctrname>, 1, <savreg,loaddses>, far32
PvwMtCtST       pers, spr, <ctrname>, 1, <savreg,loaddses>, far32
PvwMtCt         pers, spr, <ctrname>, 1, <savreg,loaddses>, far32


_TEXT   ENDS

endm















PvwPatchFnSpare macro ctrname

PvwPatchFn      ET, spr, <ctrname>, 0
PvwPatchFn      ST, spr, <ctrname>, 0
PvwPatchFn      CtST, spr, <ctrname>, 0
PvwPatchFn      Ct, spr, <ctrname>, 0

endm


