示例#1
0
void cgLdCns(IRLS& env, const IRInstruction* inst) {
  auto const cnsName = inst->src(0)->strVal();
  auto const ch = makeCnsHandle(cnsName, false);
  auto const dst = dstLoc(env, inst, 0);
  auto& v = vmain(env);
  assertx(inst->taken());

  if (rds::isNormalHandle(ch)) {
    auto const sf = checkRDSHandleInitialized(v, ch);
    fwdJcc(v, env, CC_NE, sf, inst->taken());
    loadTV(v, inst->dst(), dst, rvmtl()[ch]);
    return;
  }
  assertx(rds::isPersistentHandle(ch));

  auto const& cns = rds::handleToRef<TypedValue>(ch);

  if (cns.m_type == KindOfUninit) {
    loadTV(v, inst->dst(), dst, rvmtl()[ch]);
    auto const sf = v.makeReg();
    irlower::emitTypeTest(
      v, env, TUninit, dst.reg(1), dst.reg(0), sf,
      [&] (ConditionCode cc, Vreg sf) {
        fwdJcc(v, env, cc, sf, inst->taken());
      }
    );
  } else {
    // Statically known constant.
    assertx(!dst.isFullSIMD());
    switch (cns.m_type) {
      case KindOfNull:
        v << copy{v.cns(nullptr), dst.reg(0)};
        break;
      case KindOfBoolean:
        v << copy{v.cns(!!cns.m_data.num), dst.reg(0)};
        break;
      case KindOfInt64:
      case KindOfPersistentString:
      case KindOfPersistentVec:
      case KindOfPersistentDict:
      case KindOfPersistentKeyset:
      case KindOfPersistentArray:
      case KindOfString:
      case KindOfVec:
      case KindOfDict:
      case KindOfKeyset:
      case KindOfArray:
      case KindOfObject:
      case KindOfResource:
      case KindOfRef:
        v << copy{v.cns(cns.m_data.num), dst.reg(0)};
        break;
      case KindOfDouble:
        v << copy{v.cns(cns.m_data.dbl), dst.reg(0)};
        break;
      case KindOfUninit:
      case KindOfClass:
        not_reached();
    }
    v << copy{v.cns(cns.m_type), dst.reg(1)};
  }
}
示例#2
0
/*
 - regcomp - compile a regular expression into internal code
 *
 * We can't allocate space until we know how big the compiled form will be,
 * but we can't compile it (and thus know how big it is) until we've got a
 * place to put the code.  So we cheat:  we compile it twice, once with code
 * generation turned off and size counting turned on, and once "for real".
 * This also means that we don't allocate space until we are sure that the
 * thing really will compile successfully, and we never have to move the
 * code and thus invalidate pointers into it.  (Note that it has to be in
 * one piece because free() must be able to free it all.)
 *
 * Beware that the optimization-preparation code in here knows about some
 * of the structure of the compiled regexp.
 */
int regcomp(regex_t *preg, const char *exp, int cflags)
{
	int scan;
	int longest;
	unsigned len;
	int flags;

#ifdef DEBUG
	fprintf(stderr, "Compiling: '%s'\n", exp);
#endif
	memset(preg, 0, sizeof(*preg));

	if (exp == NULL)
		FAIL(preg, REG_ERR_NULL_ARGUMENT);

	/* First pass: determine size, legality. */
	preg->cflags = cflags;
	preg->regparse = exp;

	/* Allocate space. */
	preg->proglen = (strlen(exp) + 1) * 5;
	preg->program = malloc(preg->proglen * sizeof(int));
	if (preg->program == NULL)
		FAIL(preg, REG_ERR_NOMEM);

	/* Note that since we store a magic value as the first item in the program,
	 * program offsets will never be 0
	 */
	regc(preg, REG_MAGIC);
	if (reg(preg, 0, &flags) == 0) {
		return preg->err;
	}

	/* Small enough for pointer-storage convention? */
	if (preg->re_nsub >= REG_MAX_PAREN)		/* Probably could be 65535L. */
		FAIL(preg,REG_ERR_TOO_BIG);

	/* Dig out information for optimizations. */
	preg->regstart = 0;	/* Worst-case defaults. */
	preg->reganch = 0;
	preg->regmust = 0;
	preg->regmlen = 0;
	scan = 1;			/* First BRANCH. */
	if (OP(preg, regnext(preg, scan)) == END) {		/* Only one top-level choice. */
		scan = OPERAND(scan);

		/* Starting-point info. */
		if (OP(preg, scan) == EXACTLY) {
			preg->regstart = preg->program[OPERAND(scan)];
		}
		else if (OP(preg, scan) == BOL)
			preg->reganch++;

		/*
		 * If there's something expensive in the r.e., find the
		 * longest literal string that must appear and make it the
		 * regmust.  Resolve ties in favor of later strings, since
		 * the regstart check works with the beginning of the r.e.
		 * and avoiding duplication strengthens checking.  Not a
		 * strong reason, but sufficient in the absence of others.
		 */
		if (flags&SPSTART) {
			longest = 0;
			len = 0;
			for (; scan != 0; scan = regnext(preg, scan)) {
				if (OP(preg, scan) == EXACTLY) {
					int plen = str_int_len(preg->program + OPERAND(scan));
					if (plen >= len) {
						longest = OPERAND(scan);
						len = plen;
					}
				}
			}
			preg->regmust = longest;
			preg->regmlen = len;
		}
	}

#ifdef DEBUG
	regdump(preg);
#endif

	return 0;
}
示例#3
0
void Serveur::readServeur()
{
        QString message=QString::fromUtf8(this->readAll());


	QString currentChan=tab->tabText(tab->currentIndex());

	if(message.startsWith("PING :"))
	{
		QStringList liste=message.split(" ");
		QString msg="PONG "+liste.at(1);
		sendData(msg);
	}
	else if(message.contains("Nickname is already in use."))
	{
        pseudo=pseudo+"_2";
		pseudo.remove("\r\n");
		sendData("NICK "+pseudo);
		emit pseudoChanged(pseudo);
        ecrire("-> Name changed to "+pseudo);
	}
        else if(updateUsers==true)
	{
		updateUsersList("",message);
	}

    QStringList list=message.split("\r\n");
        foreach(QString msg,list)
        {
            if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)")))
            {
                QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)");
                QString msg2=msg;
                    ecrire(msg.replace(reg,"\\2 <b>&lt;\\1&gt;</b> \\3"),"",msg2.replace(reg,"\\2 <\\1> \\3"));
            }
            else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)")))
            {
                QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)");
                QString msg2=msg;
                ecrire(msg.replace(reg,"\\2 <i>-> \\1 join \\2</i><br />"),"",msg2.replace(reg,"-> \\1 join \\2"));
                updateUsersList(msg.replace(reg,"\\2"));
            }
            else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+)")))
            {
                QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+) :(.+)");
                QString msg2=msg;
                ecrire(msg.replace(reg,"\\2 <i>-> \\1 quit \\2 (\\3)</i><br />"),"",msg2.replace(reg,"-> \\1 quit \\2"));
                updateUsersList(msg.replace(reg,"\\2"));
            }
            else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ QUIT (.+)")))
            {
                QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ QUIT (.+)");
                QString msg2=msg;
                ecrire(msg.replace(reg,"\\2 <i>-> \\1 quit this server (\\2)</i><br />"),"",msg2.replace(reg,"-> \\1 left"));
                updateUsersList(msg.replace(reg,"\\2"));
            }
            else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ NICK :(.+)")))
            {
                QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ NICK :(.+)");
                QString msg2=msg;
                ecrire(msg.replace(reg,"<i>\\1 is now called \\2</i><br />"),"",msg2.replace(reg,"-> \\1 is now called \\2"));
                updateUsersList(currentChan);
            }
            else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)")))
            { 
                QRegExp reg(":([a-zA-Z0-9]+)\\!~[a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)");
                QString msg2=msg;
                ecrire(msg.replace(reg,"\\2 <i>-> \\1 kicked \\3 (\\4)</i><br />"),"",msg2.replace(reg,"-> \\1 quit \\3"));
                updateUsersList(msg.replace(reg,"\\2"));
            }
            else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ NOTICE ([a-zA-Z0-9]+) :(.+)")))
            {
                if(conversations.contains(currentChan))
                {
                    QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)");
                    ecrire(msg.replace(reg,"<b>[NOTICE] <i>\\1</i> : \\2 <br />"),currentChan);
                }
                else if(currentChan==serveur)
                {
                    QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9][email protected][a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)");
                    ecrire(msg.replace(reg,"<b>[NOTICE] <i>\\1</i> : \\2 <br />"));
                }
            }
            else if(msg.contains("/MOTD command."))
            {
             joins();


            }
            else if(msg.contains(QRegExp("= ([a-zA-Z0-9\\#]+) :")))
            {

             QStringList msg3 = msg.split("= ");
             QStringList msg4 = msg3[1].split(" :");
             updateUsersList(msg4[0],msg);
            }


        }

        //}
}
示例#4
0
文件: uart.c 项目: crazy2be/cs452
char uart_read(int channel) {
	return *reg(channel, UART_DATA_OFFSET);
}
示例#5
0
/*
 - regcomp - compile a regular expression into internal code
 *
 * We can't allocate space until we know how big the compiled form will be,
 * but we can't compile it (and thus know how big it is) until we've got a
 * place to put the code.  So we cheat:  we compile it twice, once with code
 * generation turned off and size counting turned on, and once "for real".
 * This also means that we don't allocate space until we are sure that the
 * thing really will compile successfully, and we never have to move the
 * code and thus invalidate pointers into it.  (Note that it has to be in
 * one piece because free() must be able to free it all.)
 *
 * Beware that the optimization-preparation code in here knows about some
 * of the structure of the compiled regexp.
 */
