Skip to content

Commit 88a26bb

Browse files
committed
cpu: Got rid of the rest of the static member function trampolines.
cpu/drcbearm64.cpp, cpu/drcbex64.cpp: Removed static trampoline fallbacks for get map variable value and debugger instrcution hook functions. cpu/drcbex86.cpp: Removed static trampolines for get map variable value and debugger instrcution hook functions. cpu/drcbex64.cpp: Corrected stack diagram in comment.
1 parent c6b97a6 commit 88a26bb

File tree

6 files changed

+84
-67
lines changed

6 files changed

+84
-67
lines changed

src/devices/cpu/drcbearm64.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -973,10 +973,7 @@ drcbe_arm64::drcbe_arm64(drcuml_state &drcuml, device_t &device, drc_cache &cach
973973
// resolve the actual addresses of member functions we need to call
974974
m_drcmap_get_value.set(m_map, &drc_map_variables::get_value);
975975
if (!m_drcmap_get_value)
976-
{
977-
m_drcmap_get_value.obj = uintptr_t(&m_map);
978-
m_drcmap_get_value.func = reinterpret_cast<uint8_t *>(uintptr_t(&drc_map_variables::static_get_value));
979-
}
976+
throw emu_fatalerror("Error resolving map variable get value function!\n");
980977
m_resolved_accessors.resize(m_space.size());
981978
for (int space = 0; m_space.size() > space; ++space)
982979
{
@@ -1096,12 +1093,7 @@ void drcbe_arm64::generate(drcuml_block &block, const instruction *instlist, uin
10961093
{
10971094
m_debug_cpu_instruction_hook.set(*m_device.debug(), &device_debug::instruction_hook);
10981095
if (!m_debug_cpu_instruction_hook)
1099-
{
1100-
m_debug_cpu_instruction_hook.obj = uintptr_t(m_device.debug());
1101-
using debugger_hook_func = void (*)(device_debug *, offs_t);
1102-
static const auto debugger_inst_hook = [] (device_debug *dbg, offs_t pc) { dbg->instruction_hook(pc); };
1103-
m_debug_cpu_instruction_hook.func = reinterpret_cast<uint8_t *>(uintptr_t(debugger_hook_func(debugger_inst_hook)));
1104-
}
1096+
throw emu_fatalerror("Error resolving debugger instruction hook member function!\n");
11051097
}
11061098

11071099
// tell all of our utility objects that a block is beginning
@@ -1200,7 +1192,7 @@ void drcbe_arm64::op_handle(a64::Assembler &a, const uml::instruction &inst)
12001192
// register the current pointer for the handle
12011193
inst.param(0).handle().set_codeptr(drccodeptr(a.code()->baseAddress() + a.offset()));
12021194

1203-
// the handle points to prolog code that creates a minimal non-leaf frame
1195+
// the handle points to prologue code that creates a minimal non-leaf frame
12041196
a.stp(a64::x29, a64::x30, arm::Mem(a64::sp, -16).pre());
12051197
a.bind(skip);
12061198
}

src/devices/cpu/drcbeut.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,6 @@ uint32_t drc_map_variables::get_value(drccodeptr codebase, uint32_t mapvar) cons
407407
return result;
408408
}
409409

410-
uint32_t drc_map_variables::static_get_value(drc_map_variables &map, drccodeptr codebase, uint32_t mapvar)
411-
{
412-
return map.get_value(codebase, mapvar);
413-
}
414-
415410

416411

417412
//-------------------------------------------------

src/devices/cpu/drcbeut.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ class drc_map_variables
9898
uint32_t get_value(drccodeptr codebase, uint32_t mapvar) const;
9999
uint32_t get_last_value(uint32_t mapvar);
100100

101-
// static accessors to be called directly by generated code
102-
static uint32_t static_get_value(drc_map_variables &map, drccodeptr codebase, uint32_t mapvar);
103-
104101
private:
105102
// internal state
106103
drc_cache & m_cache; // pointer to the cache

src/devices/cpu/drcbex64.cpp

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,44 @@
146146
Exit point:
147147
Assumes exit value is in RAX.
148148
149-
Entry stack:
150-
[rsp] - return
151-
152-
Runtime stack:
153-
[rsp] - r9 home
154-
[rsp+8] - r8 home
155-
[rsp+16] - rdx home
156-
[rsp+24] - rcx home
157-
[rsp+40] - saved r15
158-
[rsp+48] - saved r14
159-
[rsp+56] - saved r13
160-
[rsp+64] - saved r12
161-
[rsp+72] - saved rbp
162-
[rsp+80] - saved rdi
163-
[rsp+88] - saved rsi
164-
[rsp+96] - saved rbx
165-
[rsp+104] - ret
149+
Top-level generated code frame:
150+
[rsp+0x00] - rcx home/scratch
151+
[rsp+0x08] - rdx home/scratch
152+
[rsp+0x10] - r8 home/scratch
153+
[rsp+0x18] - r9 home/scratch
154+
[rsp+0x20] - scratch
155+
[rsp+0x28] - saved r15
156+
[rsp+0x30] - saved r14
157+
[rsp+0x38] - saved r13
158+
[rsp+0x40] - saved r12
159+
[rsp+0x48] - saved rbp
160+
[rsp+0x50] - saved rdi
161+
[rsp+0x58] - saved rsi
162+
[rsp+0x60] - saved rbx
163+
[rsp+0x68] - ret
164+
165+
Generated code subroutine call frame:
166+
[rsp+0x00] - rcx home/scratch
167+
[rsp+0x08] - rdx home/scratch
168+
[rsp+0x10] - r8 home/scratch
169+
[rsp+0x18] - r9 home/scratch
170+
[rsp+0x20] - scratch
171+
[rsp+0x28] - ret
172+
...
173+
- rcx home/scratch
174+
- rdx home/scratch
175+
- r8 home/scratch
176+
- r9 home/scratch
177+
- scratch
178+
- saved r15
179+
- saved r14
180+
- saved r13
181+
- saved r12
182+
- saved rdi
183+
- saved rsi
184+
- saved rbp
185+
- saved rbx
186+
- ret
166187
167188
***************************************************************************/
168189

@@ -689,10 +710,7 @@ drcbe_x64::drcbe_x64(drcuml_state &drcuml, device_t &device, drc_cache &cache, u
689710
// resolve the actual addresses of member functions we need to call
690711
m_drcmap_get_value.set(m_map, &drc_map_variables::get_value);
691712
if (!m_drcmap_get_value)
692-
{
693-
m_drcmap_get_value.obj = uintptr_t(&m_map);
694-
m_drcmap_get_value.func = reinterpret_cast<uint8_t *>(uintptr_t(&drc_map_variables::static_get_value));
695-
}
713+
throw emu_fatalerror("Error resolving map variable get value function!\n");
696714
m_resolved_accessors.resize(m_space.size());
697715
for (int space = 0; m_space.size() > space; ++space)
698716
{
@@ -872,12 +890,7 @@ void drcbe_x64::generate(drcuml_block &block, const instruction *instlist, uint3
872890
{
873891
m_debug_cpu_instruction_hook.set(*m_device.debug(), &device_debug::instruction_hook);
874892
if (!m_debug_cpu_instruction_hook)
875-
{
876-
m_debug_cpu_instruction_hook.obj = uintptr_t(m_device.debug());
877-
using debugger_hook_func = void (*)(device_debug *, offs_t);
878-
static const auto debugger_inst_hook = [] (device_debug *dbg, offs_t pc) { dbg->instruction_hook(pc); };
879-
m_debug_cpu_instruction_hook.func = reinterpret_cast<uint8_t *>(uintptr_t(debugger_hook_func(debugger_inst_hook)));
880-
}
893+
throw emu_fatalerror("Error resolving debugger instruction hook member function!\n");
881894
}
882895

883896
// tell all of our utility objects that a block is beginning
@@ -1420,14 +1433,14 @@ void drcbe_x64::op_handle(Assembler &a, const instruction &inst)
14201433

14211434
// emit a jump around the stack adjust in case code falls through here
14221435
Label skip = a.newLabel();
1423-
a.short_().jmp(skip); // jmp skip
1436+
a.short_().jmp(skip);
14241437

14251438
// register the current pointer for the handle
14261439
inst.param(0).handle().set_codeptr(drccodeptr(a.code()->baseAddress() + a.offset()));
14271440

1428-
// by default, the handle points to prolog code that moves the stack pointer
1429-
a.lea(rsp, ptr(rsp, -40)); // lea rsp,[rsp-40]
1430-
a.bind(skip); // skip:
1441+
// by default, the handle points to prologue code that moves the stack pointer
1442+
a.lea(rsp, ptr(rsp, -40));
1443+
a.bind(skip);
14311444
}
14321445

14331446

src/devices/cpu/drcbex86.cpp

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

857860
void 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

src/devices/cpu/drcbex86.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ class drcbe_x86 : public drcbe_interface
292292
uint64_t m_reshi; // extended high result
293293

294294
// resolved memory handler functions
295+
resolved_member_function m_debug_cpu_instruction_hook;
296+
resolved_member_function m_drcmap_get_value;
295297
resolved_memory_accessors_vector m_memory_accessors;
296298

297299
// globals

0 commit comments

Comments
 (0)