Exemplo n.º 1
0
void mov_r32_addr(int dest, void *source)
{
	//eg, "mov %eax, 0x0" where 0x0 = C_stack
	if(isreg(dest)) {
		//special case for eax
		if(dest==EAX) {
			putbyte(0xa3);
			put_addr(source);
		}
		else {
			putbyte(0x89);
			putbyte((dest*0x8)+0x5);
			put_addr(source);
		}
	}
	else aerror("Error in moving an address to a reg");
}	
Exemplo n.º 2
0
void
evermore80(Place pl, int baud)
{
	char buf[32], *s;
	long now, seconds, week;

	fprint(2, "Evermore80");

	time(&now);
	seconds = now - 315964800;
	week = (seconds / (7*24*3600));
	seconds = seconds %  (7*24*3600);
	s = buf;

	s = putbyte(s, 0x80);		/* message ID */
	s = putshort(s, week);		/* week number */
	s = putlong(s, seconds*100);	/* seconds */
	s = putshort(s, pl.lat*10.0);	/* latitude tenths degree */
	s = putshort(s, pl.lon*10.0);	/* longitude tenths degree */
	s = putshort(s, 100);		/* altitude meters */
	s = putshort(s, 0);		/* datumn ID */
	s = putbyte(s, 2);		/* warm start */
	s = putbyte(s, GGAon|GSAon|GSVon|RMCon|CRCon);
	switch(baud){
	case 4800:	s = putbyte(s, 0);	break;
	case 9600:	s = putbyte(s, 1);	break;
	case 19200:	s = putbyte(s, 2);	break;
	case 38400:	s = putbyte(s, 3);	break;
	default:
		sysfatal("Illegal baud rate");
	}

	evermoresend(buf, s - buf);
	fprint(2, "\n");
}
Exemplo n.º 3
0
void lea_m32_r32_disp(int source, int dest, int disp)
{
	if(!isreg(source)) {
		if(isreg(dest)) {
			putbyte(0x8d);
			if(-127<=(PSIZE*disp) && (disp*PSIZE)<=128) {
				putbyte(0x40+(dest*0x8)+source-0x8);
				putbyte((PSIZE*disp)&0xff);
			}
			else {
				putbyte(0x80+(dest*0x8)+source-0x8);
				put_little_endian(PSIZE*disp);
			}
		}
		else aerror("Error in lea. dest is not a register");
	}
	else aerror("Error in lea. source is not a memory loc");
}
Exemplo n.º 4
0
Arquivo: code.c Projeto: BlockoS/pceas
void
class3(int *ip)
{
	check_eol(ip);

	/* update location counter */
	loccnt += 2;

	/* generate code */
	if (pass == LAST_PASS) {
		/* opcodes */
		putbyte(data_loccnt, opval);
		putbyte(data_loccnt+1, optype);

		/* output line */
		println();
	}
}
Exemplo n.º 5
0
char*
putlong(char *s, long v)
{
	s = putbyte(s, v);
	s = putbyte(s, v >> 8);
	s = putbyte(s, v >> 16);
	s = putbyte(s, v >> 24);
	return s;
}
Exemplo n.º 6
0
//串口发送一个字符串
void putstring(uchar *puts,uchar n)
{	
	int j;
	ES=0;
	for(j=0;j<n;j++)
		putbyte(puts[j]);
    ES=1;
	memset(puts,0x00,10);
}
Exemplo n.º 7
0
Arquivo: code.c Projeto: BlockoS/pceas
void
class5(int *ip)
{
	int	zp;
	unsigned int addr;
	int mode;

	/* update location counter */
	loccnt += 3;

	/* get first operand */
	mode = getoperand(ip, ZP, ',');
	zp   = value;
	if (!mode)
		return;

	/* get second operand */
	mode = getoperand(ip, ABS, ';');
	if (!mode)
		return;

	/* generate code */
	if (pass == LAST_PASS) {
		/* opcodes */
		putbyte(data_loccnt, opval);
		putbyte(data_loccnt+1, zp);

		/* calculate branch offset */
		addr = value - (loccnt + (page << 13));

		/* check range */
		if (addr > 0x7F && addr < 0xFFFFFF80) {
			error("Branch address out of range!");
			return;
		}

		/* offset */
		putbyte(data_loccnt+2, addr);

		/* output line */
		println();
	}
}
Exemplo n.º 8
0
void add_imm32_rm32(int size, int reg)
{
	//size is bigger than imm8
	if(isreg(reg)) {
		//special case for accumulator register eax
		if(reg==EAX) {
			putbyte(0x05);
			put_little_endian(size);
		}
		else {
			putbyte(0x81);
			putbyte(0xc0+reg);
			put_little_endian(size);
		}
	}
	else {
		putbyte(0x81);
		putbyte(reg-0x8);
		put_little_endian(size);
	}
}
Exemplo n.º 9
0
void cmp_imm_r32(int size, int reg)
{
	//sign extended imm
	if(0<=size && size<=255) {
		if(isreg(reg)) {
			putbyte(0x83);
			putbyte(0xf8+reg);
			putbyte(size);
		}
		else aerror("Error: not reg in cmp_imm_r32");
	}
	else {
		//imm32
		if(isreg(reg)) {
			putbyte(0x81);
			putbyte(0xf8+reg);
			put4bytes(size);
		}
		else aerror("Error: not reg in cmp_imm_r32");
	}
}
Exemplo n.º 10
0
static void
send_ssh_cmsg_session_key(Conn *c)
{
	int i, n, buflen, serverkeylen, hostkeylen;
	mpint *b;
	uchar *buf;
	Msg *m;
	RSApub *ksmall, *kbig;

	m = allocmsg(c, SSH_CMSG_SESSION_KEY, 2048);
	putbyte(m, c->cipher->id);
	putbytes(m, c->cookie, COOKIELEN);

	serverkeylen = mpsignif(c->serverkey->n);
	hostkeylen = mpsignif(c->hostkey->n);
	ksmall = kbig = nil;
	if(serverkeylen+128 <= hostkeylen){
		ksmall = c->serverkey;
		kbig = c->hostkey;
	}else if(hostkeylen+128 <= serverkeylen){
		ksmall = c->hostkey;
		kbig = c->serverkey;
	}else
		error("server session and host keys do not differ by at least 128 bits");
	
	buflen = (mpsignif(kbig->n)+7)/8;
	buf = emalloc(buflen);

	debug(DBG_CRYPTO, "session key is %.*H\n", SESSKEYLEN, c->sesskey);
	memmove(buf, c->sesskey, SESSKEYLEN);
	for(i = 0; i < SESSIDLEN; i++)
		buf[i] ^= c->sessid[i];
	debug(DBG_CRYPTO, "munged session key is %.*H\n", SESSKEYLEN, buf);

	b = rsaencryptbuf(ksmall, buf, SESSKEYLEN);
	n = (mpsignif(ksmall->n)+7) / 8;
	mptoberjust(b, buf, n);
	mpfree(b);
	debug(DBG_CRYPTO, "encrypted with ksmall is %.*H\n", n, buf);

	b = rsaencryptbuf(kbig, buf, n);
	putmpint(m, b);
	debug(DBG_CRYPTO, "encrypted with kbig is %B\n", b);
	mpfree(b);

	memset(buf, 0, buflen);
	free(buf);

	putlong(m, c->flags);
	sendmsg(m);
}
void promt_bt_cmd(AT_PROMPT_CMD cmd)
{
	u8 i=0;
	if(cmd<AT_CMD_LEN){

		//UTCON = 0x01;

		for(i=0;i<7;i++){
			putbyte(BT_AT_CMD[cmd][i]);
		}

		//UTCON = 0x09;		
	}
}
Exemplo n.º 12
0
void
evermoresend(char *body, int l)
{
	char buf[8], *s;
	int crc, i;

	s = buf;
	*s++ = 0x10;			/* DCE */
	*s++ = 0x02;			/* STX */
	s = putbyte(s, l);		/* length */
	write(ttyfd, buf, s-buf);	/* write header */

	write(ttyfd, body, l);		/* write body */

	crc = 0;
	for(i = 0; i < l; i++)
		crc += body[i];		/* calculate crc */
	s = buf;
	s = putbyte(s, crc);		/* checksum */
	*s++ = 0x10;			/* DCE */
	*s++ = 0x03;			/* ETX */
	write(ttyfd, buf, s-buf);	/* write trailer */
}
Exemplo n.º 13
0
void
evermore8e(void)
{
	char buf[32], *s;

	fprint(2, "Evermore8e");
	s = buf;
	s = putbyte(s, 0x8e);		/* message ID */
	s = putbyte(s, GGAon|GSAon|GSVon|RMCon);		/* all messages except GLL and VTG */
	s = putbyte(s, 0x01);		/* checksum on */
	s = putbyte(s, 0x01);		/* GGA update rate */
	s = putbyte(s, 0x0b);		/* GLL update rate */
	s = putbyte(s, 0x0a);		/* GSA update rate */
	s = putbyte(s, 0x14);		/* GSV update rate */
	s = putbyte(s, 0x08);		/* RMC update rate */
	s = putbyte(s, 0x0d);		/* VTG update rate */

	evermoresend(buf, s - buf);
	fprint(2, "\n");
}
Exemplo n.º 14
0
bool gsm_send_tcp( unsigned char *send_buf, unsigned int dat_len )
{
	unsigned int i ;
	u8 respond_str[AT_CMD_LENGTH];

	//debug_gsm("TCP Send: ");
	for ( i = 0 ; i < dat_len ; i++ ) {
		putbyte(COM2, send_buf[i]) ;
		#ifdef DEBUG_GSM
			;//printf("%02X ",send_buf[i]);
		#endif
	}

	#ifdef DEBUG_GSM
		printf("\r\n");
	#endif

	//wait GSM return: ERROR or OK
	memset(respond_str, 0x0, AT_CMD_LENGTH);
	if ( my_icar.stm32_u2_rx.empty ) {//no data...
		OSTimeDlyHMSM(0, 0,	0, 100);
	}
	while ( !my_icar.stm32_u2_rx.empty ) {//have data ...
		if ( get_respond(respond_str) ) {

			if (strstr((char *)respond_str,"^SISR: 0,") \
				&& respond_str[10] > 0x30 ) {
				my_icar.mg323.rx_empty = false ;
			}

			if (strstr((char *)respond_str,"ERROR")) {
				return false;
			}
			if (strstr((char *)respond_str,"OK")) {
				OSTimeDlyHMSM(0, 0,	0, 20);//wait ^SISW: 0,1
			}

			if (strstr((char *)respond_str,"^SISW: 0,1")) {
				return true;
			}
		}
		else {
			debug_gsm("CMD:Send TCP data timeout!\r\n");
			return false ;
		}
	}

	return false ;
}
Exemplo n.º 15
0
Arquivo: code.c Projeto: BlockoS/pceas
void
class9(int *ip)
{
	int bit;
	int mode;

	/* update location counter */
	loccnt += 2;

	/* get the bit index */
	mode = getoperand(ip, IMM, ',');
	bit  = value;
	if (!mode)
		return;

	/* get the zero page address */
	mode = getoperand(ip, ZP, ';');
	if (!mode)
		return;

	/* generate code */
	if (pass == LAST_PASS) {
		/* check bit number */
		if (bit > 7) {
			error("Incorrect bit number!");
			return;
		}

		/* opcodes */
		putbyte(data_loccnt, opval + (bit << 4));
		putbyte(data_loccnt+1, value);

		/* output line */
		println();
	}
}
Exemplo n.º 16
0
/*
 * Putchar(tc) does what putbyte(c) do for a byte c.
 * Note that putbyte(c) just send the byte c (provided c is not
 * a control character) as it is, while Putchar(tc) may expand the
 * character tc to some byte sequnce that represents the character
 * in EUC form.
 */
