/********************************************************** * Tells the flashloader to erase one page at the * given address. **********************************************************/ void sendErasePageCmd(uint32_t addr) { writeMem((uint32_t)&(flState->writeAddress1), addr); writeMem((uint32_t)&(flState->numBytes1), 1); writeMem((uint32_t)&(flState->debuggerStatus), DEBUGGERCMD_ERASE_PAGE); waitForFlashloader(); }
static void writeBrowserEntry() { uint8_t i; const uint8_t *p = buf_entry; ram_addr = BROWSER_START + BROWSER_ENTRY_SIZE * images_written; for (i = MENU_ENTRY_OFFSET; i > 0; --i) writeMem(*p++); p += 5; // skip next, start, len for (i = ENTRY_NAME_LEN; i > 0; --i) writeMem(*p++); }
static void closeEntries() { uint8_t i; if (images_written <= 8) { // patch last "next item" entry ram_addr = images_written ? MENU_START + MENU_ENTRY_SIZE * images_written - ENTRY_NAME_LEN - 4 : 0x0006; writeMem(0); writeMem(0); } ram_addr = BROWSER_START + BROWSER_ENTRY_SIZE * images_written; for (i = MENU_ENTRY_OFFSET + 2; i > 0; --i) writeMem(0); }
static void writeMenuCode() { const uint8_t *p = menu; ram_addr = 0; for (uint16_t i = sizeof(menu); i > 0; --i, ++p) writeMem(pgm_read_byte(p)); }
void RiscComm::onConsoleInput(QString input) { m_sp->readAll(); // flush any residual crap out (from FPGA reset for example) if (input.compare("s") == 0) { sendStep(); doScan(); } else if (input.compare("sc") == 0) doScan(); else if (input.compare("q") == 0) QCoreApplication::exit(); else if (input.compare("r") == 0) sendRun(); else if (input.compare("rs") == 0) sendReset(); else if (input.compare("st") == 0) { sendStop(); doScan(); } else if (input.startsWith("wp")) { QStringList args = input.split(" "); if (args.length() == 2) { // upload a file sendProgram(args.at(1)); } } else if (input.compare("clrmem") == 0) { QByteArray zeros; zeros.fill(0, 256); writeMem(zeros, 0, true); } else if (input.compare("dm") == 0) { dumpMem(); } else qDebug() << "Unknown command:" << input; }
/* * submodule extended SVC function * fno function code * p1-p3 parameter(s) * er_p returns error code * return value if the function is handled, returns TRUE. * if not, returns FALSE */ EXPORT BOOL memDiskSVC( W fno, W p1, W p2, W p3, W *er_p ) { MDINFO *mdi; UW type; W er, n, v; switch ( fno ) { case TMEF_RDAINFO: /* ROM disk information */ mdi = (MDINFO*)&ROMInfo->rd_type; type = ROMDISK; goto info; info: if ( mdi->rd_blksz > 0 && mdi->rd_type == type ) { v = (UW)mdi; n = writeMem(p1, &v, sizeof(W), sizeof(W)); er = ( n == sizeof(W) )? E_OK: E_MACV; } else { er = E_NOEXS; } break; default: return FALSE; /* unsupported */ } *er_p = er; return TRUE; }
void WhileObject::assign( shared_ptr<X86Reference> other, bool write ) { ref = other; if ( write ) { writeMem(); } }
void WhileObject::assign( shared_ptr<WhileObject> other, bool write ) { ref = other->valueDirect(); type = other->tagDirect(); if ( write ) { writeMem(); } }
void post(state *s,int U_Bit,int L_Bit,uint32_t inst){ int I_Bit = bitCheck(inst,25); uint32_t offset = getOp2(s,inst,!I_Bit); uint32_t rd = getRD(inst); uint32_t rn = getRN(inst); uint32_t rnValue = getContents(s,rn); uint32_t rdValue = getContents(s,rd); uint32_t memLoc = getContents(s,rn); uint32_t memValue; if(rn == 15){ memLoc = s-> PC; memLoc += offset; } int type = typeofAddress(memLoc,s->Special_Memory); if(memLoc > 16380 && type == NOT_GPIO){ printf("Error: Out of bounds memory access at address 0x%08x\n",memLoc); return; } if(type != 0 && L_Bit == 0){ handleGPIOTypes(type); return; }else if(type != 0 && L_Bit == 1){ memValue = s->Special_Memory[type-1]; handleGPIOTypes(type); }else{ memValue = (memLoc%4 == 0) ? s-> ARM_mem[memLoc/4] : getUnallignedWord(memLoc,s); } if(U_Bit == 1){ switch(L_Bit){ case(0) : writeMem(s,rdValue,memLoc); add_offset(s,rn,offset); break; case(1) : writeReg(s,rd,memValue); add_offset(s,rn,offset); break; default : perror("Error in post"); break; } }else{ switch(L_Bit){ case(0) : writeMem(s,rdValue,memLoc); subtract_offset(s,rn,offset); break; case(1) : writeReg(s,rd,memValue); add_offset(s,rn,offset); break; default : perror("Error in post"); break; } } }
void WhileObject::initialise( shared_ptr<X86Reference> v, bool write ) { ref = v; type = make_shared<X86ConstRef>(getTypeTag(w_type)); if ( write ) { writeMem(); } }
/********************************************************** * Resets the target CPU by using the AIRCR register. * Does not reset the debug interface **********************************************************/ void resetTarget(void) { uint32_t dhcsr; int timeout = DEBUG_EVENT_TIMEOUT; /* Clear the VC_CORERESET bit */ writeMem((uint32_t)&(CoreDebug->DEMCR), 0); /* Do a dummy read of sticky bit to make sure it is cleared */ readMem((uint32_t)&(CoreDebug->DHCSR)); dhcsr = readMem((uint32_t)&(CoreDebug->DHCSR)); /* Reset CPU */ writeMem((uint32_t)&(SCB->AIRCR), AIRCR_RESET_CMD); /* Wait for reset to complete */ /* First wait until sticky bit is set. This means we are * or have been in reset */ delayUs(100); do { delayUs(10); dhcsr = readMem((uint32_t)&(CoreDebug->DHCSR)); timeout--; } while ( !(dhcsr & CoreDebug_DHCSR_S_RESET_ST_Msk) && timeout > 0 ); /* Throw error if sticky bit is never set */ if ( !(dhcsr & CoreDebug_DHCSR_S_RESET_ST_Msk) ) { RAISE(SWD_ERROR_TIMEOUT_WAITING_RESET); } /* Wait for sticky bit to be cleared. When bit is cleared are we out of reset */ timeout = DEBUG_EVENT_TIMEOUT; do { delayUs(10); dhcsr = readMem((uint32_t)&(CoreDebug->DHCSR)); timeout--; } while ( dhcsr & CoreDebug_DHCSR_S_RESET_ST_Msk && timeout > 0 ); /* Throw error if bit is never cleared */ if ( dhcsr & CoreDebug_DHCSR_S_RESET_ST_Msk ) { RAISE(SWD_ERROR_TIMEOUT_WAITING_RESET); } }
void WhileObject::setLocation( mem_space m, bool write ) { space = m; if (write) { writeMem(); } ref = NULL; type = NULL; initialised = true; }
/** * set an existing location */ void WhileObject::setLocation( shared_ptr<X86Register> r, bool write ) { space = mem_space{ r->ref(0), 0 }; if (write) { writeMem(); } ref = NULL; type = NULL; initialised = true; }
unsigned int pushExceptionRecord(EXCEPTION_RECORD *rec) { unsigned char *ptr = (unsigned char*) rec; unsigned int addr, i; unsigned int rec_size = (sizeof(EXCEPTION_RECORD) + 3) & ~3; //round up to next unsigned int addr = esp -= rec_size; for (i = 0; i < sizeof(EXCEPTION_RECORD); i++) { writeMem(addr++, *ptr++, SIZE_BYTE); } return esp; }
void RiscComm::sendProgram(QString filename) { QFile program(filename); if (!program.open(QFile::ReadOnly)) { qDebug() << "Can't open" << filename; return; } QByteArray data = program.readAll(); writeMem(data, 0, false); }
/* * obtain disk information * devnm device name (possibly with the partition number) * blksz return block size (* ) * tblks return the number of all blocks (* ) * return value error code * if there is a partition number to the device name, return the specific information to that partition. * argument marked with (* ) may be an address specified from external sources. */ EXPORT ER infoDisk( const UB *devnm, W *blksz, W *tblks ) { DISKCB *dcb; W pno, buf, n; /* initialize disk */ pno = openDisk(devnm, &dcb); if ( pno < E_OK ) return pno; /* obtain disk information * since there are addresses specified from external source, use writeMem() */ buf = dcb->part[pno].nblk; n = writeMem((UW)tblks, &buf, sizeof(W), sizeof(W)); if ( n < sizeof(W) ) return E_MACV; buf = dcb->blksz; n = writeMem((UW)blksz, &buf, sizeof(W), sizeof(W)); if ( n < sizeof(W) ) return E_MACV; return E_OK; }
int MemMapper::writeMemPtr(int virtAddress, byte *data, int length) { for (int i = 0; i < length; i++) { int result; result = writeMem(virtAddress + i, data[i]); if (result != MEM_MAPPER_SUCCESS) { return result; } } return MEM_MAPPER_SUCCESS; }
void WhileObject::assignType( shared_ptr<lang::Type> t, bool write ) { if (t->nameStr() == "real") { shared_ptr<X86Register> r = program->getFreeMmxRegister(); r->assign_itof( valueDirect() ); ref = r->ref(); } w_type = t; type = make_shared<X86ConstRef>(getTypeTag(t)); if ( write ) { writeMem(); } }
static void writeMenuEntry() { if (images_written > 8) return; const uint8_t *p; uint8_t i; // browser instead of menu entries? if (images_written == 8) { ram_addr = MENU_START; // reset menu p = browser_entry; for (i = sizeof(browser_entry); i > 0; --i, ++p) writeMem(pgm_read_byte(p)); return; } // write prepared entry to RAM ram_addr = MENU_START + MENU_ENTRY_SIZE * images_written; p = buf_entry; for (i = MENU_ENTRY_SIZE; i > 0; --i) writeMem(*p++); }
int MemMapper::setUIntX(int virtAddress, int length, int val) { unsigned int ret = 0; int address; for(int i = 0; i < length; i++) { if(endianess == BIG_ENDIAN) address = virtAddress + length - i - 1; else address = virtAddress + i; ret |= writeMem(address, val & 0xff); val >>= 8; } return ret; }
static ssize_t dm_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos) { struct drvr_device * dev = filp->private_data; /* for other methods */ switch (dev->type) { case prog: return loadBitFile((dev->data.prog.i2c_io), buf, count); case mem: return writeMem(filp, buf, count, f_pos); default: return loadBitFile((dev->data.prog.i2c_io), buf, count); }; }
void WhileRecord::initialise(shared_ptr<X86Reference> v, bool write) { // this object must free r // structure: // number of elements - int // pairs of string -> any type // size = 16 + n * 32 shared_ptr<X86Register> r = program->malloc( make_shared<X86ConstRef>(64) ); ref = r->ref(); type = make_shared<X86ConstRef>(16); if (write) { writeMem(); } }
/* load memory image */ LOCAL W loadImage(void) { W i, c; UB buf[512]; for (i = 0;;) { if ((c = (*readFn)()) >= 0) buf[i++] = c; if (i < sizeof(buf) && c >= 0) continue; if (i > 0) { if (e_addr < loaddr || e_addr - 1 > hiaddr - i) return E_RANGE; if (writeMem(e_addr, buf, i, 1) != i) return E_MACV; e_addr += i; i = 0; } if (c < 0) return c; } }
void WhileList::initialise(shared_ptr<X86Reference> v, bool write) { shared_ptr<X86Register> r1 = program->getFreeRegister(); r1->assign( v ); r1->add( make_shared<X86ConstRef>(1) ); r1->multiply( make_shared<X86ConstRef>(16) ); // TODO not writing may lose address shared_ptr<X86Register> r2 = program->malloc( r1->ref() ); ref = r2->ref(); type = make_shared<X86ConstRef>(8); // set length shared_ptr<WhileObject> l = make_shared<WhileObject>(program, lang::intType); length(l); program->addInstruction( "text", make_shared<InstrMov>( make_shared<X86ConstRef>(4), l->tagRef() ) ); program->addInstruction( "text", make_shared<InstrMov>( v, l->valueRef() ) ); if (write) { writeMem(); } }
/********************************************************** * Resets the target CPU by using the AIRCR register. * The target will be halted immediately when coming * out of reset. Does not reset the debug interface. **********************************************************/ void resetAndHaltTarget(void) { uint32_t dhcsr; int timeout = DEBUG_EVENT_TIMEOUT; /* Halt target first. This is necessary before setting * the VECTRESET bit */ haltTarget(); /* Set halt-on-reset bit */ writeMem((uint32_t)&(CoreDebug->DEMCR), CoreDebug_DEMCR_VC_CORERESET_Msk); /* Clear exception state and reset target */ writeAP(AP_TAR, (uint32_t)&(SCB->AIRCR)); writeAP(AP_DRW, (0x05FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_VECTCLRACTIVE_Msk | SCB_AIRCR_VECTRESET_Msk); /* Wait for target to reset */ do { delayUs(10); timeout--; dhcsr = readMem((uint32_t)&(CoreDebug->DHCSR)); } while ( dhcsr & CoreDebug_DHCSR_S_RESET_ST_Msk ); /* Check if we timed out */ dhcsr = readMem((uint32_t)&(CoreDebug->DHCSR)); if ( dhcsr & CoreDebug_DHCSR_S_RESET_ST_Msk ) { RAISE(SWD_ERROR_TIMEOUT_WAITING_RESET); } /* Verify that target is halted */ if ( !(dhcsr & CoreDebug_DHCSR_S_HALT_Msk) ) { RAISE(SWD_ERROR_TARGET_NOT_HALTED); } }
/* * I/O functions * blk start block number * this is not a block number within a partition, but * it is a disk-wide block number unique inside the whole disk. * nblk number of blocks * buf buffer (* ) * wrt FALSE : read * TRUE : write * return value error code * argument marked with (* ) may be an address specified from external sources. */ LOCAL ER rwdisk( DISKCB *dcb, W blk, W nblk, void *buf, BOOL wrt ) { MDINFO *mdi = (MDINFO*)dcb->info; W sz, asz; void *adr; if ( dcb->blksz <= 0 ) return E_NOEXS; /* not yet initialized */ adr = (void*)(mdi->rd_saddr + blk * dcb->blksz); sz = nblk * dcb->blksz; if ( wrt ) { /* write */ if ( mdi->rd_type == ROMDISK ) return E_RONLY; asz = readMem((UW)buf, adr, sz, 1); } else { /* read */ asz = writeMem((UW)buf, adr, sz, 1); } if ( asz < sz ) return E_IO; return E_OK; }
int MemMapper::setUInt8(int virtAddress, byte data) { return writeMem(virtAddress, data); }
/* * service call */ EXPORT W procSVC( W fno, W p1, W p2, W p3, W p4 ) { W er = E_OK; W n; switch ( fno ) { case TM_MONITOR: /* void tm_monitor( void ) */ procCommand(NULL, 0); break; case TM_GETCHAR: /* INT tm_getchar( INT wait ) */ er = getChar(p1); break; case TM_PUTCHAR: /* INT tm_putchar( INT c ) */ er = putChar(p1); break; case TM_GETLINE: /* INT tm_getline( UB *buff ) */ er = getString(wrkBuf); if ( er < 0 ) break; n = er + 1; if ( writeMem(p1, wrkBuf, n, 1) != n ) er = E_MACV; break; case TM_PUTSTRING: /* INT tm_putstring( const UB *buff ) */ n = readMemStr(p1, wrkBuf, WRKBUF_SZ); if ( n < 0 ) { er = E_MACV; break; } er = putString(wrkBuf); break; case TM_COMMAND: /* INT tm_command( const UB *buff ) */ n = readMemStr(p1, lineBuf, L_LINE); if ( n < 0 ) { er = E_MACV; break; } procCommand(( n == 0 )? NULL: lineBuf, 1); break; case TM_READDISK: case TM_WRITEDISK: case TM_INFODISK: /* INT tm_readdisk( const UB *dev, INT sec, INT nsec, void *addr ) * INT tm_writedisk( const UB *dev, INT sec, INT nsec, void *addr ) * INT tm_infodisk( const UB *dev, INT *blksz, INT *nblks ) */ n = readMemStr(p1, lineBuf, L_LINE); if ( n < 0 ) { er = E_MACV; break; } if ( fno == TM_INFODISK ) { er = infoDisk(lineBuf, (UW*)p2, (UW*)p3); } else { n = ( fno == TM_READDISK )? 0: 1; er = rwDisk(lineBuf, p2, p3, (void*)p4, n); } break; case TM_EXIT: /* void tm_exit( INT mode ) */ sysExit(p1); /* do not return */ break; case TM_EXTSVC: /* INT tm_extsvc( INT fno, INT par1, INT par2, INT par3 ) */ er = procExtSVC(p1, p2, p3, p4); break; default: er = E_PAR; } return er; }
void Ts206::disp(uint8_t address, uint8_t data) { uint8_t font[] = { 0b00000000, 0b11010000, 0b00010010, 0b01111110, 0b01101011, 0b00000000, 0b00000000, 0b00010000, 0b00000110, 0b01010000, 0b00110011, 0b00000000, 0b01000000, 0b00100000, 0b10000000, 0b00110100, 0b01011111, 0b01010000, 0b00111101, 0b01111001, 0b01110010, 0b01101011, 0b01101111, 0b01010011, 0b01111111, 0b01111011, 0b00000000, 0b00000000, 0b00000000, 0b00101000, 0b00000000, 0b00110101, 0b01111101, 0b01110111, 0b01111111, 0b00001111, 0b01011111, 0b00101111, 0b00100111, 0b01001111, 0b01110110, 0b01010000, 0b01011101, 0b00101011, 0b00001110, 0b01000101, 0b01010111, 0b01011111, 0b00110111, 0b01110011, 0b00000111, 0b01101011, 0b00101110, 0b01011110, 0b00011010, 0b01001101, 0b01110110, 0b01111010, 0b00111101, 0b00001111, 0b01100010, 0b01011001, 0b00000000, 0b00001000, 0b00000010, 0b01111101, 0b01101110, 0b00101100, 0b01111100, 0b00111111, 0b00000111, 0b01111011, 0b01100110, 0b01000000, 0b01011000, 0b01100111, 0b00000110, 0b01100101, 0b01100100, 0b01101100, 0b00110111, 0b01110011, 0b00100100, 0b01101011, 0b00101110, 0b01001100, 0b00011010, 0b01001101, 0b01110110, 0b01111010, 0b01110001, 0b01110000, 0b01010000, 0b00100110, 0b00000001, }; uint8_t d = font[data - 32]; uint8_t a = address * 2 + 4; uint8_t e = d & 0x0f; writeMem(a, e); d = d >> 4; a = a + 1; writeMem(a, d); }
static ssize_t dm_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos) { return writeMem(filp, buf, count, f_pos); }