Beispiel #1
0
void
cpu_node_setup(void)
{
    const char		*node_path = "sys/devices/system/node";
    pmInDom		cpus, nodes;
    unsigned int	cpu, node;
    struct dirent	**node_files = NULL;
    struct dirent	*cpu_entry;
    DIR			*cpu_dir;
    int			i, count;
    char		path[MAXPATHLEN];
    static int		setup;

    if (setup)
	return;
    setup = 1;

    nodes = INDOM(NODE_INDOM);
    cpus = INDOM(CPU_INDOM);
    setup_cpu_indom(cpus);

    snprintf(path, sizeof(path), "%s/%s", linux_statspath, node_path);
    count = scandir(path, &node_files, NULL, versionsort);
    if (!node_files || (linux_test_mode & LINUX_TEST_NCPUS)) {
	/* QA mode or no sysfs support, assume single NUMA node */
	node_add(nodes, 0);	/* default to just node zero */
	for (cpu = 0; cpu < _pm_ncpus; cpu++)
	    cpu_add(cpus, cpu, 0);	/* all in node zero */
	goto done;
    }

    for (i = 0; i < count; i++) {
	if (sscanf(node_files[i]->d_name, "node%u", &node) != 1)
	    continue;
	node_add(nodes, node);
	snprintf(path, sizeof(path), "%s/%s/%s",
		 linux_statspath, node_path, node_files[i]->d_name);
	if ((cpu_dir = opendir(path)) == NULL)
	    continue;
	while ((cpu_entry = readdir(cpu_dir)) != NULL) {
	    if (sscanf(cpu_entry->d_name, "cpu%u", &cpu) != 1)
		continue;
	    cpu_add(cpus, cpu, node);
	}
	closedir(cpu_dir);
    }

done:
    if (node_files) {
	for (i = 0; i < count; i++)
	    free(node_files[i]);
	free(node_files);
    }
}
Beispiel #2
0
Datei: apic.c Projekt: glguida/mh
void lapic_platform_done(void)
{
	int i;

	for (i = 0; i < lapics_no; i++)
		cpu_add(lapics[i].physid, lapics[i].platformid);
	/* Since we're here, configure LAPIC of BSP */
	lapic_configure();
}
Beispiel #3
0
static int
mptable_probe_cpus(void)
{
	int i, rc;

	for (i = 0; i < MAXCPU; i++) {
		rc = HYPERVISOR_vcpu_op(VCPUOP_is_up, i, NULL);
		if (rc >= 0)
			cpu_add(i, (i == 0));
	}

	return (0);
}
Beispiel #4
0
END_TEST

START_TEST (test_cpu_add)
{
    cpu_t cpu;

    cpu.A = 0;
    cpu_set_n(&cpu, true);
    cpu_set_z(&cpu, true);
    cpu_set_c(&cpu, true);
    cpu_set_h(&cpu, true);

    cpu_add(&cpu, 0xD);

    fail_unless(cpu.A == 0xD, "cpu_add failed, A = %d", cpu.A);
    fail_unless(!cpu_get_z(&cpu), "cpu_add set Z flag");
    fail_unless(!cpu_get_n(&cpu), "cpu_add failed to reset N flag");
    fail_unless(!cpu_get_c(&cpu));
    fail_unless(!cpu_get_h(&cpu));

    cpu_add(&cpu, 0x3);

    fail_unless(cpu.A == 0x10);
    fail_unless(!cpu_get_c(&cpu));
    fail_unless(cpu_get_h(&cpu));

    cpu_add(&cpu, 0xEF);

    fail_unless(cpu.A == 0xFF);
    fail_unless(!cpu_get_c(&cpu));
    fail_unless(!cpu_get_h(&cpu));

    cpu_add(&cpu, 1);

    fail_unless(cpu.A == 0);
    fail_unless(cpu_get_c(&cpu));
    fail_unless(cpu_get_h(&cpu));
}
Beispiel #5
0
/*
 * Create a local APIC instance.
 */
