File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / d / event / vksnv_evt.s
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:24:19 2019 UTC (6 years, 11 months ago) by root
Branches: bsd, MAIN
CVS tags: v12b, v121, HEAD
Power 6/32 Unix version 1.2b


 #
 #	Kernel stack not valid event test. 
 #	This test is entered in Kernel mode, running virtual on ISP.
 #	The test then REI to USER which will execute a KCALL with an
 #	invalid Kernel stack. Kernel stack not valid fault is expected
 #	to occure.
 #
 #	R0 = error code
 #	     1 - Did not generate Kernel stack not valid when executing
 #		 Kcall with a invalid KSP
 #		 R1 = KSP after Kcall exception,  R2 = P2BR,  R3 = P2LR
 #	     2 - Too many parameters pushed on ISP
 #		 R1 = ISP after KSP not valid exception
 #	     3 - ISP is not correct after KSP not valid exception
 #		 R1 = actual,  R2 = expected
 #	     4 - Current PSL is not correct after KSP not valid exception
 #		 R1 = actual,  R2 = expected
 #	     5 - PC pushed on ISP is not correct after KSP not valid exception
 #		 R1 = actual,  R2 = expected
 #	     6 - PSL pushed on ISP is not correct after KSP not valid exception
 #		 R1 = actual,  R2 = expected
 #
	.set   LAST_VPGNO,0xfffff	/* Last virtual page no 	*/
	.set   TST_PTEP2,LAST_VPGNO
	.set   P2ADDR,0x80000000
	.set   EXP_UPSL,0x01000000	/* User mode, IPL = 0 */

	.globl	_ksnv_evt		
_ksnv_evt:
	.word	0x1fff			/* Save r0-r12			*/

	mtpr	$0x1f,$IPL
	movl	$1,tst_cnt

 #	Set up P2PT :	2 entries
 #	PTE 0  : Physical page 254, PTE_V off, Kernel R/W
 #	PTE 1  : Physical page 255, PTE_V off, Kernel R/W
 #
	movab 	_u0p2pt,r10		/* System virtual addr of P2PT	*/
	orl3	$254,$PG_KW,(r10)	/* PTE 0 : Kernel write, V bit off */
	orl3	$255,$PG_KW,4(r10)	/* PTE 1 : Kernel write, V bit off */
	subl3	$((LAST_VPGNO - 1) << 2),r10,r11
					/* Virtual address of P2BR */

 #	Set up P0PT
 #	virtual page 0 = physical page of routine _uxtest
 #
	clrl	r2
	andl3	$_uxtest,$0x3fffffff,r1
	andl3	$0x000003ff,r1,r7	/* R7 : offset to 1st instruction */
	shrl	$PGSHIFT,r1,r1		/* Page no. of _uxtest		*/
	andl3	$_eutest+NBPG-1,$0x3fffffff,r3
	shrl	$PGSHIFT,r3,r3		/* Last page no. of _uxtest	*/
1:	orl3	$PG_V|PG_URKW,r1,_u0p0pt[r2]
	incl	r2
	aoblss	r3,r1,1b

	movl	$_pcb0,r1		/* Initialize PCB slightly	*/
	movl	$((LAST_VPGNO<<PGSHIFT)|0x8|P2ADDR),PCB_KSP(r1)	
					/* Set up KSP	*/
	movl	r7,PCB_PC(r1)		/* Set PCB_PC */
	movl	$EXP_UPSL,PCB_PSL(r1)	/* Set PCB_PSL : User	*/
	movab	_u0p0pt,PCB_P0BR(r1)	/* Set PCB_P0BR */
	movl	$2,PCB_P0LR(r1)		/* Set PCB_P0LR : 2 PTEs */
	movl	r11,PCB_P2BR(r1)	/* Set PCB_P2BR */
	movl	$0xffffd,PCB_P2LR(r1)	/* Two PTE for P2PT	*/
	andl2	$0x3fffffff,r1
	mtpr	r1,$PCBB		/* Init PCBB			*/

					/* Set expected parameters	*/
	movab	fpc0,exp_pc		/* expected PC pushed on ISP */
	movpsl	r1
	andl3	$0xfbfffff0,r1,exp_psl	/* Exp. PSL pushed on ISP : IS off */
	movl	$0x41f0000,exp_cpsl	/* Expected PSL after fault : */
				/* Mode : Kernel, IS : on, IPL => 0x1f.  */
				/* the rest are screwed up on Kstack not */
				/* valid exception ! */
	movl	$-1,-(sp)		/* Set marker for ISP		*/
	movab	(sp),r8
	subl3	$0x8,r8,exp_isp		/* Expected ISP after fault	*/

	movl	fp,sfp			/* Save FP */
