コード例 #1
0
ファイル: CPU.cpp プロジェクト: ivanychev/iLab_firstcourse
int cpu_ctor(cpu_t** _this, int length, char* addr)
{
    int __errnum = 0;
    cpu_t* cpu = (cpu_t*) calloc(sizeof(cpu_t), 1);

    ISNOTNULL(cpu);
    assert(length > 0);

    __errnum = stack_Ctor(&(cpu->stk), length);

    __errnum = stack_Ctor(&(cpu->call), MAX_CALL_STACK_LEN);


    if (__errnum)
        {
            errlog(__errnum, __FILE__, __LINE__);
            cpu_dump(*_this);
            return __errnum;
        }

    cpu->ax = 0.0;
    cpu->bx = 0.0;
    cpu->cx = 0.0;
    cpu->dx = 0.0;
    cpu->addr = addr;

    *_this = cpu;

    return 0;
}
コード例 #2
0
void cpu_refresh()
{
    memcpy(&pre_cpu, &cur_cpu, sizeof(cur_cpu));

    cpu_dump();

    return;
}
コード例 #3
0
void cpu_init()
{
	// get uptime
	long uptime = 0;
	FILE *uptime_file = fopen("/proc/uptime", "r");

	if(!uptime_file)
		uptime =0;
	else
	{
		fscanf(uptime_file, "%lu.%*lu", &uptime);
		fclose(uptime_file);
	}
	time_t cur_time = time(0);

	boot_time = cur_time - uptime;

	cpu_dump();
	return;
}
コード例 #4
0
ファイル: stubs.c プロジェクト: lacombar/netbsd-alc
void
dodumpsys()
{
	const struct bdevsw *bdev;
	daddr_t blkno;
	int psize;
	int error;
	int addr;
	int block;
	int len;
	vaddr_t dumpspace;

	/* flush everything out of caches */
	cpu_dcache_wbinv_all();

	if (dumpdev == NODEV)
		return;
	if (dumpsize == 0) {
		cpu_dumpconf();
	}
	if (dumplo <= 0 || dumpsize == 0) {
		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
		    minor(dumpdev));
		delay(5000000);
		return;
	}
	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
	    minor(dumpdev), dumplo);


	bdev = bdevsw_lookup(dumpdev);
	if (bdev == NULL || bdev->d_psize == NULL)
		return;
	psize = (*bdev->d_psize)(dumpdev);
	printf("dump ");
	if (psize == -1) {
		printf("area unavailable\n");
		return;
	}

	if ((error = cpu_dump()) != 0)
		goto err;

	blkno = dumplo + cpu_dumpsize();
	dumpspace = memhook;
	error = 0;
	len = 0;

	for (block = 0; block < bootconfig.dramblocks && error == 0; ++block) {
		addr = bootconfig.dram[block].address;
		for (;addr < (bootconfig.dram[block].address
		    + (bootconfig.dram[block].pages * PAGE_SIZE));
		     addr += PAGE_SIZE) {
		    	if ((len % (1024*1024)) == 0)
		    		printf("%d ", len / (1024*1024));

			pmap_kenter_pa(dumpspace, addr, VM_PROT_READ);
			pmap_update(pmap_kernel());
			error = (*bdev->d_dump)(dumpdev,
			    blkno, (void *) dumpspace, PAGE_SIZE);

			if (error) goto err;
			blkno += btodb(PAGE_SIZE);
			len += PAGE_SIZE;
		}
	}
