@@ -602,6 +602,9 @@ drcbe_x86::drcbe_x86(drcuml_state &drcuml, device_t &device, drc_cache &cache, u
602602 }
603603
604604 // resolve the actual addresses of member functions we need to call
605+ m_drcmap_get_value.set (m_map, &drc_map_variables::get_value);
606+ if (!m_drcmap_get_value)
607+ throw emu_fatalerror (" Error resolving map variable get value function!\n " );
605608 m_memory_accessors.resize (m_space.size ());
606609 for (int space = 0 ; m_space.size () > space; ++space)
607610 {
@@ -856,6 +859,14 @@ int drcbe_x86::execute(code_handle &entry)
856859
857860void drcbe_x86::generate (drcuml_block &block, const instruction *instlist, uint32_t numinst)
858861{
862+ // do this here because device.debug() isn't initialised at construction time
863+ if (!m_debug_cpu_instruction_hook && (m_device.machine ().debug_flags & DEBUG_FLAG_ENABLED))
864+ {
865+ m_debug_cpu_instruction_hook.set (*m_device.debug (), &device_debug::instruction_hook);
866+ if (!m_debug_cpu_instruction_hook)
867+ throw emu_fatalerror (" Error resolving debugger instruction hook member function!\n " );
868+ }
869+
859870 // tell all of our utility objects that a block is beginning
860871 m_hash.block_begin (block, instlist, numinst);
861872 m_map.block_begin (block);
@@ -2535,25 +2546,27 @@ void drcbe_x86::op_debug(Assembler &a, const instruction &inst)
25352546 assert_no_condition (inst);
25362547 assert_no_flags (inst);
25372548
2538- using debugger_hook_func = void (*)(device_debug *, offs_t );
2539- static const debugger_hook_func debugger_inst_hook = [] (device_debug *dbg, offs_t pc) { dbg->instruction_hook (pc); }; // TODO: kill trampoline if possible
2540-
25412549 if ((m_device.machine ().debug_flags & DEBUG_FLAG_ENABLED) != 0 )
25422550 {
25432551 // normalize parameters
25442552 be_parameter const pcp (*this , inst.param (0 ), PTYPE_MRI);
25452553
25462554 // test and branch
2547- a.test (MABS (&m_device.machine ().debug_flags , 4 ), DEBUG_FLAG_CALL_HOOK); // test [debug_flags],DEBUG_FLAG_CALL_HOOK
2555+ a.test (MABS (&m_device.machine ().debug_flags , 4 ), DEBUG_FLAG_CALL_HOOK);
25482556 Label skip = a.newLabel ();
2549- a.short_ ().jz (skip); // jz skip
2557+ a.short_ ().jz (skip);
25502558
25512559 // push the parameter
2552- emit_mov_m32_p32 (a, dword_ptr (esp, 4 ), pcp); // mov [esp+4],pcp
2553- a.mov (dword_ptr (esp, 0 ), imm (m_device.debug ())); // mov [esp],device.debug
2554- a.call (imm (debugger_inst_hook)); // call debugger_inst_hook
2560+ emit_mov_m32_p32 (a, dword_ptr (esp, USE_THISCALL ? 0 : 4 ), pcp);
2561+ if (USE_THISCALL)
2562+ a.mov (ecx, imm (m_debug_cpu_instruction_hook.obj ));
2563+ else
2564+ a.mov (dword_ptr (esp, 0 ), imm (m_debug_cpu_instruction_hook.obj ));
2565+ a.call (imm (m_debug_cpu_instruction_hook.func ));
2566+ if (USE_THISCALL)
2567+ a.sub (esp, 4 );
25552568
2556- a.bind (skip); // skip:
2569+ a.bind (skip);
25572570 reset_last_upper_lower_reg ();
25582571 }
25592572}
@@ -2856,14 +2869,19 @@ void drcbe_x86::op_recover(Assembler &a, const instruction &inst)
28562869 be_parameter dstp (*this , inst.param (0 ), PTYPE_MR);
28572870
28582871 // call the recovery code
2859- a.mov (eax, MABS (&m_stacksave)); // mov eax,stacksave
2860- a.mov (eax, ptr (eax, -4 )); // mov eax,[eax-4]
2861- a.sub (eax, 1 ); // sub eax,1
2862- a.mov (dword_ptr (esp, 8 ), inst.param (1 ).mapvar ()); // mov [esp+8],param1
2863- a.mov (ptr (esp, 4 ), eax); // mov [esp+4],eax
2864- a.mov (dword_ptr (esp, 0 ), imm (&m_map)); // mov [esp],m_map
2865- a.call (imm (&drc_map_variables::static_get_value)); // call drcmap_get_value
2866- emit_mov_p32_r32 (a, dstp, eax); // mov dstp,eax
2872+ a.mov (eax, MABS (&m_stacksave));
2873+ a.mov (eax, ptr (eax, -4 ));
2874+ a.sub (eax, 1 );
2875+ a.mov (dword_ptr (esp, USE_THISCALL ? 4 : 8 ), inst.param (1 ).mapvar ());
2876+ a.mov (ptr (esp, USE_THISCALL ? 0 : 4 ), eax);
2877+ if (USE_THISCALL)
2878+ a.mov (ecx, imm (m_drcmap_get_value.obj ));
2879+ else
2880+ a.mov (dword_ptr (esp, 0 ), imm (m_drcmap_get_value.obj ));
2881+ a.call (imm (m_drcmap_get_value.func ));
2882+ if (USE_THISCALL)
2883+ a.sub (esp, 8 );
2884+ emit_mov_p32_r32 (a, dstp, eax);
28672885}
28682886
28692887
0 commit comments