int main(int argc, char *argv[]) { // A201860038A00798E903A818A9028501A60165008501860088D0F5 // const char program[] = { 0xC8, 0x20, 0x00, 0x00 }; // const char program[] = { 0xA2, 0x01, 0x86, 0x00, 0x38, 0xA0, 0x07, 0x98, 0xE9, 0x03, 0xA8, 0x18, 0xA9, 0x02, 0x85, 0x01, 0xA6, 0x01, 0x65, 0x00, 0x85, 0x01, 0x86, 0x00, 0x88, 0xD0, 0xF5 }; if(argc != 2) { printf("Usage: %s program \n", argv[0]); return -1; } char *program; int program_length = readFileBytes(argv[1], &program); printf("Program (%i bytes): \n", program_length); int i; for(i = 0; i < program_length; i++) { printf("%i:%02X ", i, (unsigned char)program[i]); } printf("\n"); CPU cpu; initializeCPU(&cpu); cpu.pc = 0x4000; writeMemory(&cpu, program, cpu.pc, program_length); // cpu.pc += 559; // 700 // 799 // cpu.pc += 799; // test 06 // cpu.pc += 1192; // test 09 // char *buf = malloc(sizeof(char) * 2); // buf[0] = 0xC0; // buf[1] = 0x01; // writeMemory(&cpu, buf, 0x0105, 2); // cpu.ps = 0x1; // cpu.a = 0x7; // cpu.x = 0x2; // cpu.y = 0x3; // char *buf2 = malloc(sizeof(char) * 2); // buf2[0] = 0x08; // buf2[1] = 0xEE; // writeMemory(&cpu, buf2, 0x0105, 2); // printf("cpu->ps: %i\n", cpu.ps); // printf("cpu->sp: %i\n", cpu.sp); char str[1]; // int i; for(;;) { printf("cpu->pc: %i\n", cpu.pc); // scanf("%s", str); step(&cpu); printMemory(&cpu); printf("\n\n\n"); printf("cpu->sp: %x\n", cpu.sp); printf("cpu->a: %x\n", cpu.a); printf("cpu->x: %x\n", cpu.x); printf("cpu->y: %x\n", cpu.y); printf("cpu->ps: %x\n\n", cpu.ps); if(cpu.pc == 17825) { break; } } printMemory(&cpu); printf("### results:\n"); printf("cpu->sp: %x\n", cpu.sp); printf("cpu->a: %x\n", cpu.a); printf("cpu->x: %x\n", cpu.x); printf("cpu->y: %x\n", cpu.y); printf("cpu->ps: %x\n", cpu.ps); printf("cpu->cycles: %i\n", cpu.cycles); // printf("%s\n", ); // printbitssimple(cpu.ps); printf("MEMORY 9: %x\n", *cpu.memory[0x80]); printf("MEMORY final: %x\n", *cpu.memory[0x0210]); freeCPU(&cpu); return 0; }
void main(void) { srand(time(NULL)); char processNameSetUp[10] = "Process"; int i = 0; FIFO_queue_p PCBContainer = createLinkedList(); PCB_p tempPCB; int PCBCounter = 0; int loopCounter = 0; int numberOfPCB = 0; FILE* outFile = fopen("scheduleTrace.txt", "w+"); fprintf(outFile, "Group 5: Nok Him Nam, Jowy Tran, Mark Johnson, David Humphreys\nDate (DD/MM/YY) : 28/ 01/ 2015\nAssignment : Problem 2 - Scheduling\n"); //Create CPU CPU_instance_p testingCPU = createCPU(); //Master CPU Loop while (loopCounter <= MAX_NUMBER_OF_RUNTIME) { if (loopCounter % PRINT_EVERY_xTIMES == 0) { fprintf(outFile, "\n__________NEXT TIME QUANTUM : %d___________\n", loopCounter); } numberOfPCB = rand() % 6; //While the number of PCBs created is less than 30, create more PCBs if (PCBCounter < MAX_NUMBER_OF_PCB && PCBCounter + numberOfPCB <= MAX_NUMBER_OF_PCB) { if (loopCounter % PRINT_EVERY_xTIMES == 0) { //fprintf(outFile, "\n__________NEXT TIME QUANTUM : %d___________\n", loopCounter); fprintf(outFile, "//----------------------------------\n"); fprintf(outFile, "We are creating %d PCBs \n\n", numberOfPCB); } for (i = 0; i < numberOfPCB; i++) { sprintf(processNameSetUp, "Process%d", PCBCounter); enqueue(PCBContainer, tempPCB = createPCB(processNameSetUp, PCBCounter, rand() % 15, 0, 1000 * PCBCounter, ready)); if (loopCounter % PRINT_EVERY_xTIMES == 0) { toStringFileVersion(tempPCB, outFile); } strcpy(processNameSetUp, "Process"); PCBCounter++; } } else if(PCBCounter == MAX_NUMBER_OF_PCB && loopCounter % 4 == 0) { fprintf(outFile, "We are done creating PCBs\n"); } if (loopCounter % PRINT_EVERY_xTIMES == 0) { fprintf(outFile, "//----------------------------------\n"); } //If we have started a running processes, increment the PC value to simulate running if (testingCPU->runningProcess != NULL) { testingCPU->runningProcess->pc += rand() % 1000 + 3000; //strcpy(testingCPU->systemStack->name, testingCPU->runningProcess->name); testingCPU->systemStack->pc = testingCPU->runningProcess->pc; } //else, create a temp "fake" processs PCB till a "real" one is created else { testingCPU->runningProcess = createPCB("Default", 0, 0, 0, 0, running); testingCPU->systemStack = createPCB("Default", 0, 0, 0, 0, running); } //Simulate Timer Interrupt timerISR(testingCPU, PCBContainer); if (loopCounter % PRINT_EVERY_xTIMES == 0) { //PRINT RESULTS AFTER TIMER ISR fprintf(outFile, "\nRunning process: \n"); //printf("//--------------------------------------\n"); toStringFileVersion(testingCPU->runningProcess, outFile); fprintf(outFile, "//---------------------------------------\n\n"); fprintf(outFile, "State of the Ready Queue: \n\n"); printListFileVersion(testingCPU->readQueue_p, outFile); fprintf(outFile, "\n\n"); } //pseudo halt for debug screen //getchar(); //one run has passed loopCounter++; } //free used memory freeLinkedList(PCBContainer); freeCPU(testingCPU); }