void
Putchar(tchar tc)
{
	int	n;

	if (isascii(tc&TRIM)) {
		putbyte((int)tc);
		return;
	}
	tc &= TRIM;
	n = wctomb(linp, tc);
	if (n == -1) {
		return;
	}
	linp += n;
	if (linp >= &linbuf[sizeof (linbuf) - 1 - MB_CUR_MAX]) {
		flush();
	}
}
Exemplo n.º 17
0
/*
 * putbyte() send a byte to SHOUT.  No interpretation is done
 * except an un-QUOTE'd control character, which is displayed
 * as ^x.
 */
void
putbyte(int c)
{

	if ((c & QUOTE) == 0 && (c == 0177 || c < ' ' && c != '\t' &&
	    c != '\n')) {
		putbyte('^');
		if (c == 0177) {
			c = '?';
		} else {
			c |= 'A' - 1;
		}
	}
	c &= TRIM;
	*linp++ = c;
	if (c == '\n' || linp >= &linbuf[sizeof (linbuf) - 2]) {
		flush();
	}
}
Exemplo n.º 18
0
void sub_imm8_rm32(int size, int reg)
{
	//check if register
	if(isreg(reg)) {
		putbyte(0x83); //sub sign-extended imm8 from r/m32
		putbyte(0xe8+reg);
		putbyte(size);
	}
	else {
		putbyte(0x83);
		putbyte(0x28+reg-0x8);//FIXME is this right?
		putbyte(size);
	}
}
Exemplo n.º 19
0
void add_imm8_rm32(int size, int reg)
{
	//check if register
	if(isreg(reg)) {
		//special case for accumulator register eax
		if(reg==EAX) {
			putbyte(0x04);
			putbyte(size);
		}
		else {
			putbyte(0x83);
			putbyte(0xc0+reg);
			putbyte(size);
		}
	}
	//memory location
	else {
		putbyte(0x83);
		putbyte(reg-0x8);
		putbyte(size);
	}
}
Exemplo n.º 20
0
/*
 * putbyte() send a byte to SHOUT.  No interpretation is done
 * except an un-QUOTE'd control character, which is displayed
 * as ^x.
 */