err:
	switch (error) {
	case ENXIO:
		printf("device bad\n");
		break;

	case EFAULT:
		printf("device not ready\n");
		break;

	case EINVAL:
		printf("area improper\n");
		break;

	case EIO:
		printf("i/o error\n");
		break;

	case EINTR:
		printf("aborted from console\n");
		break;

	case 0:
		printf("succeeded\n");
		break;

	default:
		printf("error %d\n", error);
		break;
	}
	printf("\n\n");
	delay(5000000);
}
コード例 #5
0
ファイル: machdep.c プロジェクト: avsm/openbsd-xen-sys
void
dumpsys(void)
{
	u_long totalbytesleft, bytes, i, n, memseg;
	u_long maddr;
	daddr_t blkno;
	int (*dump)(dev_t, daddr_t, caddr_t, size_t);
	int error;

	/* Save registers. */
	savectx(&dumppcb);

	if (dumpdev == NODEV)
		return;

	/*
	 * For dumps during autoconfiguration,
	 * if dump device has already configured...
	 */
	if (dumpsize == 0)
		dumpconf();
	if (dumplo <= 0 || dumpsize == 0) {
		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
		    minor(dumpdev));
		return;
	}
	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
	    minor(dumpdev), dumplo);

	error = (*bdevsw[major(dumpdev)].d_psize)(dumpdev);
	printf("dump ");
	if (error == -1) {
		printf("area unavailable\n");
		return;
	}

	if ((error = cpu_dump()) != 0)
		goto err;

	totalbytesleft = ptoa(cpu_dump_mempagecnt());
	blkno = dumplo + cpu_dumpsize();
	dump = bdevsw[major(dumpdev)].d_dump;
	error = 0;

	for (memseg = 0; memseg < mem_cluster_cnt; memseg++) {
		maddr = mem_clusters[memseg].start;
		bytes = mem_clusters[memseg].size;

		for (i = 0; i < bytes; i += n, totalbytesleft -= n) {
			/* Print out how many MBs we have left to go. */
			if ((totalbytesleft % (1024*1024)) == 0)
				printf("%ld ", totalbytesleft / (1024 * 1024));

			/* Limit size for next transfer. */
			n = bytes - i;
			if (n > BYTES_PER_DUMP)
				n = BYTES_PER_DUMP;

			(void) pmap_map(dumpspace, maddr, maddr + n,
			    VM_PROT_READ);

			error = (*dump)(dumpdev, blkno, (caddr_t)dumpspace, n);
			if (error)
				goto err;
			maddr += n;
			blkno += btodb(n);		/* XXX? */

#if 0	/* XXX this doesn't work.  grr. */
			/* operator aborting dump? */
			if (sget() != NULL) {
				error = EINTR;
				break;
			}
#endif
		}
	}

 err:
	switch (error) {

	case ENXIO:
		printf("device bad\n");
		break;

	case EFAULT:
		printf("device not ready\n");
		break;

	case EINVAL:
		printf("area improper\n");
		break;

	case EIO:
		printf("i/o error\n");
		break;

	case EINTR:
		printf("aborted from console\n");
		break;

	case 0:
		printf("succeeded\n");
		break;

	default:
		printf("error %d\n", error);
		break;
	}
	printf("\n\n");
	delay(5000000);		/* 5 seconds */
}
コード例 #6
0
ファイル: sh_machdep.c プロジェクト: alenichev/openbsd-kernel
void
dumpsys()
{
	cpu_kcore_hdr_t *h = &cpu_kcore_hdr;
	daddr64_t blkno;
	int (*dump)(dev_t, daddr64_t, caddr_t, size_t);
	u_int page = 0;
	paddr_t dumppa;
	u_int seg;
	int rc;
	extern int msgbufmapped;

	/* Don't record dump messages in msgbuf. */
	msgbufmapped = 0;

	/* Make sure dump settings are valid. */
	if (dumpdev == NODEV)
		return;
	if (dumpsize == 0) {
		dumpconf();
		if (dumpsize == 0)
			return;
	}
	if (dumplo <= 0) {
		printf("\ndump to dev 0x%x not possible, not enough space\n",
		    dumpdev);
		return;
	}

	dump = bdevsw[major(dumpdev)].d_dump;
	blkno = dumplo;

	printf("\ndumping to dev 0x%x offset %ld\n", dumpdev, dumplo);

#ifdef UVM_SWAP_ENCRYPT
	uvm_swap_finicrypt_all();
#endif

	printf("dump ");

	/* Write dump header */
	rc = cpu_dump(dump, &blkno);
	if (rc != 0)
		goto bad;

	for (seg = 0; seg < h->kcore_nsegs; seg++) {
		u_int pagesleft;

		pagesleft = atop(h->kcore_segs[seg].size);
		dumppa = (paddr_t)h->kcore_segs[seg].start;

		while (pagesleft != 0) {
			u_int npages;

#define	NPGMB	atop(1024 * 1024)
			if (page != 0 && (page % NPGMB) == 0)
				printf("%u ", page / NPGMB);

			/* do not dump more than 1MB at once */
			npages = min(pagesleft, NPGMB);
#undef NPGMB
			npages = min(npages, dumpsize);

			rc = (*dump)(dumpdev, blkno,
			    (caddr_t)SH3_PHYS_TO_P2SEG(dumppa), ptoa(npages));
			if (rc != 0)
				goto bad;

			pagesleft -= npages;
			dumppa += ptoa(npages);
			page += npages;
			dumpsize -= npages;
			if (dumpsize == 0)
				goto bad;	/* if truncated dump */
			blkno += ctod(npages);
		}
	}
bad:
	switch (rc) {
	case 0:
		printf("succeeded\n");
		break;
	case ENXIO:
		printf("device bad\n");
		break;
	case EFAULT:
		printf("device not ready\n");
		break;
	case EINVAL:
		printf("area improper\n");
		break;
	case EIO:
		printf("I/O error\n");
		break;
	case EINTR:
		printf("aborted\n");
		break;
	default:
		printf("error %d\n", rc);
		break;
	}

	/* make sure console can output our last message */
	delay(1 * 1000 * 1000);
}
コード例 #7
0
ファイル: emulator.c プロジェクト: reyheaven/PiEmu
/**
 * Prints out the state of the emulator
 *
 * @param emu Reference to the emulator structure
 */
