File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / d / entry / cmps.c
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

#define error_hdl1s error
#define error_str error
#define error_str1 error

extern long scoplp;
extern long force_lp;

#define C	0x1
#define V	0x2
#define Z	0x4
#define N	0x8

/*	CMPS2, CMPS3 instruction	*/

#define MAXLINE	500
#define NULL	0

/* Some global variables  */
static long flag_msk, psl, slen, r2;
static char *str1, *str2, *r0, *r1;

cmpstr()
{
	asm("movl	$3,_no_opr");
	cmps2();
	cmps3();
	asm("jmp *return");
}

static cmps2()
{
	long no_op,  exp_psw, exp_r2;
	char *exp_r0, *exp_r1;

	no_op = 2;
	exp_r2 = 0;

	setjmp();
	asm("c1:	movab	c1,_stpc");
	asm("movl	$1,_subtst");
	flag_msk = exp_psw = 0;
	flag_msk = N|V|C;
	exp_psw = Z | C;
	str1 = "abcdefghejk";
	str2 = "abcdefghejk";
	exp_r0 = str1 + 11;
	exp_r1 = str2 + 11;
	cmps(no_op,exp_r0,exp_r1,exp_r2,exp_psw);

	setjmp();
	asm("c2:	movab	c2,_stpc");
	asm("movl	$2,_subtst");
	flag_msk = exp_psw = 0;
	exp_psw =  C;
	flag_msk = Z|N|V|C;
	str1 = "abcdefghejk1";
	str2 = "abcdefghejk";
	exp_r0 = str1 + 11;
	exp_r1 = str2 + 11;
	cmps(no_op,exp_r0,exp_r1,exp_r2,exp_psw);

	setjmp();
	asm("c3:	movab	c3,_stpc");
	asm("movl	$3,_subtst");
	flag_msk = exp_psw = 0;
	exp_psw = N;
	flag_msk = Z|N|V|C;
	str1 = "12345678abcd";
	str2 = "12345678abce0";
	exp_r0 = str1 + 11;
	exp_r1 = str2 + 11;
	cmps(no_op,exp_r0,exp_r1,exp_r2,exp_psw);

	setjmp();
	asm("c4:	movab	c4,_stpc");
	asm("movl	$4,_subtst");
	flag_msk = exp_psw = 0;
	exp_psw = N;
	flag_msk = Z|N|V|C;
	str1 = "12345678abcd";
	str2 = "12345678abcd0";
	exp_r0 = str1 + 12;
	exp_r1 = str2 + 12;
	cmps(no_op,exp_r0,exp_r1,exp_r2,exp_psw);

	setjmp();
	asm("c5:	movab	c5,_stpc");
	asm("movl	$5,_subtst");
	flag_msk = exp_psw = 0;
	flag_msk = Z|V|C;
	exp_psw =  N;
	str1 = "abcdefg1234567zz";
	str2 = "abcdefg123456z89";
	exp_r0 = str1 + 13;
	exp_r1 = str2 + 13;
	cmps(no_op,exp_r0,exp_r1,exp_r2,exp_psw);
}

static cmps3()
{
	long no_op,  exp_psw, exp_r2;
	char *exp_r0, *exp_r1;

	no_op = 3;

	setjmp();
	asm("c6:	movab	c6,_stpc");
	asm("movl	$6,_subtst");
	slen = 11;
	flag_msk = exp_psw = 0;
	flag_msk = N|V|C;
	exp_psw =  Z | C;
	str1 = "abcdefghejk";
	str2 = "abcdefghejk";
	exp_r0 = str1 + slen;
	exp_r1 = str2 + slen;
	exp_r2 = 0;
	cmps(no_op,exp_r0,exp_r1,exp_r2,exp_psw);

	setjmp();
	asm("c7:	movab	c7,_stpc");
	asm("movl	$7,_subtst");
	slen = 15;
	flag_msk = exp_psw = 0;
	flag_msk = Z|N|V|C;
	exp_psw = N;
	str1 = "abcdefghejk1";
	str2 = "abcdefghejk2";
	exp_r0 = str1 + 11;
	exp_r1 = str2 + 11;
	exp_r2 = 4;
	cmps(no_op,exp_r0,exp_r1,exp_r2,exp_psw);

	setjmp();
	asm("c8:	movab	c8,_stpc");
	asm("movl	$8,_subtst");
	slen = 20;
	flag_msk = exp_psw = 0;
	flag_msk = Z|V|C;
	exp_psw = N;
	str1 = "abcd123456089";
	str2 = "abcd123456198";
	exp_r0 = str1 + 10;
	exp_r1 = str2 + 10;
	exp_r2 = 10;
	cmps(no_op,exp_r0,exp_r1,exp_r2,exp_psw);

	setjmp();
	asm("c9:	movab	c9,_stpc");
	asm("movl	$9,_subtst");
	slen = 11;
	flag_msk = exp_psw = 0;
	flag_msk = Z|V|C;
	exp_psw = C;
	str1 = "abcd123456289";
	str2 = "abcd123456198";
	exp_r0 = str1 + 10;
	exp_r1 = str2 + 10;
	exp_r2 = 1;
	cmps(no_op,exp_r0,exp_r1,exp_r2,exp_psw);

	setjmp();
	asm("c10:	movab	c10,_stpc");
	asm("movl	$10,_subtst");
	slen = 4;
	flag_msk = exp_psw = 0;
	flag_msk = Z|V|C;
	exp_psw = Z | C;
	str1 = "abcd1";
	str2 = "abcd2";
	exp_r0 = str1 + slen;
	exp_r1 = str2 + slen;
	exp_r2 = 0;
	cmps(no_op,exp_r0,exp_r1,exp_r2,exp_psw);

}