static void
native_lapic_create(u_int apic_id, int boot_cpu)
{
	int i;

	if (apic_id > MAX_APIC_ID) {
		printf("APIC: Ignoring local APIC with ID %d\n", apic_id);
		if (boot_cpu)
			panic("Can't ignore BSP");
		return;
	}
	KASSERT(!lapics[apic_id].la_present, ("duplicate local APIC %u",
	    apic_id));

	/*
	 * Assume no local LVT overrides and a cluster of 0 and
	 * intra-cluster ID of 0.
	 */
	lapics[apic_id].la_present = 1;
	lapics[apic_id].la_id = apic_id;
	for (i = 0; i <= APIC_LVT_MAX; i++) {
		lapics[apic_id].la_lvts[i] = lvts[i];
		lapics[apic_id].la_lvts[i].lvt_active = 0;
	}
	for (i = 0; i <= APIC_NUM_IOINTS; i++)
	    lapics[apic_id].la_ioint_irqs[i] = -1;
	lapics[apic_id].la_ioint_irqs[IDT_SYSCALL - APIC_IO_INTS] = IRQ_SYSCALL;
	lapics[apic_id].la_ioint_irqs[APIC_TIMER_INT - APIC_IO_INTS] =
	    IRQ_TIMER;
#ifdef KDTRACE_HOOKS
	lapics[apic_id].la_ioint_irqs[IDT_DTRACE_RET - APIC_IO_INTS] =
	    IRQ_DTRACE_RET;
#endif
#ifdef XENHVM
	lapics[apic_id].la_ioint_irqs[IDT_EVTCHN - APIC_IO_INTS] = IRQ_EVTCHN;
#endif


#ifdef SMP
	cpu_add(apic_id, boot_cpu);
#endif
}
Beispiel #6
0
static void
srat_parse_entry(ACPI_SUBTABLE_HEADER *entry, void *arg)
{
	ACPI_SRAT_CPU_AFFINITY *cpu;
	ACPI_SRAT_X2APIC_CPU_AFFINITY *x2apic;
	ACPI_SRAT_MEM_AFFINITY *mem;
	ACPI_SRAT_GICC_AFFINITY *gicc;
	static struct cpu_info *cpup;
	int domain, i, slot;

	switch (entry->Type) {
	case ACPI_SRAT_TYPE_CPU_AFFINITY:
		cpu = (ACPI_SRAT_CPU_AFFINITY *)entry;
		domain = cpu->ProximityDomainLo |
		    cpu->ProximityDomainHi[0] << 8 |
		    cpu->ProximityDomainHi[1] << 16 |
		    cpu->ProximityDomainHi[2] << 24;
		if (bootverbose)
			printf("SRAT: Found CPU APIC ID %u domain %d: %s\n",
			    cpu->ApicId, domain,
			    (cpu->Flags & ACPI_SRAT_CPU_ENABLED) ?
			    "enabled" : "disabled");
		if (!(cpu->Flags & ACPI_SRAT_CPU_ENABLED))
			break;
		cpup = cpu_find(cpu->ApicId);
		if (cpup != NULL) {
			printf("SRAT: Duplicate local APIC ID %u\n",
			    cpu->ApicId);
			*(int *)arg = ENXIO;
			break;
		}
		cpup = cpu_add(cpu->ApicId, domain);
		if (cpup == NULL)
			printf("SRAT: Ignoring local APIC ID %u (too high)\n",
			    cpu->ApicId);
		break;
	case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY:
		x2apic = (ACPI_SRAT_X2APIC_CPU_AFFINITY *)entry;
		if (bootverbose)
			printf("SRAT: Found CPU APIC ID %u domain %d: %s\n",
			    x2apic->ApicId, x2apic->ProximityDomain,
			    (x2apic->Flags & ACPI_SRAT_CPU_ENABLED) ?
			    "enabled" : "disabled");
		if (!(x2apic->Flags & ACPI_SRAT_CPU_ENABLED))
			break;
		KASSERT(cpu_find(x2apic->ApicId) == NULL,
		    ("Duplicate local APIC ID %u", x2apic->ApicId));
		cpup = cpu_add(x2apic->ApicId, x2apic->ProximityDomain);
		if (cpup == NULL)
			printf("SRAT: Ignoring local APIC ID %u (too high)\n",
			    x2apic->ApicId);
		break;
	case ACPI_SRAT_TYPE_GICC_AFFINITY:
		gicc = (ACPI_SRAT_GICC_AFFINITY *)entry;
		if (bootverbose)
			printf("SRAT: Found CPU UID %u domain %d: %s\n",
			    gicc->AcpiProcessorUid, gicc->ProximityDomain,
			    (gicc->Flags & ACPI_SRAT_GICC_ENABLED) ?
			    "enabled" : "disabled");
		if (!(gicc->Flags & ACPI_SRAT_GICC_ENABLED))
			break;
		KASSERT(cpu_find(gicc->AcpiProcessorUid) == NULL,
		    ("Duplicate CPU UID %u", gicc->AcpiProcessorUid));
		cpup = cpu_add(gicc->AcpiProcessorUid, gicc->ProximityDomain);
		if (cpup == NULL)
			printf("SRAT: Ignoring CPU UID %u (too high)\n",
			    gicc->AcpiProcessorUid);
		break;
	case ACPI_SRAT_TYPE_MEMORY_AFFINITY:
		mem = (ACPI_SRAT_MEM_AFFINITY *)entry;
		if (bootverbose)
			printf(
		    "SRAT: Found memory domain %d addr 0x%jx len 0x%jx: %s\n",
			    mem->ProximityDomain, (uintmax_t)mem->BaseAddress,
			    (uintmax_t)mem->Length,
			    (mem->Flags & ACPI_SRAT_MEM_ENABLED) ?
			    "enabled" : "disabled");
		if (!(mem->Flags & ACPI_SRAT_MEM_ENABLED))
			break;
		if (mem->BaseAddress >= maxphyaddr ||
		    !overlaps_phys_avail(mem->BaseAddress,
		    mem->BaseAddress + mem->Length)) {
			printf("SRAT: Ignoring memory at addr 0x%jx\n",
			    (uintmax_t)mem->BaseAddress);
			break;
		}
		if (num_mem == VM_PHYSSEG_MAX) {
			printf("SRAT: Too many memory regions\n");
			*(int *)arg = ENXIO;
			break;
		}
		slot = num_mem;
		for (i = 0; i < num_mem; i++) {
			if (mem_info[i].end <= mem->BaseAddress)
				continue;
			if (mem_info[i].start <
			    (mem->BaseAddress + mem->Length)) {
				printf("SRAT: Overlapping memory entries\n");
				*(int *)arg = ENXIO;
				return;
			}
			slot = i;
		}
		for (i = num_mem; i > slot; i--)
			mem_info[i] = mem_info[i - 1];
		mem_info[slot].start = mem->BaseAddress;
		mem_info[slot].end = mem->BaseAddress + mem->Length;
		mem_info[slot].domain = mem->ProximityDomain;
		num_mem++;
		break;
	}
}
Beispiel #7
0
int cpu_start(Cpu *cpu){
	cpu->run = 1;
	int ret_val = 0;
	while ((NPC < cpu->prog_len) && cpu->run){
		switch (cpu->firmware[NPC]){
			case push_num:
				cpu_push_num(cpu, cpu->firmware[NPC + 1]);
				NPC_INC(2);
				break;
			case pop:
				cpu_pop(cpu, cpu->firmware[NPC + 1]);
                            	if (p_errno){
					break;
				}
				NPC_INC(2);
				break;
			case push_reg:
				cpu_push_reg(cpu, cpu->firmware[NPC + 1]);
				NPC_INC(2);
				break;
			case add:
				cpu_add(cpu);
				if (p_errno){
                                        break;
                                }
				NPC_INC(1);
				break;
			case mul:
				cpu_mul(cpu);
                                if (p_errno){
                                        break;
                                }
				NPC_INC(1);
                                break;
			case sub:
                                cpu_sub(cpu);
                                if (p_errno){
                                        break;
                                }
				NPC_INC(1);
                                break;
			case divide:
                                cpu_div(cpu);
                                if (p_errno){
                                        break;
                                }
				NPC_INC(1);
                                break;
			case tr:
				cpu_tr(cpu, cpu->firmware[NPC + 1]);
				break;
			case trip:
				cpu_trip(cpu, cpu->firmware[NPC + 1]);
				break;
			case trin:
                                cpu_trin(cpu, cpu->firmware[NPC + 1]);
                                break;
			case triz:
                                cpu_triz(cpu, cpu->firmware[NPC + 1]);
                                break;
			case gsp:
				cpu_gsp(cpu, cpu->firmware[NPC + 1]);
				NPC_INC(2);
				break;
			case ssp:
				cpu_ssp(cpu, cpu->firmware[NPC + 1]);
				NPC_INC(2);
				break;
			case syscall:
				cpu_syscall(cpu, &ret_val);
				NPC_INC(1);
				break;
			case out:
				cpu_out(cpu);
				NPC_INC(1);
				break; 
			default:
				NPC_INC(1);

		}
	if (p_errno){
		printf("\nError at %d", NPC);
		return 1;
	}
	}
	cpu->run = 0;
	return ret_val;
}
Beispiel #8
0
void cpu_add_carry(cpu_t* cpu, unsigned int n) {
    cpu_add(cpu, n += cpu_get_c(cpu));
}
Beispiel #9
0
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);
	}
}
Beispiel #10
0
/**
    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;
}