void
emulator_dump(emulator_t* emu)
{
  cpu_dump(&emu->cpu);
  memory_dump(&emu->memory);
}
コード例 #8
0
ファイル: command_get.cpp プロジェクト: ivanychev/learning
int calculator(FILE* strin, FILE* strout, cpu* my_cpu)
{
	VERIFY(my_cpu != NULL);
	const char MAXLINE = 10;
	char word[MAXLINE] = {};
	const char PUSH_MAXLINE = 50;
	char push_word[PUSH_MAXLINE] = {};
	int c = 0;

	double temp = 0;
	int cond = 0;
	
	fprintf(stdout,	"# This is prototype of processor unit which calculates expressions\n"
				"# written in inverted Polish way (or something like that)\n"
				"# There are commands available:\n"
				"\n push {number}\n"
				" pop\n"
				" add\n"
				" sub\n"
				" mul\n"
				" div\n"
				" sin\n"
				" cos\n"
				" tan\n"
				" sqrt\n"
				" pow\n"
				" end\n"
				"PLEASE, USE [.] TO DIVIDE FLOAT PART\n"
				"Here you go\n");

	while (true)
	{
		cond = cpu_check(my_cpu);
		VERIFY(cond == CPU_CHECK_OK);
		
		fscanf(strin,"%s", &word);

		c = CHECK_COMMAND(word, PUSH)
			CHECK_COMMAND(word, POP)
			CHECK_COMMAND(word, ADD)
			CHECK_COMMAND(word, SUB)
			CHECK_COMMAND(word, MUL)
			CHECK_COMMAND(word, DIV)
			CHECK_COMMAND(word, SIN)
			CHECK_COMMAND(word, COS)
			CHECK_COMMAND(word, TAN)
			CHECK_COMMAND(word, SQRT)
			CHECK_COMMAND(word, POW)
			CHECK_COMMAND(word, END)
			CHECK_COMMAND(word, DUMP)
			CMD_NONE;

		switch (c)
		{
		case CMD_PUSH:
			cond = fscanf(strin, "%s", push_word);
			VERIFY(cond);
			cond = cpu_catch_error(strout, my_cpu, cpu_push(my_cpu, push_word));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			if (cond == CPU_ERROR_PUSH_BAD_TOKEN) 
			{
				fprintf(strout, "\nPUSH BAD TOKEN [%s]\n", push_word);
				break;
			}

			break;
		case CMD_POP:
			cond = cpu_catch_error(strout, my_cpu, cpu_pop(strout, my_cpu, &temp));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_ADD:
			cond = cpu_catch_error(strout, my_cpu, cpu_add(my_cpu));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_SUB:
			cond = cpu_catch_error(strout, my_cpu, cpu_sub(my_cpu));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_MUL:
			cond = cpu_catch_error(strout, my_cpu, cpu_mul(my_cpu));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_DIV:
			cond = cpu_catch_error(strout, my_cpu, cpu_div(my_cpu));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_SIN:
			cond = cpu_catch_error(strout, my_cpu, cpu_sin(my_cpu));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_COS:
			cond = cpu_catch_error(strout, my_cpu, cpu_cos(my_cpu));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_TAN:
			cond = cpu_catch_error(strout, my_cpu, cpu_tan(my_cpu));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_SQRT:
			cond = cpu_catch_error(strout, my_cpu, cpu_sqrt(my_cpu));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_POW:
			cond = cpu_catch_error(strout, my_cpu, cpu_pow(my_cpu));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_DUMP:
			cond = cpu_catch_error(strout, my_cpu, cpu_dump(strout, my_cpu));
			//if (cond == CPU_ERROR_CATCHER_BAD) VERIFY(!"ERROR HAS BEEN CAUGHT");
			break;
		case CMD_END:
			return 0;
		default:
			fprintf(strout, "WRONG TOKEN [%s]\n", word);
			break;
		}
		cond = cpu_check(my_cpu);
		VERIFY(cond == CPU_CHECK_OK);
	}
}
コード例 #9
0
ファイル: CPU.cpp プロジェクト: ivanychev/iLab_firstcourse
/**
    This function exec byte code of instructions

    @param      code  array of byte code

    @return number of error(0 if no error)
*/
int cpu_run(char* addr_code)
{
    assert(addr_code);

    cpu_t* cpu = NULL;

    cpu_ctor(&cpu, CPU_STACK_MAX, addr_code);

    char* current_byte = addr_code;

    start_logging("logs.txt");


    while(FOREVER)
    {
        int cmd = *current_byte;
        current_byte++;

        //printf("%d \n",cmd);

        switch(cmd)
        {
        case PUSH:
            if(cpu_push(cpu, &current_byte)) printf("CPU CRASHED! PUSH HAVEN'T FULFILLED");
            break;

        case POP:
            if(cpu_pop(cpu, &current_byte)) printf("CPU CRASHED! POP HAVEN'T FULFILLED");
            break;

        case OK:
            if(cpu_ok(cpu)) printf("CPU CRASHED! CPU ISN'T OK");
            break;

        case DUMP:
            if(cpu_dump(cpu)) printf("CPU CRASHED! DUMP HAVEN'T FULFILLED");
            break;

        case ADD:
            if(cpu_add(cpu)) printf("CPU CRASHED! ADD HAVEN'T FULFILLED");
            break;

        case SUB:
            if(cpu_sub(cpu)) printf("CPU CRASHED! SUB HAVEN'T FULFILLED");
            break;

        case MUL:
            if(cpu_mul(cpu)) printf("CPU CRASHED! MUL HAVEN'T FULFILLED");
            break;

        case DIR:
            if(cpu_dir(cpu)) printf("CPU CRASHED! DIR HAVEN'T FULFILLED");
            break;

        case SIN:
            if(cpu_sin(cpu)) printf("CPU CRASHED! SIN HAVEN'T FULFILLED");
            break;

        case COS:
            if(cpu_cos(cpu)) printf("CPU CRASHED! COS HAVEN'T FULFILLED");
            break;

        case SQRT:
            if(cpu_sqrt(cpu)) printf("CPU CRASHED! SQRT HAVEN'T FULFILLED");
            break;

        case JA:
            if(cpu_ja(cpu, &current_byte)) printf("CPU CRASHED! JA HAVEN'T FULFILLED");
            break;

        case JAE:
            if(cpu_jae(cpu, &current_byte)) printf("CPU CRASHED! JAE HAVEN'T FULFILLED");
            break;

        case JB:
            if(cpu_jb(cpu, &current_byte)) printf("CPU CRASHED! JB HAVEN'T FULFILLED");
            break;

        case JBE:
            if(cpu_jbe(cpu, &current_byte)) printf("CPU CRASHED! JBE HAVEN'T FULFILLED");
            break;

        case JE:
            if(cpu_je(cpu, &current_byte)) printf("CPU CRASHED! JE HAVEN'T FULFILLED");
            break;

        case JNE:
            if(cpu_jne(cpu, &current_byte)) printf("CPU CRASHED! JNE HAVEN'T FULFILLED");
            break;

        case JMP:
            if(cpu_jmp(cpu, &current_byte)) printf("CPU CRASHED! JMP HAVEN'T FULFILLED");
            break;

        case OUT:
            if(cpu_out(cpu)) printf("CPU CRASHED! OUT HAVEN'T FULFILLED");
            break;

        case MOV:
            if(cpu_mov(cpu, &current_byte)) printf("CPU CRASHED! MOV HAVEN'T FULFILLED");
            break;

        case INC:
            if(cpu_inc(cpu, &current_byte)) printf("CPU CRASHED! INC HAVEN'T FULFILLED");
            break;

        case DEC:
            if(cpu_dec(cpu, &current_byte)) printf("CPU CRASHED! DEC HAVEN'T FULFILLED");
            break;

        case CALL:
            if(cpu_call(cpu, &current_byte)) printf("CPU CRASHED! CALL HAVEN'T FULFILLED");
            break;

        case RET:
            if(cpu_ret(cpu, &current_byte)) printf("CPU CRASHED! RET HAVEN'T FULFILLED");
            break;

        case END:
            return 0;
            break;
        default:
        {
            fprintf(stderr, "ERROR! Unknown command at address %o. \n", (int)current_byte);
            return 1;
        }

        }

    }
    return 0;
}
コード例 #10
0
ファイル: dumpsys.c プロジェクト: lacombar/netbsd-alc
void
dodumpsys(void)
{
	const struct bdevsw *bdev;
	int dumpend, psize;
	int error;

	if (dumpdev == NODEV)
		return;

	bdev = bdevsw_lookup(dumpdev);
	if (bdev == NULL || bdev->d_psize == NULL)
		return;

	/*
	 * For dumps during autoconfiguration,
	 * if dump device has already configured...
	 */
	if (dumpsize == 0)
		cpu_dumpconf();
	if (dumplo <= 0 || dumpsize == 0) {
		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
		    minor(dumpdev));
		return;
	}
	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
	    minor(dumpdev), dumplo);

	psize = (*bdev->d_psize)(dumpdev);
	printf("dump ");
	if (psize == -1) {
		printf("area unavailable\n");
		return;
	}