/* THIS ROUTINE EXECUTE CMPS2, CMPS3 INSTRUCTIONS */
 
static cmps(no_op,exp_r0,exp_r1,exp_r2, exp_psw)
char *exp_r0, *exp_r1; 
long exp_r2,  exp_psw;
int no_op;
{
	char *str, savs1[MAXLINE], savs2[MAXLINE];
	long op_len, len1 ,len2,  ix, ierror, psw;

flag_msk = flag_msk << 16;
op_len = slen;
for(;;)
     {
	slen = op_len; 

	/* SAVE SOURCE STRINGS	*/

	str = str1;
	len1 = 0;
	for(;;)
		{
		savs1[len1] = *str++;
		if (savs1[len1] == NULL)  break; 
		len1++;		/* len of source string excluding NULL	*/
		}
	str = str2;
	len2 = 0;
	for(;;)
		{
		savs2[len2] = *str++;
		if (savs2[len2] == NULL)  break; 
		len2++;		/* len of source string excluding NULL	*/
		}


	/* EXECUTE IT */
	if (no_op==2)
		{
		asm("movl _str1,r0");		/* R0 : source string */
		asm("movl _str2,r1");		/* R0 : source string */
		asm("bicpsw $0xf");	/* clear all flags */
		asm("bispsw _flag_msk");
		asm("cmps2");
		asm("movpsl _psl");
		asm("movl r0,_r0");
		asm("movl r1,_r1");
		}
	    else
		{
		asm("movl _str1,r0");		/* R0 : source string */
		asm("movl _str2,r1");		/* R1 : source string */
		asm("movl _slen,r2");		/* R2 : counter       */
		asm("bicpsw $0xf");	/* clear all flags */
		asm("bispsw _flag_msk");
		asm("cmps3");
		asm("movpsl _psl");
		asm("movl r0,_r0");
		asm("movl r1,_r1");
		asm("movl r2,_r2");
		}
	psw = psl & 0xf;

	/* check flags */
	if (psw != exp_psw)
		{
		asm("movl	$2,_ercode");
		if (scoplp) longjmp();
		error_hdl1s(psw,exp_psw,str1,str2);
		}
	/* CHECK IF SOURCE GET CHANGED	*/
	ierror = 0;
	for(ix=0;ix<len1;ix++)
		{	if (str1[ix] != savs1[ix]) 
				{ ierror++;
				  break;
				}
		}
	if (ierror)
		{
		asm("movl	$3,_ercode");
		if (scoplp) longjmp();
		error_str(str1,savs1,str1,str2,slen);
		}
	ierror = 0;
	for(ix=0;ix<len2;ix++)
		{	if (str2[ix] != savs2[ix]) 
				{ ierror++;
				  break;
				}
		}
	if (ierror)
		{
		asm("movl	$3,_ercode");
		if (scoplp) longjmp();
		error_str(str2,savs2,str1,str2,slen);
		}
	/* CHECK R0, R1		*/
	if  (r0 != exp_r0)
		{
		asm("movl	$3,_ercode");
		if (scoplp) longjmp();
		error_str1(r0,exp_r0,str1,str2,slen);
		}
	if  (r1 != exp_r1)
		{
		asm("movl	$3,_ercode");
		if (scoplp) longjmp();
		error_str1(r1,exp_r1,str1,str2,slen);
		}
	if (no_op==3)
		{	/* CMPS3 : check R2 */	
		if  (r2 != exp_r2)
			{
		        asm("movl	$3,_ercode");
		        if (scoplp) longjmp();
		        error_str1(r2,exp_r2,str1,str2,slen);
			}
		/* check if length operand get modified */
		if (slen != op_len)
		    {
	            asm("movl	$3,_ercode");
		    if (scoplp) longjmp();
		    error_str1(slen,op_len,str1,str2,slen);
		    }
		if (force_lp) longjmp();
		}
	break;
    }
}


unix.superglobalmegacorp.com

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