| 39 | } |
| 40 | |
| 41 | class ProxyUtils(Reloadable): |
| 42 | CODE_BUFFER_SIZE = 0x10000 |
| 43 | def __init__(self, p, heap_size=1024 * 1024 * 1024): |
| 44 | self.iface = p.iface |
| 45 | self.proxy = p |
| 46 | self.base = p.get_base() |
| 47 | (self.ba_addr, self.ba_rev) = p.get_bootargs_rev() |
| 48 | |
| 49 | if self.ba_rev <= 1: |
| 50 | self.ba = self.iface.readstruct(self.ba_addr, BootArgs_r1) |
| 51 | elif self.ba_rev == 2: |
| 52 | self.ba = self.iface.readstruct(self.ba_addr, BootArgs_r2) |
| 53 | elif self.ba_rev == 3: |
| 54 | self.ba = self.iface.readstruct(self.ba_addr, BootArgs_r3) |
| 55 | |
| 56 | # We allocate a 128MB heap, 128MB after the m1n1 heap, without telling it about it. |
| 57 | # This frees up from having to coordinate memory management or free stuff after a Python |
| 58 | # script runs, at the expense that if m1n1 ever uses more than 128MB of heap it will |
| 59 | # clash with Python (m1n1 will normally not use *any* heap when running proxy ops though, |
| 60 | # except when running very high-level operations like booting a kernel, so this should be |
| 61 | # OK). |
| 62 | self.heap_size = heap_size |
| 63 | try: |
| 64 | self.heap_base = p.heapblock_alloc(0) |
| 65 | except ProxyRemoteError: |
| 66 | # Compat with versions that don't have heapblock yet |
| 67 | self.heap_base = (self.base + ((self.ba.top_of_kernel_data + 0xffff) & ~0xffff) - |
| 68 | self.ba.phys_base) |
| 69 | |
| 70 | if os.environ.get("M1N1HEAP", ""): |
| 71 | self.heap_base = int(os.environ.get("M1N1HEAP", ""), 16) |
| 72 | |
| 73 | self.heap_base += 128 * 1024 * 1024 # We leave 128MB for m1n1 heap |
| 74 | self.heap_top = self.heap_base + self.heap_size |
| 75 | self.heap = Heap(self.heap_base, self.heap_top) |
| 76 | self.proxy.heap = self.heap |
| 77 | |
| 78 | self.malloc = self.heap.malloc |
| 79 | self.memalign = self.heap.memalign |
| 80 | self.free = self.heap.free |
| 81 | |
| 82 | self.code_buffer = self.malloc(self.CODE_BUFFER_SIZE) |
| 83 | |
| 84 | self.adt_data = None |
| 85 | self.adt = LazyADT(self) |
| 86 | |
| 87 | self.simd_buf = self.malloc(32 * 16) |
| 88 | self.simd_type = None |
| 89 | self.simd = None |
| 90 | |
| 91 | self.mmu_off = False |
| 92 | |
| 93 | self.inst_cache = {} |
| 94 | |
| 95 | self.exec_modes = { |
| 96 | None: (self.proxy.call, REGION_RX_EL1), |
| 97 | "el2": (self.proxy.call, REGION_RX_EL1), |
| 98 | "el1": (self.proxy.el1_call, 0), |
no outgoing calls
no test coverage detected