mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-02-25 11:46:58 +00:00
indentation
This commit is contained in:
parent
60f6fc425a
commit
5e8af30110
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Test for MIPS branch likely instructions only executing their delay slot instruction when the branch is taken.
|
Test for MIPS branch likely instructions only executing their delay slot instruction when the branch is taken.
|
||||||
Currently it seems to always execute the delay slot instruction like a normal non-"likely" style branch.
|
Currently it seems to always execute the delay slot instruction like a normal non-"likely" style branch.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// windows specific
|
// windows specific
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
@ -35,17 +35,17 @@ Currently it seems to always execute the delay slot instruction like a normal no
|
||||||
const uint64_t addr = 0x100000;
|
const uint64_t addr = 0x100000;
|
||||||
// This code SHOULD execute the instruction at 0x10000C.
|
// This code SHOULD execute the instruction at 0x10000C.
|
||||||
const unsigned char test_code_1[] = {
|
const unsigned char test_code_1[] = {
|
||||||
0x01,0x00,0x02,0x24, // 100000: li $v0, 1
|
0x01,0x00,0x02,0x24, // 100000: li $v0, 1
|
||||||
0x02,0x00,0x03,0x24, // 100004: li $v1, 2
|
0x02,0x00,0x03,0x24, // 100004: li $v1, 2
|
||||||
0x01,0x00,0x62,0x54, // 100008: bnel $v1, $v0, 0x100010
|
0x01,0x00,0x62,0x54, // 100008: bnel $v1, $v0, 0x100010
|
||||||
0x00,0x00,0x00,0x00, // 10000C: nop
|
0x00,0x00,0x00,0x00, // 10000C: nop
|
||||||
};
|
};
|
||||||
// This code SHOULD NOT execute the instruction at 0x10000C.
|
// This code SHOULD NOT execute the instruction at 0x10000C.
|
||||||
const unsigned char test_code_2[] = {
|
const unsigned char test_code_2[] = {
|
||||||
0x01,0x00,0x02,0x24, // 100000: li $v0, 1
|
0x01,0x00,0x02,0x24, // 100000: li $v0, 1
|
||||||
0x01,0x00,0x03,0x24, // 100004: li $v1, 1
|
0x01,0x00,0x03,0x24, // 100004: li $v1, 1
|
||||||
0x01,0x00,0x62,0x54, // 100008: bnel $v1, $v0, 0x100010
|
0x01,0x00,0x62,0x54, // 100008: bnel $v1, $v0, 0x100010
|
||||||
0x00,0x00,0x00,0x00, // 10000C: nop
|
0x00,0x00,0x00,0x00, // 10000C: nop
|
||||||
};
|
};
|
||||||
int test_num = 0;
|
int test_num = 0;
|
||||||
bool test1_delayslot_executed = false;
|
bool test1_delayslot_executed = false;
|
||||||
|
@ -55,17 +55,17 @@ bool test2_delayslot_executed = false;
|
||||||
// This hook is used to show that code is executing in the emulator.
|
// This hook is used to show that code is executing in the emulator.
|
||||||
static void mips_codehook(uc_engine *uc, uint64_t address, uint32_t size, void *user_data)
|
static void mips_codehook(uc_engine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||||
{
|
{
|
||||||
printf("Test %d Executing: %llX\n", test_num, address);
|
printf("Test %d Executing: %llX\n", test_num, address);
|
||||||
if( test_num == 1 && address == 0x10000C )
|
if( test_num == 1 && address == 0x10000C )
|
||||||
{
|
{
|
||||||
printf("Delay slot executed!\n");
|
printf("Delay slot executed!\n");
|
||||||
test1_delayslot_executed = true;
|
test1_delayslot_executed = true;
|
||||||
}
|
}
|
||||||
if( test_num == 2 && address == 0x10000C )
|
if( test_num == 2 && address == 0x10000C )
|
||||||
{
|
{
|
||||||
printf("Delay slot executed!\n");
|
printf("Delay slot executed!\n");
|
||||||
test2_delayslot_executed = true;
|
test2_delayslot_executed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,92 +73,92 @@ int main(int argc, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
uc_engine *uc;
|
uc_engine *uc;
|
||||||
uc_err err;
|
uc_err err;
|
||||||
uc_hook hhc;
|
uc_hook hhc;
|
||||||
|
|
||||||
// dynamically load shared library
|
// dynamically load shared library
|
||||||
#ifdef DYNLOAD
|
#ifdef DYNLOAD
|
||||||
uc_dyn_load(NULL, 0);
|
uc_dyn_load(NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize emulator in MIPS 32bit little endian mode
|
// Initialize emulator in MIPS 32bit little endian mode
|
||||||
printf("uc_open()\n");
|
printf("uc_open()\n");
|
||||||
err = uc_open(UC_ARCH_MIPS, UC_MODE_MIPS32, &uc);
|
err = uc_open(UC_ARCH_MIPS, UC_MODE_MIPS32, &uc);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
printf("Failed on uc_open() with error returned: %u\n", err);
|
printf("Failed on uc_open() with error returned: %u\n", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// map in a page of mem
|
// map in a page of mem
|
||||||
printf("uc_mem_map()\n");
|
printf("uc_mem_map()\n");
|
||||||
err = uc_mem_map(uc, addr, 0x1000, UC_PROT_ALL);
|
err = uc_mem_map(uc, addr, 0x1000, UC_PROT_ALL);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
printf("Failed on uc_mem_map() with error returned: %u\n", err);
|
printf("Failed on uc_mem_map() with error returned: %u\n", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// hook all instructions by having @begin > @end
|
// hook all instructions by having @begin > @end
|
||||||
printf("uc_hook_add()\n");
|
printf("uc_hook_add()\n");
|
||||||
uc_hook_add(uc, &hhc, UC_HOOK_CODE, mips_codehook, NULL, (uint64_t)1, (uint64_t)0);
|
uc_hook_add(uc, &hhc, UC_HOOK_CODE, mips_codehook, NULL, (uint64_t)1, (uint64_t)0);
|
||||||
if( err )
|
if( err )
|
||||||
{
|
{
|
||||||
printf("Failed on uc_hook_add(code) with error returned: %u\n", err);
|
printf("Failed on uc_hook_add(code) with error returned: %u\n", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// write test1 code to be emulated to memory
|
// write test1 code to be emulated to memory
|
||||||
test_num = 1;
|
test_num = 1;
|
||||||
printf("\nuc_mem_write(1)\n");
|
printf("\nuc_mem_write(1)\n");
|
||||||
err = uc_mem_write(uc, addr, test_code_1, sizeof(test_code_1));
|
err = uc_mem_write(uc, addr, test_code_1, sizeof(test_code_1));
|
||||||
if( err )
|
if( err )
|
||||||
{
|
{
|
||||||
printf("Failed on uc_mem_write() with error returned: %u\n", err);
|
printf("Failed on uc_mem_write() with error returned: %u\n", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
// start executing test code 1
|
// start executing test code 1
|
||||||
printf("uc_emu_start(1)\n");
|
printf("uc_emu_start(1)\n");
|
||||||
uc_emu_start(uc, addr, addr+sizeof(test_code_1), 0, 0);
|
uc_emu_start(uc, addr, addr+sizeof(test_code_1), 0, 0);
|
||||||
|
|
||||||
|
|
||||||
// write test2 code to be emulated to memory
|
// write test2 code to be emulated to memory
|
||||||
test_num = 2;
|
test_num = 2;
|
||||||
printf("\nuc_mem_write(2)\n");
|
printf("\nuc_mem_write(2)\n");
|
||||||
err = uc_mem_write(uc, addr, test_code_2, sizeof(test_code_2));
|
err = uc_mem_write(uc, addr, test_code_2, sizeof(test_code_2));
|
||||||
if( err )
|
if( err )
|
||||||
{
|
{
|
||||||
printf("Failed on uc_mem_write() with error returned: %u\n", err);
|
printf("Failed on uc_mem_write() with error returned: %u\n", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
// start executing test code 2
|
// start executing test code 2
|
||||||
printf("uc_emu_start(2)\n");
|
printf("uc_emu_start(2)\n");
|
||||||
uc_emu_start(uc, addr, addr+sizeof(test_code_2), 0, 0);
|
uc_emu_start(uc, addr, addr+sizeof(test_code_2), 0, 0);
|
||||||
|
|
||||||
|
|
||||||
// free resources
|
// free resources
|
||||||
printf("\nuc_close()\n");
|
printf("\nuc_close()\n");
|
||||||
uc_close(uc);
|
uc_close(uc);
|
||||||
|
|
||||||
// print test results
|
|
||||||
|
|
||||||
// test 1 SHOULD execute the instruction at 0x10000C.
|
|
||||||
if( test1_delayslot_executed == true )
|
|
||||||
printf("\n\nTEST 1 PASSED!\n");
|
|
||||||
else
|
|
||||||
printf("\n\nTEST 1 FAILED!\n");
|
|
||||||
|
|
||||||
// test 2 SHOULD NOT execute the instruction at 0x10000C.
|
|
||||||
if( test2_delayslot_executed == false )
|
|
||||||
printf("TEST 2 PASSED!\n\n");
|
|
||||||
else
|
|
||||||
printf("TEST 2 FAILED!\n\n");
|
|
||||||
|
|
||||||
// dynamically free shared library
|
// print test results
|
||||||
|
|
||||||
|
// test 1 SHOULD execute the instruction at 0x10000C.
|
||||||
|
if( test1_delayslot_executed == true )
|
||||||
|
printf("\n\nTEST 1 PASSED!\n");
|
||||||
|
else
|
||||||
|
printf("\n\nTEST 1 FAILED!\n");
|
||||||
|
|
||||||
|
// test 2 SHOULD NOT execute the instruction at 0x10000C.
|
||||||
|
if( test2_delayslot_executed == false )
|
||||||
|
printf("TEST 2 PASSED!\n\n");
|
||||||
|
else
|
||||||
|
printf("TEST 2 FAILED!\n\n");
|
||||||
|
|
||||||
|
// dynamically free shared library
|
||||||
#ifdef DYNLOAD
|
#ifdef DYNLOAD
|
||||||
uc_dyn_free();
|
uc_dyn_free();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue