
;
;	IBM Confidential
;
;	Copyright (c) IBM Corporation 1987, 1989
;
;	All Rights Reserved
;
;   Description:
;
;   This file contains all the local defines, data structures and
;   macros used by VDM Manager.
;
;  Update History:
;
;  6.6	08/18/91  Jeff Muir CP20 B725703  added global sysvalue for PICMask
;  6.7	09/15/91  Jeff Muir CP20 B726841  delete IOPL property
;  6.8	02/06/92  Stacey Barnes CP20 B732228 add new type define for mi_fState
;  10/19/92 56061 Stacey Barnes Changed GSVMAX to VDHGSV_BOOTDRV
;  11/27/95 72417							;72417
;  moved find.inc after tkexport.h					  ;72417
;




; Configurable defines

DOSMEMSIZE	EQU	(256 * _1K)	;Dos Heap Size
MAXLENXDD	EQU	8		;PDD/VDD Name length
MAX_FREEZE_COUNT	EQU	16		;Maximum number of pending
						;VDHFreezeVDM
MAX_INT_NEST	EQU	33		;Interrupt nesting count
SIG_AM_SWAP	EQU	0AAh		;VDHAllocMem signature
SIG_AM_NOSWAP	EQU	0BBh		;VDHAllocMem signature
VDM_MAX_TIMERS	EQU	16		;Timer Hooks Limit

VDHCP_NOYIELD	EQU	(1  SHL	 9)	   ;Dont yield if less than 2Kb
VDHCP_YIELD	EQU	(1  SHL	 10)	   ;Copy 4kb between yield

MASKUCHAR	EQU	0ffh
MASKUSHORT	EQU	0ffffh
MASKULONG	EQU	0ffffffffh

CMD_GET_INTERRUPT_HANDLER	EQU	00h	      ;command to vpic

; Bit definitions for vdmid_flVDM

VDM_VMBOOT	EQU	000000001h
;VDM_IOPL3	EQU	000000002h	; 6.7
VDM_TITLECHANGE		EQU	000010000h


; VDMM Assertion checking  macros


;***	VDM Event Handler structure
;
;	EH structure links the VDD's entry points for a VDM
;	user hook.
;


FIFO_ORDER	EQU	0
LIFO_ORDER	EQU	1

DefType PUH,dd
DefType PEXITH,dd
DefType PPDBH,dd
DefType PMEMMAPPEDH,dd

DefStruc ,EL_s			;el  event list
	PUH	el_pfn		       ;VDD handler
	ULONG	el_hmte		       ;VDD module handle
	PVOID el_pel	    ;Next entry ; Ended by NULL
EndStruc EL

DefType PEL,dd

DefStruc ,EH_s			;eh  event head
	ULONG	eh_fOrder	       ;Order in which new handler gets added
	PEL	eh_pelFirst	       ;First Event handler
	PEL	eh_pelLast	       ;Last Event handler
EndStruc EH

DefType PEH,dd




;***	Page Fault Handler Structure
;	PFH structure makes a linked list of all the page fault handler
;	registered for a VDM. The Head of the PFH list is HPFH which
;	keeps track of first and last record of this list. HPFH is
;	stored in MVDM kernel instance data.
;

DefStruc ,PFH_s			;Page fault handler structure
	PVOID	pf_pv		       ;Starting region address
	ULONG	pf_cPages	       ;Number of pages in region
	PFAULTHOOK  pf_pfn	       ;Page fault handler address
	BOOL	pf_flags	       ;Byte or page granular address
	PVOID pf_ppfh	     ;Next entry; Ended by NULL
EndStruc PFH

DefType PPFH,dd

DefStruc ,HPFH_s			;Header of PFHs
	PPFH	hf_ppfhFirst	       ;First PFH on the list
	PPFH	hf_ppfhLast	      ;Last PFH on the list
EndStruc HPFH

DefType PHPFH,dd



;***	PDD Entry Point Structure
;
;	PDDEP structure stores PDD entry points for
;	PDD/VDD communication
;


DefStruc ,PDDEP_s			;PDD Entry point structure
	CHAR	pddep_szPDD,,MAXLENXDD+1 ;PDD name
	FPFNPDD pddep_fpfn		 ;Entry point routine
	PVOID pddep_ppddep  ;Next entry point
EndStruc PDDEP

DefType PPDDEP,dd


