client/tests/dynel_lookup.c (3088B)
1 #include "recomp_types.h" 2 #include <assert.h> 3 4 void sub_38017D70(void); 5 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } 6 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } 7 recomp_func_t recomp_lookup(uint32_t address) { abort(); } 8 9 static uint32_t lookup(uint32_t type, uint32_t instance) 10 { 11 g_esp = 0x5000ff00; 12 MEM32(g_esp + 4) = 0x50000300; 13 MEM32(0x50000300) = type; 14 MEM32(0x50000304) = instance; 15 g_ebx = 123; g_ebp = 234; g_esi = 345; g_edi = 456; 16 sub_38017D70(); 17 assert(g_esp == 0x5000ff04); 18 assert(g_ebx == 123 && g_ebp == 234 && g_esi == 345 && g_edi == 456); 19 assert(g_ecx == 0x50000000); 20 return g_eax; 21 } 22 23 static void exact_identity_uses_signed_type_and_unsigned_instance(void) 24 { 25 const uint32_t nodes[][6] = { 26 {0x50000120, 0, 0x50000180, 50000, 0x80000000, 10}, 27 {0x50000140, 0, 0x50000160, 0xffffffff, 0xffffffff, 20}, 28 {0x50000200, 0, 0x50000200, 0x80000000, 0, 30}, 29 {0x50000200, 0, 0x50000200, 50000, 0, 40}, 30 {0x500001a0, 0, 0x500001c0, 0x7fffffff, 0, 50}, 31 {0x50000200, 0, 0x50000200, 50000, 0xffffffff, 60}, 32 {0x50000200, 0, 0x50000200, 0x7fffffff, 0xffffffff, 70}, 33 }; 34 for (unsigned i = 0; i < 7; ++i) 35 memcpy((void *)ADDR(0x50000100 + i * 32), nodes[i], sizeof(nodes[i])); 36 MEM32(0x50000224) = 0x50000100; 37 38 uint32_t root = lookup(50000, 0x80000000); 39 uint32_t negative = lookup(0xffffffff, 0xffffffff); 40 uint32_t minimum = lookup(0x80000000, 0); 41 uint32_t first_instance = lookup(50000, 0); 42 uint32_t maximum_type = lookup(0x7fffffff, 0); 43 uint32_t last_instance = lookup(50000, 0xffffffff); 44 uint32_t maximum = lookup(0x7fffffff, 0xffffffff); 45 46 assert(root == 10 && negative == 20 && minimum == 30); 47 assert(first_instance == 40 && maximum_type == 50); 48 assert(last_instance == 60 && maximum == 70); 49 assert(lookup(0x80000000, 1) == 0); 50 assert(lookup(0, 0) == 0); 51 assert(lookup(50000, 0x7fffffff) == 0); 52 assert(lookup(50000, 0x80000001) == 0); 53 assert(lookup(0x7fffffff, 1) == 0); 54 } 55 56 static void lookup_observes_directory_clear_and_reuse(void) 57 { 58 MEM32(0x50000224) = 0x50000200; 59 60 uint32_t empty = lookup(50000, 0x80000000); 61 MEM32(0x50000120) = 0x50000200; 62 MEM32(0x50000128) = 0x50000200; 63 MEM32(0x5000012c) = 50000; 64 MEM32(0x50000130) = 0x80000000; 65 MEM32(0x50000134) = 99; 66 MEM32(0x50000224) = 0x50000120; 67 uint32_t replacement = lookup(50000, 0x80000000); 68 69 assert(empty == 0); 70 assert(replacement == 99); 71 assert(lookup(0xffffffff, 0xffffffff) == 0); 72 } 73 74 int main(void) 75 { 76 assert(guest_map("dynel directory", 0x50000000, 0x10000)); 77 assert(guest_map("dynel directory pointer", 0x38060000, 0x10000)); 78 MEM32(0x3806C110) = 0x50000000; 79 MEM32(0x50000004) = 0x50000220; 80 MEM32(0x50000008) = 0x50000200; 81 exact_identity_uses_signed_type_and_unsigned_instance(); 82 lookup_observes_directory_clear_and_reuse(); 83 puts("Dynel lookup: signed types, unsigned instances, misses, clear/reuse and ABI passed"); 84 return 0; 85 }