def libnative_libfuncs_open_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) # new lib lib = Library.alloc(alloc, name="my.library", id_string="bla", neg_size=36) lib.new_lib() # setup open func def open_func(op, pc): # return my seglist cpu.w_reg(REG_D0, 0xCAFEBABE) trap_id = traps.setup(open_func, auto_rts=True) exp_addr = lib.get_addr() - 6 mem.w16(exp_addr, trap_id | 0xA000) # add lib lf = LibFuncs(machine, alloc) lib_base = lf.open_library(lib.get_addr(), run_sp=sp) assert lib_base == 0xCAFEBABE # cleanup lib.free() assert alloc.is_all_free()
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
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
def libnative_libfuncs_open_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) # new lib lib = Library.alloc(alloc, "my.library", "bla", 36) lib.setup() # setup open func def open_func(op, pc): # return my seglist cpu.w_reg(REG_D0, 0xcafebabe) trap_id = traps.setup(open_func, auto_rts=True) exp_addr = lib.get_addr() - 6 mem.w16(exp_addr, trap_id | 0xa000) # add lib lf = LibFuncs(machine, alloc) lib_base = lf.open_library(lib.get_addr(), run_sp=sp) assert lib_base == 0xcafebabe # cleanup lib.free() assert alloc.is_all_free()
def libnative_initres_init_test(buildlibnix): machine = Machine() mem = machine.get_mem() cpu = machine.get_cpu() traps = machine.get_traps() alloc = MemoryAlloc.for_machine(machine) init_addr = machine.get_ram_begin() - 4 sp = init_addr - 4 # load lib seglist, addr, size, end = load_lib(alloc, buildlibnix) # setup init func def init_func(op, pc): assert cpu.r_reg(REG_A0) == seglist.get_baddr() # return my lib_base cpu.w_reg(REG_D0, 0xcafebabe) trap_id = traps.setup(init_func, auto_rts=True) mem.w16(init_addr, trap_id | 0xa000) # build fake resident res = Resident.alloc(alloc, "bla.library", "blub") res.setup(flags=0, version=42, type=NodeType.NT_LIBRARY, pri=-7, init=init_addr) # init resident ir = InitRes(machine, alloc) lib_base, mem_obj = ir.init_resident( res.get_addr(), seglist.get_baddr(), run_sp=sp) assert lib_base == 0xcafebabe assert mem_obj is None seglist.free() res.free() traps.free(trap_id) assert alloc.is_all_free()
def create_machine(): m = Machine(Machine.CPU_TYPE_68000, raise_on_main_run=False) cpu = m.get_cpu() mem = m.get_mem() traps = m.get_traps() code = m.get_ram_begin() stack = code + 0x1000 return m, cpu, mem, traps, code, stack
def libnative_initres_autoinit_test(buildlibnix): machine = Machine() mem = machine.get_mem() cpu = machine.get_cpu() traps = machine.get_traps() alloc = MemoryAlloc.for_machine(machine) init_addr = machine.get_ram_begin() - 4 sp = init_addr - 4 # load lib seglist, addr, size, end = load_lib(alloc, buildlibnix) # setup init func def init_func(op, pc): assert cpu.r_reg(REG_A0) == seglist.get_baddr() trap_id = traps.setup(init_func, auto_rts=True) mem.w16(init_addr, trap_id | 0xA000) # fake vectors vectors = 0x100 mem.w32(vectors, 0x400) mem.w32(vectors + 4, 0x600) mem.w32(vectors + 8, 0x800) mem.w32(vectors + 12, 0xFFFFFFFF) # build fake resident res = Resident.alloc(alloc, "bla.library", "blub") res.setup(flags=ResidentFlags.RTF_AUTOINIT, version=42, type=NodeType.NT_LIBRARY, pri=-7) auto_init = AutoInit.alloc(alloc) auto_init.setup(functions=vectors, init_func=init_addr) res.set_auto_init(auto_init) # setup exec lib exec_lib = ExecLibrary.alloc(alloc, "exec.library", "bla", 36) exec_lib.setup() mem.w32(4, exec_lib.get_addr()) # init resident ir = InitRes(machine, alloc) lib_base, mem_obj = ir.init_resident(res.get_addr(), seglist.get_baddr(), run_sp=sp, exec_lib=exec_lib) assert lib_base assert mem_obj seglist.free() res.free() auto_init.free() alloc.free_memory(mem_obj) exec_lib.free() traps.free(trap_id) assert alloc.is_all_free()
def machine_disasm_default_test(): mach = Machine() disasm = DisAsm(mach) mem = mach.get_mem() cpu = mach.get_cpu() traps = mach.get_traps() # trap without func mem.w16(0, 0xa123) assert disasm.disassemble(0) == (2, "PyTrap #$123") # trap with func def bla(opcode, pc): pass tid = traps.setup(bla) mem.w16(2, 0xa000 | tid) assert disasm.disassemble(2) == (2, "PyTrap #$%03x ; bla" % tid) traps.free(tid)
def libnative_initres_autoinit_test(buildlibnix): machine = Machine() mem = machine.get_mem() cpu = machine.get_cpu() traps = machine.get_traps() alloc = MemoryAlloc.for_machine(machine) init_addr = machine.get_ram_begin() - 4 sp = init_addr - 4 # load lib seglist, addr, size, end = load_lib(alloc, buildlibnix) # setup init func def init_func(op, pc): assert cpu.r_reg(REG_A0) == seglist.get_baddr() trap_id = traps.setup(init_func, auto_rts=True) mem.w16(init_addr, trap_id | 0xa000) # fake vectors vectors = 0x100 mem.w32(vectors, 0x400) mem.w32(vectors+4, 0x600) mem.w32(vectors+8, 0x800) mem.w32(vectors+12, 0xffffffff) # build fake resident res = Resident.alloc(alloc, "bla.library", "blub") res.setup(flags=ResidentFlags.RTF_AUTOINIT, version=42, type=NodeType.NT_LIBRARY, pri=-7) auto_init = AutoInit.alloc(alloc) auto_init.setup(functions=vectors, init_func=init_addr) res.set_auto_init(auto_init) # setup exec lib exec_lib = ExecLibrary.alloc(alloc, "exec.library", "bla", 36) exec_lib.setup() mem.w32(4, exec_lib.get_addr()) # init resident ir = InitRes(machine, alloc) lib_base, mem_obj = ir.init_resident( res.get_addr(), seglist.get_baddr(), run_sp=sp, exec_lib=exec_lib) assert lib_base assert mem_obj seglist.free() res.free() auto_init.free() alloc.free_memory(mem_obj) exec_lib.free() traps.free(trap_id) assert alloc.is_all_free()
def libnative_initres_init_test(buildlibnix): machine = Machine() mem = machine.get_mem() cpu = machine.get_cpu() traps = machine.get_traps() alloc = MemoryAlloc.for_machine(machine) init_addr = machine.get_ram_begin() - 4 sp = init_addr - 4 # load lib seglist, addr, size, end = load_lib(alloc, buildlibnix) # setup init func def init_func(op, pc): assert cpu.r_reg(REG_A0) == seglist.get_baddr() # return my lib_base cpu.w_reg(REG_D0, 0xCAFEBABE) trap_id = traps.setup(init_func, auto_rts=True) mem.w16(init_addr, trap_id | 0xA000) # build fake resident res = Resident.alloc(alloc, "bla.library", "blub") res.setup(flags=0, version=42, type=NodeType.NT_LIBRARY, pri=-7, init=init_addr) # init resident ir = InitRes(machine, alloc) lib_base, mem_obj = ir.init_resident(res.get_addr(), seglist.get_baddr(), run_sp=sp) assert lib_base == 0xCAFEBABE assert mem_obj is None seglist.free() res.free() traps.free(trap_id) assert alloc.is_all_free()