client/tests/bulk_fill.c (1989B)
1 #include "recomp_types.h" 2 #include <assert.h> 3 4 void sub_250B4C80(void); 5 void sub_460035B5(void); 6 7 recomp_func_t recomp_lookup(uint32_t address) { abort(); } 8 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } 9 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } 10 11 int main(void) 12 { 13 assert(guest_map("fill output", 0x50000000, 0x10000)); 14 assert(guest_map("fill value and stack", 0x51000000, 0x10000)); 15 const unsigned counts[][7] = {{0, 1, 2, 3, 4, 5, 65536}, {2, 0, 1, 3, 4, 5, 32768}}; 16 for (unsigned wide = 0; wide < 2; ++wide) { 17 for (unsigned i = 0; i < 7; ++i) { 18 unsigned count = counts[wide][i], size = count * (wide ? 2 : 1); 19 uint32_t output = 0x50010000 - size; 20 memset((void *)ADDR(0x50000000), 0xa5, 0x10000); 21 MEM16(0x51000000) = 0x9234; 22 g_esp = 0x5100ff00; 23 g_ebp = 123; g_ebx = 234; g_esi = 345; g_edi = 456; 24 MEM32(g_esp + 4) = output; 25 MEM32(g_esp + 8) = count; 26 MEM32(g_esp + 12) = 0x51000000; 27 printf("bulk fill: %s count %u at %08x\n", wide ? "wide" : "byte", count, output); 28 fflush(stdout); 29 30 if (wide) sub_460035B5(); 31 else sub_250B4C80(); 32 33 assert(g_esp == 0x5100ff04 && g_ebp == 123); 34 assert(g_ebx == 234 && g_esi == 345 && g_edi == 456); 35 assert(g_ecx == 0); 36 if (wide) { 37 assert(g_eax == output); 38 assert(recomp_eflags(g_flag_k, g_flag_a, g_flag_b, g_flag_cf, 1) == 39 (count & 1 ? 0x202 : 0x246)); 40 } 41 for (unsigned j = 0; j < size; ++j) 42 assert(MEM8(output + j) == (wide ? (j & 1 ? 0x92 : 0x34) : 0)); 43 if (size < 0x10000) assert(MEM8(output - 1) == 0xa5); 44 assert(MEM16(0x51000000) == 0x9234); 45 } 46 } 47 puts("bulk fill: empty and page-ending byte/wide fills, remainders, canaries and ABI passed"); 48 }