コード例 #1
0
static void pic_ioport_write(void *opaque, uint32_t addr, uint32_t val)
{
    PicState *s = opaque;
    int priority, cmd, irq;

    DPRINTF("write: addr=0x%02x val=0x%02x\n", addr, val);
    addr &= 1;
    if (addr == 0) {
        if (val & 0x10) {
            /* init */
            pic_reset(s);
            /* deassert a pending interrupt */
            qemu_irq_lower(s->pics_state->parent_irq);
            s->init_state = 1;
            s->init4 = val & 1;
            s->single_mode = val & 2;
            if (val & 0x08)
                hw_error("level sensitive irq not supported");
        } else if (val & 0x08) {
            if (val & 0x04)
                s->poll = 1;
            if (val & 0x02)
                s->read_reg_select = val & 1;
            if (val & 0x40)
                s->special_mask = (val >> 5) & 1;
        } else {
            cmd = val >> 5;
            switch(cmd) {
            case 0:
            case 4:
                s->rotate_on_auto_eoi = cmd >> 2;
                break;
            case 1: /* end of interrupt */
            case 5:
                priority = get_priority(s, s->isr);
                if (priority != 8) {
                    irq = (priority + s->priority_add) & 7;
                    s->isr &= ~(1 << irq);
                    if (cmd == 5)
                        s->priority_add = (irq + 1) & 7;
                    pic_update_irq(s->pics_state);
                }
                break;
            case 3:
                irq = val & 7;
                s->isr &= ~(1 << irq);
                pic_update_irq(s->pics_state);
                break;
            case 6:
                s->priority_add = (val + 1) & 7;
                pic_update_irq(s->pics_state);
                break;
            case 7:
                irq = val & 7;
                s->isr &= ~(1 << irq);
                s->priority_add = (irq + 1) & 7;
                pic_update_irq(s->pics_state);
                break;
            default:
                /* no operation */
                break;
            }
        }
    } else {
コード例 #2
0
ファイル: calculator.c プロジェクト: ytaoWang/test
int __recursive_calculator(const char *p,int size)
{
	const char *q = p;
	char str[20];
	int i;
	/*
	 * left:左边值,right:右边值,lop:当前操作符,rop:下一个操作符
	 */
	int left,right,length;
	int lop,rop;
	if(*p == '\0' || size == 0)
		return 0;
	i = 0;

    //check ( in here
    if(*q == '(') {
        
        if(!(q = __get_last_token(q,size))) {
            fprintf(stderr,"illegal expression\n");
            exit(-1);
        }

        printf("line:%d,last token:%s,p+1:%s,len:%d\n",__LINE__,q,p+1,q - p - 2);
        get_str(p+1,q-1,str);
        //计算出(expression)
        //left = __recursive_calculator(p+1,q - p - 2);
        calculator(str,&left);
        printf("line:%d,left:%d,p:%s,q:%s\n",__LINE__,left,p,q);
        
        if(*q != '*')
            return calculate(left,'+',\
                             __recursive_calculator(q,size - (q - p)));
        else {
            /*
             * 这里需要判断到直到优先级小于*为止
             */
            char expression[129];

            memset(str,0,20);
            memset(expression,0,129);
            q++;
            while(*q != '\0' && isdigit(*q))
                str[i++] = *q++;
            
            str[i++] = '\0';
            right = atoi(str);
            left = calculate(left,'*',right);
#ifdef __DEBUG
            printf("line:%d,left:%-d,p:%s,q:%s\n",__LINE__,left,p,q);
#endif
            snprintf(expression,128,"%-d%s",left,q);
#ifdef __DEBUG
            printf("exp:%s\n",expression);
#endif

            calculator(expression,&left);
            
            //return calculate(left,*q,__recursive_calculator(q+1,size-(q+1-p)));
            return left;
        }
    }
    
    memset(str,0,20);
    
	if(*q == '+' || *q == '-') 
		str[i++] = *q++;

	while(*q != '\0' && isdigit(*q))
			str[i++] = *q++;

	str[i++] = '\0';
	left = atoi(str);
    //only one operator,stop recursion
    if(*q == '\0')
        return left;
    
	lop = *q++;
    //only one operator
	if((rop = next_op(q,&right,&length)) < 0)
		return calculate(left,lop,right);

    //判断(
    if(rop == '(') {
        const char *nop = NULL;
        char first[129],second[129];
        //获取下一个)后面第一个操作符,判断优先级,进行计算
        nop = __next_op_parenthesis(q,&rop);
        if(rop == '\0')
            return calculate(left,lop,__recursive_calculator(q,size - i - 1));
        memset(first,0,129);
        memset(second,0,129);
        //计算括号与左右式子的值
        printf("line:%d,q:%s,nop:%s\n",__LINE__,q,nop);
        get_str(q,nop,second);
        printf("line:%d,(%s)\n",__LINE__,second);
        calculator(second,&left);
        printf("line:%d,(%d)\n",__LINE__,left);
        //重新生成一个字符串求值
        get_str(p,q,first);
        printf("line:%d,first:%s,p:%s\n",__LINE__,first,p);
        memset(second,'\0',129);
        snprintf(second,129,"%s%d%s",first,left,nop);
        printf("line:%d,new str:%s\n",__LINE__,second);
        calculator(second,&left);
        return left;
    }
    
	//q 指向右边表达式
	switch(get_priority(lop,rop)) {
	case 0: // lop == rop //从左到右进行计算
		{
			left = calculate(left,lop,right);
            printf("right:%s,size:%d\n",q+length,(size - (q - p +length)));
			return calculate(left,rop,__recursive_calculator(q+length,size - (q - p + length)));
		} break;
	case 1: //lop < rop,右边优先级高先算右边表达式的值,再计算左边
        /*
         * 也可以不需要,直接加上符号位就可以
         */
        printf("left operand less than right operand,str:%s,left:%d\n",q,left);
        getchar();
        //return calculate(left,lop,__recursive_calculator(q,size - (q-p)));
        return calculate(left,'+',__recursive_calculator(q - 1,1 + size - (q-p)));
		break;
	case 2: //lop > rop //从左到右进行计算
		{
            printf("left operand greater than right operand,str:%s,left:%d,right:%d\n",q+length-1,left,right);
			left = calculate(left,lop,right);
            //将第一个符号位加入到后面的表达式中去
            return calculate(left,'+',__recursive_calculator(q + length - 1,1 + size - (q - p + length)));
			//return calculate(left,rop,__recursive_calculator(q+length,size - (q - p + length)));
		} break;
	default: assert(1);break;
	}
	

	return 0;
}
コード例 #3
0
ファイル: iplog_options.c プロジェクト: NathanGibbs3/iplog
void get_options(int argc, char *const argv[]) {
	extern u_char *logfile, *lockfile, *user, *group, *ifstring;
	int opt;

	while ((opt = getopt_long(argc, argv, opts, longopts, NULL)) != EOF) {
		switch (opt) {
			case 10:
				enable(optarg, LOG_TCP);
				break;
			case 11:
				enable(optarg, LOG_UDP);
				break;
			case 12:
				enable(optarg, LOG_ICMP);
				break;
			case 13:
				facility = get_facility(optarg);
				break;
			case 14:
				priority = get_priority(optarg);
				break;
			case 15:
				if (lockfile != NULL)
					free(lockfile);
				lockfile = xstrdup(optarg);
				break;
			case 'w':
				enable(optarg, LOG_IP);
				break;
			case 'd':
				flags |= IGNORE_NS;
				break;
			case 'u':
				if (user != NULL)
					free(user);
				user = xstrdup(optarg);
				break;
			case 'g':
				if (group != NULL)
					free(group);
				group = xstrdup(optarg);
				break;
			case 'k':
				kill_iplog(15, lockfile);
				break;
			case 'l':
				if (opt_enabled(LOG_STDOUT)) {
					mysyslog("Warning: Overriding --stdout");
					flags &= ~LOG_STDOUT;
				} else if (logfile != NULL)
					free(logfile);
				logfile = xstrdup(optarg);
				break;
			case 'L':
				if (logfile != NULL) {
					mysyslog("Warning: Overriding --logfile");
					xfree(logfile);
				}
				flags |= LOG_STDOUT;
				break;
			case 'm':
				enable(optarg, SCANS_ONLY);
				break;
			case 'o':
				flags |= NO_FORK;
				break;
			case 'c':
				enable(optarg, DNS_CACHE);
				break;
			case 'y':
				enable(optarg, LOG_FRAG);
				break;
			case 'a':
				flags |= (PROMISC | LOG_DEST);
				if (pcap_network != NULL)
					free(pcap_network);
				pcap_network = xstrdup(optarg);
				break;
			case 'D':
				enable(optarg, LOG_DEST);
				break;
			case 'e':
#ifdef __linux__
				enable(optarg, GET_IDENT);
#else
				mysyslog("Ident lookups are only supported on Linux.");
#endif
				break;
			case 'T':
				enable(optarg, TCP_RES);
				break;
			case 'U':
				enable(optarg, UDP_RES);
				break;
			case 'V':
				enable(optarg, VERBOSE);
				break;
			case 'I':
				enable(optarg, ICMP_RES);
				break;
			case 'S':
				enable(optarg, SMURF);
				break;
			case 'b':
				enable(optarg, BOGUS);
				break;
			case 'P':
				enable(optarg, PING_FLOOD);
				break;
			case 'p':
				enable(optarg, PORTSCAN);
				break;
			case 'x':
				enable(optarg, XMAS_SCAN);
				break;
			case 'f':
				enable(optarg, FIN_SCAN);
				break;
			case 'q':
				enable(optarg, SYN_SCAN);
				break;
			case 'F':
				enable(optarg, UDP_SCAN);
				break;
			case 'N':
				flags |= NO_RESOLV;
				break;
			case 'n':
				enable(optarg, NULL_SCAN);
				break;
			case 's':
				enable(optarg, SYN_FLOOD);
				break;
			case 't':
				enable(optarg, TRACEROUTE);
				break;
			case 'i':
				if (ifstring != NULL)
					free(ifstring);
				ifstring = xstrdup(optarg);
				break;
			case 'R':
				kill_iplog(1, lockfile);
				break;
			case 'z':
				enable(optarg, FOOL_NMAP);
				break;
			case 'v':
				mysyslog("iplog version %s\nby %s\n%s",
					VERSION, AUTHORS, WEBPAGE);
				exit(0);
			case 'h':
			default:
				print_help();
				break;
		}
	}
}
コード例 #4
0
ファイル: i8259.c プロジェクト: AmesianX/winkvm
static void pic_ioport_write(void *opaque, u32 addr, u32 val)
{
	struct kvm_kpic_state *s = opaque;
	int priority, cmd, irq;

	addr &= 1;
	if (addr == 0) {
		if (val & 0x10) {
			kvm_pic_reset(s);	/* init */
			/*
			 * deassert a pending interrupt
			 */
			s->pics_state->irq_request(s->pics_state->
						   irq_request_opaque, 0);
			s->init_state = 1;
			s->init4 = val & 1;
			if (val & 0x02)
				printk(KERN_ERR "single mode not supported");
			if (val & 0x08)
				printk(KERN_ERR
				       "level sensitive irq not supported");
		} else if (val & 0x08) {
			if (val & 0x04)
				s->poll = 1;
			if (val & 0x02)
				s->read_reg_select = val & 1;
			if (val & 0x40)
				s->special_mask = (val >> 5) & 1;
		} else {
			cmd = val >> 5;
			switch (cmd) {
			case 0:
			case 4:
				s->rotate_on_auto_eoi = cmd >> 2;
				break;
			case 1:	/* end of interrupt */
			case 5:
				priority = get_priority(s, s->isr);
				if (priority != 8) {
					irq = (priority + s->priority_add) & 7;
					s->isr &= ~(1 << irq);
					if (cmd == 5)
						s->priority_add = (irq + 1) & 7;
					pic_update_irq(s->pics_state);
				}
				break;
			case 3:
				irq = val & 7;
				s->isr &= ~(1 << irq);
				pic_update_irq(s->pics_state);
				break;
			case 6:
				s->priority_add = (val + 1) & 7;
				pic_update_irq(s->pics_state);
				break;
			case 7:
				irq = val & 7;
				s->isr &= ~(1 << irq);
				s->priority_add = (irq + 1) & 7;
				pic_update_irq(s->pics_state);
				break;
			default:
				break;	/* no operation */
			}
		}
	} else