int main (void) { init(); while (1) { printRegisters(); _delay_ms(5000); } }
void cosimWriteBlock(Core *core, uint32_t pc, uint32_t address, int mask, const uint32_t values[16]) { uint64_t byteMask; int lane; byteMask = 0; for (lane = 0; lane < 16; lane++) { if (mask & (1 << lane)) byteMask |= 0xfLL << (lane * 4); } cosimEventTriggered = 1; if (cosimCheckEvent != kEventMemStore || cosimCheckPc != pc || cosimCheckAddress != (address & ~63) || cosimCheckMask != byteMask || !compareMasked(mask, cosimCheckValues, values)) { cosimError = 1; printRegisters(core, cosimCheckThread); printf("COSIM MISMATCH, thread %d\n", cosimCheckThread); printf("Reference: %08x memory[%x]{%016llx} <= ", pc, address, byteMask); for (lane = 15; lane >= 0; lane--) printf("%08x ", values[lane]); printf("\nHardware: "); printCosimExpected(); return; } }
void cosimSetVectorReg(Core *core, uint32_t pc, uint32_t reg, uint32_t mask, const uint32_t *values) { int lane; cosimEventTriggered = true; if (cosimCheckEvent != EVENT_VECTOR_WRITEBACK || cosimCheckPc != pc || cosimCheckRegister != reg || !compareMasked(mask, cosimCheckValues, values) || cosimCheckMask != (mask & 0xffff)) { cosimError = true; printRegisters(core, cosimCheckThread); printf("COSIM MISMATCH, thread %d\n", cosimCheckThread); printf("Reference: %08x v%d{%04x} <= ", pc, reg, mask & 0xffff); for (lane = NUM_VECTOR_LANES - 1; lane >= 0; lane--) printf("%08x ", values[lane]); printf("\n"); printf("Hardware: "); printCosimExpected(); return; } }
void cosimWriteBlock(Core *core, uint32_t pc, uint32_t address, uint32_t mask, const uint32_t *values) { uint64_t byteMask; int lane; byteMask = 0; for (lane = 0; lane < NUM_VECTOR_LANES; lane++) { if (mask & (1 << lane)) byteMask |= 0xfull << (lane * 4); } cosimEventTriggered = true; if (cosimCheckEvent != EVENT_MEM_STORE || cosimCheckPc != pc || cosimCheckAddress != (address & ~(NUM_VECTOR_LANES * 4u - 1)) || cosimCheckMask != byteMask || !compareMasked(mask, cosimCheckValues, values)) { cosimError = true; printRegisters(core, cosimCheckThread); printf("COSIM MISMATCH, thread %d\n", cosimCheckThread); printf("Reference: %08x memory[%x]{%016" PRIx64 "} <= ", pc, address, byteMask); for (lane = NUM_VECTOR_LANES - 1; lane >= 0; lane--) printf("%08x ", values[lane]); printf("\nHardware: "); printCosimExpected(); return; } }
void cosimWriteMemory(Core *core, uint32_t pc, uint32_t address, uint32_t size, uint32_t value) { uint32_t hardwareValue; uint64_t referenceMask; hardwareValue = cosimCheckValues[(address & CACHE_LINE_MASK) / 4]; if (size < 4) { uint32_t mask = (1 << (size * 8)) - 1; hardwareValue &= mask; value &= mask; } referenceMask = ((1ull << size) - 1ull) << (CACHE_LINE_MASK - (address & CACHE_LINE_MASK) - (size - 1)); cosimEventTriggered = true; if (cosimCheckEvent != EVENT_MEM_STORE || cosimCheckPc != pc || cosimCheckAddress != (address & ~CACHE_LINE_MASK) || cosimCheckMask != referenceMask || hardwareValue != value) { cosimError = true; printRegisters(core, cosimCheckThread); printf("COSIM MISMATCH, thread %d\n", cosimCheckThread); printf("Reference: %08x memory[%x]{%016" PRIx64 "} <= %08x\n", pc, address & ~CACHE_LINE_MASK, referenceMask, value); printf("Hardware: "); printCosimExpected(); return; } }
void cosimWriteMemory(Core *core, uint32_t pc, uint32_t address, size_t size, uint32_t value) { uint32_t hardwareValue; uint64_t referenceMask; hardwareValue = cosimCheckValues[(address % 63) / 4]; if (size < 4) { uint32_t mask = (1 << (size * 8)) - 1; hardwareValue &= mask; value &= mask; } referenceMask = ((1ull << size) - 1ull) << (63 - (address & 63) - (size - 1)); cosimEventTriggered = 1; if (cosimCheckEvent != kEventMemStore || cosimCheckPc != pc || cosimCheckAddress != (address & ~63) || cosimCheckMask != referenceMask || hardwareValue != value) { cosimError = 1; printRegisters(core, cosimCheckThread); printf("COSIM MISMATCH, thread %d\n", cosimCheckThread); printf("Reference: %08x memory[%x]{%016llx} <= %08x\n", pc, address & ~63, referenceMask, value); printf("Hardware: "); printCosimExpected(); return; } }
/** * The halt service routine. It should simulate * a halt of the program and computer */ void halt(){ printRegisters(); //printMemory(); fprintf(stderr, "Simulator halted\n"); exit(1); }
int main() { uart_init(UART_BAUD_SELECT(UART_BAUD_RATE, F_CPU)); sei(); uart_puts("begin\r\n"); nrfInit(); writeReg(RF_SETUP, SET_RF_SETUP); writeAddr(RX_ADDR_P0, SET_RX_ADDR_P0); writeAddr(TX_ADDR, SET_TX_ADDR); writeReg(DYNPD, SET_DYNPD); writeReg(FEATURE, SET_FEATURE); writeReg(RF_CH, SET_RF_CH); writeReg(CONFIG, SET_CONFIG); startRadio(); uint8_t worked; uint8_t size; char sendbuffer[] = "Testing 1..2..3.. Testing."; size = sizeof (sendbuffer); char receivebuffer[33]; char c; char count[10]; int charbuffer; char payloadlength; // uart_puts(sendbuffer); worked = transmit(sendbuffer, size); if (worked == 1) { uart_puts("Transmit Worked!\r\n"); } else { uart_puts("Transmit Failed.\r\n"); } startRx(); while (1) { payloadlength = dynReceive(receivebuffer); if (payloadlength > 0) { uart_puts("Got something:"); uart_puts(receivebuffer); uart_puts("\r\n"); } else { uart_puts("nothin received\r\n"); } c = uart_getc(); if (!(c & UART_NO_DATA)) { uart_putc(c); } printRegisters(); _delay_ms(2000); } }
static uint32_t readMemoryWord(const Thread *thread, uint32_t address) { if ((address & 0xffff0000) == 0xffff0000) return readDeviceRegister(address & 0xffff); if (address >= thread->core->memorySize) { printf("Load Access Violation %08x, pc %08x\n", address, thread->currentPc - 4); printRegisters(thread->core, thread->id); thread->core->halt = 1; // XXX Perhaps should stop some other way... return 0; } return thread->core->memory[address / 4]; }
void LLScriptLSOParse::printData(LLFILE *fp) { printNameDesc(fp); printRegisters(fp); printGlobals(fp); printGlobalFunctions(fp); printStates(fp); printHeap(fp); }
void cosimSetScalarReg(Core *core, uint32_t pc, uint32_t reg, uint32_t value) { cosimEventTriggered = true; if (cosimCheckEvent != EVENT_SCALAR_WRITEBACK || cosimCheckPc != pc || cosimCheckRegister != reg || cosimCheckValues[0] != value) { cosimError = true; printRegisters(core, cosimCheckThread); printf("COSIM MISMATCH, thread %d\n", cosimCheckThread); printf("Reference: %08x s%d <= %08x\n", pc, reg, value); printf("Hardware: "); printCosimExpected(); return; } }
void Debugger::debugConsole(std::uint16_t address) { std::cout << "Debugger [" << pc_<< "]> "; std::string command; std::getline( std::cin, command); std::vector<std::string> command_list = split(command, ' '); if(command_list.front() == "help") { printHelp(); } else if (command_list.front() == "c") { continueExec(); return; } else if (command_list.front() == "pr") { printRegisters(); } else if (command_list.front() == "pm") { uint16_t addr = (command_list.size() == 2)? atoi(command_list[1].c_str()) : pc_; printMemory(addr); } else if (command_list.front() == "ps") { std::cout << "--Stack--" << std::endl; printStack(stack_); } else if (command_list.front() == "disa") { uint16_t addr = (command_list.size() == 2)? atoi(command_list[1].c_str()) : pc_; printCodeBlockAt(addr); } else if(command_list.front() == "br") { uint16_t addr = (command_list.size() == 2)? atoi(command_list[1].c_str()) : pc_; setBreakPoint(addr); } else if(command_list.front() == "cbr") { uint16_t addr = (command_list.size() == 2)? atoi(command_list[1].c_str()) : pc_; clearBreakPoint(addr); } else if(command_list.front() == "setr") { setRegester(atoi(command_list[1].c_str()), atoi(command_list[2].c_str())); } else if(command_list.front() == "setm") { setMemeory(atoi(command_list[1].c_str()), atoi(command_list[2].c_str())); } else if(command_list.front() == "push") { stack_.push(atoi(command_list[1].c_str())); } else if(command_list.front() == "pop") { stack_.pop(); } else if (command_list.front() == "s") { return; } else { std::cout << "Unknowen command type 'help' for list of comamnds" << std::endl; } debugConsole(pc_); return; }
static void illegalInstruction(Thread *thread, uint32_t instr) { if (thread->core->stopOnFault) { printf("Illegal instruction %08x thread %d PC %08x\n", instr, thread->id, thread->currentPc - 4); printRegisters(thread->core, thread->id); thread->core->halt = 1; } else { // Allow core to dispatch thread->lastFaultPc = thread->currentPc - 4; thread->currentPc = thread->core->faultHandlerPc; thread->lastFaultReason = FR_ILLEGAL_INSTRUCTION; thread->interruptEnable = 0; } }
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; }
static void memoryAccessFault(Thread *thread, uint32_t address, int isLoad) { if (thread->core->stopOnFault) { printf("Invalid %s access thread %d PC %08x address %08x\n", isLoad ? "load" : "store", thread->id, thread->currentPc - 4, address); printRegisters(thread->core, thread->id); thread->core->halt = 1; } else { // Allow core to dispatch thread->lastFaultPc = thread->currentPc - 4; thread->currentPc = thread->core->faultHandlerPc; thread->lastFaultReason = FR_INVALID_ACCESS; thread->interruptEnable = 0; thread->lastFaultAddress = address; } }
int main(int argc, const char * argv[]) { // stackAlignmentCheck(); callPrintf(); // forLoop(); // // insert code here... // printf("Hello\n"); // asmMain(666); printRegisters(); // foo(7); // intelDoNothing(); // intelDoNothingExplicitPush(); // callAssemblyFunctionFromAnotherFile(); //labels(); int* array = getGlobalArray(); //useGlobalVariables(); // int res = intelMultiplyTwoInt32(7, 12); // res = res + 3; return 11; }
void cosimSetVectorReg(Core *core, uint32_t pc, int reg, int mask, const uint32_t values[16]) { int lane; cosimEventTriggered = 1; if (cosimCheckEvent != kEventVectorWriteback || cosimCheckPc != pc || cosimCheckRegister != reg || !compareMasked(mask, cosimCheckValues, values) || cosimCheckMask != (mask & 0xffff)) { cosimError = 1; printRegisters(core, cosimCheckThread); printf("COSIM MISMATCH, thread %d\n", cosimCheckThread); printf("Reference: %08x v%d{%04x} <= ", pc, reg, mask & 0xffff); for (lane = 15; lane >= 0; lane--) printf("%08x ", values[lane]); printf("\n"); printf("Hardware: "); printCosimExpected(); return; } }
void TbTrace::onItem(unsigned traceIndex, const s2e::plugins::ExecutionTraceItemHeader &hdr, void *item) { //m_output << "Trace index " << std::dec << traceIndex << std::endl; if (hdr.type == s2e::plugins::TRACE_MOD_LOAD) { const s2e::plugins::ExecutionTraceModuleLoad &load = *(s2e::plugins::ExecutionTraceModuleLoad*)item; m_output << "Loaded module " << load.name << " at 0x" << std::hex << load.loadBase; m_output << std::endl; return; } if (hdr.type == s2e::plugins::TRACE_MOD_UNLOAD) { const s2e::plugins::ExecutionTraceModuleUnload &unload = *(s2e::plugins::ExecutionTraceModuleUnload*)item; m_output << "Unloaded module at 0x" << unload.loadBase; m_output << std::endl; return; } if (hdr.type == s2e::plugins::TRACE_PAGEFAULT) { const s2e::plugins::ExecutionTracePageFault &fault = *(s2e::plugins::ExecutionTracePageFault*)item; m_output << "PF @" << std::hex << fault.pc << " addr=" << fault.address << " isWrite=" << (int) fault.isWrite; m_output << std::endl; return; } if (hdr.type == s2e::plugins::TRACE_EXCEPTION) { const s2e::plugins::ExecutionTraceException &fault = *(s2e::plugins::ExecutionTraceException*)item; m_output << "EXCP @" << std::hex << fault.pc << " vec=" << fault.vector; m_output << std::endl; return; } if (hdr.type == s2e::plugins::TRACE_STATE_SWITCH) { const s2e::plugins::ExecutionTraceStateSwitch &s = *(s2e::plugins::ExecutionTraceStateSwitch*)item; m_output << "State switch " << hdr.stateId << " => " << s.newStateId; m_output << std::endl; return; } if (hdr.type == s2e::plugins::TRACE_FORK) { s2e::plugins::ExecutionTraceFork *f = (s2e::plugins::ExecutionTraceFork*)item; m_output << "Forked at 0x" << std::hex << f->pc << " - "; printDebugInfo(hdr.pid, f->pc, 0, false); m_output << std::endl; return; } if (hdr.type == s2e::plugins::TRACE_TB_START) { const s2e::plugins::ExecutionTraceTb *te = (const s2e::plugins::ExecutionTraceTb*) item; m_output << "0x" << std::hex << te->pc<< " - "; if (PrintRegisters) { m_output << std::endl << " "; printRegisters(te); m_output << std::endl << " "; } printDebugInfo(hdr.pid, te->pc, te->size, true); m_output << std::endl; m_hasItems = true; return; } if (PrintMemory && (hdr.type == s2e::plugins::TRACE_MEMORY)) { const s2e::plugins::ExecutionTraceMemory *te = (const s2e::plugins::ExecutionTraceMemory*) item; std::string type; type += te->flags & EXECTRACE_MEM_SYMBHOSTADDR ? "H" : "-"; type += te->flags & EXECTRACE_MEM_SYMBADDR ? "A" : "-"; type += te->flags & EXECTRACE_MEM_SYMBVAL ? "S" : "-"; type += te->flags & EXECTRACE_MEM_WRITE ? "W" : "R"; m_output << "S=" << std::dec << hdr.stateId << " P=0x" << std::hex << hdr.pid << " PC=0x" << std::hex << te->pc << " " << type << (int)te->size << "[0x" << std::hex << te->address << "]=0x" << std::setw(10) << std::setfill('0') << te->value; if (te->flags & EXECTRACE_MEM_HASHOSTADDR) { m_output << " hostAddr=0x" << te->hostAddress << " "; } if (te->flags & EXECTRACE_MEM_OBJECTSTATE) { m_output << " cb=0x" << te->concreteBuffer << " "; } m_output << "\t"; printDebugInfo(hdr.pid, te->pc, 0, false); m_output << std::setfill(' '); m_output << std::endl; return; } if (PrintMemoryChecker && (hdr.type == s2e::plugins::TRACE_MEM_CHECKER)) { const s2e::plugins::ExecutionTraceMemChecker::Serialized *te = (const s2e::plugins::ExecutionTraceMemChecker::Serialized*) item; printMemoryChecker(te); } }
/* * function processes each command the user enters * returns 1 if step or continue * returns 0 on success * returns -1 on error */ int runCommand(char command[]) { char *name = strtok(command, " "); char *arg1, *arg2, *arg3; int arg1value, arg2value; struct address translatedAddr; if(strcmp(name,"help")==0 || strcmp(name,"h")==0) //"help" to display all commands { printf("\n step / s\n\t Single step the exection\n\n"); printf(" continue / c\n\t Continue to next breakpoint \n\n"); printf(" reg / r \n\t Prints the value of all registers \n\n"); printf(" reg / r <register_name> \n\t Prints the value of a particular register \n\n"); printf(" reg / r <register_name1> <register_name2> \n\t Prints the value of all registers from <register_name1> to <register_name2> \n\n"); printf(" mem / m <page_num> \n\t Displays contents of a memory page \n\n"); printf(" mem / m <page_num1> <page_num2> \n\t Displays contents of memory pages from <page_num1> to <page_num2>\n\n"); printf(" pcb / p \n \t Displays the PCB with state as running \n\n"); printf(" pcb / p <pid> \n\t Displays the <pid> th PCB \n\n"); printf(" pagetable / pt \n \t Displays the page table at location pointed by PTBR \n\n"); printf(" pagetable / pt <pid> \n\t Displays the <pid> th page table \n\n"); printf(" filetable / ft \n \t Displays the System Wide Open File Table\n\n"); printf(" memfreelist / mf \n \t Displays the Memory Free List\n\n"); printf(" diskfreelist / df \n \t Displays the Memory copy of Disk Free List\n\n"); printf(" fat \n \t Displays the Memory Copy of File Allocation Table\n\n"); printf(" location / l <address> \n \t Displays the content at memory address (Translation takes place in USER mode)\n\n"); printf(" watch / w <physical address> \n \t Sets a watch point at this address\n\n"); printf(" watchclear / wc \n \t Clears all the watch points\n\n"); printf(" exit / e \n\t Exit the interface and Halt the machine\n"); printf(" help / h\n"); } else if (strcmp(name,"step") == 0 || strcmp(name,"s") == 0) //Single Stepping { step_flag = ENABLE; return 1; } else if (strcmp(name,"continue") == 0 || strcmp(name,"c") == 0) //Continue till next breakpoint { step_flag = DISABLE; return 1; } else if (strcmp(name,"reg")==0 || strcmp(name,"r")==0) //Prints the registers. { arg1 = strtok(NULL, " "); arg2 = strtok(NULL, " "); if(arg1 == NULL) printRegisters(R0, NUM_REGS-1); else if(arg2 == NULL) { arg1value = getRegArg(arg1); if(arg1value == -1) { printf("Illegal argument for \"%s\". See \"help\" for more information",name); return -1; } else printRegisters(arg1value,arg1value); } else { arg1value = getRegArg(arg1); arg2value = getRegArg(arg2); if(arg1value == -1 || arg2value == -1) { printf("Illegal argument for \"%s\". See \"help\" for more information",name); return -1; } else { if(arg1value > arg2value) //swap them { arg1value = arg1value + arg2value; arg2value = arg1value - arg2value; arg1value = arg1value - arg2value; } printRegisters(arg1value,arg2value); } } } else if (strcmp(name,"mem")==0 || strcmp(name,"m")==0) //displays pages in memory { arg1 = strtok(NULL, " "); arg2 = strtok(NULL, " "); if(arg1 == NULL) { printf("Insufficient argument for \"%s\". See \"help\" for more information",name); return -1; } else if(arg2 == NULL) { arg1value = atoi(arg1); if(arg1value >0 && arg1value < NUM_PAGES) printMemory(arg1value); else { printf("Illegal argument for \"%s\". See \"help\" for more information",name); return -1; } } else { arg1value = atoi(arg1); arg2value = atoi(arg2); if(arg1value > arg2value) //swap them { arg1value = arg1value + arg2value; arg2value = arg1value - arg2value; arg1value = arg1value - arg2value; } if(arg1value >0 && arg2value < NUM_PAGES) { while(arg1value <= arg2value) { printMemory(arg1value); arg1value++; } } else { printf("Illegal argument for \"%s\". See \"help\" for more information",name); return -1; } } } else if (strcmp(name,"pcb")==0 || strcmp(name,"p")==0) //displays PCB of a process { arg1 = strtok(NULL, " "); if(arg1 == NULL) //finds the PCB with state as running { int page_no, word_no; arg1value = 0; while(arg1value < NUM_PCB) { page_no = (READY_LIST + arg1value * PCB_ENTRY + 1) / PAGE_SIZE; word_no = (READY_LIST + arg1value * PCB_ENTRY + 1) % PAGE_SIZE; if(getInteger(page[page_no].word[word_no]) == STATE_RUNNING) break; arg1value++; } if(arg1value == NUM_PCB) { printf("No PCB found with state as running"); return -1; } } else { arg1value = atoi(arg1); if(arg1value<0 || arg1value >=NUM_PCB) { printf("Illegal argument for \"%s\". See \"help\" for more information",name); return -1; } } printPCB(arg1value); } else if (strcmp(name,"pagetable")==0 || strcmp(name,"pt")==0) //displays Page Table of a process { arg1 = strtok(NULL, " "); if(arg1 == NULL) //finds the page table using PTBR { int page_no, word_no; arg1value = getInteger(reg[PTBR_REG]); if(arg1value < PAGE_TABLE || arg1value > (PAGE_TABLE + ((NUM_PCB-1)*NUM_PAGE_TABLE*PAGE_TABLE_ENTRY)) ) { printf("Illegal PTBR value"); return -1; } } else { if(atoi(arg1) < 0 || atoi(arg1) >= NUM_PCB ) { printf("Illegal argument for \"%s\". See \"help\" for more information",name); return -1; } arg1value = PAGE_TABLE + atoi(arg1) * (PAGE_TABLE_ENTRY * NUM_PAGE_TABLE); } printPageTable(arg1value); } else if (strcmp(name,"filetable")==0 || strcmp(name,"ft")==0) //displays System Wide Open File Table printFileTable(); else if (strcmp(name,"memfreelist")==0 || strcmp(name,"mf")==0) //displays Memory Free Lisk printMemFreeList(); else if (strcmp(name,"diskfreelist")==0 || strcmp(name,"df")==0) //displays Disk Free List printDiskFreeList(); else if (strcmp(name,"fat")==0) //displays File Allocation Table printFAT(); else if (strcmp(name,"location")==0 || strcmp(name,"l")==0 ) //displays a content of a memory location { arg1 = strtok(NULL, " "); if(arg1 == NULL) { printf("Insufficient argument for \"%s\". See \"help\" for more information",name); return -1; } translatedAddr = translate_debug(atoi(arg1)); if(getType(arg1) == TYPE_STR || (translatedAddr.page_no == -1 && translatedAddr.word_no == -1) ) { printf("Illegal argument for \"%s\". See \"help\" for more information",name); return -1; } printLocation(translatedAddr); } else if (strcmp(name,"watch")==0 || strcmp(name,"w")==0 ) //Sets watch point to a memory location { arg1 = strtok(NULL, " "); if(arg1 == NULL) { printf("Insufficient argument for \"%s\". See \"help\" for more information",name); return -1; } if( getType(arg1) == TYPE_STR || atoi(arg1) < 0 || atoi(arg1) >= SIZE_OF_MEM ) { printf("Illegal argument for \"%s\". See \"help\" for more information",name); return -1; } if( watch_count >= NUM_WATCH) { printf("You have already used %d watch points. No more watch points can be set.\nUse \"watchclear\" to clear all watch points. \n", NUM_WATCH ); return -1; } watch[watch_count].addr.page_no = atoi(arg1) / PAGE_SIZE; watch[watch_count].addr.word_no = atoi(arg1) % PAGE_SIZE; strcpy(watch[watch_count].value, page[watch[watch_count].addr.page_no].word[watch[watch_count].addr.word_no]); watch_count++; printf("Watch point %d set.\n",watch_count); } else if (strcmp(name,"watchclear")==0 || strcmp(name,"wc")==0 ) //Clears all watch points { initialize_Watch(); printf("All watch points cleared.\n"); } else if (strcmp(name,"exit")==0 || strcmp(name,"e")==0) //Exits the interface exit(0); else { printf("Unknown command \"%s\". See \"help\" for more information",name); return -1; } return 0; }
void interpretPrompt(References* r, CPUStatus* cpu, int* status) { // show prompt ready printf("> "); fflush(stdout); // get new command char* line = (char*) calloc(MAX_STRING_LENGTH, sizeof(char)); if (line == NULL) { perror("calloc error in interpretPrompt\n"); exit(EXIT_FAILURE); } if (fgets(line, MAX_STRING_LENGTH, stdin) == NULL) { perror("fgets error in interpretPrompt\n"); exit(EXIT_FAILURE); } // remove endline removeEndLine(line); int assembleCode = 0; // interpreter commands if (stringEquals(line, "regs") == 0) { printRegisters(cpu); *status = RUN_COMMAND; free(line); return; } else if (stringEquals(line, "mem") == 0) { printMemory(cpu); *status = RUN_COMMAND; free(line); return; } else if (stringEquals(line, "exit") == 0) { *status = EXECUTE_HALT; free(line); return; } else if (stringEquals(line, "show") == 0) { printInstructions(r); *status = RUN_COMMAND; free(line); return; } else { // assemble One Pass assembleCode = onePass(r, cpu, line); } // execute interpreter if (assembleCode == ASSEMBLE_OK || (assembleCode == ASSEMBLE_LABEL && r->currentAddress > 4)) { interpret(r, cpu, status); } free(line); }
/** * Executes one instruction */ void clockTick(int sig) { //Uses bit manipulation to isolate all values int instruction = (instructionMemory[programCounter] >> 26) & 0x3f; //000111111 int field1 = instructionMemory[programCounter] >> 21 & 0x01f; //00000011111; int field2 = (instructionMemory[programCounter] >> 16) & 0x01f; //0000000000011111; int field3 = (instructionMemory[programCounter] >> 11) & 0x01f; //000000000000000011111; int field5 = instructionMemory[programCounter] & 0x03f; //00000000000000000000000000111111; int addressField = instructionMemory[programCounter] & 0x0000ffff; //00000000000000001111111111111111; int jType = instructionMemory[programCounter] & 0x03ffffff ; //00000011111111111111111111111111 //Print Summary printf("\nProgram Counter: %d op: %d field1: %d field2: %d field3 Register: %d address: %d\n", programCounter, instruction, registers[field1].value, registers[field2].value, field3, addressField); switch(instruction) { //add or subtract case 0: switch(field5) { //add case 32:; int sum = registers[field1].value + registers[field2].value; changeRegisterValue(®isters[field3], sum); programCounter++; break; //subtract case 34:; int difference = registers[field1].value - registers[field2].value; changeRegisterValue(®isters[field3], difference); programCounter++; break; //slt case 42:; int lessThan = 0; if(registers[field1].value < registers[field2].value) { lessThan = 1; } changeRegisterValue(®isters[field3], lessThan); programCounter++; break; //and case 36:; int andValue = 0; if(registers[field1].value == 1 && registers[field2].value == 1) { andValue = 1; } changeRegisterValue(®isters[field3], andValue); programCounter++; break; //end case 12:; flag = 1; //call exit break; } break; //addi case 8:; int sum = registers[field1].value + addressField; changeRegisterValue(®isters[field2], sum); programCounter++; break; //sw case 43:; int address1 = registers[field1].value + addressField; memory[address1] = registers[field2].value; programCounter++; break; //j case 2:; int moveTo = (jType-(4194304/4))-9; //this could be off by 1 programCounter = moveTo; break; //beq case 4:; if(registers[field1].value == registers[field2].value) { programCounter = programCounter + addressField; } else { programCounter++; } break; //illegal operation default:; flag = 1; break; } printf("REGISTERS\n"); printRegisters(); printf("MEMORY\n"); printMemory(); printf("\n"); //Call next alarm alarm(1); }
void printARM (ARM* arm) { printRegisters(arm); printMemory(arm); }