X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/b26d3165c52589d1f8de37bf0df27ad96f460f47..2236410f4582ab45ae8c384dd6eeeef5d10aab15:/lunaix-os/scripts/expand.py diff --git a/lunaix-os/scripts/expand.py b/lunaix-os/scripts/expand.py index cd62164..9fe3d94 100644 --- a/lunaix-os/scripts/expand.py +++ b/lunaix-os/scripts/expand.py @@ -269,42 +269,54 @@ class MemoryMapObject(DataObject): super().__init__("", record) def _parse(self, record): - if "granule" in self._record: - self.__g = MemoryMapObject.GranuleObject(self._record["granule"]) - if "regions" in self._record: - self.__regions = ArrayObject(self._record["regions"]) - if "width" in self._record: - self.__width = DataObject.create("width", self._record["width"]) - - def __process(self, start_addr, idx, regions, size_lookahead = False): + for k, v in record.items(): + if k.startswith("$"): + self.ctrl_field[k.strip("$")] = FieldType.create(k, v) + elif k.startswith("@"): + self.ctrl_field[k.strip("@")] = DataObject.create(k, v) + + if "granule" in record: + self.__g = MemoryMapObject.GranuleObject(record["granule"]) + + if "regions" in record: + self.__regions = ArrayObject(record["regions"]) + + if "width" in record: + self.__width = DataObject.create("width", record["width"]) + + def __process(self, start_addr, idx, regions): if idx >= len(regions): raise Exception("Unbounded region definition") e = regions[idx] - if "boundary" in e: - b = e["boundary"] - 1 - start_addr = (start_addr + b) & ~b - if "start" not in e: - e["start"] = start_addr - elif e["start"] < start_addr: + ne = regions[idx + 1] + if "start" not in ne or "size" not in e: + e["start"] = start_addr + else: + self.__process(start_addr + e["size"], idx + 1, regions) + e["start"] = ne['start'] - e["size"] + + if "block" in e: + b = e["block"] - 1 + e["start"] = (e["start"] + b) & ~b + + if e["start"] < start_addr: raise Exception(f"starting addr {hex(e['start'])} overrlapping with {hex(start_addr)}") - else: - start_addr = e["start"] - if "size" not in e: - if size_lookahead: - raise Exception("could not infer size from unbounded region") - tmp_addr = self.__process(start_addr, idx + 1, regions, size_lookahead=True) - e["size"] = tmp_addr - start_addr + start_addr = e["start"] - if not size_lookahead: - start_addr += e["size"] + if "size" not in e: + self.__process(start_addr, idx + 1, regions) + ne = regions[idx + 1] + e["size"] = ne['start'] - start_addr - return start_addr + return start_addr + e["size"] def expand(self, param={}): + super().expand(param) + g = self.__g.expand(param) param["granule"] = g