Example #1
0
void execute()
{
    //printInstructionTable();
	
    int pc = 0;
    char opcode[OPCODE_SIZE];
    char operand[OPERAND_SIZE];
    
    while(strcmp(opcode, "halt")){
        
        fetchInstruction(pc, opcode, operand);
        
        // execution of current instruction
        if(strcmp(opcode, "nop") == 0){pc = nop(pc);}
        else if(strcmp(opcode, "add") == 0){pc = add(pc);}
        else if(strcmp(opcode, "sub") == 0){pc = sub(pc);}
        else if(strcmp(opcode, "mul") == 0){pc = mul(pc);}
        else if(strcmp(opcode, "divide") == 0){pc = divide(pc);}
        else if(strcmp(opcode, "get") == 0){pc = get(pc, operand);}
        else if(strcmp(opcode, "put") == 0){pc = put(pc, operand);}
        else if(strcmp(opcode, "push") == 0){pc = push(pc, operand);}
        else if(strcmp(opcode, "pop") == 0){pc = pop(pc, operand);}
        else if(strcmp(opcode, "not") == 0){pc = not(pc);}
        else if(strcmp(opcode, "and") == 0){pc = and(pc);}
        else if(strcmp(opcode, "or") == 0){pc = or(pc);}
        else if(strcmp(opcode, "testeq") == 0){pc = testeq(pc);}
        else if(strcmp(opcode, "testne") == 0){pc = testne(pc);}
        else if(strcmp(opcode, "testlt") == 0){pc = testlt(pc);}
        else if(strcmp(opcode, "testle") == 0){pc = testle(pc);}
        else if(strcmp(opcode, "testgt") == 0){pc = testgt(pc);}
        else if(strcmp(opcode, "testge") == 0){pc = testge(pc);}
        else if(strcmp(opcode, "jump") == 0){pc = jump(pc, operand);}
        else if(strcmp(opcode, "jf") == 0){pc = jf(pc, operand);}
    }
}
Example #2
0
void Cpu::runProcessor() {
    unsigned int timer = 0;

    do {
        _ir = fetchInstruction();
        processInstruction();
        timer = checkAndUpdateTimer(timer);
    } while (endNotReached());
}
Example #3
0
void Cpu::putPort() {
    const int port = fetchInstruction();
    if (port == 1) {
        std::cout << _ac << std::flush;
    } else if (port == 2) {
        char value = _ac;
        std::cout << value << std::flush;
    }
}
Example #4
0
void BX_CPU_C::serveICacheMiss(bxICacheEntry_c *cache_entry, Bit32u eipBiased, bx_phy_address pAddr)
{
  unsigned remainingInPage = BX_CPU_THIS_PTR eipPageWindowSize - eipBiased;
  const Bit8u *fetchPtr = BX_CPU_THIS_PTR eipFetchPtr + eipBiased;
      
  // The entry will be marked valid if fetchdecode will succeed
  cache_entry->writeStamp = ICacheWriteStampInvalid;

  if (fetchInstruction(cache_entry->i, fetchPtr, remainingInPage)) {
    cache_entry->pAddr = pAddr;
    cache_entry->writeStamp = *(BX_CPU_THIS_PTR currPageWriteStampPtr);
  }
}
Example #5
0
void CpuRiscV_Functional::updatePipeline() {
    IInstruction *instr;
    CpuContextType *pContext = getpContext();

    if (dport.valid) {
        dport.valid = 0;
        updateDebugPort();
    }

    pContext->pc = pContext->npc;
    if (isRunning()) {
        fetchInstruction();
    }

    updateState();
    if (pContext->reset) {
        updateQueue();
        reset();
        return;
    } 

    instr = decodeInstruction(cacheline_);
    if (isRunning()) {
        last_hit_breakpoint_ = ~0;
        if (instr) {
            executeInstruction(instr, cacheline_);
        } else {
            pContext->npc += 4;
            generateException(EXCEPTION_InstrIllegal, pContext);

            RISCV_info("[%" RV_PRI64 "d] pc:%08x: %08x \t illegal instruction",
                        getStepCounter(),
                        static_cast<uint32_t>(pContext->pc), cacheline_[0]);
        }
    }

    updateQueue();

    handleTrap();
}
Example #6
0
int main(int argc, char *argv[])
{
    load();
    output = fopen("stacktrace.txt", "w");

    fprintf(output, "Line  OP    L  M\n");

    printCode(code);

    fprintf(output, "                    pc  bp  sp   stack\n");
    fprintf(output, "Initial values      %d   %d   %d\n", pc, bp, sp);

    while(halt == 0)
    {
        fetchInstruction();
        executeInstruction();
        printInfo();
    }

    fclose(output);
    return 0;
}
Example #7
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;
			    }
			}
		    }
		}
