Package envi :: Module pagelookup
[hide private]
[frames] | no frames]

Source Code for Module envi.pagelookup

 1  ''' 
 2  A home for the page lookup construct.  Basically it is a 
 3  python object which implements a similar lookup mechanism 
 4  to the i386 page table lookups... 
 5  ''' 
 6   
 7  # FIXME move functions in here too so there is procedural "speed" way 
 8  # and objecty pythonic way... 
 9   
10 -class PageLookup:
11 ''' 12 An object capable of rapid lookups across a sparse address 13 space which will also NOT eat *all* the RAMS like a straight 14 dictionary full of millions of entries would. 15 ''' 16
17 - def __init__(self):
18 self._page_dict = {}
19
20 - def getPageLookup(self, va):
21 base = va >> 16 22 offs = va & 0xffff 23 page = self._page_dict.get(base) 24 if page == None: 25 return None 26 return page[offs]
27
28 - def setPageLookup(self, va, size, obj):
29 vamax = va+size 30 while va < vamax: 31 base = va >> 16 32 offs = va & 0xffff 33 page = self._page_dict.get(base) 34 if page == None: 35 page = [None] * 0xffff 36 self._page_dict[base] = page 37 page[offs] = obj 38 va += 1
39 40 # __getitem__ 41 # __getslice__ 42 # __setslice__ 43
44 -class MapLookup:
45 46 ''' 47 A specialized lookup object for large densely populated ranges 48 which are layed out in a sparse field space themselves... 49 ''' 50
51 - def __init__(self):
52 self._maps_list = []
53
54 - def initMapLookup(self, va, size, obj=None):
55 marray = [obj] * size 56 # FIXME optimize by size! 57 self._maps_list.append((va, va+size, marray))
58
59 - def setMapLookup(self, va, size, obj):
60 for mva, mvamax, marray in self._maps_list: 61 if va >= mva and va < mvamax: 62 off = va - mva 63 s = [obj] * size 64 marray[off:off+size] = s 65 return 66 raise Exception('Address (0x%.8x) not in maps!' % va)
67
68 - def getMapLookup(self, va):
69 for mva, mvamax, marray in self._maps_list: 70 if va >= mva and va < mvamax: 71 off = va - mva 72 return marray[off] 73 return None
74
75 - def __getslice__(self, start, end):
76 print 'GET SLICE'
77