;***	VDD Entry Point Structure
;	VDDEP stores VDD entry points for VDD-VDD and VDD_OS2
;	communication. VDDEP makes a linked list and each record
;	represents entry points for a VDD. VDDs can register
;	entry points with same name. VDDPROC is used to keep
;	entry points in a linked list for VDDs registered with
;	same name. HDLVDD is the handle returned to the caller
;	of VDHOpenVDD or DosOpenVDD.
;

DefStruc ,VDDPROC_s
	PFNDEVREQ     vddproc_pfnvdd	 ;Entry point for VDD/VDD comm.
	PFNSYSREQ     vddproc_pfnos2	 ;Entry point for OS2/VDD comm.
	PVOID pvddproc	  ;Entry points registered with same name
EndStruc VDDPROC

DefType PVDDPROC,dd

DefStruc ,VDDEP_s			;VDD Entry point structure
	CHAR	 vddep_szVDD,,MAXLENXDD+1 ;VDD Name
	PVDDPROC vddep_vddp		  ;VDD entry points
	ULONG	 vddep_hmte		  ;For Deregistering if VDD fails
	PVOID vddep_pvddep  ;Next VDD
EndStruc VDDEP

DefType PVDDEP,dd

DefStruc ,HDLVDD_s			;VDD handle
	PVDDPROC hdlvdd_pvddproc	  ;VDD routine to be called
	PVOID hdlvdd	    ;Next VDD handle;NULL if no more
EndStruc HDLVDD

DefType PHDLVDD,dd

; Communication Types Offered by a VDD

VDDVDD	EQU	0
OS2VDD	EQU	1



;***	Block Pool Data structures
;
;	BPH is the Block Pool Header which stores all the block
;	pools in a linked list. Each record on the list is a block
;	pool which will have chain of blocks of same size. Every
;	block on the pool keeps a pointer to its next block.
;

DefStruc ,BPH_s			;Block Pool Header
    ULONG   bph_cb		       ;Block size
    ULONG   bph_fl		       ;Block pool flag
    PVOID   bph_pUseList	       ;List of blocks in use
    PVOID   bph_pFreeList	       ;List of free blocks
    PVOID bph_pbph	      ;Block pool headers list
EndStruc BPH

DefType PBPH,dd			;Handle to the block pool



;***	Linear Map Structures
;
;	LR is the linear record for a page aligned memory
;	allocation. LA is the linear arena constituting of
;	LR's to represent either the global memory map or the
;	local memory map for a VDM. BYTEHEAP represents the byte
;	heap which is used to get the current starting heap
;	address for allocation and the size of remaining heap.
;	Byte heap management does'nt keep track of each byte
;	granular allocation.
;

;  MM - Memory Map structure
;
;	Valid rgfState combinations:
;
;	MM_ALLOCATED	- allocated linear space.  For example:
;			  The DOS Emulation "kernel" data and
;			  the DOS Memory Arena.
;
;	MM_RESERVED	- space reserved for later aliasing or
;			  allocation, not currently aliased.
;
;	MM_INSTANCE_VDD	    - For VDD Instance data.
;
;	MM_INSTANCE_KERNEL - for MVDM Kernel instance data
;
;	lr_sig is useful in those cases where the record gets broken
;	in more than one. This will have the unique starting address
;	of the orginal record. Will be used as a safegaurd against
;	improper coalescing and VDHUnresrvepages.
;


DefStruc ,LR_s			;Linear Memory Record
	PVOID	lr_pv		       ;starting linear address
	ULONG	lr_cb		       ;length in bytes(always page granular)
	ULONG	lr_cbAllocated	       ;bytes commited(always page granular)
	ULONG	lr_fState	       ;state of region
	PVOID	lr_sig		       ;signature.Starting address of record
	PVOID lr_plr	      ;Next entry
EndStruc LR

DefType PLR,dd

DefStruc ,LA_s			;Linear arena
	PLR	la_plrFirst	       ;First LR
	PLR	la_plrLast	       ;Last LR
	PLR	la_plrAbove1MB	       ;First record above 1Mb; It makes
					;the search fast.
EndStruc LA

DefType HLA,dd

; lr_fState values.
; Note that the mapped/unmapped state of a record is determined
; by MM_ALLOCATED. MM_BLACKHOLE is an additional flag for
; LHMapPages as a single object of size bigger then black hole size
; will have more then one mapping and this flag will indicate the
; use of repeated VMfree on the same record.
; Reason why MM_SWAPPABLE and MM_RESIDENT are kept separate is
; that in the code most of the time we just want to know whether
; record is allocated or not.

