client/tests/resolved_calls.c (2171B)
1 #define RECOMP_GENERATED_CODE 2 #include "recomp_types.h" 3 #include "guest_memory.h" 4 #include <assert.h> 5 6 void sub_10002000(void); 7 const recomp_dispatch_entry_t test_dispatch[] = {{0x10002000u, sub_10002000}}; 8 static unsigned lookups; 9 10 #ifdef RECOMP_TRACE 11 void recomp_trace_enter(uint32_t address) { assert(address == 0x10002000); } 12 #endif 13 14 /* The callee observes the same guest boundary as a dispatched function. */ 15 void sub_10002000(void) 16 { 17 uint32_t _flag_k = FK_NONE, _flag_a = 0, _flag_b = 0, _cf = 0; 18 RECOMP_REGS_LOCALS 19 RECOMP_ENTER(0x10002000); 20 assert(MEM32(esp) == RECOMP_RETADDR); 21 assert(_flag_a == 7 && _flag_b == 9 && _cf == 1); 22 assert(eax == 41 && ecx == 17 && g_st[0] == 3.5); 23 eax = 42; 24 ecx = 18; 25 g_st[0] = 4.5; 26 _flag_a = 11; 27 esp += 4; 28 RECOMP_FLAGS_OUT(); 29 RECOMP_REGS_OUT(); 30 } 31 32 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } 33 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } 34 recomp_func_t recomp_lookup(uint32_t address) 35 { 36 assert(address == 0x10002000); 37 lookups++; 38 return sub_10002000; 39 } 40 41 static void check_call(int computed) 42 { 43 uint32_t _flag_k = FK_NONE, _flag_a = 7, _flag_b = 9, _cf = 1; 44 RECOMP_REGS_LOCALS 45 esp = 0x5000ff00; 46 eax = 41; 47 ecx = 17; 48 g_st[0] = 3.5; 49 g_cur_func = 0x10001000; 50 g_icall_count = 0; 51 g_icall_trace_idx = 0; 52 lookups = 0; 53 54 if (computed) { 55 uint32_t target = 0x10002000; 56 RECOMP_ICALL(target); 57 } else { 58 RECOMP_ICALL(0x10002000u); 59 } 60 61 assert(esp == 0x5000ff00 && g_cur_func == 0x10001000); 62 assert(eax == 42 && ecx == 18 && g_st[0] == 4.5); 63 assert(g_flag_a == 11 && g_flag_b == 9 && g_flag_cf == 1); 64 assert(g_icall_count == 1 && lookups == (unsigned)computed); 65 #ifdef RECOMP_TRACE 66 assert(g_icall_trace_idx == 1); 67 assert(g_icall_trace[0] == 0x10002000 && g_icall_from[0] == 0x10001000); 68 #else 69 assert(g_icall_trace_idx == 0); 70 #endif 71 } 72 73 int main(void) 74 { 75 assert(guest_map("resolved call test", 0x50000000, 0x10000)); 76 check_call(0); 77 check_call(1); 78 puts("resolved calls: guest state, diagnostics and computed dispatch passed"); 79 }