samples: update sample_sparc to use new API
This commit is contained in:
parent
0d69d81c2e
commit
fa11e9dddb
@ -15,21 +15,21 @@
|
|||||||
// memory address where emulation starts
|
// memory address where emulation starts
|
||||||
#define ADDRESS 0x10000
|
#define ADDRESS 0x10000
|
||||||
|
|
||||||
static void hook_block(uch handle, uint64_t address, uint32_t size, void *user_data)
|
static void hook_block(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||||
{
|
{
|
||||||
printf(">>> Tracing basic block at 0x%"PRIx64 ", block size = 0x%x\n", address, size);
|
printf(">>> Tracing basic block at 0x%"PRIx64 ", block size = 0x%x\n", address, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hook_code(uch handle, uint64_t address, uint32_t size, void *user_data)
|
static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||||
{
|
{
|
||||||
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_sparc(void)
|
static void test_sparc(void)
|
||||||
{
|
{
|
||||||
uch handle;
|
struct uc_struct *uc;
|
||||||
uc_err err;
|
uc_err err;
|
||||||
uch trace1, trace2;
|
uc_hook_h trace1, trace2;
|
||||||
|
|
||||||
int g1 = 0x1230; // G1 register
|
int g1 = 0x1230; // G1 register
|
||||||
int g2 = 0x6789; // G2 register
|
int g2 = 0x6789; // G2 register
|
||||||
@ -38,7 +38,7 @@ static void test_sparc(void)
|
|||||||
printf("Emulate SPARC code\n");
|
printf("Emulate SPARC code\n");
|
||||||
|
|
||||||
// Initialize emulator in Sparc mode
|
// Initialize emulator in Sparc mode
|
||||||
err = uc_open(UC_ARCH_SPARC, UC_MODE_BIG_ENDIAN, &handle);
|
err = uc_open(UC_ARCH_SPARC, UC_MODE_BIG_ENDIAN, &uc);
|
||||||
if (err) {
|
if (err) {
|
||||||
printf("Failed on uc_open() with error returned: %u (%s)\n",
|
printf("Failed on uc_open() with error returned: %u (%s)\n",
|
||||||
err, uc_strerror(err));
|
err, uc_strerror(err));
|
||||||
@ -46,25 +46,25 @@ static void test_sparc(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// map 2MB memory for this emulation
|
// map 2MB memory for this emulation
|
||||||
uc_mem_map(handle, ADDRESS, 2 * 1024 * 1024);
|
uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024);
|
||||||
|
|
||||||
// write machine code to be emulated to memory
|
// write machine code to be emulated to memory
|
||||||
uc_mem_write(handle, ADDRESS, (uint8_t *)SPARC_CODE, sizeof(SPARC_CODE) - 1);
|
uc_mem_write(uc, ADDRESS, (uint8_t *)SPARC_CODE, sizeof(SPARC_CODE) - 1);
|
||||||
|
|
||||||
// initialize machine registers
|
// initialize machine registers
|
||||||
uc_reg_write(handle, UC_SPARC_REG_G1, &g1);
|
uc_reg_write(uc, UC_SPARC_REG_G1, &g1);
|
||||||
uc_reg_write(handle, UC_SPARC_REG_G2, &g2);
|
uc_reg_write(uc, UC_SPARC_REG_G2, &g2);
|
||||||
uc_reg_write(handle, UC_SPARC_REG_G3, &g3);
|
uc_reg_write(uc, UC_SPARC_REG_G3, &g3);
|
||||||
|
|
||||||
// tracing all basic blocks with customized callback
|
// tracing all basic blocks with customized callback
|
||||||
uc_hook_add(handle, &trace1, UC_HOOK_BLOCK, hook_block, NULL, (uint64_t)1, (uint64_t)0);
|
uc_hook_add(uc, &trace1, UC_HOOK_BLOCK, hook_block, NULL, (uint64_t)1, (uint64_t)0);
|
||||||
|
|
||||||
// tracing one instruction at ADDRESS with customized callback
|
// tracing one instruction at ADDRESS with customized callback
|
||||||
uc_hook_add(handle, &trace2, UC_HOOK_CODE, hook_code, NULL, (uint64_t)ADDRESS, (uint64_t)ADDRESS);
|
uc_hook_add(uc, &trace2, UC_HOOK_CODE, hook_code, NULL, (uint64_t)ADDRESS, (uint64_t)ADDRESS);
|
||||||
|
|
||||||
// emulate machine code in infinite time (last param = 0), or when
|
// emulate machine code in infinite time (last param = 0), or when
|
||||||
// finishing all the code.
|
// finishing all the code.
|
||||||
err = uc_emu_start(handle, ADDRESS, ADDRESS + sizeof(SPARC_CODE) -1, 0, 0);
|
err = uc_emu_start(uc, ADDRESS, ADDRESS + sizeof(SPARC_CODE) -1, 0, 0);
|
||||||
if (err) {
|
if (err) {
|
||||||
printf("Failed on uc_emu_start() with error returned: %u (%s)\n",
|
printf("Failed on uc_emu_start() with error returned: %u (%s)\n",
|
||||||
err, uc_strerror(err));
|
err, uc_strerror(err));
|
||||||
@ -73,10 +73,10 @@ static void test_sparc(void)
|
|||||||
// now print out some registers
|
// now print out some registers
|
||||||
printf(">>> Emulation done. Below is the CPU context\n");
|
printf(">>> Emulation done. Below is the CPU context\n");
|
||||||
|
|
||||||
uc_reg_read(handle, UC_SPARC_REG_G3, &g3);
|
uc_reg_read(uc, UC_SPARC_REG_G3, &g3);
|
||||||
printf(">>> G3 = 0x%x\n", g3);
|
printf(">>> G3 = 0x%x\n", g3);
|
||||||
|
|
||||||
uc_close(&handle);
|
uc_close(uc);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv, char **envp)
|
int main(int argc, char **argv, char **envp)
|
||||||
|
Loading…
Reference in New Issue
Block a user