def readBytes(self, cpu, vaddr, maxlen): ''' return a bytearray of maxlen read from vaddr ''' remain = maxlen start = vaddr retval = () while remain > 0: count = min(remain, 1024) ps = self.v2p(cpu, start) if ps is not None: remain_in_page = pageUtils.pageLen(ps, pageUtils.PAGE_SIZE) if remain_in_page < count: self.lgr.debug('readBytes remain_in_page %d' % remain_in_page) first_read = readPhysBytes(cpu, ps, remain_in_page) if first_read is not None and len( first_read) == remain_in_page: ''' get the rest ''' ps = self.v2p(cpu, start + remain_in_page) self.lgr.debug('readBytes first read %s new ps 0x%x' % (first_read, ps)) second_read = readPhysBytes(cpu, ps, count - remain_in_page) self.lgr.debug('readBytes second read %s from 0x%x' % (second_read, ps)) retval = retval + first_read + second_read else: retval = retval + first_read else: retval = retval + readPhysBytes(cpu, ps, count) #self.lgr.debug('readBytes normal read %s from phys 0x%x' % (retval, ps)) self.lgr.debug('readBytes got %d' % len(retval)) start = start + count remain = remain - count retval = bytearray(retval) return retval
def getBytes(self, cpu, num_bytes, addr): ''' Get a hex string of num_bytes from the given address using Simics physical memory reads, which return tuples. ''' done = False curr_addr = addr bytes_to_go = num_bytes retval = '' retbytes = () #print 'in getBytes for 0x%x bytes' % (num_bytes) while not done and bytes_to_go > 0 and curr_addr is not None: bytes_to_read = bytes_to_go remain_in_page = pageUtils.pageLen(curr_addr, pageUtils.PAGE_SIZE) #print 'remain is 0x%x bytes to go is 0x%x cur_addr is 0x%x end of page would be 0x%x' % (remain_in_page, bytes_to_read, curr_addr, end) if remain_in_page < bytes_to_read: bytes_to_read = remain_in_page if bytes_to_read > 1024: bytes_to_read = 1024 #phys_block = cpu.iface.processor_info.logical_to_physical(curr_addr, Sim_Access_Read) phys = self.v2p(cpu, curr_addr) if phys is None: self.lgr.error('memUtils v2p for 0x%x returned None' % curr_addr) #SIM_break_simulation('bad phys memory mapping at 0x%x' % curr_addr) return None, None #print 'read (bytes_to_read) 0x%x bytes from 0x%x phys:%x ' % (bytes_to_read, curr_addr, phys_block.address) try: #read_data = readPhysBytes(cpu, phys_block.address, bytes_to_read) read_data = readPhysBytes(cpu, phys, bytes_to_read) except ValueError: #except: #print 'trouble reading phys bytes, address %x, num bytes %d end would be %x' % (phys_block.address, bytes_to_read, phys_block.address + bytes_to_read - 1) print( 'trouble reading phys bytes, address %x, num bytes %d end would be %x' % (phys, bytes_to_read, phys + bytes_to_read - 1)) print('bytes_to_go %x bytes_to_read %d' % (bytes_to_go, bytes_to_read)) self.lgr.error('bytes_to_go %x bytes_to_read %d' % (bytes_to_go, bytes_to_read)) return retval, retbytes holder = '' count = 0 for v in read_data: count += 1 holder = '%s%02x' % (holder, v) #self.lgr.debug('add v of %2x holder now %s' % (v, holder)) retbytes = retbytes + read_data del read_data retval = '%s%s' % (retval, holder) bytes_to_go = bytes_to_go - bytes_to_read #self.lgr.debug('0x%x bytes of data read from %x bytes_to_go is %d' % (count, curr_addr, bytes_to_go)) curr_addr = curr_addr + bytes_to_read return retval, retbytes
def readString(self, cpu, vaddr, maxlen): retval = None ps = self.v2p(cpu, vaddr) if ps is not None: #self.lgr.debug('readString vaddr 0x%x ps is 0x%x' % (vaddr, ps)) remain_in_page = pageUtils.pageLen(ps, pageUtils.PAGE_SIZE) if remain_in_page < maxlen: #self.lgr.debug('remain_in_page %d' % remain_in_page) try: first_read = self.readStringPhys(cpu, ps, remain_in_page) except ValueError: self.lgr.debug( 'memUtils readString value error reading %d bytes from 0x%x' % (remain_in_page, ps)) return retval if first_read is not None and len( first_read) == remain_in_page: ''' get the rest ''' ps = self.v2p(cpu, vaddr + remain_in_page) #self.lgr.debug('first read %s new ps 0x%x' % (first_read, ps)) try: second_read = self.readStringPhys( cpu, ps, maxlen - remain_in_page) except ValueError: self.lgr.debug( 'memUtils readString 2nd read value error reading %d bytes from 0x%x' % (remain_in_page, ps)) return retval #self.lgr.debug('second read %s from 0x%x' % (second_read, ps)) retval = first_read + second_read else: retval = first_read else: retval = self.readStringPhys(cpu, ps, maxlen) #self.lgr.debug('normal read %s from phys 0x%x' % (retval, ps)) return retval