MM_ALLOCATED	EQU	00001h		;allocated linear space
MM_RESERVED	EQU	00002h		;reserved  linear space
MM_BLACKHOLE	EQU	00004h		;Mapped to black hole
MM_FINSTANCE	EQU	00008h		;instance data record (fixed)
MM_SINSTANCE	EQU	00010h		;instance data record (Swap)
MM_SWAPPABLE	EQU	00020h		;These two flags further
MM_RESIDENT	EQU	00040h		;explains MM_ALLOCATED.
					    ;Valid only with MM_ALLOCATED
MM_BROCKEN	EQU	00080h		;If a record is brocken in
					    ;more than one records this
					    ;flag will be marked on,so
					    ;that no further reallocation
					    ;can be done on it.

; LHAllocPages Flag type values
LH_RESERVE	EQU	0
LH_ALLOC_SWAPPABLE	EQU	1
LH_ALLOC_RESIDENT	EQU	2


; LHAllocPages return	 values

LHAP_FAIL	EQU	0
LHAP_SUCCESS	EQU	1
LHAP_ABOVE	EQU	2

; LHFreePages return values

LHFP_FAIL	EQU	0
LHFP_SUCCESS	EQU	1
LHFP_ABOVE	EQU	2

; LHCheckForFault return values
RECORD_INVALID	EQU	0
RECORD_MAPPED	EQU	1
RECORD_CREATED	EQU	2

; VDHReallocPages Undo bits

VDHRP_UNDO_RESERVE	EQU	00001h
VDHRP_UNDO_RECORD	EQU	00002h



DefStruc ,BYTEHEAP_s			;byte heap structure
    PVOID   bh_pv		       ;Starting address of heap
    PVOID   bh_pCur		       ;heap address to allocate from
    ULONG   bh_cb		       ;bytes remaining in heap
EndStruc BYTEHEAP

DefType PBYTEHEAP,dd


;***	Pid/SGid to HVDM Mapping Structure
;
;	MAPID structure stores the pid, SGid and the hvdm for
;	a VDM. HMAPID is the head of MAPID list.
;

DefStruc ,MAPID_s			;mi	 ;PID,SGID and HVDM structure
	PID	mi_Pid
	SGID	mi_SGid
	HVDM	mi_hvdm
	ULONG	mi_fState		  ;VDM State
	PVOID mi_pmi
EndStruc MAPID

DefType PMAPID,dd

DefStruc ,HMAPID_s			;header for MAPID list
	PMAPID	hm_pmiFirst	       ;first MAPID
	PMAPID	hm_pmiLast	       ;last  MAPID
EndStruc HMAPID

DefType PHMAPID,dd

VDM_BEING_CREATED	EQU	00001h
VDM_BEING_TERMINATED	EQU	00002h
VDM_AFTER_CREATE_TIME	EQU	00003h	;6.8



;***	VDD Heap data structures
;
;	VDMMAssignAddress uses these heaps to allocate addresses
;	for VDD code/Global data/Instance data, to be loaded by loader.
;
;	A HEAP always has a free block to allocate from.
;
;


DefStruc ,HEAPBLOCK_s			;hb
    PVOID   hb_pv		       ;starting address
    ULONG   hb_cb		       ;length
    SEL	    hb_sel		       ;selector
    ULONG   hb_fFree		       ;TRUE => block is free
    PVOID hb_phb	;Next entry
EndStruc HEAPBLOCK
DefType PHEAPBLOCK,dd

DefStruc ,HEAP_s			;hp
    ULONG	hp_fl		       ;heap type flags
    PVOID	hp_pv		       ;Starting addr of heap
    ULONG	hp_cbMax	       ;Maximum size of heap
    ULONG	hp_cbFreeHeapBlock     ;Size of new free blocks
    PHEAPBLOCK	hp_phb		       ;Heap entries of this heap
EndStruc HEAP
DefType PHEAP,dd


DefStruc ,HEAPINIT_s			;hpi
    ULONG   hpi_fl		       ;heap type flags
    ULONG   hpi_cb		       ;maximum heap size
EndStruc HEAPINIT
DefType PHEAPINIT,dd

; Object types of heaps (Heap Indices)

