Exemplo n.º 1
0
void armv7a::arm_sbfx(armv7a_ir& inst)
{
    inst.print_inst("arm_sbfx");
    inst.check(27, 21, B(011 1101));
    inst.check(6, 4, B(101));

    if(rf.condition_passed(inst.cond()))
    {
        uint32_t widthm1 = inst(20, 16);
        uint32_t rd = inst(15, 12);
        uint32_t lsb = inst(11, 7);
        uint32_t rn = inst(3, 0);
        uint32_t d = rd;
        uint32_t n = rn;
        uint32_t lsbit = lsb;
        uint32_t widthminus1 = widthm1;

        if((d == 15) || (n == 15))
        {
            printb(d_inst, "arm_sbfx error");
        }

        //ESO
        uint32_t msbit = lsbit + widthminus1;

        if(msbit <= 31)
        {
            bits _rn(get_field(rf.r_read(n), msbit, lsbit), widthm1 + 1);
            bits _rd;
            sign_extend(&_rd, _rn, 32);
            rf.r_write(d, _rd.val);
        }

        else
        {
            printb(d_inst, "arm_sbfx error 2");
        }
    }
}
Exemplo n.º 2
0
Arquivo: mci.cpp Projeto: ufoderek/mvp
/* write registers of the MCI module */
bool MCI::write(uint32_t data, uint32_t addr, int size)
{
    bool result = true;

    switch (addr) {
        default:
            printb(d_mci, "write unknown: 0x%.4x\n", addr);
            result = false;
            break;
    }

    return result;
}
Exemplo n.º 3
0
bool ARMV5::check_be()
{
    bool b = cp15.c1_b();
    bool e = (CPSR_E(rf.cpsr)) ? true : false;

    if (!b && !e) {
        return true;
    }

    else {
        printb(core_id, d_armv5, "%s endian check error", current_inst_name);
    }
}
Exemplo n.º 4
0
int test_apply_move() {
	int status, num_moves, i;
	Board board;
	Move *moves;
	status = WIN;
	num_moves = 0;
	setup(&board);
	printb(&board);
	moves = gen_moves(&board, &num_moves);
	printf("found %d moves\n", num_moves);
	for(i=0; i<35 && i<num_moves; i++) {
		printf("move %d: %d is moving from %d to %d, capturing %d\n",
			i, moving_type(moves[i]), moves[i].from,
			moves[i].to, capturing_type(moves[i]));
		printf("board after move %d looks like:\n", i+1);
		apply_move(&board, moves[i]);
		printb(&board);
		undo_move(&board, moves[i]);
	}
	
	return status;
}
Exemplo n.º 5
0
bool gic2_vctrl::read(uint32_t* data, uint32_t offset)
{
    if(offset == 0x0)
    {
        *data = en;
    }
    else if(offset == 0x30)
    {
        //ELSR0, for list[0]~list[31]
        *data = 0;
        for(int i = 0; i <= 31; i++)
        {
            if(!list[i].valid)
            {
                set_bit(data, i, 1);
            }
        }
    }
    else if(offset == 0x34)
    {
        //ELSR1, for list[32]~list[63]
        *data = 0;
        for(int i = 32; i <= 63; i++)
        {
            if(!list[i - 32].valid)
            {
                set_bit(data, i - 32, 1);
            }
        }
    }
    else if((offset >= 0x100) && (offset <= 0x1FC))
    {
        //list[n]
        uint32_t n = (offset - 0x100) / 4;

        *data = 0;
        set_bit(data, 31, list[n].hw);
        set_bit(data, 30, list[n].group1);
        set_field(data, 29, 28, list[n].state);
        set_field(data, 27, 23, list[n].priority);
        set_field(data, 19, 10, list[n].pid);
        set_field(data, 9, 0, list[n].vid);
        printd(d_gic2_vctrl, "read list[%d], pid = %d, vid = %d", n, list[n].pid, list[n].vid);
    }
    else
    {
        printb(d_gic2_vctrl, "read 0x%X error", offset);
    }

    return true;
}
Exemplo n.º 6
0
/* load the initrd image or binary data to RAM */
void board_realvieweb::load_initrd(char* path_initrd)
{
    int fid;

    printd(d_realvieweb, "loading initrd...");

    if (path_initrd != NULL) {
        fid = open(path_initrd, O_RDONLY);

        if (fid > 0) {
            uint32_t addr = ADDR_INITRD;
            uint32_t buff;
            int count;
            bool result;

            do {
                count = read(fid, &buff, 4);
                result = ram->write(buff, addr, 4);
                //result = ram->local_access(false, addr, buff, 4);
                size_initrd += count;

                if (result == false) {
                    printb(d_realvieweb, "cannot load initrd");
                }

                else {
                    addr += 4;
                }

            }
            while (count > 0);
        }

        else {
            printb(d_realvieweb, "cannot open initrd");
        }
    }
}
Exemplo n.º 7
0
int main(int argc, char * argv[]) {
    struct mem_pool * pool = mem_pool_new(4);

    int r1,r2,r3,r4;

    r1 = mem_pool_alloc(pool, 16);
    printb(pool, r1);

    r2 = mem_pool_alloc(pool, 32);
    printb(pool, r2);

    r3 = mem_pool_alloc(pool, 16);
    printb(pool, r3);

    mem_pool_free(pool, r1);
    mem_pool_free(pool, r3);

    r4 = mem_pool_alloc(pool, 32);
    printb(pool, r4);

    mem_pool_destroy(pool);
    return 0;
}
Exemplo n.º 8
0
void
bridge_addrs(const char *delim, int d)
{
	char dstaddr[NI_MAXHOST];
	char dstport[NI_MAXSERV];
	const int niflag = NI_NUMERICHOST|NI_DGRAM;
	struct ifbaconf ifbac;
	struct ifbareq *ifba;
	char *inbuf = NULL, buf[sizeof(ifba->ifba_ifsname) + 1], *inb;
	struct sockaddr *sa;
	int i, len = 8192;

	/* ifconfig will call us with the argv of the command */
	if (strcmp(delim, "addr") == 0)
		delim = "";

	while (1) {
		ifbac.ifbac_len = len;
		inb = realloc(inbuf, len);
		if (inb == NULL)
			err(1, "malloc");
		ifbac.ifbac_buf = inbuf = inb;
		strlcpy(ifbac.ifbac_name, name, sizeof(ifbac.ifbac_name));
		if (ioctl(s, SIOCBRDGRTS, &ifbac) < 0) {
			if (errno == ENETDOWN)
				return;
			err(1, "%s", name);
		}
		if (ifbac.ifbac_len + sizeof(*ifba) < len)
			break;
		len *= 2;
	}

	for (i = 0; i < ifbac.ifbac_len / sizeof(*ifba); i++) {
		ifba = ifbac.ifbac_req + i;
		strlcpy(buf, ifba->ifba_ifsname, sizeof(buf));
		printf("%s%s %s %u ", delim, ether_ntoa(&ifba->ifba_dst),
		    buf, ifba->ifba_age);
		sa = (struct sockaddr *)&ifba->ifba_dstsa;
		printb("flags", ifba->ifba_flags, IFBAFBITS);
		if (sa->sa_family != AF_UNSPEC &&
		    getnameinfo(sa, sa->sa_len,
		    dstaddr, sizeof(dstaddr),
		    dstport, sizeof(dstport), niflag) == 0)
			printf(" tunnel %s:%s", dstaddr, dstport);
		printf("\n");
	}
	free(inbuf);
}
Exemplo n.º 9
0
static void
gre_status(int s)
{
	uint32_t opts = 0;

	ifr.ifr_data = (caddr_t)&opts;
	if (ioctl(s, GREGKEY, &ifr) == 0)
		if (opts != 0)
			printf("\tgrekey: 0x%x (%u)\n", opts, opts);
	opts = 0;
	if (ioctl(s, GREGOPTS, &ifr) != 0 || opts == 0)
		return;
	printb("\toptions", opts, GREBITS);
	putchar('\n');
}
Exemplo n.º 10
0
/* load the application program to RAM */
void board_realvieweb::load_prog(char* path_prog)
{
    int fid;

    if (path_prog != NULL) {
        fid = open(path_prog, O_RDONLY);

        if (fid > 0) {
            uint32_t addr = ADDR_PROG;
            uint32_t buff;
            int count;
            bool result;

            do {
                count = read(fid, &buff, 4);
                result = ram->write(buff, addr, 4);
                //result = ram->local_access(true, addr, buff, 4);
                size_prog += count;

                if (result == false) {
                    printb(d_realvieweb, "cannot load program");
                }

                else {
                    addr += 4;
                }

            }
            while (count > 0);
        }

        else {
            printb(d_realvieweb, "cannot load program");
        }
    }
}
Exemplo n.º 11
0
void armv7a::arm_add_sp_plus_imm(armv7a_ir& inst)
{
    inst.print_inst("arm_add_sp_plus_imm");
    inst.check(27, 21, B(001 0100));
    inst.check(19, 16, B(1101));

    if(rf.condition_passed(inst.cond()))
    {
        uint32_t s = inst(20);
        uint32_t rd = inst(15, 12);
        bits imm12(inst(11, 0), 12);

        if((rd == B(1111)) && (s == 1))
        {
            printb(d_inst, "arm_add_sp_plus_imm SUBS PC LR");
        }

        uint32_t d = rd;
        bool setflags = s == 1;
        bits imm32;
        arm_expand_imm(&imm32, imm12);
        //ESO
        bits result;
        uint32_t carry;
        uint32_t overflow;
        bits sp(rf.r_read(SP), 32);
        add_with_carry(&result, &carry, &overflow, sp, imm32, 0);
        printd(d_inst, "SP(R%d)=0x%X, imm32=0x%X, result=r%d=0x%X", SP, sp.val, imm32.val, d, result.val);

        if(d == 15)
        {
            rf.alu_write_pc(result.val);
        }

        else
        {
            rf.r_write(d, result.val);

            if(setflags)
            {
                rf.cpsr_N(result(31));
                rf.cpsr_Z(is_zero_bit(result));
                rf.cpsr_C(carry);
                rf.cpsr_V(overflow);
            }
        }
    }
}
Exemplo n.º 12
0
static void
print_port(struct cfg *cfg, int port)
{
	etherswitch_port_t p;
	int ifm_ulist[IFMEDIAREQ_NULISTENTRIES];
	int i;

	bzero(&p, sizeof(p));
	p.es_port = port;
	p.es_ifmr.ifm_ulist = ifm_ulist;
	p.es_ifmr.ifm_count = IFMEDIAREQ_NULISTENTRIES;
	if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0)
		err(EX_OSERR, "ioctl(IOETHERSWITCHGETPORT)");
	printf("port%d:\n", port);
	if (cfg->conf.vlan_mode == ETHERSWITCH_VLAN_DOT1Q)
		printf("\tpvid: %d\n", p.es_pvid);
	printb("\tflags", p.es_flags, ETHERSWITCH_PORT_FLAGS_BITS);
	printf("\n");
	if (p.es_nleds) {
		printf("\tled: ");
		for (i = 0; i < p.es_nleds; i++) {
			printf("%d:%s%s", i+1, ledstyles[p.es_led[i]], (i==p.es_nleds-1)?"":" ");
		}
		printf("\n");
	}
	printf("\tmedia: ");
	print_media_word(p.es_ifmr.ifm_current, 1);
	if (p.es_ifmr.ifm_active != p.es_ifmr.ifm_current) {
		putchar(' ');
		putchar('(');
		print_media_word(p.es_ifmr.ifm_active, 0);
		putchar(')');
	}
	putchar('\n');
	printf("\tstatus: %s\n", (p.es_ifmr.ifm_status & IFM_ACTIVE) != 0 ? "active" : "no carrier");
	if (cfg->mediatypes) {
		printf("\tsupported media:\n");
		if (p.es_ifmr.ifm_count > IFMEDIAREQ_NULISTENTRIES)
			p.es_ifmr.ifm_count = IFMEDIAREQ_NULISTENTRIES;
		for (i=0; i<p.es_ifmr.ifm_count; i++) {
			printf("\t\tmedia ");
			print_media_word(ifm_ulist[i], 0);
			putchar('\n');
		}
	}
}
Exemplo n.º 13
0
int resolve(char* path)
{
    BOARD b;

    // decode path
    decodepath(path,&b);
    printb(&b);
    // check status

    // analyze next

    // resolve next

    // resolve current

    return 0;
}
Exemplo n.º 14
0
/* read instruction from RAM within 32-bits ARM mode */
bool ARMV5::inst_arm_read(void)
{
    int fault = FAULT_NONE;
    uint32_t addr = 0;
    bool cachable = true;

    if ((rf.pc & B8(11)) != 0) {
        printb(core_id, d_armv5, "instruction address is not word boundary aligned: 0x%X", rf.pc);
    }

    /* address translation */
    if (mmu_enable) {
        fault = vir2phy(rf.pc, &addr, CPSR_MODE(rf.cpsr), false, &cachable);
    }

    else {
        addr = rf.pc;
        fault = FAULT_NONE;
    }

    /* memory access */
    if (fault == FAULT_NONE) {
        if (icache_enable && cachable) {
            if (!icache_read(rf.pc)) {
                delay += CYC_ICACHE_MISS;
            }
        }

        else {
            delay += 2;
        }

        if (bus_read(&inst, addr, 4)) {
            return true;
        }

        else {
            fault = FAULT_EXTERNAL;
        }
    }

    /* fault handler */
    cp15.c5_ifsr = fault;
    cp15.c6_far = rf.pc;
    return false;
}
Exemplo n.º 15
0
void armv7a::arm_swp(armv7a_ir& inst)
{
    inst.print_inst("arm_swp");
    inst.check(27, 23, B(10));
    inst.check(21, 20, 0);
    inst.check(11, 4, B(1001));

    if(rf.condition_passed(inst.cond()))
    {
        uint32_t b = inst(22);
        uint32_t rn = inst(19, 16);
        uint32_t rt = inst(15, 12);
        uint32_t rt2 = inst(3, 0);

        uint32_t t = rt;
        uint32_t t2 = rt2;
        uint32_t n = rn;
        uint32_t size = (b == 1) ? 1 : 4;

        if((t == 15) || (t2 == 15) || (n == t) || (n == t2))
        {
            printb(d_inst, "arm_swp error");
        }

        //ESO

        bits data;
        mem_a_read(&data, rf.r_read(n), size);

        bits _t2(rf.r_read(t2), 8 * size);
        mem_a_write(rf.r_read(n), size, _t2);

        if(size == 1)
        {
            rf.r_write(t, data.val);
        }

        else
        {
            rf.r_write(t, data.val);
        }
    }
}
Exemplo n.º 16
0
void
bridge_list(char *delim)
{
	struct ifbreq *reqp;
	struct ifbifconf bifc;
	int i, len = 8192;
	char buf[sizeof(reqp->ifbr_ifsname) + 1], *inbuf = NULL, *inb;

	while (1) {
		bifc.ifbic_len = len;
		inb = realloc(inbuf, len);
		if (inb == NULL)
			err(1, "malloc");
		bifc.ifbic_buf = inbuf = inb;
		strlcpy(bifc.ifbic_name, name, sizeof(bifc.ifbic_name));
		if (ioctl(s, SIOCBRDGIFS, &bifc) < 0)
			err(1, "%s", name);
		if (bifc.ifbic_len + sizeof(*reqp) < len)
			break;
		len *= 2;
	}
	for (i = 0; i < bifc.ifbic_len / sizeof(*reqp); i++) {
		reqp = bifc.ifbic_req + i;
		strlcpy(buf, reqp->ifbr_ifsname, sizeof(buf));
		printf("%s%s ", delim, buf);
		printb("flags", reqp->ifbr_ifsflags, IFBIFBITS);
		printf("\n");
		if (reqp->ifbr_ifsflags & IFBIF_SPAN)
			continue;
		printf("\t\t");
		printf("port %u ifpriority %u ifcost %u",
		    reqp->ifbr_portno, reqp->ifbr_priority,
		    reqp->ifbr_path_cost);
		if (reqp->ifbr_ifsflags & IFBIF_STP)
			printf(" %s role %s",
			    stpstates[reqp->ifbr_state],
			    stproles[reqp->ifbr_role]);
		printf("\n");
		bridge_rules(buf, 0);
	}
	free(bifc.ifbic_buf);
}
Exemplo n.º 17
0
uint32_t armv7a::align(uint32_t x, uint32_t y)
{
    //x is address
    //y is size in bytes
    switch(y)
    {
        case 1:
            return x;
        case 2:
            return x & mask(31, 1);
        case 4:
            return x & mask(31, 2);
            /*
                    case 8:
               return x & mask(31, 3);
             */
        default:
            printb(d_armv7a_misc, "align(0x%X,%d) error", x, y);
    }
}
Exemplo n.º 18
0
void
bridge_addrs(const char *delim, int d)
{
	struct ifbaconf ifbac;
	struct ifbareq *ifba;
	char *inbuf = NULL, buf[sizeof(ifba->ifba_ifsname) + 1], *inb;
	int i, len = 8192;

	/* ifconfig will call us with the argv of the command */
	if (strcmp(delim, "addr") == 0)
		delim = "";

	while (1) {
		ifbac.ifbac_len = len;
		inb = realloc(inbuf, len);
		if (inb == NULL)
			err(1, "malloc");
		ifbac.ifbac_buf = inbuf = inb;
		strlcpy(ifbac.ifbac_name, name, sizeof(ifbac.ifbac_name));
		if (ioctl(s, SIOCBRDGRTS, &ifbac) < 0) {
			if (errno == ENETDOWN)
				return;
			err(1, "%s", name);
		}
		if (ifbac.ifbac_len + sizeof(*ifba) < len)
			break;
		len *= 2;
	}

	for (i = 0; i < ifbac.ifbac_len / sizeof(*ifba); i++) {
		ifba = ifbac.ifbac_req + i;
		strlcpy(buf, ifba->ifba_ifsname, sizeof(buf));
		printf("%s%s %s %u ", delim, ether_ntoa(&ifba->ifba_dst),
		    buf, ifba->ifba_age);
		printb("flags", ifba->ifba_flags, IFBAFBITS);
		printf("\n");
	}
	free(inbuf);
}
Exemplo n.º 19
0
void armv7a::decode_sync(armv7a_ir& inst)
{
    uint32_t op = inst(23, 20);

    switch(op)
    {
        case B(0000) :
        case B(0100) :
            arm_swp(inst);
            return;
        case B(1000) :
            arm_strex(inst);
            return;
        case B(1001) :
            arm_ldrex(inst);
            return;
        case B(1010) :
            arm_strexd(inst);
            return;
        case B(1011) :
            arm_ldrexd(inst);
            return;
        case B(1100) :
            arm_strexb(inst);
            return;
        case B(1101) :
            arm_ldrexb(inst);
            return;
        case B(1110) :
            arm_strexh(inst);
            return;
        case B(1111) :
            arm_ldrexh(inst);
            return;
        default:
            printb(core_id, d_armv7a_decode_sync, "decode error: %X", inst.val);
            return;
    }
}
Exemplo n.º 20
0
int main(int argc, char** argv)
{
    BOARD b;
    char path[1024];

    if( argc < 2 ) {
        memcpy(&b, &Initial_Board, sizeof(BOARD));
        sprintf(path,"top/32/22");

        struct stat st;
        if(stat("top",&st)!=0) {
            mkdir("top",775);
        };
    } else {
        printf("currently, resume function is not implemented.\n");
        return 0;
    }

    printb(&b);

    resolve(path);
}
Exemplo n.º 21
0
// Tests the above functions
int main(int argc, char **argv) {
    char buffer[9] = {'\0'};

    char sig;
    short ssig;

    printf("Unit tests:\n");

    printf("Iterate IDs\n");
    for (int i = 0; i < 4; i++) {
        sig = pack_signal(i, false, false, false);
        printb(1, &sig);
    }
    printf("\n");
    
    printf("Left blinker\t");
    sig = pack_signal(1, true, false, false);
    printb(1, &sig);
    printf("Signed\t\t"); 
    ssig = sign(sig);
    printb(2, &ssig);
    if (valid(ssig)) printf("Valid!\n");
    printf("\n");

    printf("Stop!\t\t");
    sig = pack_signal(1, false, true, false);
    printb(1, &sig);
    printf("Signed\t\t"); 
    ssig = sign(sig);
    printb(2, &ssig);
    if (valid(ssig)) printf("Valid!\n");
    printf("\n");

    printf("Right blinker\t");
    sig = pack_signal(1, false, false, true);
    printb(1, &sig);
    printf("Signed\t\t"); 
    ssig = sign(sig);
    printb(2, &ssig);
    if (valid(ssig)) printf("Valid!\n");
}
Exemplo n.º 22
0
int main(int argc, char *argv[])
{
	int m=0, n=0;
	int mvnum = 1, i=0;
	int M[ROWS][COLS], mvchoice[TOT+1];/*mvchoice[0] is not used... yet*/
	if(argc==3)
		m=atoi(argv[1])-1, n=atoi(argv[2])-1;
	
/*Initialize the arrays*/
	Aones(mvchoice);
	M_init(M, m, n);

	while(mvnum){
		while(mvnum < TOT)
			mvnum = move(M, mvnum, mvchoice, &m, &n);
		printb(M);
		printf("%d\n", ++i);
		while(mvnum == TOT)
			mvnum = move(M, mvnum, mvchoice, &m, &n);
		//mvchoice[--mvnum] = 9;
	}
	return 0;
}
Exemplo n.º 23
0
Arquivo: mci.cpp Projeto: ufoderek/mvp
/* read registers of the MCI module */
bool MCI::read(uint32_t* data, uint32_t addr, int size)
{
    bool result = true;

    switch (addr) {
        case 0x0fe0:
            *data = 0x81;
            break;
        case 0x0fe4:
            *data = 0x11;
            break;
        case 0x0fe8:
            *data = 0x04;
            break;
        case 0x0fec:
            *data = 0x00;
            break;
        case 0x0ff0:
            *data = 0x0d;
            break;
        case 0x0ff4:
            *data = 0xf0;
            break;
        case 0x0ff8:
            *data = 0x05;
            break;
        case 0x0ffc:
            *data = 0xb1;
            break;
        default:
            printb(d_mci, "write unknown: 0x%.4x\n", addr);
            result = false;
            break;
    }

    return result;
}
Exemplo n.º 24
0
sr_type armv7a::decode_reg_shift(uint32_t type)
{
    sr_type shift_t;

    switch(type)
    {
        case B(00):
            shift_t = SRType_LSL;
            break;
        case B(01):
            shift_t = SRType_LSR;
            break;
        case B(10):
            shift_t = SRType_ASR;
            break;
        case B(11):
            shift_t = SRType_ROR;
            break;
        default:
            printb(d_armv7a_misc, "decode_reg_shift error");
    }

    return shift_t;
}
Exemplo n.º 25
0
Arquivo: pestr.c Projeto: Pr0teus/pev
int main(int argc, char *argv[])
{
	if (argc < 2) {
		usage();
		exit(EXIT_FAILURE);
	}

	options_t *options = parse_options(argc, argv); // opcoes

	const char *path = argv[argc-1];
	pe_ctx_t ctx;

	pe_err_e err = pe_load_file(&ctx, path);
	if (err != LIBPE_E_OK) {
		pe_error_print(stderr, err);
		return EXIT_FAILURE;
	}

	err = pe_parse(&ctx);
	if (err != LIBPE_E_OK) {
		pe_error_print(stderr, err);
		return EXIT_FAILURE;
	}

	if (!pe_is_pe(&ctx))
		EXIT_ERROR("not a valid PE file");

	const uint64_t pe_size = pe_filesize(&ctx);
	const uint8_t *pe_raw_data = ctx.map_addr;
	uint64_t pe_raw_offset = 0;

	unsigned char buff[LINE_BUFFER];
	memset(buff, 0, LINE_BUFFER);
	uint64_t buff_index = 0;

	uint32_t ascii = 0;
	uint32_t utf = 0;

	while (pe_raw_offset < pe_size) {
		const uint8_t byte = pe_raw_data[pe_raw_offset];

		if (isprint(byte)) {
			ascii++;
			buff[buff_index++] = byte;
			pe_raw_offset++;
			continue;
		} else if (ascii == 1 && byte == '\0') {
			utf++;
			buff[buff_index++] = byte;
			ascii = 0;
			pe_raw_offset++;
			continue;
		} else {
			if (ascii >= (options->strsize ? options->strsize : 4)) {
				printb(&ctx, options, buff, 0, ascii, pe_raw_offset - ascii);
			} else if (utf >= (options->strsize ? options->strsize : 4)) {
				printb(&ctx, options, buff, 0, utf*2, pe_raw_offset - utf*2);
			}
			ascii = utf = buff_index = 0;
			memset(buff, 0, LINE_BUFFER);
		}

		pe_raw_offset++;
	}

	// libera a memoria
	free_options(options);

	// free
	err = pe_unload(&ctx);
	if (err != LIBPE_E_OK) {
		pe_error_print(stderr, err);
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 26
0
/*
 * Print the status of the interface.  If an address family was
 * specified, show it and it only; otherwise, show them all.
 */
void
status(void)
{
	struct afswtch *p = NULL;
	char *mynext;
	struct if_msghdr *myifm;

	printf("%s: ", name);
	printb("flags", flags, IFFBITS);
	if (metric)
		printf(" metric %d", metric);
	if (mtu)
		printf(" mtu %d", mtu);
	putchar('\n');

	/*
	 * XXX: Sigh. This is bad, I know.  At this point, we may have
	 * *zero* RTM_NEWADDR's, so we have to "feel the water" before
	 * incrementing the loop.  One day, I might feel inspired enough
	 * to get the top level loop to pass a count down here so we
	 * dont have to mess with this.  -Peter
	 */
	myifm = ifm;

	while (1) {

		mynext = next + ifm->ifm_msglen;

		if (mynext >= lim)
			break;

		myifm = (struct if_msghdr *)mynext;

		if (myifm->ifm_type != RTM_NEWADDR)
			break;

		next = mynext;

		ifm = (struct if_msghdr *)next;

		ifam = (struct ifa_msghdr *)myifm;
		info.rti_addrs = ifam->ifam_addrs;

		/* Expand the compacted addresses */
		rt_xaddrs((char *)(ifam + 1), ifam->ifam_msglen + (char *)ifam,
			  &info);

		if (afp) {
			if (afp->af_af == info.rti_info[RTAX_IFA]->sa_family &&
			    afp->af_status != ether_status) {
				p = afp;
				if (p->af_status != ether_status)
					(*p->af_status)(1);
			}
		} else for (p = afs; p->af_name; p++) {
			if (p->af_af == info.rti_info[RTAX_IFA]->sa_family &&
			    p->af_status != ether_status)
				(*p->af_status)(0);
		}
	}
	if (afp == NULL || afp->af_status == ether_status)
		ether_status(0);
	else if (afp && !p) {
		warnx("%s has no %s IFA address!", name, afp->af_name);
	}

	phys_status(0);
}
Exemplo n.º 27
0
//finally here. Whew that's a lot of functions
int main(int argc,char* args[]) {
    srand(time(NULL));  	//spin the wheel!
    int i;                  //loop counter
    int frame=0;            //total frames past

    if(init()==false) return 1;
    if(prepAssets()==false) return 1;
    if(Mix_PlayMusic(muBGM,-1)==-1) return 1;

    //read and store the string of appropriate language
    FILE *pLang;
    char strLang[25];       //language string
    if((pLang=fopen("text/en.WhyCantIHoldAllTheseFileExtensions","r"))!=NULL) {
        if(fgets(strLang,25,pLang)==NULL) return 1;
    }
    fclose(pLang);
    sfMenuPrompt=TTF_RenderText_Blended(fnMenu,strLang,clMenu);

    //read and store current highscore
    FILE *pHighScoreR;
    char strHighScore[10];
    if((pHighScoreR=fopen("text/highscore.WhyCantIHoldAllTheseFileExtensions","r"))!=NULL) {
        if(fgets(strHighScore,10,pHighScoreR)==NULL) return 1;
    }
    fclose(pHighScoreR);
    sfHighScore=TTF_RenderText_Shaded(fnHighScore,strHighScore,clHighScore,clDefault);
    iHighScore=atoi(strHighScore);		//string contents as an int

    //menu runs here
    while(quitMenu==false) {
        //display menu
        printb(0,0,sfMenu,sfScreen);
        printb((SCREEN_WIDTH-sfMenuPrompt->w)/2,315,sfMenuPrompt,sfScreen);
        //menu-only key controls
        while(SDL_PollEvent(&event)) {
            if(event.type==SDL_KEYDOWN) {
                switch(event.key.keysym.sym) {
                case SDLK_RETURN:
                    quitMenu=true;
                    break;
                case SDLK_ESCAPE:
                    quitMenu=true;
                    quitGame=true;
                    quitOver=true;
                    quitAll=true;
                    break;
                default:
                    ;
                }
            }

            //if the window gets X'd
            if(event.type==SDL_QUIT) {
                quitMenu=true;          //quit the menu
                quitGame=true;          //skip the game
                quitOver=true;
                quitAll=true;
            }
        }

        //refresh the screen
        if(SDL_Flip(sfScreen)==-1) return 1;
    }

    //game is starting! set up everything!
    tmTime.start();
    tmFPS.start();
    tmFPSUpd.start();
    tmDelta.start();
    tmMusic.start();

    //REPLAY LOOP
    while(quitAll==false) {
        randBullets();
        //game runs here
        while(quitGame==false) {
            //once wave time is up: level up and restart wave timer
            //setup phase is active
            if(waveZero==true&&tmTime.getTicks()>10000) {
                iWave++;
                nextWave();
                tmTime.start();
                waveZero=false;
                newBGM();
                tmScore.start();
                tmTimeAlive.start();
            }
            //setup phase is off
            else if(tmTime.getTicks()>WAVE_LENGTH) {
                iWave++;
                nextWave();
                tmTime.start();
            }

            //change music after 90 seconds
            if(tmMusic.getTicks()>90000) {
                newBGM();
                tmMusic.start();
            }

            //score acceleration
            if(tmTimeAlive.getTicks()>30000) iScoreAccel=13;
            else if(tmTimeAlive.getTicks()>15000) iScoreAccel=6;
            else if(tmTimeAlive.getTicks()>7500) iScoreAccel=3;
            else if(tmTimeAlive.getTicks()>0) iScoreAccel=1;

            //score timing
            if(tmScore.getTicks()>250) {
                iScore+=iScoreAccel;
                tmScore.start();
            }

            //1up timing
            if(tmTimeAlive.getTicks()>45000) {
                tmTimeAlive.start();
                iLife++;

                //don't let player have too many lives
                //if 1up is allowed, play sound
                if(iLife>5)iLife=5;
                else if(Mix_PlayChannel(-1,chGain,0)==-1) return 1;
            }

            //while there's science to do
            while(SDL_PollEvent(&event)) {
                //ship controls
                myship.handleInput();

                //other controls
                if(event.type==SDL_KEYDOWN) {
                    switch(event.key.keysym.sym) {
                    case SDLK_ESCAPE:
                        quitGame=true;
                        quitOver=true;
                        quitAll=true;
                        break;
                    case SDLK_x:
                        if(useBomb()==false) return 1;
                        break;
                    default:
                        ;
                    }
                }

                //if the window gets X'd
                if(event.type == SDL_QUIT) {
                    quitGame = true;
                    quitOver=true;
                    quitAll=true;
                }
            }


            //update screen data
            myship.move(tmDelta.getTicks());    //update ship's position
            tmDelta.start();                    //restart change of time timer
            printb(0,0,sfBG,sfScreen);          //print background
            myship.show();                      //print position to screen
            if(diedRecently==true) printb(120,0,sfDeathOverlay,sfScreen,NULL);
            if(bombedRecently==true) printb(120,0,sfBombFlash,sfScreen,NULL);

            if(waveZero==true) {					//reset bullets to original when looping game
                printb(0,0,sfHowTo,sfScreen,NULL);
                iMaxBul=-1;
            }
            for(i=0; i<=iMaxBul; i++) {
                //player has died: do all relevant tracking
                if(isCol(myship.hitbox,b[i].hitbox)) {
                    iLife--;
                    iBomb=3;
                    iScore-=50;
                    if(iLife==0) quitGame=true;
                    diedRecently=true;
                    b[i].hitbox.x=rand()%420-120;
                    b[i].hitbox.y=0;
                    tmDeathOverlay.start();
                    tmTimeAlive.start();
                    if(Mix_PlayChannel(-1,chDeath,0)==-1) return 1;
                }

                if(b[i].hitbox.x>515) b[i].hitbox.x=120;
                if(b[i].hitbox.x<120) b[i].hitbox.x=515;        //compensate for bullet width
                if(b[i].hitbox.y>480) {                         //because collision is counted from sScore of the picture
                    b[i].hitbox.y=0;                            //so bulletwidth had to be subtracted
                    b[i].xVel=rand()%5-2;                      //bullet can travel left or right
                    b[i].yVel=rand()%4+1;                       //can only travel down
                }
                b[i].hitbox.y+=b[i].yVel;
                b[i].hitbox.x+=b[i].xVel;
                printb(b[i].hitbox.x,b[i].hitbox.y,sfBullet,sfScreen,NULL);
            }

            //expiry dates for death and bomb notifications
            if(tmDeathOverlay.getTicks()>500) diedRecently=false;
            if(tmBombFlash.getTicks()>250) bombedRecently=false;

            //display all stats
            renderHUD();
            printb(7,50,sfHighScore,sfScreen,NULL);

            //refresh the screen
            if(SDL_Flip(sfScreen)==-1) return 1;

            //limit the frame rate
            if(tmFPS.getTicks()<1000/FRAMES_PER_SECOND) {
                SDL_Delay((1000/FRAMES_PER_SECOND)-tmFPS.getTicks());
                tmFPS.start();
            }

            frame++;    //one frame has passed

            //update this once per second
            if(tmFPSUpd.getTicks()>1000) {
                std::stringstream newCaption;
                newCaption<<frame/(tmFPS.getTicks()/1000.f)<<" fps";
                SDL_WM_SetCaption(newCaption.str().c_str(),NULL);
                tmFPSUpd.start();         //restart for the next one-second wait
            }
        }

        //store new high score, if there is one
        if(iScore>iHighScore) {
            FILE *pHighScoreW;
            if((pHighScoreW=fopen("text/highscore.WhyCantIHoldAllTheseFileExtensions","w"))!=NULL) {
                if(fprintf(pHighScoreW,"%d",iScore)==0) return 1;
            }
            fclose(pHighScoreW);
            newHighScore=true;
        }

        //stop playing music
        Mix_HaltMusic();

        //game over runs here
        while(quitOver==false) {
            //some key events
            while(SDL_PollEvent(&event)) {
                if(event.type==SDL_KEYDOWN) {
                    switch(event.key.keysym.sym) {
                    case SDLK_RETURN:
                        quitOver=true;
                        break;
                    case SDLK_ESCAPE:
                        quitOver=true;
                        quitAll=true;
                        break;
                    default:
                        ;
                    }
                }

                //if the window gets X'd
                if(event.type == SDL_QUIT) {
                    quitOver=true;
                    quitAll=true;
                }
            }

            //end surfaces
            std::stringstream finalScore;
            finalScore<<iScore;
            sfScore=TTF_RenderText_Blended(fnFinalScore,finalScore.str().c_str(),clMenu);

            //display restart prompt
            FILE *pRestart;
            char strRestart[30];
            if((pRestart=fopen("text/enr.WhyCantIHoldAllTheseFileExtensions","r"))!=NULL) {
                if(fgets(strRestart,30,pRestart)==NULL) return 1;
            }
            fclose(pRestart);
            sfRestart=TTF_RenderText_Blended(fnMenu,strRestart,clScore);

            //print everything
            printb(0,0,sfOverBG,sfScreen,NULL);
            printb((SCREEN_WIDTH-sfRestart->w)/2,385,sfRestart,sfScreen,NULL);
            printb((SCREEN_WIDTH-sfScore->w)/2,240,sfScore,sfScreen,NULL);
            if(newHighScore==true)	printb(430,280,sfNewHigh,sfScreen,NULL);

            //refresh the screen
            if(SDL_Flip(sfScreen)==-1) return 1;

            SDL_WM_SetCaption("Shutengu!!",NULL);
        }

        //reset loop conditions to allow replaying
        resetGame();
    }
    //user has now quit
    cleanUp();

    return 0;
}
Exemplo n.º 28
0
static void
lagg_status(int s)
{
	struct lagg_protos lpr[] = LAGG_PROTOS;
	struct lagg_reqport rp, rpbuf[LAGG_MAX_PORTS];
	struct lagg_reqall ra;
	struct lagg_reqflags rf;
	struct lacp_opreq *lp;
	const char *proto = "<unknown>";
	bool isport = false;
	size_t i;

	bzero(&rp, sizeof(rp));
	bzero(&ra, sizeof(ra));

	strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
	strlcpy(rp.rp_portname, name, sizeof(rp.rp_portname));

	if (ioctl(s, SIOCGLAGGPORT, &rp) == 0)
		isport = true;

	strlcpy(ra.ra_ifname, name, sizeof(ra.ra_ifname));
	ra.ra_size = sizeof(rpbuf);
	ra.ra_port = rpbuf;

	strlcpy(rf.rf_ifname, name, sizeof(rf.rf_ifname));
	if (ioctl(s, SIOCGLAGGFLAGS, &rf) != 0)
		rf.rf_flags = 0;

	if (ioctl(s, SIOCGLAGG, &ra) == 0) {
		lp = (struct lacp_opreq *)&ra.ra_lacpreq;

		for (i = 0; i < nitems(lpr); i++) {
			if ((int)ra.ra_proto == lpr[i].lpr_proto) {
				proto = lpr[i].lpr_name;
				break;
			}
		}

		printf("\tlaggproto %s", proto);
		if (rf.rf_flags & LAGG_F_HASHMASK) {
			const char *sep = "";

			printf(" lagghash ");
			if (rf.rf_flags & LAGG_F_HASHL2) {
				printf("%sl2", sep);
				sep = ",";
			}
			if (rf.rf_flags & LAGG_F_HASHL3) {
				printf("%sl3", sep);
				sep = ",";
			}
			if (rf.rf_flags & LAGG_F_HASHL4) {
				printf("%sl4", sep);
				sep = ",";
			}
		}
		if (isport)
			printf(" laggdev %s", rp.rp_ifname);
		putchar('\n');
		if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
			printf("\tlag id: %s\n",
			    lacp_format_peer(lp, "\n\t\t "));

		for (i = 0; i < (size_t)ra.ra_ports; i++) {
			lp = (struct lacp_opreq *)&rpbuf[i].rp_lacpreq;
			printf("\tlaggport: %s ", rpbuf[i].rp_portname);
			printb("flags", rpbuf[i].rp_flags, LAGG_PORT_BITS);
			if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
				printf(" state=%X", lp->actor_state);
			putchar('\n');
			if (verbose && ra.ra_proto == LAGG_PROTO_LACP)
				printf("\t\t%s\n",
				    lacp_format_peer(lp, "\n\t\t "));
		}

		if (0 /* XXX */) {
			printf("\tsupported aggregation protocols:\n");
			for (i = 0; i < nitems(lpr); i++)
				printf("\t\tlaggproto %s\n", lpr[i].lpr_name);
		}
	}
}
Exemplo n.º 29
0
void armv7a::arm_smul(armv7a_ir& inst)
{
    printb(core_id, d_inst, "arm_smul not implemented yet.");
}
Exemplo n.º 30
0
int test_moves() {
	Board b;
	Move *moves;
	int status, num_moves, expected;
	status = WIN;

	/* on startup, there shouldn't be any king moves */
	setup(&b);
	moves = gen_moves(&b, &num_moves);
	expected = 20;
	if(num_moves != expected) {
		if(!QUIET) {
			if(to_play(&b) == WHITE)
				printf("\t>> WHITE to play, ");
			else
				printf("\t>> BLACK to play, ");
			printf("expected %d moves, but saw %d\n", expected, num_moves);
			printb(&b);
		}
		status = FAIL;
	}
	free(moves);
	
	/* try this config (black moves) */
	initf(&b, "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2");
	moves = gen_moves(&b, &num_moves);
	expected = 22;
	if(num_moves != expected) {
		if(!QUIET) {
			if(to_play(&b) == WHITE)
				printf("\t>> WHITE to play, ");
			else
				printf("\t>> BLACK to play, ");
			printf("expected %d moves, but saw %d\n", expected, num_moves);
			printb(&b);
		}
		status = FAIL;
	}
	free(moves);
	
	/* try this config (white moves) */
	initf(&b, "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2");
	set_play(&b, WHITE);
	moves = gen_moves(&b, &num_moves);
	expected = 13 + 7 + 1 + 1 + 5; /* pawns, knights, king, queen, bishop */
	if(num_moves != expected) {
		if(!QUIET) {
			if(to_play(&b) == WHITE)
				printf("\t>> WHITE to play, ");
			else
				printf("\t>> BLACK to play, ");
			printf("expected %d moves, but saw %d\n", expected, num_moves);
			printb(&b);
		}
		status = FAIL;
	}
	free(moves);
	
	/* here is one with only rook moves */
	initf(&b, "8/8/8/2r5/8/5R2/8/8 b KQkq - 1 2");
	moves = gen_moves(&b, &num_moves);
	expected = 14;
	if(num_moves != expected) {
		if(!QUIET) {
			if(to_play(&b) == WHITE)
				printf("\t>> WHITE to play, ");
			else
				printf("\t>> BLACK to play, ");
			printf("expected %d moves, but saw %d\n", expected, num_moves);
			printb(&b);
		}
		status = FAIL;
	}
	free(moves);
	
	/* here is one with only rook moves */
	initf(&b, "8/2p5/8/2r5/8/5R2/8/8 b KQkq - 1 2");
	moves = gen_moves(&b, &num_moves);
	expected = 13;
	if(num_moves != expected) {
		if(!QUIET) {
			if(to_play(&b) == WHITE)
				printf("\t>> WHITE to play, ");
			else
				printf("\t>> BLACK to play, ");
			printf("expected %d moves, but saw %d\n", expected, num_moves);
			printb(&b);
		}
		status = FAIL;
	}
	free(moves); 
	
	/* here is another one with only rook moves */
	initf(&b, "8/2p5/8/2rp4/8/5R2/8/8 b KQkq - 1 2");
	moves = gen_moves(&b, &num_moves);
	expected = 9;
	if(num_moves != expected) {
		if(!QUIET) {
			if(to_play(&b) == WHITE)
				printf("\t>> WHITE to play, ");
			else
				printf("\t>> BLACK to play, ");
			printf("expected %d moves, but saw %d\n", expected, num_moves);
			printb(&b);
		}
		status = FAIL;
	}
	free(moves);
	
	/* here is one last one with only rook moves */
	initf(&b, "8/2p5/8/2rp4/8/2p2R2/8/8 b KQkq - 1 2");
	moves = gen_moves(&b, &num_moves);
	expected = 7;
	if(num_moves != expected) {
		if(!QUIET) {
			if(to_play(&b) == WHITE)
				printf("\t>> WHITE to play, ");
			else
				printf("\t>> BLACK to play, ");
			printf("expected %d moves, but saw %d\n", expected, num_moves);
			printb(&b);
		}
		status = FAIL;
	}
	free(moves);
	
	/* and again for white... */
	initf(&b, "8/2p5/8/2rp4/8/2p2R2/8/8 w KQkq - 1 2");
	moves = gen_moves(&b, &num_moves);
	expected = 12;
	if(num_moves != expected) {
		if(!QUIET) {
			if(to_play(&b) == WHITE)
				printf("\t>> WHITE to play, ");
			else
				printf("\t>> BLACK to play, ");
			printf("expected %d moves, but saw %d\n", expected, num_moves);
			printb(&b);
		}
		status = FAIL;
	}
	free(moves);


	/* try to figure out bishop issue */
	initf(&b, "8/3/8/2B5/8/8/8/8 w KQkq - 1 2");
	moves = gen_moves(&b, &num_moves);
	expected = 11;
	if(num_moves != expected) {
		if(!QUIET) {
			if(to_play(&b) == WHITE)
				printf("\t>> WHITE to play, ");
			else
				printf("\t>> BLACK to play, ");
			printf("expected %d moves, but saw %d\n", expected, num_moves);
			printb(&b);
		}
		status = FAIL;
	}
	free(moves);
	
	return status;
}