int main(int argc, char** argv) { if (argc != 2) { printf("Usage: %s <path to srec>\n", argv[0]); exit(1); } cpu* _cpu = (cpu*)malloc(sizeof(cpu)); initCPU(_cpu); if(loadSREC(_cpu->_mmu, argv[1])){ fputs("failed to load srec...\n",stderr); return 1; } _cpu->pc = 0; _cpu->pc = _cpu->_mmu->entryPoint; printf("Finished loading SREC, running from entryPoint: %llx\n", _cpu->pc); while(1) { _cpu->step(_cpu); } free(_cpu); }
// 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); }
// 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 8, Your name\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 while (!commands_done) { printf("%s", prompt); fgets(command, sizeof command, stdin); // Read through end of current line. nbr_read = sscanf("%c", &cmd_char); if (nbr_read > 0) { printf("*** STUB *** read in %c command\n"); } else { printf("*** STUB *** read in a number or empty line\n"); } } // When we see the quit command, dump the control unit and memory // and quit // printf("*** STUB *** quitting'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); }
// Create the cpu Cpu* createCPU() { Cpu *cpu = (Cpu *) malloc(sizeof(Cpu)); // Initialise the cpu initCPU(cpu); return cpu; }
int main(int argc, char* argv[]) { VirtualCPU cpu0; initCPU(&cpu0); //initialise the program Settings* set = setup(argc,argv); header(set->htmloutput); list_Job* list=FileToJobList(set->jobinput); // list would be sorted on arrival time list_Job_sort(list, compare_Job_Arrival); setSchedulingMode(&cpu0,set->mode); setRoundRobinCPUQuanta(&cpu0,set->rr_quanta); setMemoryManagement(&cpu0,set->mem_management); int clock=cpu0.current_clock; int totalclocks=0; int startclocks=clock; list_iterator_Job* it = malloc(sizeof(*it)); list_Job_iterator_init(it, list); Job* current = list_Job_examine(it); while(current!=NULL){ while(current!=NULL && clock==current->arrival_time){ if(current->arrival_time < clock){ //Error when process is behind the clock fprintf(stderr,"Process to be scheduled in the past- ERROR\n"); exit(EXIT_FAILURE); } if(totalclocks==0) startclocks=clock; totalclocks+=current->length_time; debug_print("%s: %d @ %d \n",current->jobname,current->arrival_time,clock); addJobToCPU(&cpu0,current); current= list_Job_next(it); } clock=incrementClock(&cpu0); dumpMemory(clock,set,&cpu0); } free(list); while(isCPUIdle(&cpu0)==false){ debug_print("Incrementing clock %d\n",clock); clock=incrementClock(&cpu0); dumpMemory(clock,set,&cpu0); } debug_print_string("Complete!\n"); list_JobScheduleResult* results = getResults(&cpu0); printResultsCompressed(results); footer(set->htmloutput); return 0; }
// 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 main(int argc, char *argv[]) { setvbuf(stdout, NULL, _IONBF, 0); /* Initiate the CPU */ CPU_p cpu = constructCPU(); initCPU(cpu); /* Initate the memory */ //loadMemory(memory); /* Start the controller, requires debug flag to be set (./cpuDriver -d) in order to run the debug console.*/ controller(cpu, memory, 1); return(0); }
bool AppleI386CPU::startCommon() { if (startCommonCompleted) return true; cpuIC = new AppleI386CPUInterruptController; if (cpuIC == 0) return false; if (cpuIC->initCPUInterruptController(1) != kIOReturnSuccess) return false; cpuIC->attach(this); cpuIC->registerCPUInterruptController(); setCPUState(kIOCPUStateUninitalized); initCPU(true); registerService(); startCommonCompleted = true; return true; }
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); }
int main(void) { // print welcome message char* pathbuffer = (char*) calloc(MAX_LINE_LENGTH, sizeof(char)); if (pathbuffer == NULL) { perror("calloc error in interpreter\n"); exit(EXIT_FAILURE); } assert(readlink("/proc/self/exe", pathbuffer, MAX_LINE_LENGTH) != -1); removeExecutableName(pathbuffer); strcat(pathbuffer, "/msg/interpreter_welcome.txt"); // print welcome message // assert(system("cat IAT/msg/interpreter_welcome.txt\n") != -1); printTextFile(pathbuffer); free(pathbuffer); // initialize references and cpu References* references = initReferences(); CPUStatus* cpu = initCPU(); int status = 0; // main loop while (1) { interpretPrompt(references, cpu, &status); if (status == EXECUTE_HALT) { break; } } // print status printRegisters(cpu); printMemory(cpu); // garbage collecting destroyReferences(references); destroyCPU(cpu); return EXIT_SUCCESS; }
void initializeGameboy() { sgbMode = false; switch(gbcModeOption) { case 0: // GB initGBMode(); break; case 1: // GBC if needed if (rom[0][0x143] == 0xC0) initGBCMode(); else initGBMode(); break; case 2: // GBC if (rom[0][0x143] == 0x80 || rom[0][0x143] == 0xC0) initGBCMode(); else initGBMode(); break; } bool sgbEnhanced = rom[0][0x14b] == 0x33 && rom[0][0x146] == 0x03; if (sgbEnhanced && resultantGBMode != 2 && probingForBorder) { resultantGBMode = 2; nukeBorder = false; } else { probingForBorder = false; } initMMU(); initCPU(); initLCD(); initGFX(); initSND(); if (!probingForBorder && suspendStateExists) { loadState(-1); // enter the console on resume advanceFrame = true; } updateScreens(); }
bool ARMCPU::start(IOService* provider) { IOLog("ARMCPU::start: Starting ARM CPU IOKit provider...\n"); if(!super::start(provider)) { panic("Failed to start super IOCPU provider"); } gIC = new ARMDumbInterruptController; if(!gIC) { panic("Failed to alloc class for dumb interrupt controller, we suck hard"); } gIC->initCPUInterruptController(1); gIC->attach(this); gIC->registerCPUInterruptController(); setCPUState(kIOCPUStateUninitalized); initCPU(true); registerService(); return true; }
bool AppleI386CPU::start(IOService * provider) { // kern_return_t result; if (!super::start(provider)) return false; cpuIC = new AppleI386CPUInterruptController; if (cpuIC == 0) return false; if (cpuIC->initCPUInterruptController(1) != kIOReturnSuccess) return false; cpuIC->attach(this); cpuIC->registerCPUInterruptController(); #ifdef NOTYET // Register this CPU with mach. result = ml_processor_register((cpu_id_t)this, 0, &machProcessor, &ipi_handler, true); if (result == KERN_FAILURE) return false; #endif setCPUState(kIOCPUStateUninitalized); #ifdef NOTYET processor_start(machProcessor); #endif // Hack. Call initCPU() ourself since no one else will. initCPU(true); registerService(); return true; }
// Reset the cpu void resetCPU(Cpu *cpu) { // Re-initialise the cpu initCPU(cpu); // TDOD: reset timers and display stuff }
void Host::initialize() { initCPU(); initGPU(); initOS(); }
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(int argc, char **argv){ // Be nice to other processes. Helps reduce mouse lag setpriority(PRIO_PROCESS, 0, 20); // Make sure we're running in the exe's directory char path[PATH_MAX]; if (realpath("/proc/self/exe", path)){ char *slash = strrchr(path, '/'); if (slash) *slash = '\0'; chdir(path); } initGlobals(); float runTime = 1e30f; float staticTime = 0; bool isStatic = false, lastStatic = false; for (int i = 1; i < argc; i++){ if (strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--run-for") == 0){ if (++i < argc){ runTime = atof(argv[i]); } } else if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--static") == 0){ isStatic = true; lastStatic = true; continue; } else if (lastStatic){ staticTime = atof(argv[i]); } else { printf("Unknown argument: %s\n", argv[i]); } lastStatic = false; } Display *display; int screen; initCPU(); cpuHz = getHz(); if (!app->init()) return 0; app->resetCamera(); display = XOpenDisplay(0); screen = DefaultScreen(display); app->setDisplay(display, screen); app->initDisplayModes(); app->initMenu(); //toggleFullscreen = false; time = 0; // uint64 prev, curr = getCycleNumber(); timeval prev, curr; gettimeofday(&curr, NULL); float rTime = 0; do { //if (toggleFullscreen) fullscreen = !fullscreen; toggleFullscreen = false; captureMouse = fullscreen; if (fullscreen) app->setDisplayMode(width = fullscreenWidth, height = fullscreenHeight, refreshRate); if (app->initAPI()){ app->showCursor(!captureMouse); if (captureMouse) XWarpPointer(display, None, window, 0,0,0,0, middleX, middleY); if (app->load()){ XEvent event; unsigned int key; done = false; do { ///* while (XPending(display) > 0){ XNextEvent(display, &event); switch (event.type){ case Expose: if (event.xexpose.count != 0) break; break; case MotionNotify: if (captureMouse){ static bool changeMouse; float mouseSensibility = 0.0005f * mouseSpeed; //app->rotateView(mouseSensibility * (middleY - event.xmotion.y) * (invertMouse? 1 : -1), // mouseSensibility * (middleX - event.xmotion.x)); //float a = mouseSensibility * (middleY - event.xmotion.y) * (invertMouse? 1 : -1); //float b = mouseSensibility * (middleX - event.xmotion.x); mousexxxxxx = mouseSensibility * (middleY - event.xmotion.y) * (invertMouse? 1 : -1); mouseyyyyyy = mouseSensibility * (middleX - event.xmotion.x); printf("%f %f\n", mouseSensibility, middleY); if (changeMouse = !changeMouse) XWarpPointer(display, None, window, 0,0,0,0, middleX, middleY); } app->setMousePos(event.xmotion.x, event.xmotion.y, 0); break; case ConfigureNotify: app->setViewport(width = event.xconfigure.width, height = event.xconfigure.height); if (!fullscreen){ windowedLeft = event.xconfigure.x; windowedRight = event.xconfigure.width + windowedLeft; windowedTop = event.xconfigure.y; windowedBottom = event.xconfigure.height + windowedTop; } middleX = event.xconfigure.width / 2; middleY = event.xconfigure.height / 2; break; case ButtonPress: if (!captureMouse && event.xbutton.button == 1){ //XGrabPointer(display, window, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, window, blankCursor, CurrentTime); app->showCursor(false); XWarpPointer(display, None, window, 0, 0, 0, 0, middleX, middleY); captureMouse = true; } app->setButton((event.xbutton.button == 1)? MOUSE_LEFT : MOUSE_RIGHT, true); break; case ButtonRelease: app->setButton((event.xbutton.button == 1)? MOUSE_LEFT : MOUSE_RIGHT, false); break; case KeyPress: key = XLookupKeysym(&event.xkey, 0); if (key == XK_Return && app->getKey(XK_Alt_L)){ app->toggleScreenMode(); app->closeWindow(); } else { app->processKey(key); char str[8]; int nChar = XLookupString(&event.xkey, str, sizeof(str), NULL, NULL); for (int i = 0; i < nChar; i++) app->processChar(str[i]); } break; case KeyRelease: key = XLookupKeysym(&event.xkey, 0); app->setKey(key, false); break; case ClientMessage: if (*XGetAtomName(display, event.xclient.message_type) == *"WM_PROTOCOLS"){ app->closeWindow(); } break; default: break; } } //*/ prev = curr; // curr = getCycleNumber(); // frameTime = (float) (double(curr - prev) / cpuHz); gettimeofday(&curr, NULL); frameTime = (float(curr.tv_sec - prev.tv_sec) + 0.000001f * float(curr.tv_usec - prev.tv_usec)); if (isStatic){ time = staticTime; } else { time += frameTime; } rTime += frameTime; if (rTime > runTime) done = true; app->controls(); /*int a = 0; for (unsigned long int i = 0; i < 10000000000; i++){ a++; } printf("%d ",a);*/ app->beginFrame(); app->drawFrame(); app->drawGUI(); app->endFrame(); } while (!done); app->unload(); } else { printf(getLogString()); } app->closeAPI(); } else { printf(getLogString()); } //if (fullscreen) app->resetDisplayMode(); XDestroyWindow(display, window); } while (toggleFullscreen); if (fullscreen) app->resetDisplayMode(); app->exit(); delete app; XCloseDisplay(display); flushGlobals(); clearLog(); return 0; }
int processor() { pid_t pid; int result; //Creating the two pipes: toMemory and toProcessor. result = pipe(toMemory); if (result == -1) exit(1); result = pipe(toProcessor); if (result == -1) exit(1); //Creating a child process pid = fork(); switch(pid) { case -1: printf("The fork call was not completed. Check system configuration\n"); exit(1); break; /*******************************************THIS IS THE MEMORY CODE**********************************/ case 0: result = -1; struct data obj; int memory[1000]; //Load the program from the file result = loadProgramFromFile(memory, 1000); if (result == -1){ printf("\nError while reading the program from the file. Exiting Program.\n"); fflush(stdout); exit(1); } read(toMemory[0], &obj , sizeof(obj)); while(obj.controlCharacter!=' ') { switch(obj.controlCharacter) { //Read Operation. Data is written into data bus and sent to the parent/processor case 'r': obj.data = memory[obj.address]; //to write the data into Data Bus write(toProcessor[1], &obj, sizeof(obj)); break; //Write Operation. Data from the data bus is written into the address from the Data Bus. case 'w': memory[obj.address] = obj.data; break; //Exit signal is sent to child process/memory. case 'e': _exit(0); break; //Control Signal could not be identified. Erroneous control signal. default: printf("\n\nControl Signal could not be indentified\n\n"); fflush(stdout); break; } read(toMemory[0], &obj, sizeof(obj)); } _exit(0); break; /**********************************THIS IS THE PROCESSOR CODE******************************/ default: result = -1; //Registers int PC, IR, SP, AC, X, Y, TEMP; char eop = '0'; //Initialise the CPU registers initCPU(&PC,&SP,&IR,&AC,&X,&Y,&TEMP); while(eop == '0') { //Get the Instruction from the memory process by pipe and store it in IR IR = readDataFromMemory(PC); PC++; //printf("\nAC=%d ", AC); //printf("PC=%d ", PC-1); //printf("IR=%d ", IR); //printf("SP=%d ", SP); //printf("X=%d ", X); //printf("Y=%d\n", Y); //Code that will interpret instructions and execute them switch(IR) { case 0: //No Operation instruction break; case 1: AC = readDataFromMemory(PC); PC++; break; case 2: TEMP = readDataFromMemory(PC); PC++; AC = readDataFromMemory(TEMP); break; case 3: TEMP = readDataFromMemory(PC); PC++; writeDataIntoMemory(TEMP,AC); break; case 4: AC = AC + X; break; case 5: AC = AC + Y; break; case 6: AC = AC - X; break; case 7: AC = AC - Y; break; case 8: TEMP = readDataFromMemory(PC); PC++; fflush(stdout); char c; switch(TEMP) { case 1: scanf("%d",&AC); break; case 2: scanf("%c",&c); AC = c; break; default: exitParent("Invalid operand for Get Port instruction"); } break; //Put port instruction case 9: TEMP = readDataFromMemory(PC); PC++; switch(TEMP) { case 1: printf("%d",AC); break; case 2: printf("%c",AC); break; default: exitParent("Invalid operand for Put Port instruction."); } fflush(stdout); break; case 10: X=AC; break; case 11: Y=AC; break; case 12: AC=X; break; case 13: AC=Y; break; //Jump case 14: PC = readDataFromMemory(PC); break; //Jump if AC=0 case 15: if(AC == 0) PC = readDataFromMemory(PC); else PC++; break; //Jump if AC!=0 case 16: if(AC != 0) PC = readDataFromMemory(PC); else PC++; break; //Call subroutine case 17: TEMP=readDataFromMemory(PC); PC++; writeDataIntoMemory(SP,PC); PC = TEMP; SP = SP - 1; break; //Return case 18: SP = SP + 1; PC=readDataFromMemory(SP); break; //Increment X case 19: X = X + 1; break; //Decrement X case 20: X = X - 1; break; case 30: exitParent(""); break; default: fflush(stdout); exitParent("Invalid Instruction encountered"); } } } return 0; }