예제 #1
0
def libnative_libfuncs_close_library_test():
    machine = Machine()
    mem = machine.get_mem()
    cpu = machine.get_cpu()
    traps = machine.get_traps()
    sp = machine.get_ram_begin() - 4
    alloc = MemoryAlloc.for_machine(machine)
    segloader = SegmentLoader(alloc)
    # new lib
    lib = Library.alloc(alloc, name="my.library", id_string="bla", neg_size=36)
    lib.new_lib()
    # setup seglist
    seglist = SegList.alloc(alloc, [64])
    segloader.register_seglist(seglist.get_baddr())

    # setup expunge func

    def close_func(op, pc):
        # return my seglist
        cpu.w_reg(REG_D0, seglist.get_baddr())

    trap_id = traps.setup(close_func, auto_rts=True)
    exp_addr = lib.get_addr() - 12
    mem.w16(exp_addr, trap_id | 0xA000)
    # add lib
    lf = LibFuncs(machine, alloc)
    sl = lf.close_library(lib.get_addr(), segloader, run_sp=sp)
    assert seglist.get_baddr() == sl
    # cleanup
    lib.free()
    assert alloc.is_all_free()
    assert segloader.shutdown() == 0
예제 #2
0
def libnative_libfuncs_close_library_test():
  machine = Machine()
  mem = machine.get_mem()
  cpu = machine.get_cpu()
  traps = machine.get_traps()
  sp = machine.get_ram_begin() - 4
  alloc = MemoryAlloc.for_machine(machine)
  segloader = SegmentLoader(alloc)
  # new lib
  lib = Library.alloc(alloc, "my.library", "bla", 36)
  lib.setup()
  # setup seglist
  seglist = SegList.alloc(alloc, [64])
  segloader.register_seglist(seglist.get_baddr())
  # setup expunge func

  def close_func(op, pc):
    # return my seglist
    cpu.w_reg(REG_D0, seglist.get_baddr())
  trap_id = traps.setup(close_func, auto_rts=True)
  exp_addr = lib.get_addr() - 12
  mem.w16(exp_addr, trap_id | 0xa000)
  # add lib
  lf = LibFuncs(machine, alloc)
  sl = lf.close_library(lib.get_addr(), segloader, run_sp=sp)
  assert seglist.get_baddr() == sl
  # cleanup
  lib.free()
  assert alloc.is_all_free()
  assert segloader.shutdown() == 0
예제 #3
0
파일: loader.py 프로젝트: kowoba/amitools
 def _load_common(self, seglist_baddr, run_sp):
     # find resident in first hunk
     seglist = SegList(self.alloc, seglist_baddr)
     seg = seglist.get_segment()
     res = Resident.find(self.mem, seg.get_addr(), seg.get_size())
     # unload seglist if no resident was found
     if not res:
         self.segloader.unload_seglist(seglist_baddr)
         return 0, 0
     # init resident
     lib_base, _ = self.initres.init_resident(res.get_addr(),
                                              seglist.get_baddr(),
                                              run_sp=run_sp)
     # unload seglist on error
     if lib_base == 0:
         self.segloader.unload_seglist(seglist_baddr)
         return 0, 0
     return lib_base, seglist_baddr
예제 #4
0
def loader_seglist_alloc_test(buildlibnix, mem_alloc):
  mem, alloc = mem_alloc
  sizes = [23, 17, 32]
  alloc_sizes = [24, 20, 32]
  # alloc seg_list
  seg_list = SegList.alloc(alloc, sizes)
  # check segment allocation
  assert seg_list.get_all_sizes() == alloc_sizes
  assert seg_list.get_all_addrs() == [12, 44, 72]
  segs = seg_list.get_all_segments()
  assert len(segs) == 3
  assert segs[0].get_size() == alloc_sizes[0]
  assert segs[1].get_size() == alloc_sizes[1]
  assert segs[2].get_size() == alloc_sizes[2]
  # iterator
  i = 0
  for seg in seg_list:
    assert seg.get_size() == alloc_sizes[i]
    i += 1
  # free
  seg_list.free()
  assert alloc.is_all_free()