u32 x_va::convertToUInt32() const { u32 i = 0; switch (mType) { case TYPE_BOOL: case TYPE_UINT32: case TYPE_INT32: { i = (u32)(*(u32*)mArg); } break; case TYPE_UINT8: case TYPE_INT8: { i = (u32)(*(u8*)mArg); } break; case TYPE_UINT16: case TYPE_INT16: { i = (u32)(*(u16*)mArg); } break; case TYPE_UINT64: case TYPE_INT64: { i = (u32)(*(u64*)mArg); } break; case TYPE_FLOAT32: { i = (u32)(*(f32*)mArg); } break; case TYPE_FLOAT64: { i = (u32)(*(f64*)mArg); } break; case TYPE_PCTCHAR: { ascii::crunes const& ch = *(ascii::crunes const*)mArg; ascii::parse(ch, i); } break; case TYPE_PCUCHAR32: { utf32::crunes const& ch = *(utf32::crunes const*)mArg; i = StrToU32(ch.m_str, ch.m_end); } break; default: break; // Fall through }; return i; }
void patchHelper(const wxString& cmd, const wxString& param) { // Error Handling Note: I just throw simple wxStrings here, and then catch them below and // format them into more detailed cmd+data+error printouts. If we want to add user-friendly // (translated) messages for display in a popup window then we'll have to upgrade the // exception a little bit. // print the actual patch lines only in verbose mode (even in devel) if (DevConWriterEnabled) DevCon.WriteLn(cmd + L" " + param); try { if (isCheat && cheatnumber >= MAX_CHEAT) throw wxString( L"Maximum number of cheats reached" ); if(!isCheat && patchnumber >= MAX_PATCH) throw wxString( L"Maximum number of patches reached" ); IniPatch& iPatch = isCheat ? Cheat[cheatnumber] : Patch[patchnumber]; PatchPieces pieces(param); iPatch.enabled = 0; iPatch.placetopatch = StrToU32(pieces.PlaceToPatch(), 10); iPatch.cpu = (patch_cpu_type)PatchTableExecute(pieces.CpuType(), cpuCore); iPatch.addr = StrToU32(pieces.MemAddr(), 16); iPatch.type = (patch_data_type)PatchTableExecute(pieces.OperandSize(), dataType); iPatch.data = StrToU64(pieces.WriteValue(), 16); if (iPatch.cpu == 0) throw wxsFormat(L"Unrecognized CPU Target: '%s'", WX_STR(pieces.CpuType())); if (iPatch.type == 0) throw wxsFormat(L"Unrecognized Operand Size: '%s'", WX_STR(pieces.OperandSize())); iPatch.enabled = 1; // omg success!! if (isCheat) cheatnumber++; else patchnumber++; } catch( wxString& exmsg ) { Console.Error(L"(Patch) Error Parsing: %s=%s", WX_STR(cmd), WX_STR(param)); Console.Indent().Error( exmsg ); } }
static void ExecuteCmd(const char const *input, const u32 base) { SendStr("\r\n", base); // Tokenize the command #define MAX_CMD_WORDS 4 char *token[MAX_CMD_WORDS]; char *cmd = (char *)input; u8 numTokens = 0; while (1) { // Skip leading whitespace. while ((*cmd) && isspace(*cmd)) cmd++; // If we get here and we are at the end of the string, then the last // token must have had trailing white spaces. Let's ignore them if (!(*cmd)) break; // If we have exceeded the maximum number of allowable tokens, then // return as error if (numTokens >= MAX_CMD_WORDS) { SendStr(NO_ANSWER, base); return; } // Store the token. token[numTokens] = cmd; numTokens++; // Everything that isn't a whitespace is part of the token. Let's make // sure it is in UPPER CASE while ((*cmd) && (!isspace(*cmd))) { *cmd = toupper(*cmd); cmd++; } // When we get here, we are just past the current token, either because // it ended on a whitespace or because it is the end of the user input. // If the former, then let's force a null termination for that token. If // the latter, then we are done tokenizing. if (!(*cmd)) break; *cmd = '\0'; cmd++; } if (0 == numTokens) { SendStr(NO_ANSWER, base); return; } // Process the command switch (token[0][0]) { case 'R': { if (2 != numTokens) SendStr(NO_ANSWER, base); else { u32 regAddr; u32 regValue; if (StrToU32(token[1], ®Addr) && RegRead(regAddr, ®Value)) { SendStr("Y ", base); char regValStr[9]; U32ToStr(regValue, regValStr); SendStr(regValStr, base); SendStr("\r\n", base); } else SendStr(NO_ANSWER, base); } break; } case 'W': { if (3 != numTokens) SendStr(NO_ANSWER, base); else { u32 regAddr; u32 regValue; if (StrToU32(token[1], ®Addr) && StrToU32(token[2], ®Value) && RegWrite(regAddr, regValue)) SendStr(YES_ANSWER, base); else SendStr(NO_ANSWER, base); } break; } case 'V': { SendStr("FPGA=0x", base); char versionStr[9]; FpgaRegisters * FPGARegs = (FpgaRegisters *)(REGISTER_BASE | BYPASS_DCACHE_MASK); U32ToStr(FPGARegs->fpgaVersion, versionStr); SendStr(versionStr, base); SendStr(" NIOS=0x", base); U32ToStr(NIOS_VERSION, versionStr); SendStr(versionStr, base); SendStr("\r\n", base); break; } case 'F': { if (4 != numTokens) SendStr(NO_ANSWER, base); else { u32 startAddr; u32 length; u32 checksum; StrToU32(token[1], &startAddr); StrToU32(token[2], &length); StrToU32(token[3], &checksum); // Transfer two chunks to get a full sector worth #define FLASH_SECTOR_SIZE (64*1024) #define TRANSFER_SIZE (4*1024) u8 buffer[FLASH_SECTOR_SIZE]; // Validate the requested transfer size if (length != TRANSFER_SIZE) SendStr(NO_ANSWER, base); else { u32 bufferIndex = startAddr % FLASH_SECTOR_SIZE; u32 runningSum = 0; u32 numBytesReceived = 0; // Clear the input buffer FlushRx(base); // Acknowledge that the command is good. This will tell the // sender to actually send the specified number of bytes SendStr(YES_ANSWER, base); // We must receive the correct number of bytes while (true) { while (IORD_FIFOED_AVALON_UART_STATUS(base) & FIFOED_AVALON_UART_CONTROL_RRDY_MSK) { // Read the Uart u8 rx = IORD_FIFOED_AVALON_UART_RXDATA(base); runningSum += rx; buffer[bufferIndex++] = rx; numBytesReceived++; if (numBytesReceived >= length) break; } if (numBytesReceived >= length) break; } // check the checksum if (runningSum != checksum) SendStr(NO_ANSWER, base); else { // If we don't have a full sector worth of data, then ACK and wait for more if (bufferIndex != FLASH_SECTOR_SIZE) SendStr(YES_ANSWER, base); else { u32 totalWriteBufferChecksum = 0; int i; for (i=0; i<sizeof(buffer); i++) { totalWriteBufferChecksum += buffer[i]; } alt_flash_fd* fd = alt_flash_open_dev(SERIAL_FLASH_NAME); if (NULL == fd) SendStr(NO_ANSWER, base); else { u32 sectorStartAddr = (startAddr / FLASH_SECTOR_SIZE) * FLASH_SECTOR_SIZE; if (0 == alt_write_flash(fd, sectorStartAddr, buffer, length)) { memset(buffer, 0x99, sizeof(buffer)); if (0 == alt_read_flash(fd, sectorStartAddr, buffer, sizeof(buffer))) { u32 totalReadBufferChecksum = 0; for (i=0; i<sizeof(buffer); i++) { totalReadBufferChecksum += buffer[i]; } if (totalReadBufferChecksum == totalWriteBufferChecksum) SendStr(YES_ANSWER, base); else SendStr(NO_ANSWER, base); } else SendStr(NO_ANSWER, base); } else SendStr(NO_ANSWER, base); alt_flash_close_dev(fd); } } } } } break; } default: SendStr(NO_ANSWER, base); break; } return; }