more:	movl	_scb+SYSVEC,_savvec0	/* Save current syscall vector	*/
	movl	_scb+KSPVEC,_savvec1
	movab	_u0ret,_scb+SYSVEC	/* New vector for KCALL		*/
	movab	_ksnotvalid,_scb+KSPVEC /* New vector for Kstack not valid */	
	mtpr	$0,$TBIA	
fpc0:	ldpctx			/* Save ISP, Switch context to user, should */
				/* Cause Kstack not valid fault !!	*/
	rei
	halt
#
#
/*	KCALL handler		*/
	.align	2
_u0ret:		
		/* Error -- did not receive kernel stack not valid 	*/
		/* fault during KCALL which try to push 3 parameters on	*/
		/* an invalid Kernel stack. 				*/
	mtpr	$HIGH,$IPL
	movl	_savvec0,_scb+SYSVEC	/* Restore original vectors 	*/
	movl	_savvec1,_scb+KSPVEC
	movl	$1,r0
	movab	(sp),r1			/* Kernel stack pointer		*/
	mfpr	$P2BR,r2		/* P2 page table base		*/
	mfpr	$P2LR,r3		/* P2 page table base		*/
	jmp	*badrtn


/*	Kernel stack not valid event handler; serviced on ISP	*/
	.align	2		
_ksnotvalid:
	movl	_savvec1,_scb+KSPVEC	/* Restore original vectors	*/
	movl	_savvec0,_scb+SYSVEC

	movab	(sp),r1			/* actual ISP */
	addl3	$8,r1,r7
	cmpl	$-1,(r7)		/* Check marker on ISP */
	jeql	1f
	movl	$2,r0
	jmp	*badrtn			/* Too many params. pushed on ISP */
1:
	movl	exp_isp,r2
	cmpl	r1,r2			/* Make sure ISP is correct	*/
	beql	0f
	movl	$3,r0
	jmp	*badrtn

0:	movpsl	r1			/* Check  current PSL 		*/
	andl2	$0xfffffff0,r1
	movl	exp_cpsl,r2		/* Expected PSL after fault 	*/
	cmpl	r1,r2
	beql	1f
	movl	$4,r0		/* Error code = 2			*/
	jmp	*badrtn		/* PSL not right after kernel stack not	*/
				/* valid fault; r1 = actual; r2 = expected */
1:
	movl	exp_pc,r2	/* Get expected PC			*/
	movl	(sp),r1		/* Pop actual PC from ISP		*/
	cmpl	r1,r2
	beql	1f
	movl	$5,r0		/* Error : incorrect PC on ISP		*/
	jmp	*badrtn		/* Error code r0 = 3			*/
1:		
	movl	4(sp),r1	/* Pop actual PSL on ISP		*/
	andl3	$0xffffffff0,4(sp),r1	
	movl	exp_psl,r2	/* R2 : expected PSL	*/
	cmpl	r1,r2
	beql	1f
	movl	$6,r0		/* Error : incorrect PSL		*/
	jmp	*badrtn		/* Error code r0 = 4			*/
1:
	andl3	$_kc_flt,$0x3ff,exp_pc	/* Set expected PC */
	movl	$0x41d0000,exp_cpsl	/* IPL should raised to 0x1d    */
	movl	$EXP_UPSL,exp_psl	/* Expected PSL pushed on ISP */

	movab 	_u0p2pt,r10		/* System virtual addr of P2PT	*/
	orl2	$0x80000000,4(r10)  	/* Set V_bit of PTE1 On */
	movl	$0,r0
	mtpr	$1,$TBIA
endt:	
	movl	(sp)+,r12	/* Pop PC, PSL out of ISP */
	movl	(sp)+,r12
	decl	tst_cnt		/* decrement test count */
	blss	0f		/* branch if less than 0 */
	movab	_u0ret,_scb+SYSVEC	/* New vector for KCALL		*/
	movab	_ksnotvalid,_scb+KSPVEC /* New vector for Kstack not valid */	
	jmp	fpc0		/* restart LDPCTX : Should be O.K */
0:
	movl	(sp)+,r0	/* Pop marker off ISP */
	movl	sfp,fp		/* Restore FP */
	ret			/* Done !! return to monitor		*/
#
#
#
	.globl	_uxtest
_uxtest:
	clrl	r0
_kc_flt:
	kcall	$DONE	/* KCALL should cause Kernel stack not valid fault */
			/* when try to push the 3rd paramater on Kstack    */
_eutest:	
	halt

	.align	2
exp_pc:
	.long	0
exp_psl:
	.long	0
exp_cpsl:
	.long	0		/* Expected current PSL */
exp_isp:
	.long	0	/* expected ISP while in Kstack not valid handler */
sfp:
	.long   0		/* saved FP */
tst_cnt:
	.long	0

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.