cst_regex *
hs_regcomp(const char *exp)
{
        cst_regex *r;
	char *scan;
	char *longest;
	unsigned int len;
	int flags;
	if (exp == NULL)
		FAIL("NULL argument");

	/* First pass: determine size, legality. */
#ifdef notdef
	if (exp[0] == '.' && exp[1] == '*') exp += 2;  /* aid grep */
#endif
	regparse = exp;
	regnpar = 1;
	regsize = 0L;
	regcode = &regdummy;
	regc(CST_REGMAGIC);
	if (reg(0, &flags) == NULL)
		return(NULL);

	/* Small enough for pointer-storage convention? */
	if (regsize >= 32767L)		/* Probably could be 65535L. */
		FAIL("regexp too big");

	/* Allocate space. */
	r = cst_alloc(cst_regex,1);
	r->regsize = regsize;
	r->program = cst_alloc(char,regsize);
	if (r == NULL)
		FAIL("out of space");

	/* Second pass: emit code. */
	regparse = exp;
	regnpar = 1;
	regcode = r->program;
	regc(CST_REGMAGIC);
	if (reg(0, &flags) == NULL)
		return(NULL);

	/* Dig out information for optimizations. */
	r->regstart = '\0';	/* Worst-case defaults. */
	r->reganch = 0;
	r->regmust = NULL;
	r->regmlen = 0;
	scan = r->program+1;			/* First BRANCH. */

	if (OP(regnext(scan)) == END) {		/* Only one top-level choice. */
		scan = OPERAND(scan);

		/* Starting-point info. */
		if (OP(scan) == EXACTLY)
			r->regstart = *OPERAND(scan);
		else if (OP(scan) == BOL)
			r->reganch++;

		/*
		 * If there's something expensive in the r.e., find the
		 * longest literal string that must appear and make it the
		 * regmust.  Resolve ties in favor of later strings, since
		 * the regstart check works with the beginning of the r.e.
		 * and avoiding duplication strengthens checking.  Not a
		 * strong reason, but sufficient in the absence of others.
		 */
		if (flags&SPSTART) {
			longest = NULL;
			len = 0;
			for (; scan != NULL; scan = regnext(scan))
				if ((OP(scan) == EXACTLY) && 
				    (strlen(OPERAND(scan)) >= len)) {
					longest = OPERAND(scan);
					len = strlen(OPERAND(scan));
				}
			r->regmust = longest;
			r->regmlen = len;
		}
	}
	return(r);

}
示例#6
0
文件: uart.c 项目: crazy2be/cs452
void uart_clear_modem_irq(int channel) {
#ifndef QEMU
	*reg(channel, UART_INTR_OFFSET) = 0;
#endif
}
示例#7
0
文件: uart.c 项目: crazy2be/cs452
int uart_err(int channel) {
	return *reg(channel, UART_RSR_OFFSET); // TODO
}
示例#8
0
void test_addressing_modes() {
	asm_p as = &(asm_t){ 0 };
	char* disassembly = NULL;
	as_new(as);
	
	// reg reg
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_mov(as, reg(i), reg(i));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"mov    rax,rax\n"
		"mov    rcx,rcx\n"
		"mov    rdx,rdx\n"
		"mov    rbx,rbx\n"
		"mov    rsp,rsp\n"
		"mov    rbp,rbp\n"
		"mov    rsi,rsi\n"
		"mov    rdi,rdi\n"
		"mov    r8,r8\n"
		"mov    r9,r9\n"
		"mov    r10,r10\n"
		"mov    r11,r11\n"
		"mov    r12,r12\n"
		"mov    r13,r13\n"
		"mov    r14,r14\n"
		"mov    r15,r15\n"
	);
	
	// reg [RIP + displ]
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_mov(as, reg(i), reld(0xbeba));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"mov    rax,QWORD PTR [rip+0xbeba]        # 0x40bec1\n"
		"mov    rcx,QWORD PTR [rip+0xbeba]        # 0x40bec8\n"
		"mov    rdx,QWORD PTR [rip+0xbeba]        # 0x40becf\n"
		"mov    rbx,QWORD PTR [rip+0xbeba]        # 0x40bed6\n"
		"mov    rsp,QWORD PTR [rip+0xbeba]        # 0x40bedd\n"
		"mov    rbp,QWORD PTR [rip+0xbeba]        # 0x40bee4\n"
		"mov    rsi,QWORD PTR [rip+0xbeba]        # 0x40beeb\n"
		"mov    rdi,QWORD PTR [rip+0xbeba]        # 0x40bef2\n"
		"mov    r8,QWORD PTR [rip+0xbeba]        # 0x40bef9\n"
		"mov    r9,QWORD PTR [rip+0xbeba]        # 0x40bf00\n"
		"mov    r10,QWORD PTR [rip+0xbeba]        # 0x40bf07\n"
		"mov    r11,QWORD PTR [rip+0xbeba]        # 0x40bf0e\n"
		"mov    r12,QWORD PTR [rip+0xbeba]        # 0x40bf15\n"
		"mov    r13,QWORD PTR [rip+0xbeba]        # 0x40bf1c\n"
		"mov    r14,QWORD PTR [rip+0xbeba]        # 0x40bf23\n"
		"mov    r15,QWORD PTR [rip+0xbeba]        # 0x40bf2a\n"
	);
	
	// reg [displ]
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_mov(as, reg(i), memd(0xbeba));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		// Funny syntax when disassembling with intel syntax. Looks normal with
		// GNU syntax.
		"mov    rax,QWORD PTR ds:0xbeba\n"
		"mov    rcx,QWORD PTR ds:0xbeba\n"
		"mov    rdx,QWORD PTR ds:0xbeba\n"
		"mov    rbx,QWORD PTR ds:0xbeba\n"
		"mov    rsp,QWORD PTR ds:0xbeba\n"
		"mov    rbp,QWORD PTR ds:0xbeba\n"
		"mov    rsi,QWORD PTR ds:0xbeba\n"
		"mov    rdi,QWORD PTR ds:0xbeba\n"
		"mov    r8,QWORD PTR ds:0xbeba\n"
		"mov    r9,QWORD PTR ds:0xbeba\n"
		"mov    r10,QWORD PTR ds:0xbeba\n"
		"mov    r11,QWORD PTR ds:0xbeba\n"
		"mov    r12,QWORD PTR ds:0xbeba\n"
		"mov    r13,QWORD PTR ds:0xbeba\n"
		"mov    r14,QWORD PTR ds:0xbeba\n"
		"mov    r15,QWORD PTR ds:0xbeba\n"
	);
	
	// reg [reg + displ]
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_mov(as, reg(i), memrd(reg(i), 0xbeba));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"mov    rax,QWORD PTR [rax+0xbeba]\n"
		"mov    rcx,QWORD PTR [rcx+0xbeba]\n"
		"mov    rdx,QWORD PTR [rdx+0xbeba]\n"
		"mov    rbx,QWORD PTR [rbx+0xbeba]\n"
		"mov    rsp,QWORD PTR [rsp+0xbeba]\n"
		"mov    rbp,QWORD PTR [rbp+0xbeba]\n"
		"mov    rsi,QWORD PTR [rsi+0xbeba]\n"
		"mov    rdi,QWORD PTR [rdi+0xbeba]\n"
		"mov    r8,QWORD PTR [r8+0xbeba]\n"
		"mov    r9,QWORD PTR [r9+0xbeba]\n"
		"mov    r10,QWORD PTR [r10+0xbeba]\n"
		"mov    r11,QWORD PTR [r11+0xbeba]\n"
		"mov    r12,QWORD PTR [r12+0xbeba]\n"
		"mov    r13,QWORD PTR [r13+0xbeba]\n"
		"mov    r14,QWORD PTR [r14+0xbeba]\n"
		"mov    r15,QWORD PTR [r15+0xbeba]\n"
	);
	
	free(disassembly);
}
示例#9
0
void test_compare_instructions() {
	asm_p as = &(asm_t){ 0 };
	char* disassembly = NULL;
	as_new(as);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_cmp(as, reg(i), reg(i));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"cmp    rax,rax\n"
		"cmp    rcx,rcx\n"
		"cmp    rdx,rdx\n"
		"cmp    rbx,rbx\n"
		"cmp    rsp,rsp\n"
		"cmp    rbp,rbp\n"
		"cmp    rsi,rsi\n"
		"cmp    rdi,rdi\n"
		"cmp    r8,r8\n"
		"cmp    r9,r9\n"
		"cmp    r10,r10\n"
		"cmp    r11,r11\n"
		"cmp    r12,r12\n"
		"cmp    r13,r13\n"
		"cmp    r14,r14\n"
		"cmp    r15,r15\n"
	);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_cmp(as, reg(i), memrd(reg(i), 0xbeba));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"cmp    rax,QWORD PTR [rax+0xbeba]\n"
		"cmp    rcx,QWORD PTR [rcx+0xbeba]\n"
		"cmp    rdx,QWORD PTR [rdx+0xbeba]\n"
		"cmp    rbx,QWORD PTR [rbx+0xbeba]\n"
		"cmp    rsp,QWORD PTR [rsp+0xbeba]\n"
		"cmp    rbp,QWORD PTR [rbp+0xbeba]\n"
		"cmp    rsi,QWORD PTR [rsi+0xbeba]\n"
		"cmp    rdi,QWORD PTR [rdi+0xbeba]\n"
		"cmp    r8,QWORD PTR [r8+0xbeba]\n"
		"cmp    r9,QWORD PTR [r9+0xbeba]\n"
		"cmp    r10,QWORD PTR [r10+0xbeba]\n"
		"cmp    r11,QWORD PTR [r11+0xbeba]\n"
		"cmp    r12,QWORD PTR [r12+0xbeba]\n"
		"cmp    r13,QWORD PTR [r13+0xbeba]\n"
		"cmp    r14,QWORD PTR [r14+0xbeba]\n"
		"cmp    r15,QWORD PTR [r15+0xbeba]\n"
	);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_cmp(as, reg(i), imm(0x11223344));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"cmp    rax,0x11223344\n"
		"cmp    rcx,0x11223344\n"
		"cmp    rdx,0x11223344\n"
		"cmp    rbx,0x11223344\n"
		"cmp    rsp,0x11223344\n"
		"cmp    rbp,0x11223344\n"
		"cmp    rsi,0x11223344\n"
		"cmp    rdi,0x11223344\n"
		"cmp    r8,0x11223344\n"
		"cmp    r9,0x11223344\n"
		"cmp    r10,0x11223344\n"
		"cmp    r11,0x11223344\n"
		"cmp    r12,0x11223344\n"
		"cmp    r13,0x11223344\n"
		"cmp    r14,0x11223344\n"
		"cmp    r15,0x11223344\n"
	);
	
	free(disassembly);
}
int
print_insn_sparc (bfd_vma memaddr, disassemble_info *info)
{
  FILE *stream = info->stream;
  bfd_byte buffer[4];
  unsigned long insn;
  sparc_opcode_hash *op;
  /* Nonzero of opcode table has been initialized.  */
  static int opcodes_initialized = 0;
  /* bfd mach number of last call.  */
  static unsigned long current_mach = 0;
  bfd_vma (*getword) (const void *);

  if (!opcodes_initialized
      || info->mach != current_mach)
    {
      int i;

      current_arch_mask = compute_arch_mask (info->mach);

      if (!opcodes_initialized)
	sorted_opcodes =
	  xmalloc (sparc_num_opcodes * sizeof (sparc_opcode *));
      /* Reset the sorted table so we can resort it.  */
      for (i = 0; i < sparc_num_opcodes; ++i)
	sorted_opcodes[i] = &sparc_opcodes[i];
      qsort ((char *) sorted_opcodes, sparc_num_opcodes,
	     sizeof (sorted_opcodes[0]), compare_opcodes);

      build_hash_table (sorted_opcodes, opcode_hash_table, sparc_num_opcodes);
      current_mach = info->mach;
      opcodes_initialized = 1;
    }

  {
    int status =
      (*info->read_memory_func) (memaddr, buffer, sizeof (buffer), info);

    if (status != 0)
      {
	(*info->memory_error_func) (status, memaddr, info);
	return -1;
      }
  }

  /* On SPARClite variants such as DANlite (sparc86x), instructions
     are always big-endian even when the machine is in little-endian mode.  */
  if (info->endian == BFD_ENDIAN_BIG || info->mach == bfd_mach_sparc_sparclite)
    getword = bfd_getb32;
  else
    getword = bfd_getl32;

  insn = getword (buffer);

  info->insn_info_valid = 1;			/* We do return this info.  */
  info->insn_type = dis_nonbranch;		/* Assume non branch insn.  */
  info->branch_delay_insns = 0;			/* Assume no delay.  */
  info->target = 0;				/* Assume no target known.  */

  for (op = opcode_hash_table[HASH_INSN (insn)]; op; op = op->next)
    {
      const sparc_opcode *opcode = op->opcode;

      /* If the insn isn't supported by the current architecture, skip it.  */
      if (! (opcode->architecture & current_arch_mask))
	continue;

      if ((opcode->match & insn) == opcode->match
	  && (opcode->lose & insn) == 0)
	{
	  /* Nonzero means that we have found an instruction which has
	     the effect of adding or or'ing the imm13 field to rs1.  */
	  int imm_added_to_rs1 = 0;
	  int imm_ored_to_rs1 = 0;

	  /* Nonzero means that we have found a plus sign in the args
	     field of the opcode table.  */
	  int found_plus = 0;

	  /* Nonzero means we have an annulled branch.  */
	  int is_annulled = 0;

	  /* Do we have an `add' or `or' instruction combining an
             immediate with rs1?  */
	  if (opcode->match == 0x80102000) /* or */
	    imm_ored_to_rs1 = 1;
	  if (opcode->match == 0x80002000) /* add */
	    imm_added_to_rs1 = 1;

	  if (X_RS1 (insn) != X_RD (insn)
	      && strchr (opcode->args, 'r') != 0)
	      /* Can't do simple format if source and dest are different.  */
	      continue;
	  if (X_RS2 (insn) != X_RD (insn)
	      && strchr (opcode->args, 'O') != 0)
	      /* Can't do simple format if source and dest are different.  */
	      continue;

	  (*info->fprintf_func) (stream, opcode->name);

	  {
	    const char *s;

	    if (opcode->args[0] != ',')
	      (*info->fprintf_func) (stream, " ");

	    for (s = opcode->args; *s != '\0'; ++s)
	      {
		while (*s == ',')
		  {
		    (*info->fprintf_func) (stream, ",");
		    ++s;
		    switch (*s)
		      {
		      case 'a':
			(*info->fprintf_func) (stream, "a");
			is_annulled = 1;
			++s;
			continue;
		      case 'N':
			(*info->fprintf_func) (stream, "pn");
			++s;
			continue;

		      case 'T':
			(*info->fprintf_func) (stream, "pt");
			++s;
			continue;

		      default:
			break;
		      }
		  }

		(*info->fprintf_func) (stream, " ");

		switch (*s)
		  {
		  case '+':
		    found_plus = 1;
		    /* Fall through.  */

		  default:
		    (*info->fprintf_func) (stream, "%c", *s);
		    break;

		  case '#':
		    (*info->fprintf_func) (stream, "0");
		    break;

#define	reg(n)	(*info->fprintf_func) (stream, "%%%s", reg_names[n])
		  case '1':
		  case 'r':
		    reg (X_RS1 (insn));
		    break;

		  case '2':
		  case 'O':
		    reg (X_RS2 (insn));
		    break;

		  case 'd':
		    reg (X_RD (insn));
		    break;
#undef	reg

#define	freg(n)		(*info->fprintf_func) (stream, "%%%s", freg_names[n])
#define	fregx(n)	(*info->fprintf_func) (stream, "%%%s", freg_names[((n) & ~1) | (((n) & 1) << 5)])
		  case 'e':
		    freg (X_RS1 (insn));
		    break;
		  case 'v':	/* Double/even.  */
		  case 'V':	/* Quad/multiple of 4.  */
		    fregx (X_RS1 (insn));
		    break;

		  case 'f':
		    freg (X_RS2 (insn));
		    break;
		  case 'B':	/* Double/even.  */
		  case 'R':	/* Quad/multiple of 4.  */
		    fregx (X_RS2 (insn));
		    break;

		  case 'g':
		    freg (X_RD (insn));
		    break;
		  case 'H':	/* Double/even.  */
		  case 'J':	/* Quad/multiple of 4.  */
		    fregx (X_RD (insn));
		    break;
#undef	freg
#undef	fregx

#define	creg(n)	(*info->fprintf_func) (stream, "%%c%u", (unsigned int) (n))
		  case 'b':
		    creg (X_RS1 (insn));
		    break;

		  case 'c':
		    creg (X_RS2 (insn));
		    break;

		  case 'D':
		    creg (X_RD (insn));
		    break;
#undef	creg

		  case 'h':
		    (*info->fprintf_func) (stream, "%%hi(%#x)",
					   ((unsigned) 0xFFFFFFFF
					    & ((int) X_IMM22 (insn) << 10)));
		    break;

		  case 'i':	/* 13 bit immediate.  */
		  case 'I':	/* 11 bit immediate.  */
		  case 'j':	/* 10 bit immediate.  */
		    {
		      int imm;

		      if (*s == 'i')
		        imm = X_SIMM (insn, 13);
		      else if (*s == 'I')
			imm = X_SIMM (insn, 11);
		      else
			imm = X_SIMM (insn, 10);

		      /* Check to see whether we have a 1+i, and take
			 note of that fact.

			 Note: because of the way we sort the table,
			 we will be matching 1+i rather than i+1,
			 so it is OK to assume that i is after +,
			 not before it.  */
		      if (found_plus)
			imm_added_to_rs1 = 1;

		      if (imm <= 9)
			(*info->fprintf_func) (stream, "%d", imm);
		      else
			(*info->fprintf_func) (stream, "%#x", imm);
		    }
		    break;

		  case 'X':	/* 5 bit unsigned immediate.  */
		  case 'Y':	/* 6 bit unsigned immediate.  */
		    {
		      int imm = X_IMM (insn, *s == 'X' ? 5 : 6);

		      if (imm <= 9)
			(info->fprintf_func) (stream, "%d", imm);
		      else
			(info->fprintf_func) (stream, "%#x", (unsigned) imm);
		    }
		    break;

		  case '3':
		    (info->fprintf_func) (stream, "%ld", X_IMM (insn, 3));
		    break;

		  case 'K':
		    {
		      int mask = X_MEMBAR (insn);
		      int bit = 0x40, printed_one = 0;
		      const char *name;

		      if (mask == 0)
			(info->fprintf_func) (stream, "0");
		      else
			while (bit)
			  {
			    if (mask & bit)
			      {
				if (printed_one)
				  (info->fprintf_func) (stream, "|");
				name = sparc_decode_membar (bit);
				(info->fprintf_func) (stream, "%s", name);
				printed_one = 1;
			      }
			    bit >>= 1;
			  }
		      break;
		    }

		  case 'k':
		    info->target = memaddr + SEX (X_DISP16 (insn), 16) * 4;
		    (*info->print_address_func) (info->target, info);
		    break;

		  case 'G':
		    info->target = memaddr + SEX (X_DISP19 (insn), 19) * 4;
		    (*info->print_address_func) (info->target, info);
		    break;

		  case '6':
		  case '7':
		  case '8':
		  case '9':
		    (*info->fprintf_func) (stream, "%%fcc%c", *s - '6' + '0');
		    break;

		  case 'z':
		    (*info->fprintf_func) (stream, "%%icc");
		    break;

		  case 'Z':
		    (*info->fprintf_func) (stream, "%%xcc");
		    break;

		  case 'E':
		    (*info->fprintf_func) (stream, "%%ccr");
		    break;

		  case 's':
		    (*info->fprintf_func) (stream, "%%fprs");
		    break;

		  case 'o':
		    (*info->fprintf_func) (stream, "%%asi");
		    break;

		  case 'W':
		    (*info->fprintf_func) (stream, "%%tick");
		    break;

		  case 'P':
		    (*info->fprintf_func) (stream, "%%pc");
		    break;

		  case '?':
		    if (X_RS1 (insn) == 31)
		      (*info->fprintf_func) (stream, "%%ver");
		    else if ((unsigned) X_RS1 (insn) < 17)
		      (*info->fprintf_func) (stream, "%%%s",
					     v9_priv_reg_names[X_RS1 (insn)]);
		    else
		      (*info->fprintf_func) (stream, "%%reserved");
		    break;

		  case '!':
		    if ((unsigned) X_RD (insn) < 17)
		      (*info->fprintf_func) (stream, "%%%s",
					     v9_priv_reg_names[X_RD (insn)]);
		    else
		      (*info->fprintf_func) (stream, "%%reserved");
		    break;

		  case '$':
		    if ((unsigned) X_RS1 (insn) < 32)
		      (*info->fprintf_func) (stream, "%%%s",
					     v9_hpriv_reg_names[X_RS1 (insn)]);
		    else
		      (*info->fprintf_func) (stream, "%%reserved");
		    break;

		  case '%':
		    if ((unsigned) X_RD (insn) < 32)
		      (*info->fprintf_func) (stream, "%%%s",
					     v9_hpriv_reg_names[X_RD (insn)]);
		    else
		      (*info->fprintf_func) (stream, "%%reserved");
		    break;

		  case '/':
		    if (X_RS1 (insn) < 16 || X_RS1 (insn) > 25)
		      (*info->fprintf_func) (stream, "%%reserved");
		    else
		      (*info->fprintf_func) (stream, "%%%s",
					     v9a_asr_reg_names[X_RS1 (insn)-16]);
		    break;

		  case '_':
		    if (X_RD (insn) < 16 || X_RD (insn) > 25)
		      (*info->fprintf_func) (stream, "%%reserved");
		    else
		      (*info->fprintf_func) (stream, "%%%s",
					     v9a_asr_reg_names[X_RD (insn)-16]);
		    break;

		  case '*':
		    {
		      const char *name = sparc_decode_prefetch (X_RD (insn));

		      if (name)
			(*info->fprintf_func) (stream, "%s", name);
		      else
			(*info->fprintf_func) (stream, "%ld", X_RD (insn));
		      break;
		    }

		  case 'M':
		    (*info->fprintf_func) (stream, "%%asr%ld", X_RS1 (insn));
		    break;

		  case 'm':
		    (*info->fprintf_func) (stream, "%%asr%ld", X_RD (insn));
		    break;

		  case 'L':
		    info->target = memaddr + SEX (X_DISP30 (insn), 30) * 4;
		    (*info->print_address_func) (info->target, info);
		    break;

		  case 'n':
		    (*info->fprintf_func)
		      (stream, "%#x", SEX (X_DISP22 (insn), 22));
		    break;

		  case 'l':
		    info->target = memaddr + SEX (X_DISP22 (insn), 22) * 4;
		    (*info->print_address_func) (info->target, info);
		    break;

		  case 'A':
		    {
		      const char *name = sparc_decode_asi (X_ASI (insn));

		      if (name)
			(*info->fprintf_func) (stream, "%s", name);
		      else
			(*info->fprintf_func) (stream, "(%ld)", X_ASI (insn));
		      break;
		    }

		  case 'C':
		    (*info->fprintf_func) (stream, "%%csr");
		    break;

		  case 'F':
		    (*info->fprintf_func) (stream, "%%fsr");
		    break;

		  case 'p':
		    (*info->fprintf_func) (stream, "%%psr");
		    break;

		  case 'q':
		    (*info->fprintf_func) (stream, "%%fq");
		    break;

		  case 'Q':
		    (*info->fprintf_func) (stream, "%%cq");
		    break;

		  case 't':
		    (*info->fprintf_func) (stream, "%%tbr");
		    break;

		  case 'w':
		    (*info->fprintf_func) (stream, "%%wim");
		    break;

		  case 'x':
		    (*info->fprintf_func) (stream, "%ld",
					   ((X_LDST_I (insn) << 8)
					    + X_ASI (insn)));
		    break;

		  case 'y':
		    (*info->fprintf_func) (stream, "%%y");
		    break;

		  case 'u':
		  case 'U':
		    {
		      int val = *s == 'U' ? X_RS1 (insn) : X_RD (insn);
		      const char *name = sparc_decode_sparclet_cpreg (val);

		      if (name)
			(*info->fprintf_func) (stream, "%s", name);
		      else
			(*info->fprintf_func) (stream, "%%cpreg(%d)", val);
		      break;
		    }
		  }
	      }
	  }

	  /* If we are adding or or'ing something to rs1, then
	     check to see whether the previous instruction was
	     a sethi to the same register as in the sethi.
	     If so, attempt to print the result of the add or
	     or (in this context add and or do the same thing)
	     and its symbolic value.  */
	  if (imm_ored_to_rs1 || imm_added_to_rs1)
	    {
	      unsigned long prev_insn;
	      int errcode;

	      if (memaddr >= 4)
		errcode =
		  (*info->read_memory_func)
		  (memaddr - 4, buffer, sizeof (buffer), info);
	      else
		errcode = 1;

	      prev_insn = getword (buffer);

	      if (errcode == 0)
		{
		  /* If it is a delayed branch, we need to look at the
		     instruction before the delayed branch.  This handles
		     sequences such as:

		     sethi %o1, %hi(_foo), %o1
		     call _printf
		     or %o1, %lo(_foo), %o1  */

		  if (is_delayed_branch (prev_insn))
		    {
		      if (memaddr >= 8)
			errcode = (*info->read_memory_func)
			  (memaddr - 8, buffer, sizeof (buffer), info);
		      else
			errcode = 1;

		      prev_insn = getword (buffer);
		    }
		}

	      /* If there was a problem reading memory, then assume
		 the previous instruction was not sethi.  */
	      if (errcode == 0)
		{
		  /* Is it sethi to the same register?  */
		  if ((prev_insn & 0xc1c00000) == 0x01000000
		      && X_RD (prev_insn) == X_RS1 (insn))
		    {
		      (*info->fprintf_func) (stream, "\t! ");
		      info->target =
			((unsigned) 0xFFFFFFFF
			 & ((int) X_IMM22 (prev_insn) << 10));
		      if (imm_added_to_rs1)
			info->target += X_SIMM (insn, 13);
		      else
			info->target |= X_SIMM (insn, 13);
		      (*info->print_address_func) (info->target, info);
		      info->insn_type = dis_dref;
		      info->data_size = 4;  /* FIXME!!! */
		    }
		}
	    }

	  if (opcode->flags & (F_UNBR|F_CONDBR|F_JSR))
	    {
		/* FIXME -- check is_annulled flag.  */
	      if (opcode->flags & F_UNBR)
		info->insn_type = dis_branch;
	      if (opcode->flags & F_CONDBR)
		info->insn_type = dis_condbranch;
	      if (opcode->flags & F_JSR)
		info->insn_type = dis_jsr;
	      if (opcode->flags & F_DELAYED)
		info->branch_delay_insns = 1;
	    }

	  return sizeof (buffer);
	}
    }
示例#11
0
void test_arithmetic_instructions() {
	asm_p as = &(asm_t){ 0 };
	char* disassembly = NULL;
	as_new(as);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_add(as, reg(i), reg(i));
		for(size_t i = 0; i < 16; i++)
			as_add(as, reg(i), imm(0x7abbccdd));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"add    rax,rax\n"
		"add    rcx,rcx\n"
		"add    rdx,rdx\n"
		"add    rbx,rbx\n"
		"add    rsp,rsp\n"
		"add    rbp,rbp\n"
		"add    rsi,rsi\n"
		"add    rdi,rdi\n"
		"add    r8,r8\n"
		"add    r9,r9\n"
		"add    r10,r10\n"
		"add    r11,r11\n"
		"add    r12,r12\n"
		"add    r13,r13\n"
		"add    r14,r14\n"
		"add    r15,r15\n"
		"add    rax,0x7abbccdd\n"
		"add    rcx,0x7abbccdd\n"
		"add    rdx,0x7abbccdd\n"
		"add    rbx,0x7abbccdd\n"
		"add    rsp,0x7abbccdd\n"
		"add    rbp,0x7abbccdd\n"
		"add    rsi,0x7abbccdd\n"
		"add    rdi,0x7abbccdd\n"
		"add    r8,0x7abbccdd\n"
		"add    r9,0x7abbccdd\n"
		"add    r10,0x7abbccdd\n"
		"add    r11,0x7abbccdd\n"
		"add    r12,0x7abbccdd\n"
		"add    r13,0x7abbccdd\n"
		"add    r14,0x7abbccdd\n"
		"add    r15,0x7abbccdd\n"
	);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_sub(as, reg(i), reg(i));
		for(size_t i = 0; i < 16; i++)
			as_sub(as, reg(i), imm(0x7abbccdd));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"sub    rax,rax\n"
		"sub    rcx,rcx\n"
		"sub    rdx,rdx\n"
		"sub    rbx,rbx\n"
		"sub    rsp,rsp\n"
		"sub    rbp,rbp\n"
		"sub    rsi,rsi\n"
		"sub    rdi,rdi\n"
		"sub    r8,r8\n"
		"sub    r9,r9\n"
		"sub    r10,r10\n"
		"sub    r11,r11\n"
		"sub    r12,r12\n"
		"sub    r13,r13\n"
		"sub    r14,r14\n"
		"sub    r15,r15\n"
		"sub    rax,0x7abbccdd\n"
		"sub    rcx,0x7abbccdd\n"
		"sub    rdx,0x7abbccdd\n"
		"sub    rbx,0x7abbccdd\n"
		"sub    rsp,0x7abbccdd\n"
		"sub    rbp,0x7abbccdd\n"
		"sub    rsi,0x7abbccdd\n"
		"sub    rdi,0x7abbccdd\n"
		"sub    r8,0x7abbccdd\n"
		"sub    r9,0x7abbccdd\n"
		"sub    r10,0x7abbccdd\n"
		"sub    r11,0x7abbccdd\n"
		"sub    r12,0x7abbccdd\n"
		"sub    r13,0x7abbccdd\n"
		"sub    r14,0x7abbccdd\n"
		"sub    r15,0x7abbccdd\n"
	);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_mul(as, reg(i));
		for(size_t i = 0; i < 16; i++)
			as_mul(as, memrd(reg(i), 0xbeba));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"mul    rax\n"
		"mul    rcx\n"
		"mul    rdx\n"
		"mul    rbx\n"
		"mul    rsp\n"
		"mul    rbp\n"
		"mul    rsi\n"
		"mul    rdi\n"
		"mul    r8\n"
		"mul    r9\n"
		"mul    r10\n"
		"mul    r11\n"
		"mul    r12\n"
		"mul    r13\n"
		"mul    r14\n"
		"mul    r15\n"
		"mul    QWORD PTR [rax+0xbeba]\n"
		"mul    QWORD PTR [rcx+0xbeba]\n"
		"mul    QWORD PTR [rdx+0xbeba]\n"
		"mul    QWORD PTR [rbx+0xbeba]\n"
		"mul    QWORD PTR [rsp+0xbeba]\n"
		"mul    QWORD PTR [rbp+0xbeba]\n"
		"mul    QWORD PTR [rsi+0xbeba]\n"
		"mul    QWORD PTR [rdi+0xbeba]\n"
		"mul    QWORD PTR [r8+0xbeba]\n"
		"mul    QWORD PTR [r9+0xbeba]\n"
		"mul    QWORD PTR [r10+0xbeba]\n"
		"mul    QWORD PTR [r11+0xbeba]\n"
		"mul    QWORD PTR [r12+0xbeba]\n"
		"mul    QWORD PTR [r13+0xbeba]\n"
		"mul    QWORD PTR [r14+0xbeba]\n"
		"mul    QWORD PTR [r15+0xbeba]\n"
	);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_div(as, reg(i));
		for(size_t i = 0; i < 16; i++)
			as_div(as, memrd(reg(i), 0xbeba));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"div    rax\n"
		"div    rcx\n"
		"div    rdx\n"
		"div    rbx\n"
		"div    rsp\n"
		"div    rbp\n"
		"div    rsi\n"
		"div    rdi\n"
		"div    r8\n"
		"div    r9\n"
		"div    r10\n"
		"div    r11\n"
		"div    r12\n"
		"div    r13\n"
		"div    r14\n"
		"div    r15\n"
		"div    QWORD PTR [rax+0xbeba]\n"
		"div    QWORD PTR [rcx+0xbeba]\n"
		"div    QWORD PTR [rdx+0xbeba]\n"
		"div    QWORD PTR [rbx+0xbeba]\n"
		"div    QWORD PTR [rsp+0xbeba]\n"
		"div    QWORD PTR [rbp+0xbeba]\n"
		"div    QWORD PTR [rsi+0xbeba]\n"
		"div    QWORD PTR [rdi+0xbeba]\n"
		"div    QWORD PTR [r8+0xbeba]\n"
		"div    QWORD PTR [r9+0xbeba]\n"
		"div    QWORD PTR [r10+0xbeba]\n"
		"div    QWORD PTR [r11+0xbeba]\n"
		"div    QWORD PTR [r12+0xbeba]\n"
		"div    QWORD PTR [r13+0xbeba]\n"
		"div    QWORD PTR [r14+0xbeba]\n"
		"div    QWORD PTR [r15+0xbeba]\n"
	);
	
	free(disassembly);
}
示例#12
0
void UFindReplaceTextDialog::find(bool next)
{
    if(!textEdit)
        return;

    // backward search
    bool up = !next;

    const QString toSearch = lineEditFindText->text();

    bool result = false;

    QTextDocument::FindFlags flags;

    bool caseSensitive      = checkBoxCaseSensitive->isChecked();
    bool wholeWords         = checkBoxWholeWords->isChecked();
    bool regularExpressions = checkBoxRegExp->isChecked();

    if(up)
        flags |= QTextDocument::FindBackward;

    if(caseSensitive)
        flags |= QTextDocument::FindCaseSensitively;

    if(wholeWords)
        flags |= QTextDocument::FindWholeWords;

    QTextCursor _textCursor = textEdit->textCursor();

    if(regularExpressions)
    {
        QRegExp reg(toSearch,
                    caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);

        _textCursor = textEdit->document()->find(reg, _textCursor, flags);
        result = !_textCursor.isNull();

    }else
        result = textEdit->find(toSearch, flags);

    if(result)
        showError("");

    else
    {
        showError(strNoMatchFound);

        // move to the beginning of the document for the next find
        _textCursor.setPosition(0);
        textEdit->setTextCursor(_textCursor);
    }

    if(!regularExpressions)
        _textCursor = textEdit->textCursor();

    textCursor = _textCursor;

    _textCursor.clearSelection();
    textEdit->setTextCursor(_textCursor);

    if(textCursor.hasSelection())
    {
        QTextEdit::ExtraSelection selection;
        QTextCharFormat format;
        format.setBackground(colorSelection);
        selection.format = format;
        selection.cursor = textCursor;
        textEdit->setExtraSelections(QList <QTextEdit::ExtraSelection>()
                                     << selection);
    }
}
void QGenieSmartnetworkThread::doCmdAttachDevice(const QStringList &reqlist, QStringList &retlist)
{
    retlist.clear();
    if(reqlist.count()<1)
    {
        retlist<<"-1"<<"lack parameter";
        return;
    }
    QMap<QString,QString> paras;
    int iret;
    QString sret;

    const QDomNode &node=doFunc(reqlist[0]
                                ,"DeviceInfo"
                               ,"GetAttachDevice"
                                ,&iret,&sret
                                ,paras);
    if(iret!=0)
    {
        retlist<<QString::number(iret)<<sret;
        return;
    }

    QDomElement elem=node.firstChild().toElement();
    retlist<<elem.attribute("_responseCode");
    QString stemp=elem.attribute("NewAttachDevice");

    if(stemp.isEmpty())
    {
        retlist<<"0"<<"0";
    }
    else
    {
        //[email protected];192.168.1.2;geines-Mac-mini;28:37:37:12:09:2F;wireless;54;86;[email protected];192.168.1.6;xgywz-PC;00:1D:0F:33:08:1C;wireless;54;87;[email protected];192.168.1.10;Android_359836041571187;A8:26:D9:CB:2E:A4;wireless;54;79;[email protected];192.168.1.11;Android_357710047293728;64:A7:69:3F:E6:E9;wireless;54;67;[email protected];192.168.1.14;android_8eb092bb95e89cf;C8:AA:21:80:A8:F1;wireless;54;87;[email protected];192.168.1.15;--;28:37:37:12:C6:9D;wireless;54;86;[email protected];192.168.1.29;PC2011110909BPO;14:E6:E4:06:F8:E8;wireless;54;92;Allow
        QRegExp reg("@\\d+;");
        QStringList slist=stemp.split(reg);
        qDebug()<<slist;

        int c=slist.count();
        if(c<1)
        {
            retlist<<"0"<<"0";
        }
        else
        {
            retlist<<"0";
            for(int i=0;i<c;i++)
            {
                QStringList ssublist=slist[i].split(";");
                int cc=ssublist.count();

                for(int j=0;j<cc;j++)
                {
                    retlist<<ssublist[j];
                }
                if(1==i)
                {
                    retlist.insert(2,QString::number(cc));
                }

            }
        }
    }

}
示例#14
0
void PreferencesNetwork::syncSettings()
{
	auto cloud = qPrefCloudStorage::instance();
	auto proxy = qPrefProxy::instance();

	proxy->set_proxy_type(ui->proxyType->itemData(ui->proxyType->currentIndex()).toInt());
	proxy->set_proxy_host(ui->proxyHost->text());
	proxy->set_proxy_port(ui->proxyPort->value());
	proxy->set_proxy_auth(ui->proxyAuthRequired->isChecked());
	proxy->set_proxy_user(ui->proxyUsername->text());
	proxy->set_proxy_pass(ui->proxyPassword->text());

	QString email = ui->cloud_storage_email->text();
	QString password = ui->cloud_storage_password->text();
	QString newpassword = ui->cloud_storage_new_passwd->text();

	//TODO: Change this to the Cloud Storage Stuff, not preferences.
	if (prefs.cloud_verification_status == qPref::CS_VERIFIED && !newpassword.isEmpty()) {
		// deal with password change
		if (!email.isEmpty() && !password.isEmpty()) {
			// connect to backend server to check / create credentials
			QRegularExpression reg("^[[email protected]+_-]+$");
			if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) {
				report_error(qPrintable(tr("Change ignored. Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
				return;
			}
			if (!reg.match(email).hasMatch() || (!newpassword.isEmpty() && !reg.match(newpassword).hasMatch())) {
				report_error(qPrintable(tr("Change ignored. Cloud storage email and new password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
				ui->cloud_storage_new_passwd->setText("");
				return;
			}
			CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
			connect(cloudAuth, &CloudStorageAuthenticate::finishedAuthenticate, this, &PreferencesNetwork::updateCloudAuthenticationState);
			connect(cloudAuth, &CloudStorageAuthenticate::passwordChangeSuccessful, this, &PreferencesNetwork::passwordUpdateSuccessful);
			cloudAuth->backend(email, password, "", newpassword);
			ui->cloud_storage_new_passwd->setText("");
		}
	} else if (prefs.cloud_verification_status == qPref::CS_UNKNOWN ||
		   prefs.cloud_verification_status == qPref::CS_INCORRECT_USER_PASSWD ||
		   email != prefs.cloud_storage_email ||
		   password != prefs.cloud_storage_password) {

		// different credentials - reset verification status
		int oldVerificationStatus = cloud->cloud_verification_status();
		cloud->set_cloud_verification_status(qPref::CS_UNKNOWN);
		if (!email.isEmpty() && !password.isEmpty()) {
			// connect to backend server to check / create credentials
			QRegularExpression reg("^[[email protected]+_-]+$");
			if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) {
				report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
				cloud->set_cloud_verification_status(oldVerificationStatus);
				return;
			}
			CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
			connect(cloudAuth, &CloudStorageAuthenticate::finishedAuthenticate, this, &PreferencesNetwork::updateCloudAuthenticationState);
			cloudAuth->backend(email, password);
		}
	} else if (prefs.cloud_verification_status == qPref::CS_NEED_TO_VERIFY) {
		QString pin = ui->cloud_storage_pin->text();
		if (!pin.isEmpty()) {
			// connect to backend server to check / create credentials
			QRegularExpression reg("^[[email protected]+_-]+$");
			if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) {
				report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
				return;
			}
			CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
			connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(updateCloudAuthenticationState()));
			cloudAuth->backend(email, password, pin);
		}
	}
	cloud->set_cloud_storage_email(email);
	cloud->set_save_password_local(ui->save_password_local->isChecked());
	cloud->set_cloud_storage_password(password);
	cloud->set_cloud_verification_status(prefs.cloud_verification_status);
	cloud->set_cloud_base_url(prefs.cloud_base_url);
}
示例#15
0
文件: uart.c 项目: crazy2be/cs452
void uart_disable_modem_irq(int channel) {
#ifndef QEMU
	volatile int *ctrl = reg(channel, UART_CTLR_OFFSET);
	*ctrl &= ~MSIEN_MASK;
#endif
}
示例#16
0
void test_stack_instructions() {
	asm_p as = &(asm_t){ 0 };
	char* disassembly = NULL;
	as_new(as);
	
	as_clear(as);
		as_push(as, imm(0x11223344));
		for(size_t i = 0; i < 16; i++)
			as_push(as, reg(i));
		for(size_t i = 0; i < 16; i++)
			as_push(as, memrd(reg(i), 0xbeba));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"push   0x11223344\n"
		"push   rax\n"
		"push   rcx\n"
		"push   rdx\n"
		"push   rbx\n"
		"push   rsp\n"
		"push   rbp\n"
		"push   rsi\n"
		"push   rdi\n"
		"push   r8\n"
		"push   r9\n"
		"push   r10\n"
		"push   r11\n"
		"push   r12\n"
		"push   r13\n"
		"push   r14\n"
		"push   r15\n"
		"push   QWORD PTR [rax+0xbeba]\n"
		"push   QWORD PTR [rcx+0xbeba]\n"
		"push   QWORD PTR [rdx+0xbeba]\n"
		"push   QWORD PTR [rbx+0xbeba]\n"
		"push   QWORD PTR [rsp+0xbeba]\n"
		"push   QWORD PTR [rbp+0xbeba]\n"
		"push   QWORD PTR [rsi+0xbeba]\n"
		"push   QWORD PTR [rdi+0xbeba]\n"
		"push   QWORD PTR [r8+0xbeba]\n"
		"push   QWORD PTR [r9+0xbeba]\n"
		"push   QWORD PTR [r10+0xbeba]\n"
		"push   QWORD PTR [r11+0xbeba]\n"
		"push   QWORD PTR [r12+0xbeba]\n"
		"push   QWORD PTR [r13+0xbeba]\n"
		"push   QWORD PTR [r14+0xbeba]\n"
		"push   QWORD PTR [r15+0xbeba]\n"
	);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_pop(as, reg(i));
		for(size_t i = 0; i < 16; i++)
			as_pop(as, memrd(reg(i), 0xbeba));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"pop    rax\n"
		"pop    rcx\n"
		"pop    rdx\n"
		"pop    rbx\n"
		"pop    rsp\n"
		"pop    rbp\n"
		"pop    rsi\n"
		"pop    rdi\n"
		"pop    r8\n"
		"pop    r9\n"
		"pop    r10\n"
		"pop    r11\n"
		"pop    r12\n"
		"pop    r13\n"
		"pop    r14\n"
		"pop    r15\n"
		"pop    QWORD PTR [rax+0xbeba]\n"
		"pop    QWORD PTR [rcx+0xbeba]\n"
		"pop    QWORD PTR [rdx+0xbeba]\n"
		"pop    QWORD PTR [rbx+0xbeba]\n"
		"pop    QWORD PTR [rsp+0xbeba]\n"
		"pop    QWORD PTR [rbp+0xbeba]\n"
		"pop    QWORD PTR [rsi+0xbeba]\n"
		"pop    QWORD PTR [rdi+0xbeba]\n"
		"pop    QWORD PTR [r8+0xbeba]\n"
		"pop    QWORD PTR [r9+0xbeba]\n"
		"pop    QWORD PTR [r10+0xbeba]\n"
		"pop    QWORD PTR [r11+0xbeba]\n"
		"pop    QWORD PTR [r12+0xbeba]\n"
		"pop    QWORD PTR [r13+0xbeba]\n"
		"pop    QWORD PTR [r14+0xbeba]\n"
		"pop    QWORD PTR [r15+0xbeba]\n"
	);
	
	free(disassembly);
}
示例#17
0
文件: uart.c 项目: crazy2be/cs452
void uart_restore_modem_irq(int channel) {
#ifndef QEMU
	volatile int *ctrl = reg(channel, UART_CTLR_OFFSET);
	*ctrl |= MSIEN_MASK;
#endif
}
示例#18
0
void test_byte_registers() {
	asm_p as = &(asm_t){ 0 };
	char* disassembly = NULL;
	as_new(as);
	
	// reg reg
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_mov(as, regb(i), regb(i));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"mov    al,al\n"
		"mov    cl,cl\n"
		"mov    dl,dl\n"
		"mov    bl,bl\n"
		"mov    spl,spl\n"
		"mov    bpl,bpl\n"
		"mov    sil,sil\n"
		"mov    dil,dil\n"
		"mov    r8b,r8b\n"
		"mov    r9b,r9b\n"
		"mov    r10b,r10b\n"
		"mov    r11b,r11b\n"
		"mov    r12b,r12b\n"
		"mov    r13b,r13b\n"
		"mov    r14b,r14b\n"
		"mov    r15b,r15b\n"
	);
	
	
	// reg [RIP + displ]
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_mov(as, regb(i), reldb(0x7abbccdd));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"mov    al,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcce4\n"
		"mov    cl,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcceb\n"
		"mov    dl,BYTE PTR [rip+0x7abbccdd]        # 0x7afbccf2\n"
		"mov    bl,BYTE PTR [rip+0x7abbccdd]        # 0x7afbccf9\n"
		"mov    spl,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd00\n"
		"mov    bpl,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd07\n"
		"mov    sil,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd0e\n"
		"mov    dil,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd15\n"
		"mov    r8b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd1c\n"
		"mov    r9b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd23\n"
		"mov    r10b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd2a\n"
		"mov    r11b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd31\n"
		"mov    r12b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd38\n"
		"mov    r13b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd3f\n"
		"mov    r14b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd46\n"
		"mov    r15b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd4d\n"
	);
	
	// reg [displ]
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_mov(as, regb(i), memdb(0x7abbccdd));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"mov    al,BYTE PTR ds:0x7abbccdd\n"
		"mov    cl,BYTE PTR ds:0x7abbccdd\n"
		"mov    dl,BYTE PTR ds:0x7abbccdd\n"
		"mov    bl,BYTE PTR ds:0x7abbccdd\n"
		"mov    spl,BYTE PTR ds:0x7abbccdd\n"
		"mov    bpl,BYTE PTR ds:0x7abbccdd\n"
		"mov    sil,BYTE PTR ds:0x7abbccdd\n"
		"mov    dil,BYTE PTR ds:0x7abbccdd\n"
		"mov    r8b,BYTE PTR ds:0x7abbccdd\n"
		"mov    r9b,BYTE PTR ds:0x7abbccdd\n"
		"mov    r10b,BYTE PTR ds:0x7abbccdd\n"
		"mov    r11b,BYTE PTR ds:0x7abbccdd\n"
		"mov    r12b,BYTE PTR ds:0x7abbccdd\n"
		"mov    r13b,BYTE PTR ds:0x7abbccdd\n"
		"mov    r14b,BYTE PTR ds:0x7abbccdd\n"
		"mov    r15b,BYTE PTR ds:0x7abbccdd\n"
	);
	
	// reg [reg + displ]
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_mov(as, regb(i), memrdb(reg(i), 0x7abbccdd));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"mov    al,BYTE PTR [rax+0x7abbccdd]\n"
		"mov    cl,BYTE PTR [rcx+0x7abbccdd]\n"
		"mov    dl,BYTE PTR [rdx+0x7abbccdd]\n"
		"mov    bl,BYTE PTR [rbx+0x7abbccdd]\n"
		"mov    spl,BYTE PTR [rsp+0x7abbccdd]\n"
		"mov    bpl,BYTE PTR [rbp+0x7abbccdd]\n"
		"mov    sil,BYTE PTR [rsi+0x7abbccdd]\n"
		"mov    dil,BYTE PTR [rdi+0x7abbccdd]\n"
		"mov    r8b,BYTE PTR [r8+0x7abbccdd]\n"
		"mov    r9b,BYTE PTR [r9+0x7abbccdd]\n"
		"mov    r10b,BYTE PTR [r10+0x7abbccdd]\n"
		"mov    r11b,BYTE PTR [r11+0x7abbccdd]\n"
		"mov    r12b,BYTE PTR [r12+0x7abbccdd]\n"
		"mov    r13b,BYTE PTR [r13+0x7abbccdd]\n"
		"mov    r14b,BYTE PTR [r14+0x7abbccdd]\n"
		"mov    r15b,BYTE PTR [r15+0x7abbccdd]\n"
	);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_mul(as, regb(i));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"mul    al\n"
		"mul    cl\n"
		"mul    dl\n"
		"mul    bl\n"
		"mul    spl\n"
		"mul    bpl\n"
		"mul    sil\n"
		"mul    dil\n"
		"mul    r8b\n"
		"mul    r9b\n"
		"mul    r10b\n"
		"mul    r11b\n"
		"mul    r12b\n"
		"mul    r13b\n"
		"mul    r14b\n"
		"mul    r15b\n"
	);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_cmp(as, regb(i), regb(i));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"cmp    al,al\n"
		"cmp    cl,cl\n"
		"cmp    dl,dl\n"
		"cmp    bl,bl\n"
		"cmp    spl,spl\n"
		"cmp    bpl,bpl\n"
		"cmp    sil,sil\n"
		"cmp    dil,dil\n"
		"cmp    r8b,r8b\n"
		"cmp    r9b,r9b\n"
		"cmp    r10b,r10b\n"
		"cmp    r11b,r11b\n"
		"cmp    r12b,r12b\n"
		"cmp    r13b,r13b\n"
		"cmp    r14b,r14b\n"
		"cmp    r15b,r15b\n"
	);
	
	as_clear(as);
		for(size_t i = 0; i < 16; i++)
			as_cmp(as, regb(i), reldb(0x7abbccdd));
	disassembly = disassemble(as);
	st_check_str(disassembly,
		"cmp    al,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcce4\n"
		"cmp    cl,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcceb\n"
		"cmp    dl,BYTE PTR [rip+0x7abbccdd]        # 0x7afbccf2\n"
		"cmp    bl,BYTE PTR [rip+0x7abbccdd]        # 0x7afbccf9\n"
		"cmp    spl,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd00\n"
		"cmp    bpl,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd07\n"
		"cmp    sil,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd0e\n"
		"cmp    dil,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd15\n"
		"cmp    r8b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd1c\n"
		"cmp    r9b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd23\n"
		"cmp    r10b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd2a\n"
		"cmp    r11b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd31\n"
		"cmp    r12b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd38\n"
		"cmp    r13b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd3f\n"
		"cmp    r14b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd46\n"
		"cmp    r15b,BYTE PTR [rip+0x7abbccdd]        # 0x7afbcd4d\n"
	);
	
	free(disassembly);
}
示例#19
0
文件: uart.c 项目: crazy2be/cs452
int uart_irq_mask(int channel) {
	return *reg(channel, UART_INTR_OFFSET);
}
示例#20
0
文件: uart.c 项目: crazy2be/cs452
int uart_canreadfifo(int channel) {
	// receive fifo is not empty
	return !(*reg(channel, UART_FLAG_OFFSET) & RXFE_MASK);
}
示例#21
0
文件: uart.c 项目: crazy2be/cs452
void uart_clrerr(int channel) {
	*reg(channel, UART_RSR_OFFSET) = 0;
}
示例#22
0
文件: uart.c 项目: crazy2be/cs452
int uart_canwritefifo(int channel) {
	// transmit fifo is not full
	return !(*reg(channel, UART_FLAG_OFFSET) & TXFF_MASK);
}
示例#23
0
	//! Register a class with a name/a list of PIDs by storing a pointer to its constructor
	void NodeToolRegistrar::reg(const QString& name, const ProductIds& pid, const CreatorFunc func)
	{
		for (ProductIds::const_iterator it(pid.begin()); it != pid.end(); ++it)
			reg(name, *it, func);
	}
