|
|
Power 6/32 Unix version 1.2b
#define error_hdl1 error
#define error_str error
#define C 0x1
#define V 0x2
#define Z 0x4
#define N 0x8
extern long scoplp;
extern long force_lp;
/* MOVS2, MOVS3 instruction */
#define MAXLINE 500
#define MAXBYTE 95
#define NULL (char)0
/* Some global variables */
static long flag_msk, psl, len, r2;
static char *s_str, srcstr[MAXLINE], d_str[MAXLINE], *r0, *r1;
movstr()
{
asm("movl $3,_no_opr");
movs2();
movs3();
asm("jmp *return");
}
static movs2()
{
long no_op, exp_psw, ix, dummy;
char *exp_r0, *exp_r1, *cptr;
no_op = 2;
len = 0;
dummy = 0;
setjmp();
asm("m1: movab m1,_stpc");
asm("movl $1,_subtst");
flag_msk = exp_psw = 0;
flag_msk = exp_psw = N|V|C;
s_str = "** this is a test of string copy **";
exp_r0 = s_str + 35;
exp_r1 = d_str + 35;
movs(no_op,exp_r0,exp_r1,dummy,exp_psw);
setjmp();
asm("m2: movab m2,_stpc");
asm("movl $2,_subtst");
cptr = srcstr;
for(ix=0;ix<95;ix++)
*cptr++ = ' ' + ix; /* make a long string */
*cptr = '\0';
s_str = srcstr;
flag_msk = exp_psw = 0;
flag_msk = exp_psw = N|Z|V|C;
exp_r0 = s_str + 95;
exp_r1 = d_str + 95;
movs(no_op,exp_r0,exp_r1,dummy,exp_psw);
setjmp();
asm("m3: movab m3,_stpc");
asm("movl $3,_subtst");
flag_msk = exp_psw = 0;
flag_msk = exp_psw = Z;
s_str = "\0";
exp_r0 = s_str;
exp_r1 = d_str;
movs(no_op,exp_r0,exp_r1,dummy,exp_psw);
}
static movs3()
{
long no_op, exp_r2, ix, exp_psw;
char *exp_r0, *exp_r1, *cptr;
no_op = 3;
setjmp();
asm("m4: movab m4,_stpc");
asm("movl $4,_subtst");
len = MAXBYTE;
cptr = srcstr;
for(ix=0;ix<len;ix++)
*cptr++ = ' ' + ix; /* make a long string */
*cptr = '\0';
s_str = srcstr;
flag_msk = exp_psw = 0;
flag_msk = exp_psw = N|V|C;
len = 35;
exp_r0 = s_str + len;
exp_r1 = d_str + len;
exp_r2 = 0;
movs(no_op,exp_r0,exp_r1,exp_r2,exp_psw);
setjmp();
asm("m5: movab m5,_stpc");
asm("movl $5,_subtst");
flag_msk = exp_psw = 0;
flag_msk = exp_psw = Z;
len = 0;
exp_r0 = s_str + len;
exp_r1 = d_str + len;
exp_r2 = 0;
movs(no_op,exp_r0,exp_r1,exp_r2,exp_psw);
setjmp();
asm("m6: movab m6,_stpc");
asm("movl $6,_subtst");
flag_msk = exp_psw = 0;
flag_msk = exp_psw = Z;
len = MAXBYTE + 10;
exp_r0 = s_str + MAXBYTE;
exp_r1 = d_str + len;
exp_r2 = 0;
movs(no_op,exp_r0,exp_r1,exp_r2,exp_psw);
}
/* THIS ROUTINE EXECUTE MOVS2, MOVS3 INSTRUCTION */
static movs(no_op,exp_r0,exp_r1,exp_r2,exp_psw)
char *exp_r0, *exp_r1;
long no_op, exp_psw, exp_r2;
{
char *msg1, *msg2, savs[MAXLINE], *str, *cptr, *c1ptr;
long lenstr, len_op, ix, ierror, psw, n_flg;
flag_msk = flag_msk << 16;
len_op = len;
for(;;)
{
/* CLEAR DESTINATION STRING */
cptr = d_str;
for (ix=0;ix<MAXLINE;ix++) { *cptr++ = '^'; savs[ix] = NULL; }
/* SAVE SOURCE STRINGS */
str = s_str;
n_flg = lenstr = 0;
cptr = savs;
for(;;)
{
*cptr = *str++;
if (*cptr == NULL) break;
cptr++; lenstr++;
}
if (lenstr >= len) n_flg++;
len = len_op;
if (no_op == 2)
{
asm("movl _s_str,r0"); /* R0 : addr of source */
asm("movab _d_str,r1"); /* R1 : addr of destination */
asm("bicpsw $0xf"); /* clear all flags */
asm("bispsw _flag_msk");
asm(".globl _mvstr2");
asm("_mvstr2:");
asm("movs2");
asm("movpsl _psl");
asm("movl r0,_r0");
asm("movl r1,_r1");
}
else
{
asm("movl _s_str,r0"); /* R0 : addr of source */
asm("movab _d_str,r1"); /* R1 : addr of destination */
asm("movl _len,r2"); /* R2 : no of bytes to move */
asm("bicpsw $0xf"); /* clear all flags */
asm("bispsw _flag_msk");
asm(".globl _mvstr3");
asm("_mvstr3:");
asm("movs3");
asm("movpsl _psl");
asm("movl r0,_r0");
asm("movl r1,_r1");
asm("movl r2,_r2");
}
psw = psl & 0xf;
/* CHECK IF SOURCE GET CHANGED */
ierror = 0;
if (no_op==3) lenstr = len;
cptr = s_str;
c1ptr = savs;
for(ix=0;ix<lenstr;ix++)
{ if (*cptr++ != *c1ptr++)
{ ierror++;
break;
}
if (*cptr == NULL) break;
}
if (ierror)
{
asm("movl $3,_ercode");
if (scoplp) longjmp();
error_str(*cptr-1,*c1ptr-1,s_str,savs);
}
/* CHECK DESTINATION STRING */
ierror = 0;
cptr = d_str;
c1ptr = savs;
for(ix=0;ix<lenstr;ix++)
{ if (*c1ptr++ != *cptr++)
{ ierror++;
break;
}
}
if (no_op==2) { if (d_str[ix]!='\0') ierror++; }
else
if (len==0) { if (d_str[0] != '^') ierror++; }
if (ierror)
{
asm("movl $1,_ercode");
if (scoplp) longjmp();
if (n_flg) { savs[lenstr] = d_str[lenstr] = '\0'; }
error_str(*cptr-1,*c1ptr-1,d_str,savs);
}
/* CHECK R0, R1 */
if (r0 != exp_r0 )
{
asm("movl $3,_ercode");
if (scoplp) longjmp();
error_hdl1(r0,exp_r0,s_str,d_str,len);
}
if (r1 != exp_r1 )
{
asm("movl $3,_ercode");
if (scoplp) longjmp();
error_hdl1(r1,exp_r1,s_str,d_str,len);
}
if (psw != exp_psw)
{
asm("movl $3,_ercode");
if (scoplp) longjmp();
error_hdl1(psw,exp_psw,s_str,d_str,len);
}
if (no_op == 3)
{ /* MOVS3 : check r2 */
if (r2 != exp_r2 )
{
asm("movl $3,_ercode");
if (scoplp) longjmp();
error_hdl1(r2,exp_r2,s_str,d_str,len);
}
/* CHECK LENGTH OPERAND */
if (len_op != len)
{
asm("movl $3,_ercode");
if (scoplp) longjmp();
error_hdl1(len_op,len,s_str,d_str,len);
}
/* CHECK NO. OF BYTES COPIED EQUAL LENGTH SPECIFIED */
ierror = 0;
if (len<=MAXBYTE)
{ if (d_str[len]!='^')
{
asm("movl $1,_ercode");
if (scoplp) longjmp();
error_hdl1(d_str,savs,s_str,d_str,len);
}
}
/* check for NULL padded at end of dest. string */
ierror = 0;
if (len>MAXBYTE)
{ for(ix=MAXBYTE;ix<len;ix++)
{ if (d_str[ix] != NULL)
{
asm("movl $1,_ercode");
if (scoplp) longjmp();
error_str(d_str,savs,s_str,d_str,len);
}
if (force_lp) longjmp();
}
}
}
break;
}
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.