static int flash_nrf_write(struct device *dev, off_t addr, const void *data, size_t len) { int ret; if (write_protect) { return -EACCES; } if (!is_addr_valid(addr, len)) { return -EINVAL; } if (!len) { return 0; } SYNC_LOCK(); #if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC) if (ticker_is_initialized(0)) { ret = write_in_timeslice(addr, data, len); } else #endif /* CONFIG_SOC_FLASH_NRF_RADIO_SYNC */ { ret = write(addr, data, len); } SYNC_UNLOCK(); return ret; }
static void print_stacktrace (void **buffer, int size) { int i; int top, bottom; void *addr; if (!log_fd) return; if (st_skip_top + st_skip_bottom >= size){ top = bottom = 0; }else{ top = st_skip_top; bottom = st_skip_bottom; } for (i = top; i < size - bottom && i-top < st_count; ++i){ addr = buffer [i]; if (!is_addr_valid (addr)){ /* fprintf (stderr, "bad address: " POINTER_FORMAT "\n", addr); */ continue; } assert (addr); fprintf (log_fd, " " POINTER_FORMAT "\n", addr); } }
static int flash_nrf5_erase(struct device *dev, off_t addr, size_t size) { uint32_t pg_size = NRF_FICR->CODEPAGESIZE; uint32_t n_pages = size / pg_size; /* Erase can only be done per page */ if (((addr % pg_size) != 0) || ((size % pg_size) != 0) || (n_pages == 0)) { return -EINVAL; } if (!is_addr_valid(addr, size)) { return -EINVAL; } /* Erase uses a specific configuration register */ NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos; nvmc_wait_ready(); for (uint32_t i = 0; i < n_pages; i++) { NRF_NVMC->ERASEPAGE = (uint32_t)addr + (i * pg_size); nvmc_wait_ready(); } NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; nvmc_wait_ready(); return 0; }
static int flash_nrf_erase(struct device *dev, off_t addr, size_t size) { u32_t pg_size = NRF_FICR->CODEPAGESIZE; u32_t n_pages = size / pg_size; int ret; /* Erase can only be done per page */ if (((addr % pg_size) != 0) || ((size % pg_size) != 0)) { return -EINVAL; } if (!is_addr_valid(addr, size)) { return -EINVAL; } if (!n_pages) { return 0; } SYNC_LOCK(); #if defined(CONFIG_SOC_FLASH_NRF_RADIO_SYNC) if (ticker_is_initialized(0)) { ret = erase_in_timeslice(addr, size); } else #endif /* CONFIG_SOC_FLASH_NRF_RADIO_SYNC */ { ret = erase(addr, size); } SYNC_UNLOCK(); return ret; }
static int flash_nrf5_read(struct device *dev, off_t addr, void *data, size_t len) { if (!is_addr_valid(addr, len)) { return -EINVAL; } memcpy(data, (void *)addr, len); return 0; }
static int flash_nrf5_write(struct device *dev, off_t addr, const void *data, size_t len) { uint32_t addr_word; uint32_t tmp_word; void *data_word; uint32_t remaining = len; uint32_t count = 0; if (!is_addr_valid(addr, len)) { return -EINVAL; } /* Start with a word-aligned address and handle the offset */ addr_word = addr & ~0x3; /* If not aligned, read first word, update and write it back */ if (!is_aligned_32(addr)) { tmp_word = *(uint32_t *)(addr_word); count = sizeof(uint32_t) - (addr & 0x3); if (count > len) { count = len; } memcpy((uint8_t *)&tmp_word + (addr & 0x3), data, count); nvmc_wait_ready(); *(uint32_t *)addr_word = tmp_word; addr_word = addr + count; remaining -= count; } /* Write all the 4-byte aligned data */ data_word = (void *) data + count; while (remaining >= sizeof(uint32_t)) { nvmc_wait_ready(); *(uint32_t *)addr_word = *(uint32_t *)data_word; addr_word += sizeof(uint32_t); data_word += sizeof(uint32_t); remaining -= sizeof(uint32_t); } /* Write remaining data */ if (remaining) { tmp_word = *(uint32_t *)(addr_word); memcpy((uint8_t *)&tmp_word, data_word, remaining); nvmc_wait_ready(); *(uint32_t *)addr_word = tmp_word; } nvmc_wait_ready(); return 0; }
static inline void hi3620_reg_write(unsigned int value, unsigned int addr) { BUG_ON(!is_addr_valid(addr)); writel_asp_mutex(value, g_hi3620_asp_reg_base_addr + addr); }
static inline int hi3620_reg_read(unsigned int addr) { BUG_ON(!is_addr_valid(addr)); return readl_mutex(g_hi3620_asp_reg_base_addr + addr); }
void x86Analysis::get_block( uint32 entry_addr ) { if (!is_addr_valid(entry_addr)) { return; } CPU_ADDR current_addr; current_addr.addr32.seg = 0; current_addr.addr32.offset = entry_addr; uint32 end_addr = 0; debug_utils::scope_exit add_block_on_exit([entry_addr,&end_addr,this]() { assert(entry_addr != 0); assert(end_addr != 0); code_block block = {entry_addr,end_addr}; add_block(block); }); for (unsigned i=entry_addr-code_start_va_;i<code_size_;) { //assert(curAddr.addr32.offset != 0x00401029); x86dis_insn* insn = (x86dis_insn*)disasmbler_.decode(code_to_analy_+i,code_size_-i,current_addr); //const char* pcsIns = m_Decoder.str(insn,DIS_STYLE_HEX_ASMSTYLE | DIS_STYLE_HEX_UPPERCASE | DIS_STYLE_HEX_NOZEROPAD); //printf("%08X\t%s\n",curAddr.addr32.offset, pcsIns); i += insn->size; current_addr.addr32.offset += insn->size; if (cache_insn.size()>=10) { cache_insn.pop_back(); } cache_insn.push_front(*insn); end_addr = code_offset_to_va(code_to_analy_ + i); switch (is_branch(insn)) { case BR_RET: return; case BR_JMP: { if (is_jump_table(insn)) { // 获取跳转表地址 BYTE* index_tab_addr = NULL; BYTE* address_tab_addr = (BYTE*)insn->op[0].mem.disp; int index_size = 0; int index_tab_size = 0; for each (x86dis_insn insn in cache_insn) { if (insn.name == NULL) { continue; } if (strstr(insn.name,"mov") && insn.op[1].type == X86_OPTYPE_MEM && insn.op[0].type == X86_OPTYPE_REG && index_tab_addr == NULL) { index_tab_addr = (BYTE*)insn.op[1].mem.disp; index_size = insn.op[1].size; continue; } if (strstr(insn.name,"cmp") && insn.op[1].type == X86_OPTYPE_IMM && index_tab_size == 0) { index_tab_size = insn.op[1].imm+1; continue; } // if (strstr(insn.name,"")) // { // continue; // } } if (index_tab_addr == NULL || address_tab_addr == NULL || index_tab_size == 0 || index_size == 0) { // 构成跳转表的东西不够 return; } BYTE index_tab_cpy[index_tab_size*index_size]; //BOOL ret = ReadProcessMemory(hProcess,pIndexTabAddr,pIndexTabCpy,nIndexTabSize*nIndexSize,&nRead); std::shared_ptr<debug_kernel> debug_kernel_ptr = debug_kernel_wp_.lock(); debug_kernel_ptr->read_debugee_memory(index_tab_addr,index_tab_cpy,index_tab_size*index_size); int index = 0; for (int i=0;i<index_tab_size*index_size;i+=index_size) { switch (index_size) { case 1: { index = index_tab_cpy[i]; } break; case 2: { index = (WORD)index_tab_cpy[i]; } break; case 4: { index = (DWORD)index_tab_cpy[i]; } break; } uint32 address = 0; //ReadProcessMemory(hProcess,pAddressTabAddr+nIndex*4,&address,4,NULL); debug_kernel_ptr->read_debugee_memory(address_tab_addr+index*4,&address,4); AtlTrace("Index:%d,Address:0x%08x\n",index,address); add_entry(address); } return; } else { CPU_ADDR addr = branch_addr(insn); add_entry(addr.addr32.offset); return; } } case BR_JCC: { CPU_ADDR addr = branch_addr(insn); //AddEntry(uEnd); get_block(end_addr); add_entry(addr.addr32.offset); return; } case BR_CALL: { CPU_ADDR addr = branch_addr(insn); add_entry(end_addr); add_entry(addr.addr32.offset); } break; } }