def _init_base_labels(self): if self.label_mgr: # vbr label = LabelRange("vbr", 0, 0x400) self.label_mgr.add_label(label) # shutdown range label = LabelRange("machine", 0x400, 0x800) self.label_mgr.add_label(label)
def setup_old_dos_guard(self): # create a guard memory for tracking invalid old dos access raw_mem = self.machine.get_mem() self.dos_guard_base = raw_mem.reserve_special_range() if self.label_mgr: label = LabelRange("old_dos guard", self.dos_guard_base, 0x10000) self.label_mgr.add_label(label) log_mem_map.info(label)
def alloc_bstr(self, name, bstr): size = len(bstr) + 2 # front: count, end: extra zero for safety addr = self.alloc_mem(size) if self.label_mgr is not None: label = LabelRange(name, addr, size) self.label_mgr.add_label(label) else: label = None self.mem.w_bstr(addr, bstr) mem = Memory(addr, size, label, self.mem) log_mem_alloc.info("alloc b_str: %s", mem) self.mem_objs[addr] = mem return mem
def alloc_cstr(self, name, cstr): size = len(cstr) + 1 addr = self.alloc_mem(size) if self.label_mgr is not None: label = LabelRange(name, addr, size) self.label_mgr.add_label(label) else: label = None self.mem.w_cstr(addr, cstr) mem = Memory(addr, size, label, self.mem) log_mem_alloc.info("alloc c_str: %s", mem) self.mem_objs[addr] = mem return mem
def alloc_memory(self, name, size, add_label=True, except_on_failure=True): addr = self.alloc_mem(size, except_on_failure) if addr == 0: return None if add_label and self.label_mgr is not None: label = LabelRange(name, addr, size) self.label_mgr.add_label(label) else: label = None mem = Memory(addr, size, label, self.mem) log_mem_alloc.info("alloc memory: %s", mem) self.mem_objs[addr] = mem return mem
def alloc_cstr(self, cstr, label=None): size = len(cstr) + 1 addr = self.alloc_mem(size) if label and self.label_mgr: label_obj = LabelRange(label, addr, size) self.label_mgr.add_label(label_obj) else: label_obj = None self.mem.w_cstr(addr, cstr) mem = Memory(addr, size, label_obj, self.mem) log_mem_alloc.info("alloc c_str: %s", mem) self.mem_objs[addr] = mem return mem
def alloc(alloc, sizes, labels=None, bin_img_segs=None): mem = alloc.get_mem() last_addr = 0 first_addr = 0 for i in range(len(sizes)): size = sizes[i] size = (size + 3) & ~3 seg_size = size + 8 # add next segment pointer and size field # alloc mem seg_mem = alloc.alloc_memory(seg_size) seg_addr = seg_mem.addr # create label if alloc.label_mgr and labels: name = labels[i] # add a segment label if bin img segment available if bin_img_segs: bin_img_seg = bin_img_segs[i] label = LabelSegment(name, seg_addr, seg_size, bin_img_seg) else: label = LabelRange(name, seg_addr, seg_size) seg_mem.label = label alloc.label_mgr.add_label(label) # store size mem.w32(seg_addr, seg_size) # link last to me if last_addr != 0: mem.w32(last_addr + 4, (seg_addr + 4) >> 2) last_addr = seg_addr if i == 0: first_addr = seg_addr # terminate link mem.w32(seg_addr + 4, 0) # seglist start baddr baddr = (first_addr + 4) >> 2 return SegList(alloc, baddr)