void
putbyte(int c)
{

	if ((c & QUOTE) == 0 && (c == 0177 || c < ' ' && c != '\t' &&
	    c != '\n')) {
		putbyte('^');
		if (c == 0177) {
			c = '?';
		} else {
			c |= 'A' - 1;
		}
	}
	c &= TRIM;
	*linp++ = c;

	if (c == '\n' || linp >= &linbuf[sizeof (linbuf) - 1 - MB_CUR_MAX]) {
		/* 'cause the next Putchar() call may overflow the buffer.  */
		flush();
	}
}
Exemplo n.º 21
0
void mov_rm32_rm32(int dest, int source)
{
	//eg, "mov dest, source"
	if(isreg(dest)) {
		//destination is a register
		putbyte(0x89);
		if(isreg(source)) {
			//we have a "mov %eax,%ebx"
			putbyte((0xc0+(dest*0x8))+source);
		}
		else {
			if(dest==ESP) aerror("Error: ESP in mov_rm32_rm32");
			if(source==ESPM) {
				putbyte(0x4+(dest*0x8));
				putbyte(0x24); //SIB ESP
			}
			else {
				//we have a "mov %eax,(%ebx)"
				putbyte((dest*0x8)+source-0x8);
			}
		}
	}
	else {
		//destination is a memory offset located in register
		putbyte(0x8b);
		if(isreg(source)) {
			//we have a "mov (%eax),%ebx"
			putbyte((source*0x8)+dest-0x8);
		}
		else {
			//we have a "mov (%eax),(%ebx)"
			//this is an illegal instruction
			aerror("Error: in mov_rm32_rm32");
		}
	}
}
Exemplo n.º 22
0
void
evermore89(int baud)
{
	char buf[32], *s;

	fprint(2, "Evermore89");
	s = buf;
	s = putbyte(s, 0x89);		/* message ID */
	s = putbyte(s, 0x01);		/* set main serial port */
	switch(baud){
	case  4800:	s = putbyte(s, 0x00);	break;
	case  9600:	s = putbyte(s, 0x01);	break;
	case 19200:	s = putbyte(s, 0x02);	break;
	case 38400:	s = putbyte(s, 0x03);	break;
	default:
		sysfatal("illegal baud rate %d", baud);
	}

	evermoresend(buf, s - buf);
	fprint(2, "\n");
}
Exemplo n.º 23
0
lzo2a_999_compress_callback ( const lzo_byte *in , lzo_uint  in_len,
                                    lzo_byte *out, lzo_uintp out_len,
                                    lzo_voidp wrkmem,
                                    lzo_progress_callback_t cb,
                                    lzo_uint max_chain )
{
	lzo_byte *op;
	lzo_byte *bitp = 0;
	lzo_uint m_len, m_off;
	LZO_COMPRESS_T cc;
	LZO_COMPRESS_T * const c = &cc;
	lzo_swd_t * const swd = (lzo_swd_t *) wrkmem;
	int r;

	lzo_uint32 b = 0;		/* bit buffer */
	unsigned k = 0;			/* bits in bit buffer */

#if defined(__LZO_QUERY_COMPRESS)
	if (__LZO_IS_COMPRESS_QUERY(in,in_len,out,out_len,wrkmem))
		return __LZO_QUERY_COMPRESS(in,in_len,out,out_len,wrkmem,1,lzo_sizeof(lzo_swd_t));
#endif

	/* sanity check */
	if (!lzo_assert(LZO2A_999_MEM_COMPRESS >= lzo_sizeof(lzo_swd_t)))
		return LZO_E_ERROR;

	c->init = 0;
	c->ip = c->in = in;
	c->in_end = in + in_len;
	c->cb = cb;
	c->m1 = c->m2 = c->m3 = c->m4 = 0;

	op = out;

	r = init_match(c,swd,NULL,0,0);
	if (r != 0)
		return r;
	if (max_chain > 0)
		swd->max_chain = max_chain;

	r = find_match(c,swd,0,0);
	if (r != 0)
		return r;
	while (c->look > 0)
	{
		int lazy_match_min_gain = 0;
		int extra1 = 0;
		int extra2 = 0;
		lzo_uint ahead = 0;

		LZO_UNUSED(extra1);

		m_len = c->m_len;
		m_off = c->m_off;

#if (N >= 8192)
		if (m_off >= 8192)
		{
			if (m_len < M3_MIN_LEN)
				m_len = 0;
			else
				lazy_match_min_gain = 1;
		}
		else
#endif
		if (m_len >= M1_MIN_LEN && m_len <= M1_MAX_LEN && m_off <= 256)
		{
			lazy_match_min_gain = 2;
			extra1 = 3;
			extra2 = 2;
		}
		else if (m_len >= 10)
			lazy_match_min_gain = 1;
		else if (m_len >= 3)
		{
			lazy_match_min_gain = 1;
			extra1 = 1;
		}
		else
			m_len = 0;


		/* try a lazy match */
		if (lazy_match_min_gain > 0 && c->look > m_len)
		{
			int lit = swd->b_char;

			r = find_match(c,swd,1,0);
			assert(r == 0);
			assert(c->look > 0);

#if (N >= 8192)
			if (m_off < 8192 && c->m_off >= 8192)
				lazy_match_min_gain += extra1;
			else
#endif
			if (m_len >= M1_MIN_LEN && m_len <= M1_MAX_LEN && m_off <= 256)
			{
				if (!(c->m_len >= M1_MIN_LEN &&
				      c->m_len <= M1_MAX_LEN && c->m_off <= 256))
					lazy_match_min_gain += extra2;
			}
			if (c->m_len >= M1_MIN_LEN &&
			    c->m_len <= M1_MAX_LEN && c->m_off <= 256)
			{
					lazy_match_min_gain -= 1;
			}

			if (lazy_match_min_gain < 1)
				lazy_match_min_gain = 1;

			if (c->m_len >= m_len + lazy_match_min_gain)
			{
				c->lazy++;
#if !defined(NDEBUG)
				m_len = c->m_len;
				m_off = c->m_off;
				assert(lzo_memcmp(c->ip - c->look, c->ip - c->look - m_off,
			                      m_len) == 0);
				assert(m_len >= 3 || (m_len >= 2 && m_off <= 256));
#endif
				/* code literal */
				putbit(0);
				putbyte(lit);
				c->lit_bytes++;
				continue;
			}
			else
				ahead = 1;
			assert(m_len > 0);
		}


		if (m_len == 0)
		{
			/* a literal */
			putbit(0);
			putbyte(swd->b_char);
			c->lit_bytes++;
			r = find_match(c,swd,1,0);
			assert(r == 0);
		}
		else
		{
			assert(m_len >= M1_MIN_LEN);
			assert(m_off > 0);
			assert(m_off <= N);

			/* 2 - code match */
			if (m_len >= M1_MIN_LEN && m_len <= M1_MAX_LEN && m_off <= 256)
			{
				putbit(1);
				putbit(0);
				putbits(2,m_len - M1_MIN_LEN);
				putbyte(m_off - 1);
				c->m1++;
			}
#if (N >= 8192)
			else if (m_off >= 8192)
			{
				unsigned len = m_len;
				assert(m_len >= M3_MIN_LEN);
				putbit(1);
				putbit(1);
				putbyte(m_off & 31);
				putbyte(m_off >> 5);
				putbit(1);
				len -= M3_MIN_LEN - 1;
				while (len > 255)
				{
					len -= 255;
					putbyte(0);
				}
				putbyte(len);
				c->m4++;
			}
#endif
			else
			{
				assert(m_len >= 3);

				putbit(1);
				putbit(1);
				if (m_len <= 9)
				{
					putbyte(((m_len - 2) << 5) | (m_off & 31));
					putbyte(m_off >> 5);
					c->m2++;
				}
				else
				{
Exemplo n.º 24
0
static int
interpret()
{
fetch:
    Cyclecount++;
    W = M[C++];
    if ((W & DBIT) == 0)
        D = W & ABITS;
    else
        D = M[C++];

    if ((W & PBIT) != 0) D += P;
    if ((W & GBIT) != 0) D += G;
    if ((W & IBIT) != 0) D = M[D];

    switch (W >> FSHIFT) {
    error: default: printf("\nINTCODE ERROR AT C = %d\n", C - 1);
        return -1;
    case 0: B = A; A = D; goto fetch;
    case 1: M[D] = A; goto fetch;
    case 2: A = A + D; goto fetch;
    case 3: C = D; goto fetch;
    case 4: A = !A;
    case 5: if (!A) C = D; goto fetch;
    case 6: D += P;
        M[D] = P; M[D + 1] = C;
        P = D; C = A;
        goto fetch;
    case 7: switch (D) {
        default: goto error;
        case 1: A = M[A]; goto fetch;
        case 2: A = -A; goto fetch;
        case 3: A = ~A; goto fetch;
        case 4: C = M[P + 1];
            P = M[P];
            goto fetch;
        case 5: A = B * A; goto fetch;
        case 6: A = B / A; goto fetch;
        case 7: A = B % A; goto fetch;
        case 8: A = B + A; goto fetch;
        case 9: A = B - A; goto fetch;
        case 10: A = B == A ? ~0 : 0; goto fetch;
        case 11: A = B != A ? ~0 : 0; goto fetch;
        case 12: A = B < A  ? ~0 : 0; goto fetch;
        case 13: A = B >= A ? ~0 : 0; goto fetch;
        case 14: A = B > A ? ~0 : 0; goto fetch;
        case 15: A = B <= A ? ~0 : 0; goto fetch;
        case 16: A = B << A; goto fetch;
        case 17: A = B >> A; goto fetch;
        case 18: A = B & A; goto fetch;
        case 19: A = B | A; goto fetch;
        case 20: A = B ^ A; goto fetch;
        case 21: A = B ^ ~A; goto fetch;
        case 22: return 0;
        case 23: B = M[C]; D = M[C + 1];
            while (B != 0) {
                B--; C += 2;
                if (A == M[C]) { D = M[C + 1]; break; }
            }
            C = D;
            goto fetch;

        case 24: selectinput(A); goto fetch;
        case 25: selectoutput(A); goto fetch;
        case 26: A = rdch(); goto fetch;
        case 27: wrch(A); goto fetch;
        case 28: A = findinput(A); goto fetch;
        case 29: A = findoutput(A); goto fetch;
        case 30: return A;
        case 31: A = M[P]; goto fetch;
        case 32: P = A; C = B; goto fetch;
        case 33: endread(); goto fetch;
        case 34: endwrite(); goto fetch;
        case 35: D = P + B + 1;
                 M[D] = M[P];
                 M[D + 1] = M[P + 1];
                 M[D + 2] = P;
                 M[D + 3] = B;
                 P = D;
                 C = A;
                 goto fetch;
        case 36: A = getbyte(A, B); goto fetch;
        case 37: putbyte(A, B, M[P + 4]); goto fetch;
        case 38: A = input(); goto fetch;
        case 39: A = output(); goto fetch;
        }
    }
}
Exemplo n.º 25
0
static int sirf_command(char line[])
{
    unsigned char buf[BUFSIZ];
    int v;

    switch (line[0]) {
    case 'A':			/* toggle 50bps subframe data */
	(void)memset(buf, '\0', sizeof(buf));
	putbyte(buf, 0, 0x80);
	putbyte(buf, 23, 0x0c);
	putbyte(buf, 24, subframe_enabled ? 0x00 : 0x10);
	(void)monitor_control_send(buf, 25);
	/*
	 * The subframe_enabled off because we're counting on receipt of
	 * a subframe packet to turn it on if the command succeeds.
	 */
	subframe_enabled = false;
	return COMMAND_MATCH;

    case 'M':			/* static navigation */
	putbyte(buf, 0, 0x8f);	/* id */
	putbyte(buf, 1, atoi(line + 1));
	(void)monitor_control_send(buf, 2);
	return COMMAND_MATCH;

    case 'D':			/* MID 4 rate change (undocumented) */
	v = atoi(line + 1);
	if (v > 30)
	    return COMMAND_MATCH;
	putbyte(buf, 0, 0xa6);
	putbyte(buf, 1, 0);
	putbyte(buf, 2, 4);	/* satellite picture */
	putbyte(buf, 3, v);
	putbyte(buf, 4, 0);
	putbyte(buf, 5, 0);
	putbyte(buf, 6, 0);
	putbyte(buf, 7, 0);
	(void)monitor_control_send(buf, 8);
	return COMMAND_MATCH;

    case 'P':			/* poll navigation params */
	dispmode = !dispmode;
	if (dispmode) {
	    (void)syncok(mid6win, false);
	    (void)syncok(mid7win, false);
	    (void)syncok(mid9win, false);
	    (void)syncok(mid13win, false);
	    (void)syncok(mid27win, false);
	} else {
	    (void)syncok(mid6win, true);
	    (void)wsyncup(mid6win);
	    (void)syncok(mid7win, true);
	    (void)wsyncup(mid7win);
	    (void)syncok(mid9win, true);
	    (void)wsyncup(mid9win);
	    (void)syncok(mid13win, true);
	    (void)wsyncup(mid13win);
	    (void)syncok(mid27win, true);
	    (void)wsyncup(mid27win);
	}
	return COMMAND_MATCH;
    }

    return COMMAND_UNKNOWN;	/* no match */
}
Exemplo n.º 26
0
lzo2a_999_compress_callback(const lzo_bytep in , lzo_uint  in_len,
                            lzo_bytep out, lzo_uintp out_len,
                            lzo_voidp wrkmem,
                            lzo_callback_p cb,
                            lzo_uint max_chain)
{
    lzo_bytep op;
    lzo_bytep bitp = 0;
    lzo_uint m_len, m_off;
    LZO_COMPRESS_T cc;
    LZO_COMPRESS_T* const c = &cc;
    lzo_swd_p const swd = (lzo_swd_p) wrkmem;
    int r;

    lzo_uint32_t b = 0;     /* bit buffer */
    unsigned k = 0;         /* bits in bit buffer */

    /* sanity check */
    LZO_COMPILE_TIME_ASSERT(LZO2A_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)

    c->init = 0;
    c->ip = c->in = in;
    c->in_end = in + in_len;
    c->cb = cb;
    c->m1 = c->m2 = c->m3 = c->m4 = 0;

    op = out;

    r = init_match(c, swd, NULL, 0, 0);

    if (r != 0)
        return r;

    if (max_chain > 0)
        swd->max_chain = max_chain;

    r = find_match(c, swd, 0, 0);

    if (r != 0)
        return r;

    while (c->look > 0)
    {
        lzo_uint lazy_match_min_gain = 0;
#if (SWD_N >= 8192)
        lzo_uint extra1 = 0;
#endif
        lzo_uint extra2 = 0;
        lzo_uint ahead = 0;

        m_len = c->m_len;
        m_off = c->m_off;

#if (SWD_N >= 8192)

        if (m_off >= 8192)
        {
            if (m_len < M3_MIN_LEN)
                m_len = 0;
            else
                lazy_match_min_gain = 1;
        }
        else
#endif
            if (m_len >= M1_MIN_LEN && m_len <= M1_MAX_LEN && m_off <= 256)
            {
                lazy_match_min_gain = 2;
#if (SWD_N >= 8192)
                extra1 = 3;
#endif
                extra2 = 2;
            }
            else if (m_len >= 10)
                lazy_match_min_gain = 1;
            else if (m_len >= 3)
            {
                lazy_match_min_gain = 1;
#if (SWD_N >= 8192)
                extra1 = 1;
#endif
            }
            else
                m_len = 0;


        /* try a lazy match */
        if (lazy_match_min_gain > 0 && c->look > m_len)
        {
            unsigned char lit = LZO_BYTE(swd->b_char);

            r = find_match(c, swd, 1, 0);
            assert(r == 0);
            LZO_UNUSED(r);
            assert(c->look > 0);

#if (SWD_N >= 8192)

            if (m_off < 8192 && c->m_off >= 8192)
                lazy_match_min_gain += extra1;
            else
#endif
                if (m_len >= M1_MIN_LEN && m_len <= M1_MAX_LEN && m_off <= 256)
                {
                    if (!(c->m_len >= M1_MIN_LEN &&
                            c->m_len <= M1_MAX_LEN && c->m_off <= 256))
                        lazy_match_min_gain += extra2;
                }

            if (c->m_len >= M1_MIN_LEN &&
                    c->m_len <= M1_MAX_LEN && c->m_off <= 256)
            {
                lazy_match_min_gain -= 1;
            }

            if ((lzo_int) lazy_match_min_gain < 1)
                lazy_match_min_gain = 1;

            if (c->m_len >= m_len + lazy_match_min_gain)
            {
                c->lazy++;
#if !defined(NDEBUG)
                m_len = c->m_len;
                m_off = c->m_off;
                assert(lzo_memcmp(c->ip - c->look, c->ip - c->look - m_off,
                                  m_len) == 0);
                assert(m_len >= 3 || (m_len >= 2 && m_off <= 256));
#endif
                /* code literal */
                putbit(0);
                putbyte(lit);
                c->lit_bytes++;
                continue;
            }
            else
                ahead = 1;

            assert(m_len > 0);
        }


        if (m_len == 0)
        {
            /* a literal */
            putbit(0);
            putbyte(swd->b_char);
            c->lit_bytes++;
            r = find_match(c, swd, 1, 0);
            assert(r == 0);
            LZO_UNUSED(r);
        }
        else
        {
            assert(m_len >= M1_MIN_LEN);
            assert(m_off > 0);
            assert(m_off <= SWD_N);

            /* 2 - code match */
            if (m_len >= M1_MIN_LEN && m_len <= M1_MAX_LEN && m_off <= 256)
            {
                putbit(1);
                putbit(0);
                putbits(2, m_len - M1_MIN_LEN);
                putbyte(m_off - 1);
                c->m1++;
            }

#if (SWD_N >= 8192)
            else if (m_off >= 8192)
            {
                unsigned len = m_len;
                assert(m_len >= M3_MIN_LEN);
                putbit(1);
                putbit(1);
                putbyte(m_off & 31);
                putbyte(m_off >> 5);
                putbit(1);
                len -= M3_MIN_LEN - 1;

                while (len > 255)
                {
                    len -= 255;
                    putbyte(0);
                }

                putbyte(len);
                c->m4++;
            }

#endif
            else
            {
                assert(m_len >= 3);

                putbit(1);
                putbit(1);

                if (m_len <= 9)
                {
                    putbyte(((m_len - 2) << 5) | (m_off & 31));
                    putbyte(m_off >> 5);
                    c->m2++;
                }
                else
                {
Exemplo n.º 27
0
/*
 * Putchar(tc) does what putbyte(c) do for a byte c.
 * For single-byte character only environment, there is no
 * difference between Putchar() and putbyte() though.
 */
void
Putchar(tchar tc)
{
	putbyte((int)tc);
}
Exemplo n.º 28
0
Arquivo: code.c Projeto: BlockoS/pceas
void
class4(int *ip)
{
	char buffer[32];
	char c;
	int len, mode;
	int	i;

	/* skip spaces */
	while (isspace(prlnbuf[*ip]))
		(*ip)++;

	/* low/high byte prefix string */
	if (isalpha(prlnbuf[*ip])) {
		len = 0;
		i = *ip;

		/* extract string */
		for (;;) {
			c = prlnbuf[i];
			if (c == '\0' || c == ' ' || c == '\t' || c == ';')
				break;
			if ((!isalpha(c) && c != '_') || (len == 31)) {
				len = 0;
				break;
			}
			buffer[len++] = c;
			i++;
		}

		/* check */
		if (len) {
			buffer[len] = '\0';

			if (strcasecmp(buffer, "low_byte") == 0) {
				opext = 'L';
				*ip = i;
			}
			if (strcasecmp(buffer, "high_byte") == 0) {
				opext = 'H';
				*ip = i;
			}
		}
	}

	/* get operand */
	mode = getoperand(ip, opflg, ';');
	if (!mode)
		return;

	/* make opcode */
	if (pass == LAST_PASS) {
		for (i = 0; i < 32; i++) {
			if (mode & (1 << i))
				break;
		}
		opval += opvaltab[optype][i];
	}

	/* auto-tag */
	if (auto_tag) {
		if (pass == LAST_PASS) {
			putbyte(loccnt, 0xA0);
			putbyte(loccnt+1, auto_tag_value);
		}
		loccnt += 2;
	}

	/* generate code */
	switch(mode) {
	case ACC:
		/* one byte */
		if (pass == LAST_PASS)
			putbyte(loccnt, opval);

		loccnt++;
		break;

	case IMM:
	case ZP:
	case ZP_X:
	case ZP_Y:
	case ZP_IND:
	case ZP_IND_X:
	case ZP_IND_Y:
		/* two bytes */
		if (pass == LAST_PASS) {
			putbyte(loccnt, opval);
			putbyte(loccnt+1, value);
		}
		loccnt += 2;
		break;

	case ABS:
	case ABS_X:
	case ABS_Y:
	case ABS_IND:
	case ABS_IND_X:
		/* three bytes */
		if (pass == LAST_PASS) {
			putbyte(loccnt, opval);
			putword(loccnt+1, value);
		}
		loccnt += 3;
		break;
	}

	/* auto-increment */
	if (auto_inc) {
		if (pass == LAST_PASS)
			putbyte(loccnt, auto_inc);

		loccnt += 1;
	}

	/* output line */
	if (pass == LAST_PASS)
		println();
}
Exemplo n.º 29
0
Arquivo: proc.c Projeto: m6502/pceas
void
do_call(int *ip)
{
	struct t_proc *ptr;
	int value;

	/* define label */
	labldef(loccnt, 1);

	/* update location counter */
	data_loccnt = loccnt;
	loccnt += 3;

	/* generate code */
	if (pass == LAST_PASS) {
		/* skip spaces */
		while (isspace(prlnbuf[*ip]))
			(*ip)++;

		/* extract name */
		if (!colsym(ip)) {
			if (symbol[0] == 0)
				fatal_error("Syntax error!");
			return;
		}

		/* check end of line */
		check_eol(ip);

		/* lookup proc table */
		if((ptr = proc_look())) {
			/* check banks */
			if (bank == ptr->bank)
				value = ptr->org + 0xA000;
			else {
				/* different */
				if (ptr->call)
					value = ptr->call;
				else {
					/* new call */
					value = call_ptr + 0x8000;
					ptr->call = value;

					/* init */
					if (call_ptr == 0) {
						call_bank = ++max_bank;
					}

					/* install */
					poke(call_ptr++, 0xA8);			// tay
					poke(call_ptr++, 0x43);			// tma #5
					poke(call_ptr++, 0x20);
					poke(call_ptr++, 0x48);			// pha
					poke(call_ptr++, 0xA9);			// lda #...
					poke(call_ptr++, ptr->bank+bank_base);
					poke(call_ptr++, 0x53);			// tam #5
					poke(call_ptr++, 0x20);
					poke(call_ptr++, 0x98);			// tya
					poke(call_ptr++, 0x20);			// jsr ...
					poke(call_ptr++, (ptr->org & 0xFF));
					poke(call_ptr++, (ptr->org >> 8) + 0xA0);
					poke(call_ptr++, 0xA8);			// tay
					poke(call_ptr++, 0x68);			// pla
					poke(call_ptr++, 0x53);			// tam #5
					poke(call_ptr++, 0x20);
					poke(call_ptr++, 0x98);			// tya
					poke(call_ptr++, 0x60);			// rts
				}
			}
		}
		else {
			/* lookup symbol table */
			if ((lablptr = stlook(0)) == NULL) {
				fatal_error("Undefined destination!");
				return;
			}

			/* get symbol value */
			value = lablptr->value;
		}

		/* opcode */
		putbyte(data_loccnt, 0x20);
		putword(data_loccnt+1, value);

		/* output line */
		println();
	}
Exemplo n.º 30
0
void
handlefullmsg(Conn *c, Achan *a)
{
	int i;
	uint32_t chan, len, n, rt;
	uint8_t type;
	Msg *m, mm;
	Msg *r;
	Key *k;
	int nk;
	mpint *mod, *ek, *chal;
	uint8_t sessid[16];
	uint8_t chalbuf[32];
	uint8_t digest[16];
	DigestState *s;
	static int first;

	assert(a->len == a->ndata);

	chan = a->chan;
	mm.rp = a->data;
	mm.ep = a->data+a->ndata;
	mm.c = c;
	m = &mm;

	type = getbyte(m);

	if(first == 0){
		first++;
		fmtinstall('H', encodefmt);
	}

	switch(type){
	default:
		debug(DBG_AUTH, "unknown msg type\n");
	Failure:
		debug(DBG_AUTH, "agent sending failure\n");
		r = allocmsg(m->c, SSH_MSG_CHANNEL_DATA, 13);
		putlong(r, chan);
		putlong(r, 5);
		putlong(r, 1);
		putbyte(r, SSH_AGENT_FAILURE);
		sendmsg(r);
		return;

	case SSH_AGENTC_REQUEST_RSA_IDENTITIES:
		debug(DBG_AUTH, "agent request identities\n");
		nk = listkeys(&k);
		if(nk < 0)
			goto Failure;
		len = 1+4;	/* type, nk */
		for(i=0; i<nk; i++){
			len += 4;
			len += 2+(mpsignif(k[i].ek)+7)/8;
			len += 2+(mpsignif(k[i].mod)+7)/8;
			len += 4+strlen(k[i].comment);
		}
		r = allocmsg(m->c, SSH_MSG_CHANNEL_DATA, 12+len);
		putlong(r, chan);
		putlong(r, len+4);
		putlong(r, len);
		putbyte(r, SSH_AGENT_RSA_IDENTITIES_ANSWER);
		putlong(r, nk);
		for(i=0; i<nk; i++){
			debug(DBG_AUTH, "\t%B %B %s\n", k[i].ek, k[i].mod, k[i].comment);
			putlong(r, mpsignif(k[i].mod));
			putmpint(r, k[i].ek);
			putmpint(r, k[i].mod);
			putstring(r, k[i].comment);
			mpfree(k[i].ek);
			mpfree(k[i].mod);
			free(k[i].comment);
		}
		free(k);
		sendmsg(r);
		break;

	case SSH_AGENTC_RSA_CHALLENGE:
		n = getlong(m);
		USED(n);	/* number of bits in key; who cares? */
		ek = getmpint(m);
		mod = getmpint(m);
		chal = getmpint(m);
		memmove(sessid, getbytes(m, 16), 16);
		rt = getlong(m);
		debug(DBG_AUTH, "agent challenge %B %B %B %ud (%p %p)\n",
			ek, mod, chal, rt, m->rp, m->ep);
		if(rt != 1 || dorsa(mod, ek, chal, chalbuf) < 0){
			mpfree(ek);
			mpfree(mod);
			mpfree(chal);
			goto Failure;
		}
		s = md5(chalbuf, 32, nil, nil);
		md5(sessid, 16, digest, s);
		r = allocmsg(m->c, SSH_MSG_CHANNEL_DATA, 12+1+16);
		putlong(r, chan);
		putlong(r, 4+16+1);
		putlong(r, 16+1);
		putbyte(r, SSH_AGENT_RSA_RESPONSE);
		putbytes(r, digest, 16);
		debug(DBG_AUTH, "digest %.16H\n", digest);
		sendmsg(r);
		mpfree(ek);
		mpfree(mod);
		mpfree(chal);
		return;

	case SSH_AGENTC_ADD_RSA_IDENTITY:
		goto Failure;
/*
		n = getlong(m);
		pubmod = getmpint(m);
		pubexp = getmpint(m);
		privexp = getmpint(m);
		pinversemodq = getmpint(m);
		p = getmpint(m);
		q = getmpint(m);
		comment = getstring(m);
		add to factotum;
		send SSH_AGENT_SUCCESS or SSH_AGENT_FAILURE;
*/

	case SSH_AGENTC_REMOVE_RSA_IDENTITY:
		goto Failure;
/*
		n = getlong(m);
		pubmod = getmpint(m);
		pubexp = getmpint(m);
		tell factotum to del key
		send SSH_AGENT_SUCCESS or SSH_AGENT_FAILURE;
*/
	}
}