void Plus4EmuGUI_DebugWindow::updateWindow() { try { std::string buf; buf.reserve(320); gui.vm.listCPURegisters(buf); cpuRegisterDisplay->value(buf.c_str()); { char tmpBuf[64]; std::sprintf(&(tmpBuf[0]), "0000-3FFF: %02X\n4000-7FFF: %02X\n" "8000-BFFF: %02X\nC000-FFFF: %02X", (unsigned int) gui.vm.getMemoryPage(0), (unsigned int) gui.vm.getMemoryPage(1), (unsigned int) gui.vm.getMemoryPage(2), (unsigned int) gui.vm.getMemoryPage(3)); memoryPagingDisplay->value(&(tmpBuf[0])); } uint32_t tmp = gui.vm.getProgramCounter(); uint32_t startAddr = (tmp + 0xFFE8U) & 0xFFF8U; uint32_t endAddr = (startAddr + 0x0037U) & 0xFFFFU; dumpMemory(buf, startAddr, endAddr, tmp, true, true); codeMemoryDumpDisplay->value(buf.c_str()); tmp = gui.vm.getStackPointer(); startAddr = (tmp + 0xFFF4U) & 0xFFF8U; endAddr = (startAddr + 0x002FU) & 0xFFFFU; dumpMemory(buf, startAddr, endAddr, tmp, true, true); stackMemoryDumpDisplay->value(buf.c_str()); updateMemoryDumpDisplay(); updateDisassemblyDisplay(); noBreakOnDataReadValuator->value( gui.config.debug.noBreakOnDataRead ? 1 : 0); bpPriorityThresholdValuator->value( double(gui.config.debug.bpPriorityThreshold)); breakOnInvalidOpcodeValuator->value( gui.config.debug.breakOnInvalidOpcode ? 1 : 0); } catch (std::exception& e) { gui.errorMessage(e.what()); } }
// Read and dump initial values for memory // void readMemory(void) { int loc = 0; printf("Read memory: At the prompt, enter the value for the indicated\n"); printf("memory address. Enter a number > 9999 or < -9999 when you're done.\n"); printf("*** STUB *** readmemory\n"); // *** You might need this after reading the sentinel *** // fgets(skip, sizeof skip, stdin); // Clear the \n at end of terminating line printf("\nInitial value of memory:\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); }
// Read and dump initial values for memory // void readMemory(void) { int loc = 0; int temp; printf("Read memory: At the prompt, enter the value for the indicated\n"); printf("memory address. Enter a number > 9999 or < -9999 when you're done.\n"); //loop for input the value printf("Loc %02d: ",loc); scanf("%d", &temp); while((temp<=9999)&&(temp>=-9999)){ mem[loc] = temp; loc++; printf("Loc %02d: ",loc); scanf("%d", &temp); } printf("\nInitial value of memory:\n"); dumpMemory(mem); }
int main(int argc, char * argv[]) { argc -= setDebugOptions(argc, argv); initialize(); bool loadError = !load(argc, argv); if (loadError) { dumpMemory(); return 1; } unsigned int clockCount = 0; bool stop = FALSE; pipelineForward forward; clearBuffer((char*)&forward, sizeof(pipelineForward)); while(!stop) { dumpStage(DBG_WRITEBACK_STAGE); stop = writebackStage(&forward); dumpStage(DBG_MEMORY_STAGE); memoryStage(&forward); dumpStage(DBG_EXECUTE_STAGE); executeStage(&forward); dumpStage(DBG_DECODE_STAGE); decodeStage(forward); dumpStage(DBG_FETCH_STAGE); fetchStage(); ++clockCount; } printf("\nTotal clock cycles = %d\n", clockCount); return 0; }
void DumpMemoryGui::OnOK(UINT uNotifyCode, int nID, CWindow wndCtl) { DoDataExchange(DDX_SAVE); if (EditMemoryAddress.GetValue() == 0 || EditMemorySize.GetValue() == 0) { wndCtl.MessageBoxW(L"Textbox is empty!",L"Error",MB_ICONERROR); } else { if (dumpMemory()) { EndDialog(1); } else { wndCtl.MessageBoxW(L"Reading memory from process failed",L"Error",MB_ICONERROR); } } }
// Read and dump initial values for memory // void readMemory(void) { int loc = 0; printf("Read memory: At the prompt, enter the value for the indicated\n"); printf("memory address. Enter a number > 9999 or < -9999 when you're done.\n"); int num=0; while (num<=9999 && num>=-9999 && loc < 100){ printf("\nLoc %d: ",loc); // fgets(line,MEMLEN, stdin); scanf("%d", &num); if (num<=9999 && num>=-9999){ mem[loc]=num; } loc++; } // *** You might need this after reading the sentinel *** // fgets(skip, sizeof skip, stdin); // Clear the \n at end of terminating line printf("\nInitial value of memory:\n"); dumpMemory(mem); char gar[100]; fgets(gar, sizeof gar, stdin); }
int main(int argv, char * args[]){ initialize(); if(!load(argv, args)){ dumpMemory(); exit(0); } int clockCount = 0; bool stop = false; forwardType forward; //added for lab7 statusType status;//lab 9 while(!stop){ stop = writebackStage(&forward, &status); memoryStage(&forward, &status); executeStage(&forward, status); decodeStage(forward); fetchStage(forward); clockCount++; } printf("\nTotal clock cycles = %d\n", clockCount); }
void Plus4EmuGUI_DebugWindow::updateMemoryDumpDisplay() { try { uint32_t addrMask = uint32_t(memoryDumpCPUAddressMode ? 0x00FFFFU : 0x3FFFFFU); memoryDumpStartAddress &= addrMask; memoryDumpEndAddress &= addrMask; memoryDumpViewAddress &= addrMask; const char *fmt = (memoryDumpCPUAddressMode ? "%04X" : "%06X"); char tmpBuf[8]; std::sprintf(&(tmpBuf[0]), fmt, (unsigned int) memoryDumpStartAddress); memoryDumpStartAddressValuator->value(&(tmpBuf[0])); std::sprintf(&(tmpBuf[0]), fmt, (unsigned int) memoryDumpEndAddress); memoryDumpEndAddressValuator->value(&(tmpBuf[0])); std::string buf; buf.reserve(720); dumpMemory(buf, memoryDumpViewAddress, memoryDumpViewAddress + 0x87U, 0U, false, memoryDumpCPUAddressMode); memoryDumpDisplay->value(buf.c_str()); } catch (std::exception& e) { gui.errorMessage(e.what()); } }
// ************************************************************************** // ************************************************************************** // dft int P4_dumpFrameTable(int argc, char* argv[]) { dumpMemory("Frame Bit Table", LC3_FBT, LC3_FBT+0x40); return 0; } // end P4_dumpFrameTable
// Function: writebackStage // Description: Simulates the writebackStage of the y86 pipe // Params: *forward, *status // Returns: Bool // Modifies: None bool writebackStage(forwardType *forward, statusType *status) { forward->W_dstE = W.dstE; forward->W_valE = W.valE; forward->W_valM = W.valM; forward->W_dstM = W.dstM; status->W_stat = W.stat; forward->W_icode = W.icode; //setRegister(W.dstE, W.valE); //setRegister(W.dstM, W.valM); /*if (W.icode == mrmovl || W.icode == popl) { setRegister(W.dstM, W.valM); } if(W.icode == OPL || W.icode == rrmovl || W.icode == irmovl || W.icode == popl || W.icode == pushl) { setRegister(W.dstE, W.valE); }*/ if(W.dstM == none) { W.valM = 0; } if (W.stat == HLT || W.stat == INS || W.stat == ADR) { if(W.stat == INS) { printf("Invalid instruction\n"); dumpProgramRegisters(); dumpProcessorRegisters(); dumpMemory(); } if(W.stat == ADR) { printf("Invalid memory address\n"); dumpProgramRegisters(); dumpProcessorRegisters(); dumpMemory(); } return true; } else { setRegister(W.dstE, W.valE); setRegister(W.dstM, W.valM); if (W.icode == dump) { int temp_array[3] = {getBits(0,0,W.valE),getBits(1,1,W.valE),getBits(2,2,W.valE)}; if (temp_array[0]) { dumpProgramRegisters(); } if (temp_array[1]) { dumpProcessorRegisters(); } if (temp_array[2]) { dumpMemory(); } } return false; } }
int instruction_cycle(int mem[], int regs[], int memCounter) { int intCount, firstNum, secondNum, intRest; char readInput, futureInput; intCount = getcount(mem, memCounter); firstNum = getfirst(mem, memCounter, intCount); secondNum = getsecond(mem, memCounter, intCount); intRest = getrest(mem, memCounter, intCount); // TEST CASE: printf("** This is the first digit: %d **\n", firstNum); if (firstNum != 0) printf("At %02d instr %d %d %02d: ", memCounter, firstNum, secondNum, intRest); switch (firstNum) { case 0: // DONE!!! { // HALT execution // Microcode: Running ← false memCounter++; break; } case 1: // DONE!!! { // LD // EXAMPLE: LD R0 <- M[02] = 9225 // Microcode: Reg[R]←Mem[MM] regs[secondNum] = mem[intRest]; printf("LD R%d <- M[%02d] = %d\n", secondNum, intRest, regs[secondNum]); break; } case 2: // DONE!!! { // ST // EXAMPLE: ST M[22] <- R3 = -1 // Microcode: Mem[MM]←Reg[R] mem[intRest] = regs[secondNum]; printf("ST M[%02d] <- R%d = %d\n", intRest, secondNum, mem[intRest]); break; } case 3: // DONE!!! { // ADD // EXAMPLE: ADD R1 <- R1 + M[22] = 3 + -1 = 2 // Microcode: Reg[R]←Reg[R] + Mem[MM] printf("ADD R%d <- R%d + M[%02d] = %d + %d", secondNum, secondNum, intRest, regs[secondNum], mem[intRest]); regs[secondNum] = (regs[secondNum] + mem[intRest]) % 10000; printf(" = %d\n", regs[secondNum]); break; } case 4: // DONE!!! { // NEG // EXAMPLE: NEG R3 <- -(R3) = -1 // Microcode: Reg[R]←–Reg[R] regs[secondNum] = (-1 * regs[secondNum]); printf("NEG R%d <- -(R%d) = %d\n", secondNum, secondNum, regs[secondNum]); break; } case 5: // DONE!!! { // ST // EXAMPLE: LDM R3 <- 1 // Microcode: Reg[R] ← MM regs[secondNum] = intRest; printf("LDM R%d <- %d\n", secondNum, intRest); break; } case 6: // DONE!!! { // ADDM // EXAMPLE: ADDM R0 <- R0 + 01 = 9225 + 1 = 9226 // Microcode: Reg[R]←Reg[R]+MM regs[secondNum] = regs[secondNum] + 1; printf("ADDM R%d <- R%d + 01 = %d + 1 = %d\n", secondNum, secondNum, (regs[secondNum] - 1), regs[secondNum]); break; } case 7: // EQUAL 0? { // BR // EXAMPLE: BR 10 // Microcode: PC←MM printf("BR %d\n", intRest); break; } case 8: { // BRP // EXAMPLE: BRP 13 if R1 = 2 > 0: Yes // Microcode: if Reg[R]>0 then PC ← MM if(regs[secondNum] > 0) { memCounter = intRest; printf("BRP %02d if R%d = %d > 0: Yes\n", intRest, secondNum, regs[secondNum]); return(memCounter); } else { printf("BRP %02d if R%d = %d > 0: No\n", intRest, secondNum, regs[secondNum]); } break; } case 9: { // Read a character and copy its ASCII representation into R0. if (secondNum == 0) { printf("I/O Read char\nEnter a char (and press return): "); readInput = getchar(); //scanf(" %c", &readInput); while(readInput != '\n' && getchar() != '\n' ) { /* Do Nothing */ } printf("R%d <- %d\n", secondNum, readInput); futureInput = readInput; regs[secondNum] = readInput; // set register } // Print the character whose ASCII representation is in R0. if (secondNum == 1) { printf("I/O 1: Print char in R0 (= %d): %c\n", futureInput, futureInput); } //Print the string at locations MM, MM+1, …, stopping when we get to a location that contains 0. if (secondNum == 2) { printf("I/O 2: Print string: Hello, world!\n"); } // Print out the values of the registers. if (secondNum == 3) { printf("I/O 3: Dump Registers\n"); dumpRegisters(regs); } //Print out the values in memory as a 10 by 10 table if (secondNum == 4) { printf("I/O 4: Dump Memory\n"); dumpMemory(mem); } break; } default: { printf("\nAdd operaions here\n"); break; } } return 0; }
int main(void) { char command; /*display menu*/ printf("By: Dennis Konieczek and Nikolas Spendik\n"); printf("d\t dump memory\n"); printf("g\t go - run the entire program\n"); printf("l\t load a file into memory\n"); printf("m\t memory modify\n"); printf("q\t quit\n"); printf("r\t display registers\n"); printf("t\t trace - execute one instruction\n"); printf("w\t write file\n"); printf("z\t reset all registers to zero\n"); printf("?, h\t display list of commands\n"); /*prompt for command and execute corresponding task*/ while (1) { printf("\n>>Enter command: "); scanf(" %c", &command); switch (command) { case 'd': case 'D': printf("\n>>Enter offset: "); scanf(" %x", &offset); printf("\n>>Enter length: "); scanf(" %x", &length); dumpMemory(&memory, offset, length); break; case 'g': case 'G': go(); break; case 'l': case 'L': LoadFile(&memory, sizeof(memory)); break; case 'm': case 'M': printf("\n>>Enter starting address: "); scanf(" %x", &offset); memoryModify(&memory, offset); break; case 'q': case 'Q': printf("Exiting... \n"); exit(0); break; case 'r': case 'R': displayRegisters(); break; case 't': case 'T': trace(); break; case 'w': case 'W': WriteFile(&memory); break; case 'z': case 'Z': resetRegisters(); break; case '?': case 'h': case 'H': help(); break; default: printf("!wrong command!"); break; } } printf("\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); }
// Execute one instruction cycle. // void instruction_cycle(void) { running=1; if (pc>100){ printf("HALT!!\n"); running=0; } if (running){ // printf("%d pc\n", pc); ir=mem[pc]; // printf("%d ir\n", ir); char abc[100]; char a; int str; int mod; int R; int MM; int op=ir/1000; // printf("%d op \n", op); if ((op<0 )){ op= op*-1; } //printf("going to perform %d case\n", op); if (op!=0){ switch (op){ case 1: printf("performing case 1\n"); mod=mem[pc]%1000; R=mod/100; MM=mod%100; printf("As %d instr %d: LD R%d <-M[%d]=%d\n", pc, ir, R, MM, mem[MM]); regs[R]=mem[MM]; pc++; break; case 2: mod=mem[pc]%1000; R=mod/100; MM=mod%100; printf("As %d instr %d: ST M[%d] <-R%d =%d\n", pc, ir, MM, R, regs[R]); mem[MM]=regs[R]; pc++; break; case 3: mod=mem[pc]%1000; R=mod/100; MM=mod%100; printf("As %d instr %d: ADD R%d <-R%d + M[%d]=%d+%d=%d\n", pc, ir, R,R, MM,regs[R], mem[MM],regs[R]+mem[MM]); regs[R]=regs[R]+mem[MM]; pc++; break; case 4: mod=mem[pc]%1000; R=mod/100; printf("As %d instr %d: NEG R%d <- -(R%d)= -%d\n", pc, ir, R, R, regs[R]); regs[R]=regs[R]*-1; pc++; break; case 5: case -5: mod=mem[pc]%1000; R=mod/100; MM=mod%100; if (ir<0){ MM=MM*-1; } printf("As %d instr %d: LDM R%d <-%d\n",pc, ir, R, MM); regs[R]=MM; pc++; break; case 6: case -6: mod=mem[pc]%1000; R=mod/100; MM=mod%100; if (ir<0){ R=R*-1; } str=regs[R]+MM; printf("As %d instr %d: ADDM R%d <-R%d + %d = %d +%d = %d \n", pc,ir, R,R, MM, regs[R], MM, str); regs[R]=str; pc++; break; case 7: mod=mem[pc]%1000; R=mod/100; MM=mod%100; printf("As %d instr %d: BR %d \n", pc, ir, MM); pc=MM; break; case 8: mod=mem[pc]%1000; R=mod/100; MM=mod%100; if (regs[R]>0){ pc=MM; printf("As %d instr %d: BRP %d if R%d = %d>0 : Yes\n", pc, ir, MM, R, regs[R]); break; } printf("As %d instr %d: BRP %d if R%d = %d>0 : NO\n", pc, ir, MM, R, regs[R]); pc++; break; case 9: str; mod=mem[pc]%1000; R=mod/100; MM=mod%100; if (R==0){ printf("As %d instr %d: I/O Read Char \n", pc,ir ); printf("Enter a char (and press return): "); scanf("%c", &a ); str=(int)a; printf("\nR0 <- %d\n",str); regs[0]=str; pc++; } else if (R==1){ printf("As %d instr %d: I/O 1 Print Char in R0 (%d):", pc, ir, regs[0]); a=(char)regs[0]; printf("%c\n" ,a); pc++; } else if (R==2){ printf("\nAs %d instr %d: I/O 2 %d", pc, ir, regs[0]); printf("Print string: "); while(mem[MM]!=0){ a=(char)mem[MM]; printf("%c", a); MM++; } printf("\n"); pc++; } else if (R==3){ printf("As %d instr %d: Dump Control Unit", pc, ir); dumpControlUnit(pc, ir, regs); pc++; } else if (R==4){ printf("As %d instr %d: Dump Memory", pc, ir); dumpMemory(mem); pc++; } else{ printf("Inappropiate command\n"); pc++; } break; } } else{ printf("HALT!!\n"); running=0; } } // printf("At %d instr %d:"); // if pc is out of range, complain and halt machine, otherwise // set ir to instruction at pc, increment pc // if ir < 0 .... // get opcode, register, and address fields of ir // echo instruction // switch on opcode, case for each opcode ... return; }
void fsDebugMgr::checkSpecialCommand() { u8 cmd_no = 0; if (fsInputMgr::isOn(fsInputMgr::KEY_D)) { if (fsInputMgr::isPressed(fsInputMgr::KEY_1)) { cmd_no = 1; } else if (fsInputMgr::isPressed(fsInputMgr::KEY_2)) { cmd_no = 2; } else if (fsInputMgr::isPressed(fsInputMgr::KEY_3)) { cmd_no = 3; } else if (fsInputMgr::isPressed(fsInputMgr::KEY_4)) { cmd_no = 4; } else if (fsInputMgr::isPressed(fsInputMgr::KEY_5)) { cmd_no = 5; } else if (fsInputMgr::isPressed(fsInputMgr::KEY_6)) { cmd_no = 6; } else if (fsInputMgr::isPressed(fsInputMgr::KEY_7)) { cmd_no = 7; } else if (fsInputMgr::isPressed(fsInputMgr::KEY_8)) { cmd_no = 8; } else if (fsInputMgr::isPressed(fsInputMgr::KEY_PAGEUP)) { cmd_no = 100; } else if (fsInputMgr::isPressed(fsInputMgr::KEY_PAGEDOWN)) { cmd_no = 101; } } if (fsInputMgr::isPressed(fsInputMgr::KEY_LBUTTON)) { r32 mouse_x = m_dbg_mode_scr->framebufferXToScreenX(fsInputMgr::getMouseX()); r32 mouse_y = m_dbg_mode_scr->framebufferYToScreenY(fsInputMgr::getMouseY()); if (mouse_x > 0.0f && mouse_y > 0.0f) { if (m_dbg_mode_tap_cntr < 2) { m_dbg_mode_tap_cntr++; } else if (m_dbg_mode_tap_cntr > 2) { m_dbg_mode_tap_cntr = 1; } } else if ((m_dbg_mode_tap_cntr >= 2 && m_dbg_mode_tap_cntr <= 3 && mouse_x < 0.0f && mouse_y > 0.0f) || // (m_dbg_mode_tap_cntr >= 4 && m_dbg_mode_tap_cntr <= 5 && mouse_x < 0.0f && mouse_y < 0.0f) || // (m_dbg_mode_tap_cntr >= 6 && m_dbg_mode_tap_cntr <= 7 && mouse_x > 0.0f && mouse_y < 0.0f)) { m_dbg_mode_tap_cntr++; } else { m_dbg_mode_tap_cntr = 0; } if (m_dbg_mode_tap_cntr == 8) { cmd_no = 1; m_dbg_mode_tap_cntr = 0; m_dbg_dump_tap_cntr = 0; m_scroll_hold_cntr = 0; } if (m_dbg_mode.getType() == MODE_CONSOLE) { if (mouse_x > 0.0f && mouse_y > 0.0f) { if (m_dbg_dump_tap_cntr >= 3 && m_dbg_dump_tap_cntr < 100) { cmd_no = m_dbg_dump_tap_cntr - 1; m_dbg_mode_tap_cntr = 0; m_scroll_hold_cntr = 0; } m_dbg_dump_tap_cntr = 1; } else if (mouse_x < 0.0f && mouse_y < 0.0f) { m_dbg_dump_tap_cntr++; } else { m_dbg_dump_tap_cntr = 0; } } } if (m_dbg_mode.getType() == MODE_CONSOLE) { r32 mouse_y = m_dbg_mode_scr->framebufferYToScreenY(fsInputMgr::getMouseY()); if (fsInputMgr::isOn(fsInputMgr::KEY_LBUTTON)) { if (mouse_y > 0.0f) { m_scroll_hold_cntr++; } else { m_scroll_hold_cntr--; } if (fsMath::abs(m_scroll_hold_cntr) >= fsTaskMgr::getAimFPS()) { cmd_no = (m_scroll_hold_cntr > 0) ? 100 : 101; m_dbg_mode_tap_cntr = 0; m_dbg_dump_tap_cntr = 0; m_scroll_hold_cntr = 0; } } else { m_scroll_hold_cntr = 0; } } switch (cmd_no) { case 1: if (m_dbg_mode.getType() == MODE_OFF) { setDebugMode(MODE_MONITOR); } else if (m_dbg_mode.getType() == MODE_MONITOR) { setDebugMode(MODE_CONSOLE); } else { setDebugMode(MODE_OFF); } break; case 2: dumpMemory(); break; case 3: dumpTask(); break; case 4: dumpResource(); break; case 5: dumpConfig(); break; case 6: dumpScreen(); break; case 7: dumpTexture(); break; case 8: dumpShader(); break; case 100: pageUpConsole(); break; case 101: pageDownConsole(); break; default: break; } }
void main () { int rc; sBSP430m25p m25p_data; hBSP430m25p m25p; unsigned long addr; unsigned long t0; unsigned long t1; vBSP430platformInitialize_ni(); (void)iBSP430consoleInitialize(); cprintf("\nBuild " __DATE__ " " __TIME__ "\n"); cprintf("SPI is %s: %s\n", xBSP430serialName(BSP430_PLATFORM_M25P_SPI_PERIPH_HANDLE), xBSP430platformPeripheralHelp(BSP430_PLATFORM_M25P_SPI_PERIPH_HANDLE, 0)); #ifdef BSP430_PLATFORM_M25P_PWR_PORT_PERIPH_HANDLE cprintf("PWR at %s.%u\n", xBSP430portName(BSP430_PLATFORM_M25P_PWR_PORT_PERIPH_HANDLE), iBSP430portBitPosition(BSP430_PLATFORM_M25P_PWR_PORT_BIT)); #else /* BSP430_PLATFORM_M25P_PWR_PORT_PERIPH_HANDLE */ cprintf("PWR is hard-wired\n"); #endif /* BSP430_PLATFORM_M25P_PWR_PORT_PERIPH_HANDLE */ #ifdef BSP430_PLATFORM_M25P_RSTn_PORT_PERIPH_HANDLE cprintf("RSTn at %s.%u\n", xBSP430portName(BSP430_PLATFORM_M25P_RSTn_PORT_PERIPH_HANDLE), iBSP430portBitPosition(BSP430_PLATFORM_M25P_RSTn_PORT_BIT)); #else /* BSP430_PLATFORM_M25P_RSTn_PORT_PERIPH_HANDLE */ cprintf("RSTn is hard-wired\n"); #endif /* BSP430_PLATFORM_M25P_RSTn_PORT_PERIPH_HANDLE */ cprintf("CSn at %s.%u\n", xBSP430portName(BSP430_PLATFORM_M25P_CSn_PORT_PERIPH_HANDLE), iBSP430portBitPosition(BSP430_PLATFORM_M25P_CSn_PORT_BIT)); memset(&m25p_data, 0, sizeof(m25p_data)); m25p_data.spi = hBSP430serialLookup(BSP430_PLATFORM_M25P_SPI_PERIPH_HANDLE); m25p_data.csn_port = xBSP430hplLookupPORT(BSP430_PLATFORM_M25P_CSn_PORT_PERIPH_HANDLE); m25p_data.csn_bit = BSP430_PLATFORM_M25P_CSn_PORT_BIT; #ifdef BSP430_PLATFORM_M25P_RSTn_PORT_PERIPH_HANDLE m25p_data.rstn_port = xBSP430hplLookupPORT(BSP430_PLATFORM_M25P_RSTn_PORT_PERIPH_HANDLE); m25p_data.rstn_bit = BSP430_PLATFORM_M25P_RSTn_PORT_BIT; #endif /* BSP430_PLATFORM_M25P_RSTn_PORT_PERIPH_HANDLE */ m25p = hBSP430m25pInitialize(&m25p_data, BSP430_SERIAL_ADJUST_CTL0_INITIALIZER(UCCKPL | UCMSB | UCMST), UCSSEL_2, 1); if (NULL == m25p) { cprintf("M25P device initialization failed.\n"); return; } #ifdef BSP430_PLATFORM_M25P_PWR_PORT_PERIPH_HANDLE { volatile sBSP430hplPORT * pwr_hpl; /* Turn on power, then wait 10 ms for chip to stabilize before releasing RSTn. */ pwr_hpl = xBSP430hplLookupPORT(BSP430_PLATFORM_M25P_PWR_PORT_PERIPH_HANDLE); pwr_hpl->out &= ~BSP430_PLATFORM_M25P_PWR_PORT_BIT; pwr_hpl->dir |= BSP430_PLATFORM_M25P_PWR_PORT_BIT; pwr_hpl->out |= BSP430_PLATFORM_M25P_PWR_PORT_BIT; BSP430_CORE_DELAY_CYCLES(10 * (BSP430_CLOCK_NOMINAL_MCLK_HZ / 1000)); } #endif /* BSP430_PLATFORM_M25P_PWR_PORT_PERIPH_HANDLE */ BSP430_M25P_RESET_CLEAR(m25p); cprintf("Status register %d\n", iBSP430m25pStatus_ni(m25p)); rc = iBSP430m25pStrobeCommand_ni(m25p, BSP430_M25P_CMD_WREN); cprintf("WREN got %d, status register %d\n", rc, iBSP430m25pStatus_ni(m25p)); rc = iBSP430m25pStrobeCommand_ni(m25p, BSP430_M25P_CMD_WRDI); cprintf("WRDI got %d, status register %d\n", rc, iBSP430m25pStatus_ni(m25p)); rc = iBSP430m25pInitiateCommand_ni(m25p, BSP430_M25P_CMD_RDID); if (0 == rc) { rc = iBSP430m25pCompleteTxRx_ni(m25p, NULL, 0, 20, buffer); } BSP430_CORE_ENABLE_INTERRUPT(); cprintf("READ_IDENTIFICATION got %d\n", rc); if (0 <= rc) { dumpMemory(buffer, rc, 0); } cprintf("Config identified %u sectors of %lu bytes each: %lu bytes total\n", BSP430_PLATFORM_M25P_SECTOR_COUNT, (unsigned long)BSP430_PLATFORM_M25P_SECTOR_SIZE, BSP430_PLATFORM_M25P_SECTOR_COUNT * (unsigned long)BSP430_PLATFORM_M25P_SECTOR_SIZE); #if (BSP430_PLATFORM_M25P_SUBSECTOR_SIZE - 0) cprintf("Config supports access as %u sub-sectors of %u bytes each\n", (unsigned int)(BSP430_PLATFORM_M25P_SECTOR_COUNT * (BSP430_PLATFORM_M25P_SECTOR_SIZE / BSP430_PLATFORM_M25P_SUBSECTOR_SIZE)), (unsigned int)BSP430_PLATFORM_M25P_SUBSECTOR_SIZE); #else /* BSP430_PLATFORM_M25P_SUBSECTOR_SIZE */ cprintf("Config indicates device is not sub-sector addressable\n"); #endif /* BSP430_PLATFORM_M25P_SUBSECTOR_SIZE */ cprintf("RDID identified %lu bytes total capacity\n", 0x1UL << buffer[2]); addr = 0; rc = readFromAddress(m25p, addr, sizeof(flashContents)); if (sizeof(flashContents) != rc) { cprintf("ERROR %d reading initial block\n", rc); } else { dumpMemory(buffer, rc, addr); if (0 == memcmp(flashContents, buffer, rc)) { cprintf("Found expected contents.\n"); } } #if (BSP430_PLATFORM_M25P_SUPPORTS_PE - 0) rc = writeToAddress(m25p, BSP430_M25P_CMD_PE, addr, NULL, 0); cprintf("PAGE_ERASE got %d\n", rc); #else /* BSP430_PLATFORM_M25P_SUPPORTS_PE */ rc = writeToAddress(m25p, BSP430_M25P_CMD_SE, addr, NULL, 0); cprintf("SECTOR_ERASE got %d\n", rc); #endif /* BSP430_PLATFORM_M25P_SUPPORTS_PE */ rc = readFromAddress(m25p, addr, sizeof(buffer)); if (0 < rc) { dumpMemory(buffer, rc, addr); } rc = writeToAddress(m25p, BSP430_M25P_CMD_PP, addr, flashContents, sizeof(flashContents)); cprintf("PAGE_PROGRAM got %d\n", rc); rc = readFromAddress(m25p, addr, sizeof(buffer)); if (0 < rc) { dumpMemory(buffer, rc, addr); } /* PAGE PROGRAM is the one that only clears 1s to 0s so needs a * prior page or sector erase */ rc = writeToAddress(m25p, BSP430_M25P_CMD_PP, addr, flashContents + 4, 4); cprintf("PAGE_PROGRAM to %lx returned %d\n", addr, rc); rc = readFromAddress(m25p, 0, sizeof(flashContents)); dumpMemory(buffer, rc, 0); /* Write 4 took 8 PAGE_PROGRAM to 0 returned 4 00000000 88 11 03 30 cc 33 c3 3c 01 23 45 67 89 ab cd ef ...0.3.<.#Eg.... */ /* PAGE_WRITE is the one that does not need a prior erase cycle */ addr = 8; #if (BSP430_PLATFORM_M25P_SUPPORTS_PW - 0) rc = writeToAddress(m25p, BSP430_M25P_CMD_PW, addr, flashContents + 4, 4); cprintf("PAGE_WRITE to %lx returned %d\n", addr, rc); #else rc = writeToAddress(m25p, BSP430_M25P_CMD_PP, addr, flashContents + 4, 4); cprintf("overwrite PAGE_PROGRAM to unerased %lx returned %d\n", addr, rc); #endif rc = readFromAddress(m25p, 0, sizeof(flashContents)); dumpMemory(buffer, rc, 0); /* Write 4 took 204 PAGE_WRITE to 8 returned 4 00000000 88 11 03 30 cc 33 c3 3c cc 33 c3 3c 89 ab cd ef ...0.3.<.3.<.... */ cprintf("Initiating bulk erase..."); BSP430_CORE_DISABLE_INTERRUPT(); do { t0 = t1 = 0; rc = iBSP430m25pStrobeCommand_ni(m25p, BSP430_M25P_CMD_WREN); if (0 == rc) { rc = iBSP430m25pStrobeCommand_ni(m25p, BSP430_M25P_CMD_BE); } if (0 == rc) { int sr; t0 = ulBSP430uptime_ni(); do { sr = iBSP430m25pStatus_ni(m25p); } while ((0 <= sr) && (BSP430_M25P_SR_WIP & sr)); t1 = ulBSP430uptime(); } } while (0); BSP430_CORE_ENABLE_INTERRUPT(); cprintf("\nBULK_ERASE got %d\n", rc); if (0 == rc) { char tstr[BSP430_UPTIME_AS_TEXT_LENGTH]; cprintf("Bulk erase took %lu utt = %s\n", t1-t0, xBSP430uptimeAsText(t1 - t0, tstr)); } rc = readFromAddress(m25p, 0, sizeof(flashContents)); dumpMemory(buffer, rc, 0); rc = writeToAddress(m25p, BSP430_M25P_CMD_PP, 0, flashContents, sizeof(flashContents)); cprintf("Restore got %d\n", rc); addr = 0; while (addr < (256 * 1025L)) { rc = readFromAddress(m25p, addr, sizeof(buffer)); if (0 > rc) { break; } dumpMemory(buffer, rc, addr); addr += rc; break; } }