;       SCCSID = @(#)tkksem.inc	6.1 90/11/17
;	SCCSID = @(#)tkksem.inc 13.2 90/09/17


;***LP	KSemChkOvf  - Check if count overflows
;
;	ENTRY	Flags
;
;	EXIT	Panic if overflow

KSemChkOvf macro
ifdef	MISCSTRICT
	jle	ksemovie
endif
	endm



;***LP	KSemChkUnf  - Check if count underflows
;
;	ENTRY	Flags
;
;	EXIT	Panic if underflow

KSemChkUnf macro
ifdef	MISCSTRICT
	jl	ksemovie
endif
	endm



;***LP	KSemChkSig  - Validate the signature in semaphore handle
;
;	ENTRY
;	    hreg	- semaphore handle
;	    semtype	- Blank; If semtype is not to be tested
;			KRNL_EVENTSEM - check it to be Event Semaphore
;			KRNL_MUTEXSEM - check it to be Mutex Semaphore
;
;	EXIT	Panic if invalid signature or invalid type

KSemChkSig	macro	hreg, semtype
ifdef	MISCSTRICT
	cmp	[hreg].ks_Signature,KSEM_SIGNATURE
	jne	ksemsigie
	ifnb	<semtype>
	cmp	[hreg].ks_bType,semtype
	jne	ksemsigie
	endif
endif
	endm


;***LP	KSemChkOwn  - Validate owner
;
;	ENTRY
;	    hreg	- semaphore handle
;
;	EXIT	Panic if current thread not owner
;
;	USES	AX

KSemChkOwn	macro hreg
ifdef	MISCSTRICT
	mov	ax,TaskNumber
	cmp	[hreg].ks_Owner,ax
	jne	ksemownie
endif
	endm


KSemCntAlloc	macro
ifdef	MISCSTRICT
	inc	[_ksctalc]
endif
	endm


KSemCntAllocBlk	macro
ifdef	MISCSTRICT
	inc	[_ksctalcblk]
endif
	endm


;***LP	KSemSetDbgAddr - Set kernel debugger block id display
;
;	ENTRY
;	    hreg - pSem
;
;	EXIT	none
;
;	USES	EAX

KSemSetDbgAddr macro hreg
	local	ksda
ifdef	PMDEBUG

	push	ecx
	mov	eax,hreg			; Default display ID
	test	[hreg].ks_bFlags,KSEM_DISPLAYID	; Display ID ?
	jz	short ksda			; No, use HKSEM as display ID
	
	movzx	eax,[hreg].ks_bType
	movzx	eax,szKSEM[eax]
ksda:	mov	ecx,_pTCBCur
	mov	[ecx].TCB_SemDebugAddr,edx
	pop	ecx
endif
	endm


;***LP	KSemClrDbgAddr - Clear kernel debugger block id display
;
;	ENTRY	none
;
;	EXIT	none

KSemClrDbgAddr macro
ifdef	PMDEBUG
	push	ebx
	mov	ebx,_pTCBCur
	mov	[ebx].TCB_SemDebugAddr,-1
	pop	ebx
endif
	endm