示例#24
0
文件: uart.c 项目: crazy2be/cs452
void uart_disable_irq(int channel, unsigned mask) {
	volatile int *ctrl = reg(channel, UART_CTLR_OFFSET);
	*ctrl &= ~mask;
}
示例#25
0
/*
 - regatom - the lowest level
 *
 * Optimization:  gobbles an entire sequence of ordinary characters so that
 * it can turn them into a single node, which is smaller to store and
 * faster to run.  Backslashed characters are exceptions, each becoming a
 * separate node; the code is simpler that way and it's not worth fixing.
 */
static char *
regatom(int *flagp)
{
	char *ret = NULL;
	int flags;

	*flagp = WORST;		/* Tentatively. */

	switch (*regparse++) {
	/* FIXME: these chars only have meaning at beg/end of pat? */
	case '^':
		ret = regnode(BOL);
		break;
	case '$':
		ret = regnode(EOL);
		break;
	case '.':
		ret = regnode(ANY);
		*flagp |= HASWIDTH|SIMPLE;
		break;
	case '[': {
			int class1;
			int classend;

			if (*regparse == '^') {	/* Complement of range. */
				ret = regnode(ANYBUT);
				regparse++;
			} else
				ret = regnode(ANYOF);
			if (*regparse == ']' || *regparse == '-')
				regc(*regparse++);
			while (*regparse != '\0' && *regparse != ']') {
				if (*regparse == '-') {
					regparse++;
					if (*regparse == ']' || *regparse == '\0')
						regc('-');
					else {
						class1 = UCHARAT(regparse-2)+1;
						classend = UCHARAT(regparse);
						if (class1 > classend+1)
							FAIL("invalid [] range");
						for (; class1 <= classend; class1++)
							regc(class1);
						regparse++;
					}
				} else
					regc(*regparse++);
			}
			regc('\0');
			if (*regparse != ']')
				FAIL("unmatched []");
			regparse++;
			*flagp |= HASWIDTH|SIMPLE;
		}
		break;
	case '(':
		ret = reg(1, &flags);
		if (ret == NULL)
			return(NULL);
		*flagp |= flags&(HASWIDTH|SPSTART);
		break;
	case '\0':
	case '|':
	case '\n':
	case ')':
		FAIL("internal urp");	/* Supposed to be caught earlier. */
		break;
	case '?':
	case '+':
	case '*':
		FAIL("?+* follows nothing");
		break;
	case '\\':
		switch (*regparse++) {
		case '\0':
			FAIL("trailing \\");
			break;
		case '<':
			ret = regnode(WORDA);
			break;
		case '>':
			ret = regnode(WORDZ);
			break;
		/* FIXME: Someday handle \1, \2, ... */
		default:
			/* Handle general quoted chars in exact-match routine */
			goto de_fault;
		}
		break;
	de_fault:
	default:
		/*
		 * Encode a string of characters to be matched exactly.
		 *
		 * This is a bit tricky due to quoted chars and due to
		 * '*', '+', and '?' taking the SINGLE char previous
		 * as their operand.
		 *
		 * On entry, the char at regparse[-1] is going to go
		 * into the string, no matter what it is.  (It could be
		 * following a \ if we are entered from the '\' case.)
		 *
		 * Basic idea is to pick up a good char in  ch  and
		 * examine the next char.  If it's *+? then we twiddle.
		 * If it's \ then we frozzle.  If it's other magic char
		 * we push  ch  and terminate the string.  If none of the
		 * above, we push  ch  on the string and go around again.
		 *
		 *  regprev  is used to remember where "the current char"
		 * starts in the string, if due to a *+? we need to back
		 * up and put the current char in a separate, 1-char, string.
		 * When  regprev  is NULL,  ch  is the only char in the
		 * string; this is used in *+? handling, and in setting
		 * flags |= SIMPLE at the end.
		 */
		{
			const char *regprev;
			char ch = 0;

			regparse--;			/* Look at cur char */
			ret = regnode(EXACTLY);
			for ( regprev = 0 ; ; ) {
				ch = *regparse++;	/* Get current char */
				switch (*regparse) {	/* look at next one */

				default:
					regc(ch);	/* Add cur to string */
					break;

				case '.': case '[': case '(':
				case ')': case '|': case '\n':
				case '$': case '^':
				case '\0':
				/* FIXME, $ and ^ should not always be magic */
				magic:
					regc(ch);	/* dump cur char */
					goto done;	/* and we are done */

				case '?': case '+': case '*':
					if (!regprev) 	/* If just ch in str, */
						goto magic;	/* use it */
					/* End mult-char string one early */
					regparse = regprev; /* Back up parse */
					goto done;

				case '\\':
					regc(ch);	/* Cur char OK */
					switch (regparse[1]){ /* Look after \ */
					case '\0':
					case '<':
					case '>':
					/* FIXME: Someday handle \1, \2, ... */
						goto done; /* Not quoted */
					default:
						/* Backup point is \, scan							 * point is after it. */
						regprev = regparse;
						regparse++;
						continue;	/* NOT break; */
					}
				}
				regprev = regparse;	/* Set backup point */
			}
		done:
			regc('\0');
			*flagp |= HASWIDTH;
			if (!regprev)		/* One char? */
				*flagp |= SIMPLE;
		}
		break;
	}

	return(ret);
}
示例#26
0
文件: uart.c 项目: crazy2be/cs452
void uart_disable_tx_irq(int channel) {
	volatile int *ctrl = reg(channel, UART_CTLR_OFFSET);
	*ctrl &= ~TIEN_MASK;
}
示例#27
0
/*
 - regatom - the lowest level
 *
 * Optimization:  gobbles an entire sequence of ordinary characters so that
 * it can turn them into a single node, which is smaller to store and
 * faster to run.  Backslashed characters are exceptions, each becoming a
 * separate node; the code is simpler that way and it's not worth fixing.
 */
