int main(int argc, const char* argv[]) { printf("[BEGIN] NSCreateObjectFileImageFromMemory-basic\n"); checkBundle(argv[1], true); checkBundle(argv[1], false); // Now go again enough times to flush out any limits in our dlopen encodings. for (unsigned i = 0; i != 255; ++i) checkBundle(argv[1], false); printf("[PASS] NSCreateObjectFileImageFromMemory-basic\n"); return 0; }
int main(int argc, char *argv[]) { unsigned i, j, k; systemConfig *SYS; contextConfig *CNT; hyperContextConfig *HCNT; /*clusterTemplateConfig *CLUT;*/ systemT *system; contextT *context; hyperContextT *hypercontext; /*clusterT *cluster;*/ /*unsigned *tempP, clust;*/ unsigned bundleCount; unsigned long long *bundleCountP; /*unsigned curClustTemplate, curClustInstance;*/ /*unsigned sGPROffset, sFPROffset, sVROffset, sPROffset;*/ /* signal catch (SIGSEGV and SIGUSR1) */ pid_t pid; struct sigaction sigusr1_action; sigset_t block_mask; unsigned int STACK_SIZE_ARG = 0; isLLVM = 0; cycleCount = 0; char *versionNumber = "Insizzle_Revision"; similarIRAM = 0; suppressOOB = 1; STACK_SIZE = 8; /* Default stack size to 8 KiB */ PRINT_OUT = 0; SINGLE_STEP = 0; STAGGER = 0; printf("Insizzle (%s)\n", versionNumber); /* signal catch (SIGSEGV and SIGUSR1) */ if((pid = getpid()) >= 0) { printf("PID: %d\n", pid); printf("(send SIGUSR1 signal to produce state dump)\n"); } signal(SIGSEGV, sigsegv_debug); sigfillset(&block_mask); sigusr1_action.sa_handler = sigusr1_debug; sigusr1_action.sa_mask = block_mask; sigusr1_action.sa_flags = 0; sigaction(SIGUSR1, &sigusr1_action, NULL); #ifndef INSIZZLEAPI if(argc < 2) { printf("you need to specify an xml machine model file\n"); return -1; } if(readConf(argv[1]) == -1) { printf("error reading config\n"); return -1; } /* all setup perfomed reset rand() */ srand(1); printf("Galaxy setup completed.\n"); /* for each other argv */ for(i=2;i<(unsigned)argc;i++) { if(!strncmp(argv[i], "-similarIRAM", 12)) { similarIRAM = 1; } else if(!strncmp(argv[i], "-suppressOOB", 12)) { suppressOOB = 1; } else if(!strncmp(argv[i], "-stack", 6)) { STACK_SIZE_ARG = atoi(argv[++i]); } else if(!strncmp(argv[i], "-printout", 9)) { PRINT_OUT = 1; } else if(!strncmp(argv[i], "-singlestep", 11)) { SINGLE_STEP = 1; } else if(!strncmp(argv[i], "-stagger", 8)) { STAGGER = atoi(argv[++i]); } else if(!strncmp(argv[i], "-calls_list", 11)) { /* setup calls list */ callsList = NULL; if(setupCallsList(argv[i+1]) != 0) { return -1; } i++; } else if(!strncmp(argv[i], "-llvm", 5)) { isLLVM = 1; } else { printf("Unknown argument: %s\n", argv[i]); } } /* call config to setup the galaxy */ if(setupGalaxy() == -1) { printf("error setting up galaxy\n"); return -1; } /* then run through like we do */ /* for each system for each context for each hypercontext */ SYS = (systemConfig *)((size_t)SYSTEM + (0 * sizeof(systemConfig))); system = (systemT *)((size_t)galaxyT + (0 * sizeof(systemT))); context = (contextT *)((size_t)system->context + (0 * sizeof(contextT))); /* check stack size */ if((SYS->STACK_SIZE == 0) && (STACK_SIZE_ARG == 0)) { /* this means it isn't set in the XML file or command line */ printf("Using default Stack Size / hypercontext of %d KiB\n", STACK_SIZE); } else if(STACK_SIZE_ARG != 0){ /* set at command line, this overrides others */ printf("Using Stack Size / hypercontext of %d KiB\n", STACK_SIZE_ARG); if(STACK_SIZE_ARG != SYS->STACK_SIZE) { printf("\tThis is different from Stack Size set in XML config file\n"); } STACK_SIZE = STACK_SIZE_ARG; } else if(SYS->STACK_SIZE != 0) { /* set in XML */ printf("Using Stack Size / hypercontext of %d KiB\n", SYS->STACK_SIZE); STACK_SIZE = SYS->STACK_SIZE; } #ifdef VTHREAD /* need to set single hypercontext to active c 0 hc 0 */ for(i=0;i<(GALAXY_CONFIG & 0xff);i++) { SYS = (systemConfig *)((size_t)SYSTEM + (i * sizeof(systemConfig))); system = (systemT *)((size_t)galaxyT + (i * sizeof(systemT))); /* loop through contexts */ #if 0 for(j=0;j<(SYS->SYSTEM_CONFIG & 0xff);j++) { context = (contextT *)((size_t)system->context + (j * sizeof(contextT))); hypercontext = (hyperContextT *)((size_t)context->hypercontext + (0 * sizeof(hyperContextT))); hypercontext->VT_CTRL |= RUNNING << 3; } #else context = (contextT *)((size_t)system->context + (0 * sizeof(contextT))); hypercontext = (hyperContextT *)((size_t)context->hypercontext + (0 * sizeof(hyperContextT))); hypercontext->VT_CTRL |= RUNNING << 3; #endif } /* Initialise ThreadControlUnit */ ThreadControlUnit.status = 0; #endif int totalHC = 0; /* loop through systems in the galaxy */ for(i=0;i<(GALAXY_CONFIG & 0xff);i++) { SYS = (systemConfig *)((size_t)SYSTEM + (i * sizeof(systemConfig))); system = (systemT *)((size_t)galaxyT + (i * sizeof(systemT))); /*printf("dram_size: 0x%x\n", (((SYS->DRAM_SHARED_CONFIG >> 8) & 0xffff) * 1024));*/ /* loop through contexts */ for(j=0;j<(SYS->SYSTEM_CONFIG & 0xff);j++) { CNT = (contextConfig *)((size_t)SYS->CONTEXT + (j * sizeof(contextConfig))); context = (contextT *)((size_t)system->context + (j * sizeof(contextT))); /* loop through hypercontexts */ for(k=0;k<((CNT->CONTEXT_CONFIG >> 4) & 0xf);k++) { HCNT = (hyperContextConfig *)((size_t)CNT->HCONTEXT + (k * sizeof(hyperContextConfig))); hypercontext = (hyperContextT *)((size_t)context->hypercontext + (k * sizeof(hyperContextT))); /*printf("hypercontext: %d\n", k);*/ hypercontext->initialStackPointer = (((SYS->DRAM_SHARED_CONFIG >> 8) & 0xffff) * 1024) - ((STACK_SIZE * 1024) * totalHC); *(hypercontext->S_GPR + (size_t)1) = ((((SYS->DRAM_SHARED_CONFIG >> 8) & 0xffff) * 1024) - 256) - ((STACK_SIZE * 1024) * totalHC); *(hypercontext->pS_GPR + (size_t)1) = ((((SYS->DRAM_SHARED_CONFIG >> 8) & 0xffff) * 1024) - 256) - ((STACK_SIZE * 1024) * totalHC); /*printf("\tr1: 0x%x\n", *(hypercontext->S_GPR + (unsigned)1));*/ /*printf("\tr1: 0x%x\n", *(hypercontext->pS_GPR + (unsigned)1));*/ totalHC++; } } } #endif start = time(NULL); #endif #ifdef INSIZZLEAPI int insizzleAPIClock(galaxyConfigT *galaxyConfig, hcTracePacketT gTracePacket[][MASTERCFG_CONTEXTS_MAX][MASTERCFG_HYPERCONTEXTS_MAX]) { unsigned i, j, k; systemConfig *SYS; contextConfig *CNT; hyperContextConfig *HCNT; /*clusterTemplateConfig *CLUT;*/ systemT *system; contextT *context; hyperContextT *hypercontext; unsigned bundleCount; unsigned long long *bundleCountP; unsigned bundlePos; #else while(checkActive()) { if(PRINT_OUT) { printf("------------------------------------------------------------ end of cycle %lld\n", cycleCount); } #endif #ifdef INSDEBUG printf("galaxy: 0\n"); #endif /* loop through systems in the galaxy */ for(i=0;i<(GALAXY_CONFIG & 0xff);i++) { #ifdef INSDEBUG printf("\tsystem: %d\n", i); #endif SYS = (systemConfig *)((size_t)SYSTEM + (i * sizeof(systemConfig))); system = (systemT *)((size_t)galaxyT + (i * sizeof(systemT))); /* loop through contexts */ for(j=0;j<(SYS->SYSTEM_CONFIG & 0xff);j++) { #ifdef INSDEBUG printf("\t\tcontext: %d\n", j); #endif CNT = (contextConfig *)((size_t)SYS->CONTEXT + (j * sizeof(contextConfig))); context = (contextT *)((size_t)system->context + (j * sizeof(contextT))); /* loop through hypercontexts */ for(k=0;k<((CNT->CONTEXT_CONFIG >> 4) & 0xf);k++) { #ifdef INSDEBUG printf("\t\t\thypercontext: %d\n", k); #endif HCNT = (hyperContextConfig *)((size_t)CNT->HCONTEXT + (k * sizeof(hyperContextConfig))); hypercontext = (hyperContextT *)((size_t)context->hypercontext + (k * sizeof(hyperContextT))); #ifdef INSIZZLEAPI bundlePos = 0; #endif #ifdef INSDEBUG printf("\t\t\t\thypercontext totalWidth: %d\n", hypercontext->totalWidth); #endif #ifdef INSDEBUG printf("hypercontext cycleCount: %lld\n", hypercontext->cycleCount); #endif /* TODO: here will be the status check of the hypercontext to see what state it is in */ /* check the state VT_CTRL */ #ifdef INSDEBUG printf("hypercontext->VT_CTRL: 0x%08x\n", hypercontext->VT_CTRL); #endif unsigned int deepstate = (hypercontext->VT_CTRL >> 3) & 0xff; unsigned int sstep = (hypercontext->VT_CTRL >> 2) & 0x1; unsigned int debug = (hypercontext->VT_CTRL >> 1) & 0x1; /*unsigned int kernel = hypercontext->VT_CTRL & 0x1;*/ #ifdef INSDEBUG printf("\tdeepstate: %d\n", deepstate); printf("\tsstep: %d\n", sstep); printf("\tdebug: %d\n", debug); /*printf("\tkernel: %d\n", kernel);*/ #endif #ifdef INSIZZLEAPI /* full 32 bit register */ /*gTracePacket[i][j][k].vt_ctrl = hypercontext->VT_CTRL;*/ /* just the deepstate */ gTracePacket[i][j][k].vt_ctrl = (hypercontext->VT_CTRL >> 3) & 0xff; #endif if(debug) { #ifdef INSDEBUG printf("HC STATE: DEBUG\n"); #endif /* nothing to do here */ } else { /* TODO: need to implement this it will be dependant on having something to say go */ if(sstep) { int sstmode = 0; do { printf("SINGLE STEP MODE: "); if(scanf("%d", &sstmode) == EOF) return -1; } while(!sstmode); if(deepstate == READY) printf("HC STATE: SSTEP_READY\n"); else if(deepstate == RUNNING) printf("HC STATE: SSTEP_RUNNING\n"); else if(deepstate == BLOCKED_MUTEX_LOCK) printf("HC STATE: SSTEP_BLOCKED_MUTEX_LOCK\n"); else if(deepstate == TERMINATED_SYNC) printf("HC STATE: SSTEP_TERMINATED_SYNC\n"); else { printf("HC STATE: UNKNOWN\n"); return -1; } } else { if(deepstate == READY) { #ifdef INSDEBUG printf("HC STATE: READY\n"); #endif hypercontext->idleCount++; } else if(deepstate == RUNNING) { #ifdef INSDEBUG printf("HC STATE: RUNNING\n"); printf("%d:%d:%d (system:context:hypercontext)\n", i, j, k); #endif /* TODO: check the microarchitectural state of the hypercontext */ /* stalled, running */ bundleCount = 0; if(hypercontext->stalled > 0) { hypercontext->stallCount++; hypercontext->stalled--; } else { if(hypercontext->checkedPC != (int)hypercontext->programCounter) { hypercontext->checkedPC = (int)hypercontext->programCounter; #ifdef INGDEBUG printf("checking bundle for PC: 0x%x\n", hypercontext->programCounter); #endif instructionPacket this; unsigned startPC = hypercontext->programCounter; unsigned endPC = hypercontext->programCounter; do { this = fetchInstruction(context, endPC, CNT); if((this.op >> 31) & 0x1) { if(this.immValid) { endPC += 4; } break; } endPC = this.nextPC; } while(!(this.op >> 31) & 0x1); #ifdef INSDEBUG printf("startPC: 0x%x\n", startPC); printf("endPC: 0x%x\n", endPC); #endif unsigned cB = checkBundle(hypercontext, startPC, endPC); if(cB > 0) { if(cB > hypercontext->memoryStall) { hypercontext->decodeStallCount += cB; #ifdef NOSTALLS hypercontext->stallCount += cB; #else unsigned long long *bundleCountP; bundleCountP = (unsigned long long *)((size_t)hypercontext->bundleCount); *bundleCountP = *bundleCountP + 1; hypercontext->stalled += (cB-1); hypercontext->cycleCount++; hypercontext->stallCount++; continue; #endif } else { /* don't need to add extra stall, because the memory stalls hides it */ } } } /* Memory Stalls here */ if(hypercontext->memoryStall > 0) { hypercontext->memoryStall--; hypercontext->cycleCount++; continue; } #ifdef INSDEBUG printf("already checked bundle for PC: 0x%x\n", hypercontext->programCounter); #endif /*if(cycle(context, hypercontext, (HCNT->HCONTEXT_CONFIG & 0xf)) == -1) { printf("Error\n"); return -1; }*/ instructionPacket this; instruction inst; /* TODO: possibly zero these out */ do { bundleCount++; this = fetchInstruction(context, hypercontext->programCounter, CNT); #ifdef INSDEBUG printf("PC: 0x%x, this.op: 0x%08x\n", hypercontext->programCounter, this.op); if(this.immValid) printf("PC: 0x%x, this.imm: 0x%08x\n", (hypercontext->programCounter + 4), this.imm); #endif inst = instructionDecode(this.op, this.imm, /*system->dram,*/ hypercontext, system, /*context, hypercontext->VT_CTRL, */(((SYS->DRAM_SHARED_CONFIG >> 8) & 0xffff) * 1024)); /*printf("%d : %d : ", *(hypercontext->S_GPR + 60), *(hypercontext->pS_GPR + 60));*/ if((inst.packet.addr == 0) && (inst.packet.target == 1)) { /* printf("\nsetting stack register\n"); printf("initialStackPointer: 0x%x\n", hypercontext->initialStackPointer); printf("stackSize: %d\n", STACK_SIZE); printf("diff: %d\n", (hypercontext->initialStackPointer - inst.packet.data));*/ if((hypercontext->initialStackPointer - inst.packet.data) >= (STACK_SIZE * 1024)) { /* printf("POSSIBLY OUT OF STACK?\n"); printf("diff: %d\n", (hypercontext->initialStackPointer - inst.packet.data));*/ int system_id = (((hypercontext->VT_CTRL) >> 24) & 0xff); int context_id = (((hypercontext->VT_CTRL) >> 16) & 0xff); int hypercontext_id = (((hypercontext->VT_CTRL) >> 12) & 0xf); printf("\tStack Overflow detected in [%d][%d][%d]:\n", system_id, context_id, hypercontext_id); printf("\t\tStack Pointer initially: 0x%x (%d)\n", hypercontext->initialStackPointer, hypercontext->initialStackPointer); printf("\t\tStack Size: 0x%x (%d)\n", (STACK_SIZE * 1024), (STACK_SIZE * 1024)); printf("\t\tStack Pointer now: 0x%x (%d)\n", inst.packet.data, inst.packet.data); printf("\t\tTry setting stack pointer to %d K ( -stack=%d )\n", (hypercontext->initialStackPointer - inst.packet.data), ((int)ceil((hypercontext->initialStackPointer - inst.packet.data) / 1024) + 1)); } } if(PRINT_OUT) { #ifndef INSIZZLEAPI printOut(inst, this, hypercontext, cycleCount); #else printOut(inst, this, hypercontext, 0); #endif } if(SINGLE_STEP) { stateDumpToTerminal(inst, hypercontext, cycleCount); stateDump(); printf("Press enter to continue."); getchar(); } #ifdef INSIZZLEAPI /* populate the gTracePacketT here */ gTracePacket[i][j][k].bundle[bundlePos].executed = inst.packet.executed; gTracePacket[i][j][k].bundle[bundlePos].syll = this.op; /*gTracePacket[i][j][k].bundle[bundlePos].syllValid = 1;*/ gTracePacket[i][j][k].bundle[bundlePos].pc = hypercontext->programCounter; if(this.immValid) { gTracePacket[i][j][k].bundle[bundlePos].imm = this.imm; /*gTracePacket[i][j][k].bundle[bundlePos].immValid = this.immValid;*/ } else { gTracePacket[i][j][k].bundle[bundlePos].imm = 0; /*gTracePacket[i][j][k].bundle[bundlePos].immValid = this.immValid;*/ } gTracePacket[i][j][k].bundle[bundlePos].maddr = inst.packet.maddr; gTracePacket[i][j][k].bundle[bundlePos].maddrValid = inst.packet.maddrValid; /* source register 1 */ /*gTracePacket[i][j][k].bundle[bundlePos].rs1.regType = inst.packet.source[0].target;*/ gTracePacket[i][j][k].bundle[bundlePos].rs1.reg = inst.packet.source[0].reg; gTracePacket[i][j][k].bundle[bundlePos].rs1.valid = inst.packet.source[0].valid; gTracePacket[i][j][k].bundle[bundlePos].rs1.val = inst.packet.source[0].value; gTracePacket[i][j][k].bundle[bundlePos].rs1.cluster = inst.packet.source[0].cluster; /* source register 2 */ /*gTracePacket[i][j][k].bundle[bundlePos].rs2.regType = inst.packet.source[1].target;*/ gTracePacket[i][j][k].bundle[bundlePos].rs2.reg = inst.packet.source[1].reg; gTracePacket[i][j][k].bundle[bundlePos].rs2.valid = inst.packet.source[1].valid; gTracePacket[i][j][k].bundle[bundlePos].rs2.val = inst.packet.source[1].value; gTracePacket[i][j][k].bundle[bundlePos].rs2.cluster = inst.packet.source[1].cluster; /* source register 3 */ /*gTracePacket[i][j][k].bundle[bundlePos].rs3.regType = inst.packet.source[2].target;*/ gTracePacket[i][j][k].bundle[bundlePos].rs3.reg = inst.packet.source[2].reg; gTracePacket[i][j][k].bundle[bundlePos].rs3.valid = inst.packet.source[2].valid; gTracePacket[i][j][k].bundle[bundlePos].rs3.val = inst.packet.source[2].value; gTracePacket[i][j][k].bundle[bundlePos].rs3.cluster = inst.packet.source[2].cluster; /* source register 4 */ /*gTracePacket[i][j][k].bundle[bundlePos].rs4.regType = inst.packet.source[3].target;*/ gTracePacket[i][j][k].bundle[bundlePos].rs4.reg = inst.packet.source[3].reg; gTracePacket[i][j][k].bundle[bundlePos].rs4.valid = inst.packet.source[3].valid; gTracePacket[i][j][k].bundle[bundlePos].rs4.val = inst.packet.source[3].value; gTracePacket[i][j][k].bundle[bundlePos].rs4.cluster = inst.packet.source[3].cluster; /* source register 5 */ /*gTracePacket[i][j][k].bundle[bundlePos].rs5.regType = inst.packet.source[4].target;*/ gTracePacket[i][j][k].bundle[bundlePos].rs5.reg = inst.packet.source[4].reg; gTracePacket[i][j][k].bundle[bundlePos].rs5.valid = inst.packet.source[4].valid; gTracePacket[i][j][k].bundle[bundlePos].rs5.val = inst.packet.source[4].value; gTracePacket[i][j][k].bundle[bundlePos].rs5.cluster = inst.packet.source[4].cluster; /* source register 6 */ /*gTracePacket[i][j][k].bundle[bundlePos].rs6.regType = inst.packet.source[5].target;*/ gTracePacket[i][j][k].bundle[bundlePos].rs6.reg = inst.packet.source[5].reg; gTracePacket[i][j][k].bundle[bundlePos].rs6.valid = inst.packet.source[5].valid; gTracePacket[i][j][k].bundle[bundlePos].rs6.val = inst.packet.source[5].value; gTracePacket[i][j][k].bundle[bundlePos].rs6.cluster = inst.packet.source[5].cluster; /* source register 7 */ /*gTracePacket[i][j][k].bundle[bundlePos].rs7.regType = inst.packet.source[6].target;*/ gTracePacket[i][j][k].bundle[bundlePos].rs7.reg = inst.packet.source[6].reg; gTracePacket[i][j][k].bundle[bundlePos].rs7.valid = inst.packet.source[6].valid; gTracePacket[i][j][k].bundle[bundlePos].rs7.val = inst.packet.source[6].value; gTracePacket[i][j][k].bundle[bundlePos].rs7.cluster = inst.packet.source[6].cluster; /* destination register 1 */ /*gTracePacket[i][j][k].bundle[bundlePos].rd1.regType = inst.packet.dest[0].target;*/ gTracePacket[i][j][k].bundle[bundlePos].rd1.chk = inst.packet.dest[0].chk; gTracePacket[i][j][k].bundle[bundlePos].rd1.reg = inst.packet.dest[0].reg; gTracePacket[i][j][k].bundle[bundlePos].rd1.valid = inst.packet.dest[0].valid; gTracePacket[i][j][k].bundle[bundlePos].rd1.cluster = inst.packet.dest[0].cluster; gTracePacket[i][j][k].bundle[bundlePos].rd1.res = inst.packet.dest[0].res; /* destination register 2 */ /*gTracePacket[i][j][k].bundle[bundlePos].rd2.regType = inst.packet.dest[1].target;*/ gTracePacket[i][j][k].bundle[bundlePos].rd2.chk = inst.packet.dest[1].chk; gTracePacket[i][j][k].bundle[bundlePos].rd2.reg = inst.packet.dest[1].reg; gTracePacket[i][j][k].bundle[bundlePos].rd2.valid = inst.packet.dest[1].valid; gTracePacket[i][j][k].bundle[bundlePos].rd2.cluster = inst.packet.dest[1].cluster; gTracePacket[i][j][k].bundle[bundlePos].rd2.res = inst.packet.dest[1].res; bundlePos++; #endif if(inst.packet.newPCValid) { hypercontext->programCounter = inst.packet.newPC; inst.packet.newPCValid = 0; /* TODO: add stalls for control flow change */ #ifndef INSIZZLEAPI #ifdef NOSTALLS hypercontext->stallCount += PIPELINE_REFILL; #else hypercontext->stalled += PIPELINE_REFILL; #endif #else hypercontext->stallCount += PIPELINE_REFILL; #endif #ifdef INSDEBUG printf("control flow change!\n"); #endif hypercontext->controlFlowChange++; } else { hypercontext->programCounter = this.nextPC; } if(inst.packet.opcode == NOP) { hypercontext->nopCount++; } #if 0 else { /* set previous stall count to zero */ if(hypercontext->MemoryStall > 0) { hypercontext->MemoryStall--; } } #endif } while(!(this.op >> 31) & 0x1); } /* TODO bundleCount */ bundleCountP = (unsigned long long *)((size_t)hypercontext->bundleCount + (bundleCount * (sizeof(unsigned long long)))); *bundleCountP = *bundleCountP + 1; hypercontext->cycleCount++; } else if(deepstate == BLOCKED_MUTEX_LOCK) printf("HC STATE: BLOCKED_MUTEX_LOCK\n"); else if(deepstate == TERMINATED_ASYNC_HOST) { /* TODO: this is the vthread_join thing */ #if 1 #ifdef INSDEBUG printf("HC STATE: TERMINATED_ASYNC_HOST\n"); printf("\twaiting for: 0x%x\n", hypercontext->joinWaiting); #endif hypercontext->cycleCount++; #endif } else if(deepstate == TERMINATED_ASYNC) printf("HC STATE: TERMINATED_ASYNC\n"); else if(deepstate == TERMINATED_SYNC) printf("HC STATE: TERMINATED_SYNC\n"); else { printf("HC STATE: UNKNOWN\n"); return -1; } } } }