// Main program: Initialize the cpu, read initial memory values, // and execute the read-in program starting at location 00. // int main(void) { printf("CS 350 Lab 8, Raman Walwyn-Venugopal\n"); initCPU(); readMemory(); char prompt[]="> "; printf("\nBeginning execution:\n"); printf("At the %sprompt, press return to execute the next instruction\n", prompt); printf("(or d to dump registers and memory, q to quit, or h or ? for help)\n"); char command[80]; // User inputted command line char cmd_char; // 'q' for quit etc. int simulator_quit = 0; // Have we seen simulator quit command? int nbr_read; // Number of items read by sscanf int commands_done=0; char c; while (!commands_done) { printf("%s", prompt); fgets(command, sizeof command, stdin); // Read through end of current line. //nbr_read = sscanf(command, "%c", &cmd_char); if (strcmp(command,"h\n") == 0 || strcmp(command,"?\n")==0){ helpMsg(); } else if (strcmp(command, "d\n")==0){ dumpControlUnit(pc, ir, regs); dumpMemory(mem); } else if (strcmp(command,"q\n")==0){ commands_done=1; } else if (isdigit(command[0])){ int cycles=atoi(command); int d; for (d=0;d<cycles;d++){ instruction_cycle(); } } else if(strcmp(command, "\n")==0){ instruction_cycle(); } else{ printf("Error! Please enter an appropiate value or h for help\n"); } } dumpControlUnit(pc, ir, regs); dumpMemory(mem); printf("GOODBYE!\n"); }
// // int regs[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // int mem[100] = { 0 }; // Careful: Leading 0s in constants indicates octal nbr // int isEnd = 0; // int pc; // int ir; // int opcode;//operation code // int radd;//register address // int mmadd;//memory address // Main program: Initialize the cpu, read initial memory values, // and execute the read-in program starting at location 00. // int main(void) { printf(" ******************** STUB ********************\n "); printf("Lab9 CS350 Author:Weicheng Huang\n"); CPU c; initCPU(&c); readMemory(&c); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; char command[80]; fgets(command, sizeof command, stdin); while(c.running==1){ printf("%s", prompt); fgets(command, sizeof command, stdin); // Read past end of current line. if(command[0] == 'q'){ c.running = 0; }else if(command[0] == 'h'||command[0]=='?'){ helpMsg(); }else{ c.running=instruction_cycle(&c); } } printf("\nRegisters:\n"); dumpRegisters(&c); printf("\nMemory:\n"); dumpMemory(&c); }
// Main program: Initialize the cpu, read initial memory values, // and execute the read-in program starting at location 00. // int main(void) { printf("*** STUB *** CS 350 Lab 7, Weicheng Huang\n"); initCPU(); readMemory(); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; char command[80]; fgets(command, sizeof command, stdin); while(isEnd==0){ printf("%s", prompt); fgets(command, sizeof command, stdin); // Read past end of current line. if(command[0] == 'q'){ isEnd = 1; }else if(command[0] == 'h'||command[0]=='?'){ helpMsg(); }else{ isEnd=instruction_cycle(); } } printf("\nRegisters:\n"); dumpRegisters(regs); printf("\nMemory:\n"); dumpMemory(mem); }
int main(void) { char input; int counter = 0; printf("CS 350 Lab 8, Jamal Kharrat\nSDC Simulator Framework\n\n"); initCPU(); readMemory(); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; printf("%s", prompt); char command[80]; fgets(command, sizeof command, stdin); // Read past end of current line. do { scanf("%c", &input); if(input == '\r' | input == '\n') { instruction_cycle(); printf("%s", prompt); counter++; } else if(input == 'q') printf("Quitting\n"); // display quiting message else if(input == 'h') helpMsg(); // call help message else { printf("Invalid Input, try again: "); break; } } while (input != 'q' & counter < 10); printf("\nRegisters:\n"); dumpRegisters(regs); printf("\nMemory:\n"); dumpMemory(mem); }
void GProcessor::retire() { #ifdef DEBUG // Check for progress. When a processor gets stuck, it sucks big time if ((((int)globalClock) & 0x1FFFFFL) == 0) { if (ROB.empty()) { // ROB should not be empty for lots of time if (prevDInstID == 1) { MSG("GProcessor::retire CPU[%d] ROB empty for long time @%lld", Id, globalClock); } prevDInstID = 1; }else{ DInst *dinst = ROB.top(); if (prevDInstID == dinst->getID()) { I(0); MSG("ExeEngine::retire CPU[%d] no forward progress from pc=0x%x with %d @%lld" ,Id, (uint)dinst->getInst()->getAddr() ,(uint)dinst->getInst()->currentID(), globalClock ); dinst->dump("HEAD"); LDSTBuffer::dump(""); } prevDInstID = dinst->getID(); } } #endif robUsed.sample(ROB.size()); ushort i; for(i=0;i<RetireWidth && !ROB.empty();i++) { DInst *dinst = ROB.top(); if( !dinst->isExecuted() ) { addStatsNoRetire(i, dinst, NotExecuted); return; } // save it now because retire can destroy DInst int rp = dinst->getInst()->getDstPool(); //BEGIN STAT -------------------------------------------------------------------------------------------------------- #if defined(STAT) ConfObject* statConf = new ConfObject; THREAD_ID threadID = dinst->get_threadID(); //Check to see if we're profling or not if(statConf->return_enableSynth() == 1) { Synthesis::checkContainerSizes(threadID); //FIXME Bug with flushing the instructionQueues tuple<DInst, Time_t> instruction_cycle(*dinst, globalClock); Synthesis::analysis(instruction_cycle); // instructionQueueVector[threadID]->push_back(instruction_cycle); // if((INT_32)instructionQueueVector[threadID]->size() > statConf->return_windowSize()) // { // Synthesis::analysis(instructionQueueVector[threadID]->front()); // instructionQueueVector[threadID]->pop_front(); // } // // //if this is the end of the thread, we need to flush the instruction queue // if(dinst->getInst()->getICode()->func == mint_exit) // { // while(instructionQueueVector[threadID]->empty() == 0) // { // Synthesis::analysis(instructionQueueVector[threadID]->front()); // instructionQueueVector[threadID]->pop_front(); // } // } } delete statConf; #endif //END STAT ---------------------------------------------------------------------------------------------------------- //BEGIN PROFILING -------------------------------------------------------------------------------------------------------- #if defined(PROFILE) ConfObject *statConf = new ConfObject; THREAD_ID threadID = dinst->get_threadID(); if(statConf->return_enableProfiling() == 1) { tuple<DInst, Time_t> instruction_cycle(*dinst, globalClock); //Need to ensure that the vector is large enough to hold the next thread if(threadID >= Profiling::transactionDistance.size()) { if(threadID == Profiling::transactionDistance.size()) { std::cerr << "Profiling::Push back to transactionDistance with " << threadID; UINT_32 temp_1 = 0; Profiling::transactionDistance.push_back(temp_1); std::cerr << " and new size of " << Profiling::transactionDistance.size() << "*" << std::endl; } else { std::cerr << "Profiling::Resizing transactionDistance with " << threadID; Profiling::transactionDistance.resize(threadID + 1); std::cerr << " and new size of " << Profiling::transactionDistance.size() << "*" << std::endl; } } if(threadID >= Profiling::isTransaction.size()) { if(threadID == Profiling::isTransaction.size()) { std::cerr << "Profiling::Push back to isTransaction with " << threadID; BOOL temp_1 = 0; Profiling::isTransaction.push_back(temp_1); std::cerr << " and new size of " << Profiling::isTransaction.size() << "*" << std::endl; } else { std::cerr << "Profiling::Resizing isTransaction with " << threadID; Profiling::isTransaction.resize(threadID + 1); std::cerr << " and new size of " << Profiling::isTransaction.size() << "*" << std::endl; } } if(threadID >= instructionQueueVector.size()) { if(threadID == instructionQueueVector.size()) { std::cerr << "Profiling::Push back to instructionQueueVector with " << threadID; instructionQueueVector.push_back(new std::deque< tuple<DInst, Time_t> >); std::cerr << " and new size of " << instructionQueueVector.size() << " and capacity of " << instructionQueueVector.capacity() << "*" << std::endl; } else { std::cerr << "Profiling::Resizing instructionQueueVector with " << threadID; instructionQueueVector.resize(threadID + 1, new std::deque< tuple<DInst, Time_t> >); std::cerr << " and new size of " << instructionQueueVector.size() << " and capacity of " << instructionQueueVector.capacity() << "*" << std::endl; } } if(threadID >= Profiling::currBBStats.size()) { if(threadID == Profiling::currBBStats.size()) { std::cerr << "Profiling::Push back to currBBStats with " << threadID; Profiling::currBBStats.push_back(new WorkloadCharacteristics()); std::cerr << " and new size of " << Profiling::currBBStats.size() << " and capacity of " << Profiling::currBBStats.capacity() << "*" << std::endl; } else { std::cerr << "Profiling::Resizing currBBStats with " << threadID; Profiling::currBBStats.resize(threadID + 1, new WorkloadCharacteristics()); std::cerr << " and new size of " << Profiling::currBBStats.size() << " and capacity of " << Profiling::currBBStats.capacity() << "*" << std::endl; } } if(threadID >= Profiling::firstTransaction.size()) { if(threadID == Profiling::firstTransaction.size()) { std::cerr << "Profiling::Push back to firstTransaction with " << threadID; UINT_32 temp_1 = 1; Profiling::firstTransaction.push_back(temp_1); std::cerr << " and new size of " << Profiling::firstTransaction.size() << " and capacity of " << Profiling::firstTransaction.capacity() << "*" << std::endl; } else { std::cerr << "Profiling::Resizing firstTransaction with " << threadID; Profiling::firstTransaction.resize(threadID + 1); std::cerr << " and new size of " << Profiling::firstTransaction.size() << " and capacity of " << Profiling::firstTransaction.capacity() << "*" << std::endl; Profiling::firstTransaction[threadID] = 1; } } instructionQueueVector[threadID]->push_back(instruction_cycle); if((INT_32)instructionQueueVector[threadID]->size() > statConf->return_windowSize()) { instruction_cycle = instructionQueueVector[threadID]->front(); instructionQueueVector[threadID]->pop_front(); Profiling::analysis(instruction_cycle); } } delete statConf; #endif //END PROFILING -------------------------------------------------------------------------------------------------------- #if (defined TM) // We must grab the type here since we will not be able to use it past the retirement phase transInstType tempTransType = dinst->transType; sType synchType = dinst->synchType; int transPid = dinst->transPid; int transTid = dinst->transTid; int transBCFlag = dinst->transBCFlag; #endif bool fake = dinst->isFake(); I(dinst->getResource()); RetOutcome retOutcome = dinst->getResource()->retire(dinst); if( retOutcome != Retired) { addStatsNoRetire(i, dinst, retOutcome); return; } // dinst CAN NOT be used beyond this point #if (defined TM) instCountTM++; // Call the proper reporting function based on the type of instruction switch(tempTransType){ case transCommit: if(transBCFlag != 2) tmReport->reportCommit(transPid); break; case transBegin: if(transBCFlag != 2) tmReport->reportBegin(transPid, this->Id); break; case transLoad: tmReport->reportLoad(transPid); break; case transStore: tmReport->reportStore(transPid); break; case transAbort: tmReport->beginTMStats(instCountTM); break; case transInt: case transFp: case transBJ: case transFence: tmReport->registerTransInst(transPid,tempTransType); break; case transOther: break; case transNT: tmReport->incrementCommittedInstCountByCpu ( this->Id ); break; } if (synchType == barrier ) { tmReport->reportBarrier ( this->Id); } #endif if (!fake) regPool[rp]++; ROB.pop(); robEnergy->inc(); // read ROB entry (finished?, update retirement rat...) } if(!ROB.empty() || i != 0) addStatsRetire(i); }
// -------------------- MAIN PROGRAM -------------------- // int main() { // Declare and initialize the CPU // //int temp = bitshift(0x0ff9,11,9,1); // printf("temp = %d %x\n",temp,temp); printf(" ******************** STUB ********************\n "); printf("Lab10 CS350 Author:Weicheng Huang\n"); CPU cpu; init_CPU(&cpu); Address end = readfile(&cpu); Address origin = cpu.pgm_counter; printf("origin = %x ; end = %x \n",origin,end); printf("\nRegisters:\n"); dump_registers(&cpu); printf("\nMemory:\n"); dump_memory(&cpu,cpu.pgm_counter,end,0); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; char command[80]; fgets(command, sizeof command, stdin); while(cpu.running==1){ printf("%s", prompt); fgets(command, sizeof command, stdin); // Read past end of current line. char op = command[0]; unsigned int from=0; unsigned int too = 0; switch(op){ case 'q': cpu.running = 0; break; case 'h': helpMsg(); break; case '?': helpMsg(); break; case 'r': printf("\nRegisters:\n"); dump_registers(&cpu); break; case 'm': sscanf(command,"m %x %x",&from,&too); dump_memory(&cpu,(Address)from,(Address)too,1); break; default: instruction_cycle(&cpu); break; } } /* if(command[0] == 'q'){ c.running = 0; }else if(command[0] == 'h'||command[0]=='?'){ helpMsg(); }else{ c.running=instruction_cycle(&c); } */ printf("\nRegisters:\n"); dump_registers(&cpu); printf("\nMemory:\n"); dump_memory(&cpu,origin,end,1); printf("\nAll done!\n"); }
// -------------------- MAIN PROGRAM -------------------- // // The main program creates and initializes a CPU, loads a program, // and executes it step by step (until it halts or the user quits). // The CPU is dumped before and after executing the program // int main() { // Create and initialize the CPU, read initial memory, dump CPU // CPU cpu_struct, *cpu; // cpu = &cpu_struct; printInf(); CPU cpu; init_CPU(&cpu); Address end = readfile(&cpu); Address origin = cpu.pgm_counter; printf("origin = %x ; end = %x \n",origin,end); printf("\nRegisters:\n"); dump_registers(&cpu); printf("\nMemory:\n"); dump_memory(&cpu,cpu.pgm_counter,end,0); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; char command[80]; fgets(command, sizeof command, stdin); while(cpu.running==1){ printf("%s", prompt); fgets(command, sizeof command, stdin); // Read past end of current line. char op = command[0]; unsigned int from=0; unsigned int too = 0; switch(op){ case 'q': cpu.running = 0; break; case 'h': helpMsg(); break; case '?': helpMsg(); break; case 'r': printf("\nRegisters:\n"); dump_registers(&cpu); break; case 'd': sscanf(command,"m %x %x",&from,&too); dump_memory(&cpu,(Address)from,(Address)too,1); break; default: instruction_cycle(&cpu); break; } } /* if(command[0] == 'q'){ c.running = 0; }else if(command[0] == 'h'||command[0]=='?'){ helpMsg(); }else{ c.running=instruction_cycle(&c); } */ printf("\nRegisters:\n"); dump_registers(&cpu); printf("\nMemory:\n"); dump_memory(&cpu,origin,end,1); printf("\nAll done!\n"); }
int main() { // Declare and initialize the CPU // .. CPU cpu; init_CPU(&cpu); // .. printf("CS 350 Final Project, Andrey Danilkovich\nLC3 Simulator\n\n"); printf("File to read from: "); char filename[80]; char input = 0; char prompt[] = "> "; char memoryInput; int hex1, hex2; scanf("%s", filename); FILE *file = fopen ( filename, "r" ); if ( file != NULL ) { printf("** %s contains **\n\n", filename); char line [ 128 ]; /* or other suitable maximum line size */ while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */ { fputs ( line, stdout ); /* write the line */ } fclose ( file ); } else { perror ( filename ); /* why didn't the file open? */ printf("Possible file names:\n\nhelloworld.hex\nnegaddr.hex\nprintstring.hex\nrc.hex\nreadchar.hex\nreadstring.hex\n"); return 0; printf("\nFile to read from: "); scanf("%s", filename); } printf("\nInitial CPU:\n"); dump_registers(&cpu); dump_memory(&cpu, to, from, nonzero_only); printf("\n"); printf("Beginning execution:\nAt the > prompt, press return to execute the next instruction, q to quit,\nr to dump the registers, m hex#1 hex#2 to dump memory, or h for help.\n"); printf("%s", prompt); while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear '\n' from a char */ } scanf("%c", &input); do { while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear '\n' from a char */ } if(input == '\r' | input == '\n') { instruction_cycle(&cpu); printf("%s", prompt); scanf("%c", &input); } else if(input == 'h') { helpMsg(); // call help message printf("%s", prompt); scanf("%c", &input); } else if (input == 'r') { printf("*** STUB *** Dump registers\n"); printf("%s", prompt); scanf("%c", &input); } else if(input == 'q') { printf("Quitting\n"); } else if (input == 'm') { printf("\tm: "); scanf("%c", &memoryInput); printf("\thex_n1: "); scanf("%d", &hex1); printf("\thex_n1: "); scanf("%d", &hex2); while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear '\n' from a char */ } printf("%s", prompt); scanf("%c", &input); } else { printf("Unknown command; ignoring it.\n"); printf("%s", prompt); scanf("%c", &input); } } while (input != 'q'); // & cpu->pc != 100 printf("Halting\n"); return 0; }
int main(void) { int memCounter = 0; char input; int numCountRef, firstNumRef, secondNumRef, intRestRef; printf("CS 350 Lab 8, Andrey Danilkovich\nFull SDC Simulator\n\n"); initCPU(); readMemory(); printf("\nBeginning execution:\n"); printf("At the > prompt, press return to execute the next instruction (or q to quit or h or ? for help).\n"); char prompt[] = "> "; printf("%s", prompt); char command[80]; fgets(command, sizeof command, stdin); // Read past end of current line. scanf("%c", &input); do { while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear \n from a char */ } // clear out the extra space after the char numCountRef = getcount(mem, memCounter); firstNumRef = getfirst(mem, memCounter, numCountRef); secondNumRef = getsecond(mem, memCounter, numCountRef); intRestRef = getrest(mem, memCounter, numCountRef); if(firstNumRef == 0) { memCounter++; } else if(input == '\r' | input == '\n') { instruction_cycle(mem, regs, memCounter); memCounter++; printf("%s", prompt); scanf("%c", &input); if(firstNumRef == 8 & regs[secondNumRef] > 0) { memCounter = intRestRef; } } else if(input == 'h') { helpMsg(); // call help message printf("%s", prompt); scanf("%c", &input); } else if(input == 'q') { printf("Quitting program.\n"); } else { printf("Unknown command; ignoring it.\n"); printf("%s", prompt); scanf("%c", &input); } } while (memCounter != 99 & input != 'q'); // Finish Program // Print Halting message, diplay registers and memory printf("At 00 instr 0 0 00: HALT\n\nHalting\n"); printf("\nRegisters:\n"); dumpRegisters(regs); printf("\nMemory:\n"); dumpMemory(mem); }
int main() { // Declare and initialize the CPU CPU cpu; init_CPU(&cpu); //char filename[80]; char input = 0; char prompt[] = "> "; int counter; // how many values read from file int addr = 0; description(); // Call display name and project counter = get_memory(&cpu, addr); // Call function printf("\nInitial CPU:\n"); dump_registers(&cpu); // Call dump registers function dump_memory(&cpu, to, from, nonzero_only, counter); printf("\n"); printf("Beginning execution:\nAt the > prompt, press return to execute the next instruction, q to quit,\nr to dump the registers, m hex#1 hex#2 to dump memory, or h for help.\n"); printf("%s", prompt); while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear '\n' from a char */ } scanf("%c", &input); int order = (cpu).memory[0]; // set order for instrction cycle do { while(input != '\n' && getchar() != '\n' ){ /* Do Nothing to clear '\n' from a char */ } if(input == '\r' | input == '\n') { instruction_cycle(&cpu, order); printf("%s", prompt); scanf("%c", &input); order++; } else if(input == 'h') { helpMsg(); // call help message printf("%s", prompt); scanf("%c", &input); } else if (input == 'r') { printf("Dump registers\n"); dump_registers(&cpu); printf("%s", prompt); scanf("%c", &input); } else if(input == 'q') { printf("Quitting\n"); } else if (input == 'm') { char s[] = "m 01f 359a"; sscanf(s, "m %hx %hx", &from, &to); dump_memory(&cpu, to, from, nonzero_only, counter); printf("%s", prompt); scanf("%c", &input); } else { printf("Unknown command; ignoring it.\n"); helpMsg(); // call help message printf("%s", prompt); scanf("%c", &input); } } while (input != 'q'); // End loop when user enters q. Previous command - & cpu->pc != 100 printf("Quitting\n"); printf("Halting\n"); // Final step - Dump registers and Memory dump_registers(&cpu); dump_memory(&cpu, to, from, nonzero_only, counter); return 0; }