static int regatom(regex_t *preg, int *flagp)
{
	int ret;
	int flags;
	int nocase = (preg->cflags & REG_ICASE);

	int ch;
	int n = reg_utf8_tounicode_case(preg->regparse, &ch, nocase);

	*flagp = WORST;		/* Tentatively. */

	preg->regparse += n;
	switch (ch) {
	/* FIXME: these chars only have meaning at beg/end of pat? */
	case '^':
		ret = regnode(preg, BOL);
		break;
	case '$':
		ret = regnode(preg, EOL);
		break;
	case '.':
		ret = regnode(preg, ANY);
		*flagp |= HASWIDTH|SIMPLE;
		break;
	case '[': {
			const char *pattern = preg->regparse;

			if (*pattern == '^') {	/* Complement of range. */
				ret = regnode(preg, ANYBUT);
				pattern++;
			} else
				ret = regnode(preg, ANYOF);

			/* Special case. If the first char is ']' or '-', it is part of the set */
			if (*pattern == ']' || *pattern == '-') {
				reg_addrange(preg, *pattern, *pattern);
				pattern++;
			}

			while (*pattern && *pattern != ']') {
				/* Is this a range? a-z */
				int start;
				int end;

				pattern += reg_utf8_tounicode_case(pattern, &start, nocase);
				if (start == '\\') {
					pattern += reg_decode_escape(pattern, &start);
					if (start == 0) {
						preg->err = REG_ERR_NULL_CHAR;
						return 0;
					}
				}
				if (pattern[0] == '-' && pattern[1] && pattern[1] != ']') {
					/* skip '-' */
					pattern += utf8_tounicode(pattern, &end);
					pattern += reg_utf8_tounicode_case(pattern, &end, nocase);
					if (end == '\\') {
						pattern += reg_decode_escape(pattern, &end);
						if (end == 0) {
							preg->err = REG_ERR_NULL_CHAR;
							return 0;
						}
					}

					reg_addrange(preg, start, end);
					continue;
				}
				if (start == '[') {
					if (strncmp(pattern, ":alpha:]", 8) == 0) {
						if ((preg->cflags & REG_ICASE) == 0) {
							reg_addrange(preg, 'a', 'z');
						}
						reg_addrange(preg, 'A', 'Z');
						pattern += 8;
						continue;
					}
					if (strncmp(pattern, ":alnum:]", 8) == 0) {
						if ((preg->cflags & REG_ICASE) == 0) {
							reg_addrange(preg, 'a', 'z');
						}
						reg_addrange(preg, 'A', 'Z');
						reg_addrange(preg, '0', '9');
						pattern += 8;
						continue;
					}
					if (strncmp(pattern, ":space:]", 8) == 0) {
						reg_addrange_str(preg, " \t\r\n\f\v");
						pattern += 8;
						continue;
					}
				}
				/* Not a range, so just add the char */
				reg_addrange(preg, start, start);
			}
			regc(preg, '\0');

			if (*pattern) {
				pattern++;
			}
			preg->regparse = pattern;

			*flagp |= HASWIDTH|SIMPLE;
		}
		break;
	case '(':
		ret = reg(preg, 1, &flags);
		if (ret == 0)
			return 0;
		*flagp |= flags&(HASWIDTH|SPSTART);
		break;
	case '\0':
	case '|':
	case ')':
		preg->err = REG_ERR_INTERNAL;
		return 0;	/* Supposed to be caught earlier. */
	case '?':
	case '+':
	case '*':
	case '{':
		preg->err = REG_ERR_COUNT_FOLLOWS_NOTHING;
		return 0;
	case '\\':
		switch (*preg->regparse++) {
		case '\0':
			preg->err = REG_ERR_TRAILING_BACKSLASH;
			return 0;
		case '<':
		case 'm':
			ret = regnode(preg, WORDA);
			break;
		case '>':
		case 'M':
			ret = regnode(preg, WORDZ);
			break;
		case 'd':
			ret = regnode(preg, ANYOF);
			reg_addrange(preg, '0', '9');
			regc(preg, '\0');
			*flagp |= HASWIDTH|SIMPLE;
			break;
		case 'w':
			ret = regnode(preg, ANYOF);
			if ((preg->cflags & REG_ICASE) == 0) {
				reg_addrange(preg, 'a', 'z');
			}
			reg_addrange(preg, 'A', 'Z');
			reg_addrange(preg, '0', '9');
			reg_addrange(preg, '_', '_');
			regc(preg, '\0');
			*flagp |= HASWIDTH|SIMPLE;
			break;
		case 's':
			ret = regnode(preg, ANYOF);
			reg_addrange_str(preg," \t\r\n\f\v");
			regc(preg, '\0');
			*flagp |= HASWIDTH|SIMPLE;
			break;
		/* FIXME: Someday handle \1, \2, ... */
		default:
			/* Handle general quoted chars in exact-match routine */
			/* Back up to include the backslash */
			preg->regparse--;
			goto de_fault;
		}
		break;
	de_fault:
	default: {
			/*
			 * Encode a string of characters to be matched exactly.
			 */
			int added = 0;

			/* Back up to pick up the first char of interest */
			preg->regparse -= n;

			ret = regnode(preg, EXACTLY);

			/* Note that a META operator such as ? or * consumes the
			 * preceding char.
			 * Thus we must be careful to look ahead by 2 and add the
			 * last char as it's own EXACTLY if necessary
			 */

			/* Until end of string or a META char is reached */
			while (*preg->regparse && strchr(META, *preg->regparse) == NULL) {
				n = reg_utf8_tounicode_case(preg->regparse, &ch, (preg->cflags & REG_ICASE));
				if (ch == '\\' && preg->regparse[n]) {
					/* Non-trailing backslash.
					 * Is this a special escape, or a regular escape?
					 */
					if (strchr("<>mMwds", preg->regparse[n])) {
						/* A special escape. All done with EXACTLY */
						break;
					}
					/* Decode it. Note that we add the length for the escape
					 * sequence to the length for the backlash so we can skip
					 * the entire sequence, or not as required.
					 */
					n += reg_decode_escape(preg->regparse + n, &ch);
					if (ch == 0) {
						preg->err = REG_ERR_NULL_CHAR;
						return 0;
					}
				}

				/* Now we have one char 'ch' of length 'n'.
				 * Check to see if the following char is a MULT
				 */

				if (ISMULT(preg->regparse[n])) {
					/* Yes. But do we already have some EXACTLY chars? */
					if (added) {
						/* Yes, so return what we have and pick up the current char next time around */
						break;
					}
					/* No, so add this single char and finish */
					regc(preg, ch);
					added++;
					preg->regparse += n;
					break;
				}

				/* No, so just add this char normally */
				regc(preg, ch);
				added++;
				preg->regparse += n;
			}
			regc(preg, '\0');

			*flagp |= HASWIDTH;
			if (added == 1)
				*flagp |= SIMPLE;
			break;
		}
		break;
	}

	return(ret);
}
示例#28
0
文件: uart.c 项目: crazy2be/cs452
void uart_restore_tx_irq(int channel) {
	volatile int *ctrl = reg(channel, UART_CTLR_OFFSET);
	*ctrl |= TIEN_MASK;
}
示例#29
0
/*
 * define the tab stops of the table
 */