#if 0	/* XXX this doesn't work.  grr. */
	/* toss any characters present prior to dump */
	while (sget() != NULL); /*syscons and pccons differ */
#endif

	dump_seg_prep();
	dumpend = dumplo + btodb(dump_header_size) + ctod(dump_npages);
	if (dumpend > psize) {
		printf("failed: insufficient space (%d < %d)\n",
		    psize, dumpend);
		goto failed;
	}

	dump_header_start();
	if ((error = cpu_dump()) != 0)
		goto err;
	if ((error = dump_header_finish()) != 0)
		goto err;

	if (dump_header_blkno != dumplo + btodb(dump_header_size)) {
		printf("BAD header size (%ld [written] != %ld [expected])\n",
		    (long)(dump_header_blkno - dumplo),
		    (long)btodb(dump_header_size));
		goto failed;
	}

	dump_totalbytesleft = roundup(ptoa(dump_npages), BYTES_PER_DUMP);
	error = dump_seg_iter(dumpsys_seg);

	if (error == 0 && dump_header_blkno != dumpend) {
		printf("BAD dump size (%ld [written] != %ld [expected])\n",
		    (long)(dumpend - dumplo),
		    (long)(dump_header_blkno - dumplo));
		goto failed;
	}

 err:
	switch (error) {

	case ENXIO:
		printf("device bad\n");
		break;

	case EFAULT:
		printf("device not ready\n");
		break;

	case EINVAL:
		printf("area improper\n");
		break;

	case EIO:
		printf("i/o error\n");
		break;

	case EINTR:
		printf("aborted from console\n");
		break;

	case 0:
		printf("succeeded\n");
		break;

	default:
		printf("error %d\n", error);
		break;
	}
failed:
	printf("\n\n");
	delay(5000000);		/* 5 seconds */
}