VDMAA_OT_INITCODE	EQU	0
VDMAA_OT_INITDATA	EQU	1
VDMAA_OT_GLOBALCODE	EQU	2
VDMAA_OT_GLOBALDATA	EQU	3
VDMAA_OT_FIXEDINSTANCE	EQU	4
VDMAA_OT_SWAPGLOBALCODE		EQU	5
VDMAA_OT_SWAPGLOBALDATA		EQU	6
VDMAA_OT_SWAPINSTANCE	EQU	7

; Heap Type Flags

VDMAA_HT_INITCODE	EQU	00001h
VDMAA_HT_INITDATA	EQU	00002h
VDMAA_HT_GLOBALCODE	EQU	00004h
VDMAA_HT_GLOBALDATA	EQU	00008h
VDMAA_HT_FIXEDINSTANCE	EQU	00010h
VDMAA_HT_SELECTOR	EQU	00020h
VDMAA_HT_INSTANCE	EQU	00040h
VDMAA_HT_SWAPCODE	EQU	00080h
VDMAA_HT_SWAPDATA	EQU	00100h
VDMAA_HT_SWAPINSTANCE	EQU	00200h



;Kenel instance data sizes

FIXED_KRNL_INST_SIZE	EQU	64*1024

;***	VDD module handle list
;
DefStruc ,MODULEHANDLE_s			;mh    ;Vdd Module handle list
	USHORT	mh_hmte			  ;Module handle
	PVOID mh_pmh  ;Next entry
EndStruc MODULEHANDLE

DefType PMODULEHANDLE,dd			;pmh




;***	Query System Values structure
;

DefStruc ,GSYSVAL_s
	PVOID	gsv_pv			    ;Address of system value
	ULONG	gsv_ulMask		    ;Size  Mask
EndStruc GSYSVAL

DefType PGSYSVAL,dd

DefStruc ,LSYSVAL_s
	PVOID	lsv_pv			    ;Address of system value
	ULONG	lsv_ulMask		    ;Size  Mask
	ULONG	lsv_fInstance		    ;sv_pv is global or instance
EndStruc LSYSVAL

DefType PLSYSVAL,dd

LSV_GLOBAL	EQU	0		     ;sv_pv is global
LSV_INSTANCE	EQU	1		     ;sv_pv is in instance data
LSV_UNUSED	EQU	2		     ;sv_pv is in instance data

GSVSTART	EQU	<VDHGSV_DAY>
GSVMAX	EQU	<VDHGSV_MECADDR>

LSVSTART	EQU	<VDHLSV_HVDM>
LSVMAX	EQU	<VDHLSV_VPICBASE>



DT_INIT		EQU	<VDMAA_OT_INITDATA>		;Init Data
DT_GLOBAL	EQU	<VDMAA_OT_GLOBALDATA>		;Global fixed data
DT_GLOBALSWAP	EQU	<VDMAA_OT_SWAPGLOBALDATA>		;Global swap data
DT_INSTANCEFIX	EQU	<VDMAA_OT_FIXEDINSTANCE>		;Instance fixed data
DT_INSTANCESWAP		EQU	<VDMAA_OT_SWAPINSTANCE>		;Instance Swap data
DT_STACK	EQU	10			;Stack data



;vdmmCopyConfig undo function defines

UNDO_VDMCONFIG	EQU	00001h
UNDO_PSZSHELL	EQU	00002h
UNDO_PSZZDOSDDS		EQU	00004h
UNDO_PSZZVDDVALUES	EQU	00008h

;VDM creation failure undo function count. Right now there are 6 items
;to be undone.Must be increased if more undo items are added.

CREATE_UNDO_ITEMS	EQU	10


;VDM FGND/BBND states defines

VDM_BGND	EQU	0
VDM_FGND	EQU	1
VDM_INIT	EQU	2

;VDMMSwitchFgnd/Bgnd local defines

SWITCH_FGND	EQU	0
SWITCH_BGND	EQU	1

;VDMMPDBChange/Destroy local defines

PDB_CHANGE	EQU	0
PDB_DESTROY	EQU	1

;Signature for hvdm validation (vdmid_SIG)
HVDM_SIGNATURE	EQU	04D445648h	     ;the string "HVDM"

;Undo function prototype
DefType UNDOPFN,dd

;VDD init routine prototype
DefType PVDDPOSTINIT,dd


;VDD init routine prototype
DefType PVDDINIT,dd

; Dos Emulation flag definations
DEM_SLAVE_THREAD	EQU	00001h	 ;Slave thread present flag
DEM_SLAVE_THREAD_BIT	EQU	0   ;

;Second thread defines
VPIC_SLAVE_ADDRESS	EQU	3