Example #8
0
void Cpu::processInstruction() {
    switch (_ir) {
    case 1: // load value
        _ac = fetchInstruction();
        break;
    case 2: // load value at the address into the AC
        _ac = readFromMemory(fetchInstruction());
        break;
    case 3: // Use the AC value as an address to a another value.
        // this new value is also used as an address to the final value.
        _ac = readFromMemory(readFromMemory(fetchInstruction()));
        break;
    case 4: // load the value at address + X into the AC
        _ac = readFromMemory(fetchInstruction() + _x);
        break;
    case 5: // load the value at the address + Y into the AC
        _ac = readFromMemory(fetchInstruction() + _y);
        break;
    case 6: // from from sp + X into the AC
        _ac = readFromMemory(_sp + _x);
        break;
    case 7: // store the AC value into the following address
        writeToMemory(fetchInstruction(), _ac);
        break;
    case 8: // Get a random integer from interval [1, 100]
        putRandInAC();
        break;
    case 9: // write the AC to the screen as an integer if following value is 1
        // or as an char if the following value is 2
        putPort();
        break;
    case 10: // add the value in X to the AC
        _ac = _ac + _x;
        break;
    case 11: // add the value in Y to the AC
        _ac = _ac + _y;
        break;
    case 12: // subtract the value in X from the AC
        _ac = _ac - _x;
        break;
    case 13: // subtract the value in Y from the AC
        _ac = _ac - _y;
        break;
    case 14: // Copy AC to X
        _x = _ac;
        break;
    case 15: // Copy X to AC
        _ac = _x;
        break;
    case 16: // Copy AC to Y
        _y = _ac;
        break;
    case 17: // Copy Y to AC
        _ac = _y;
        break;
    case 18: // Copy AC to SP
        _sp = _ac;
        break;
    case 19: // Copy SP to AC
        _ac = _sp;
        break;
    case 20: // Jump to following address
        jumpToAddress(fetchInstruction());
        break;
    case 21: // jump to address if AC == 0
        if (_ac == 0)
            jumpToAddress(fetchInstruction());
        else
            _pc++;
        break;
    case 22: // jump to address if AC != 0
        if (_ac != 0)
            jumpToAddress(fetchInstruction());
        else
            _pc++;
        break;
    case 23: // push return address onto the stack and jump to the following address
        callAddress();
        break;
    case 24: // return from stack
        jumpToAddress(pop());
        break;
    case 25:
        _x++;
        break;
    case 26:
        _x--;
        break;
    case 27:
        push(_ac);
        break;
    case 28:
        _ac = pop();
        break;
    case 29: // Set system mode, switch stack, push SP and PC, set new SP and PC
        if (_interruptEnabled)
            interrupt(INTERRUPT_HANDLER_ADDRESS);
        break;
    case 30: // restore registers and set to user mode
        if (_inSystemMode)
            returnFromInterrupt();
        break;
    }
}
Example #9
0
void Cpu::callAddress() {
    const int address = fetchInstruction();
    push(_pc);
    jumpToAddress(address);
}