maktab()
{
	int icol, ilin, tsep, k, ik, vforml, il, text;
	int doubled[MAXCOL], acase[MAXCOL];
	char *s;

	for(icol = 0; icol < ncol; icol++){
		doubled[icol] = acase[icol] = 0;
		printf(".nr %2s 0\n", reg(icol, CRIGHT));
		for(text = 0; text < 2; text++){
			if(text)
				printf(".%2s\n.rm %2s\n", reg(icol, CRIGHT),
							reg(icol, CRIGHT));
			for(ilin = 0; ilin < nlin; ilin++){
				if(instead[ilin] || fullbot[ilin]){
					continue;
				}
				vforml = ilin;
				for(il = prev(ilin);
				    il >= 0 && vspen(table[il][icol].col);
				    il = prev(il))
					vforml = il;
				if(fspan(vforml, icol)){
					continue;
				}
				if(filler(table[ilin][icol].col)){
					continue;
				}
				if((ctop[stynum[ilin]][icol] & ZEROW) != 0){
					continue;
				}
				switch(ctype(vforml, icol)){

				case 'a': 
					acase[icol] = 1;
					s = table[ilin][icol].col;
					if(s > 0 && s < (char *)128 && text){
						if(doubled[icol] == 0)
							printf(
							 ".nr %d 0\n.nr %d 0\n",
							 S1, S2);
						doubled[icol] = 1;
						printf(
					  ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n",
								s, S2, S2, s);
					}
				case 'n': 
					if(table[ilin][icol].rcol != 0){
						if(doubled[icol] == 0
							 && text == 0)
							printf(
							 ".nr %d 0\n.nr %d 0\n",
							 S1, S2);
						doubled[icol] = 1;
						if(real(s=table[ilin][icol].col)
						    && !vspen(s)){
							if(tx((int)s) != text)
								continue;
							printf(".nr %d ", TMP);
							wide(s,
							      FN(vforml, icol),
							      SZ(vforml, icol));
							printf("\n");
							printf(
					   ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",
							      S1, TMP, S1, TMP);
						}
						if(text == 0
						   && real(s=table[ilin][icol].rcol)
						   && !vspen(s) && !barent(s)){
							printf(
							   ".nr %d \\w%c%s%c\n",
							  	TMP, F1, s, F1);
							printf(
					    ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",
							      S2, TMP, S2, TMP);
						}
						continue;
					}
				case 'r': 
				case 'c': 
				case 'l': 
					if(real(s = table[ilin][icol].col)
					   && !vspen(s)){
						if(tx((int)s) != text)
							continue;
						printf(".nr %d ", TMP);
						wide(s,
							FN(vforml, icol),
							SZ(vforml, icol));
						printf("\n");
						printf(
	   ".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n", reg(icol, CRIGHT), TMP,
							reg(icol, CRIGHT), TMP);
					}
				}
			}
		}
		if(acase[icol]){
			printf(".if \\n(%d>=\\n(%2s .nr %2s \\n(%du+2n\n",
				S2, reg(icol, CRIGHT), reg(icol, CRIGHT), S2);
		}
		if(doubled[icol]){
			printf(".nr %2s \\n(%d\n", reg(icol, CMID), S1);
			printf(".nr %d \\n(%2s+\\n(%d\n", TMP, reg(icol, CMID),
									S2);
			printf(".if \\n(%d>\\n(%2s .nr %2s \\n(%d\n", TMP,
				    reg(icol, CRIGHT), reg(icol, CRIGHT), TMP);
			printf(
			     ".if \\n(%d<\\n(%2s .nr %2s +(\\n(%2s-\\n(%d)/2\n",
			     TMP, reg(icol, CRIGHT), reg(icol, CMID),
			     				reg(icol, CRIGHT), TMP);
		}
		if(cll[icol][0]){
			printf(".nr %d %sn\n", TMP, cll[icol]);
			printf(".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n",
				reg(icol, CRIGHT), TMP, reg(icol, CRIGHT), TMP);
		}
		for(ilin = 0; ilin < nlin; ilin++)
			if(k = lspan(ilin, icol)){
				s = table[ilin][icol - k].col;
				if(!real(s) || barent(s) || vspen(s))
					continue;
				printf(".nr %d ", TMP);
				wide(table[ilin][icol - k].col,
				      FN(ilin, icol - k), SZ(ilin, icol - k));
				for(ik = k; ik >= 0; ik--){
					printf("-\\n(%2s", reg(icol-ik,CRIGHT));
					if(!expflg && ik > 0)
						printf( "-%dn", sep[icol - ik]);
				}
				printf("\n");
				printf(".if \\n(%d>0 .nr %d \\n(%d/%d\n",
							TMP, TMP, TMP, k);
				printf(".if \\n(%d<0 .nr %d 0\n",
							TMP, TMP);
				for(ik = 1; ik <= k; ik++){
					if(doubled[icol - k + ik]){
						printf(".nr %2s +\\n(%d/2\n",
							reg(icol - k + ik,CMID),
								TMP);
					}
					printf(".nr %2s +\\n(%d\n",
						reg(icol - k + ik, CRIGHT),TMP);
				}
			}
	}
	if(textflg)
		untext();
	/*
	 * if even requested, make all columns widest width
	 */

#define TMP1 S1
#define TMP2 S2

	if(evenflg){
		printf(".nr %d 0\n", TMP);
		for(icol = 0; icol < ncol; icol++){
			if(evenup[icol] == 0)
				continue;
			printf(".if \\n(%2s>\\n(%d .nr %d \\n(%2s\n",
				reg(icol, CRIGHT), TMP, TMP, reg(icol, CRIGHT));
		}
		for(icol = 0; icol < ncol; icol++){
 			/*
			 * if column not evened just retain old interval
			 */
			if(evenup[icol] == 0)
				continue;
			if(doubled[icol])
				printf(
				   ".nr %2s (100*\\n(%2s/\\n(%2s)*\\n(%d/100\n",
				   	reg(icol, CMID), reg(icol, CMID),
				   		reg(icol, CRIGHT), TMP);
			/*
		 	* that nonsense with the 100's and parens tries to avoid
		 	* overflow while proportionally shifting the middle of
		 	* the number
		 	*/
			printf(".nr %2s \\n(%d\n", reg(icol, CRIGHT), TMP);
		}
	}
	/*
	 * now adjust for total table width
	 */
	for(tsep = icol = 0; icol < ncol; icol++)
		tsep += sep[icol];
	if(expflg){
		printf(".nr %d 0", TMP);
		for(icol = 0; icol < ncol; icol++)
			printf("+\\n(%2s", reg(icol, CRIGHT));
		printf("\n");
		/*
		 * Bug fix: Most users expect the expand to take place
		 * over the line length minus the current indentation
		 * (I do as well, a bit ugly to see the table creeping
		 * in the right margin (jna))
		 */
		printf(".nr %d \\n(.l-\\n(.i-\\n(%d\n", TMP, TMP);
		if(boxflg || dboxflg || allflg)
			tsep += 1;
		else
			tsep -= sep[ncol - 1];
		printf(".nr %d \\n(%d/%d\n", TMP, TMP, tsep);
		printf(".if \\n(%d<0 .nr %d 0\n", TMP, TMP);
	} else
		printf(".nr %d 1n\n", TMP);
	printf(".nr %2s 0\n", reg(-1,CRIGHT));
	tsep = (boxflg || allflg || dboxflg || left1flg) ? 1 : 0;
	for(icol = 0; icol < ncol; icol++){
		printf(".nr %2s \\n(%2s+(%d*\\n(%d)\n", reg(icol, CLEFT),
					reg(icol -1, CRIGHT), tsep, TMP);
		printf(".nr %2s +\\n(%2s\n",reg(icol, CRIGHT),reg(icol, CLEFT));
		if(doubled[icol]){
			/*
			 * the next line is last-ditch effort to avoid
			 * zero field width
			 */
			/*
			printf(".if \\n(%2s=0 .nr %2s 1\n", reg(icol,CMID),
		   				reg(icol,CMID));
			 */
			printf(".nr %2s +\\n(%2s\n", reg(icol, CMID),
							reg(icol, CLEFT));
			/*
			printf(".if n .if \\n(%2s%%24>0 .nr %2s +12u\n",
					reg(icol, CMID), reg(icol, CMID));
			 */
		}
		tsep = sep[icol];
	}
	if(rightl)
		printf(".nr %2s (\\n(%2s+\\n(%2s)/2\n", reg(ncol-1, CRIGHT),
							reg(ncol-1, CLEFT),
							reg(ncol-2, CRIGHT));
	printf(".nr TW \\n(%2s\n", reg(ncol-1, CRIGHT));
	if(boxflg || allflg || dboxflg)
		printf(".nr TW +%d*\\n(%d\n", sep[ncol - 1], TMP);
	printf(
".if t .if\\n(TW>\\n(.lu .tm Table at line %d file %s is too wide - \\n(TW units\n",
		iline - 1, strlen(oldname) ? oldname : ifile);
	return;
}
示例#30
0
	void init_automation() {
		reg(agi::make_unique<meta>());
		reg(agi::make_unique<open_manager>());
		reg(agi::make_unique<reload_all>());
		reg(agi::make_unique<reload_autoload>());
	}