2015-08-21 10:04:50 +03:00
|
|
|
/* Unicorn Emulator Engine */
|
|
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2015 */
|
|
|
|
|
|
|
|
#include "hw/boards.h"
|
|
|
|
#include "hw/mips/mips.h"
|
|
|
|
#include "sysemu/cpus.h"
|
|
|
|
#include "unicorn.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "unicorn_common.h"
|
2016-03-02 06:43:02 +03:00
|
|
|
#include "uc_priv.h"
|
2015-08-21 10:04:50 +03:00
|
|
|
|
|
|
|
|
2015-10-27 09:37:03 +03:00
|
|
|
static uint64_t mips_mem_redirect(uint64_t address)
|
|
|
|
{
|
|
|
|
// kseg0 range masks off high address bit
|
|
|
|
if (address >= 0x80000000 && address <= 0x9fffffff)
|
|
|
|
return address & 0x7fffffff;
|
|
|
|
|
|
|
|
// kseg1 range masks off top 3 address bits
|
|
|
|
if (address >= 0xa0000000 && address <= 0xbfffffff) {
|
|
|
|
return address & 0x1fffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no redirect
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
2015-08-21 10:04:50 +03:00
|
|
|
static void mips_set_pc(struct uc_struct *uc, uint64_t address)
|
|
|
|
{
|
|
|
|
((CPUMIPSState *)uc->current_cpu->env_ptr)->active_tc.PC = address;
|
|
|
|
}
|
|
|
|
|
2015-08-26 13:34:47 +03:00
|
|
|
void mips_reg_reset(struct uc_struct *uc)
|
2015-08-21 10:04:50 +03:00
|
|
|
{
|
2015-08-26 13:34:47 +03:00
|
|
|
(void)uc;
|
|
|
|
CPUArchState *env = first_cpu->env_ptr;
|
2015-08-21 10:04:50 +03:00
|
|
|
memset(env->active_tc.gpr, 0, sizeof(env->active_tc.gpr));
|
|
|
|
|
2015-08-26 13:34:47 +03:00
|
|
|
env->active_tc.PC = 0;
|
|
|
|
}
|
2015-08-21 10:04:50 +03:00
|
|
|
|
2015-08-26 13:34:47 +03:00
|
|
|
int mips_reg_read(struct uc_struct *uc, unsigned int regid, void *value)
|
2015-08-21 10:04:50 +03:00
|
|
|
{
|
|
|
|
CPUState *mycpu = first_cpu;
|
|
|
|
|
2015-08-24 07:36:33 +03:00
|
|
|
if (regid >= UC_MIPS_REG_0 && regid <= UC_MIPS_REG_31)
|
|
|
|
*(int32_t *)value = MIPS_CPU(uc, mycpu)->env.active_tc.gpr[regid - UC_MIPS_REG_0];
|
2015-08-21 10:04:50 +03:00
|
|
|
else {
|
|
|
|
switch(regid) {
|
|
|
|
default: break;
|
2015-08-24 07:36:33 +03:00
|
|
|
case UC_MIPS_REG_PC:
|
2015-08-21 10:04:50 +03:00
|
|
|
*(int32_t *)value = MIPS_CPU(uc, mycpu)->env.active_tc.PC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-26 13:34:47 +03:00
|
|
|
int mips_reg_write(struct uc_struct *uc, unsigned int regid, const void *value)
|
2015-08-21 10:04:50 +03:00
|
|
|
{
|
|
|
|
CPUState *mycpu = first_cpu;
|
|
|
|
|
2015-08-24 07:36:33 +03:00
|
|
|
if (regid >= UC_MIPS_REG_0 && regid <= UC_MIPS_REG_31)
|
2015-09-04 06:17:08 +03:00
|
|
|
MIPS_CPU(uc, mycpu)->env.active_tc.gpr[regid - UC_MIPS_REG_0] = *(uint32_t *)value;
|
2015-08-21 10:04:50 +03:00
|
|
|
else {
|
|
|
|
switch(regid) {
|
|
|
|
default: break;
|
2015-08-24 07:36:33 +03:00
|
|
|
case UC_MIPS_REG_PC:
|
2015-09-04 06:17:08 +03:00
|
|
|
MIPS_CPU(uc, mycpu)->env.active_tc.PC = *(uint32_t *)value;
|
2016-01-28 09:06:17 +03:00
|
|
|
// force to quit execution and flush TB
|
|
|
|
uc->quit_request = true;
|
|
|
|
uc_emu_stop(uc);
|
2015-08-21 10:04:50 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__ ((visibility ("default")))
|
|
|
|
#ifdef TARGET_MIPS64
|
|
|
|
#ifdef TARGET_WORDS_BIGENDIAN
|
|
|
|
void mips64_uc_init(struct uc_struct* uc)
|
|
|
|
#else
|
|
|
|
void mips64el_uc_init(struct uc_struct* uc)
|
|
|
|
#endif
|
|
|
|
#else // if TARGET_MIPS
|
|
|
|
#ifdef TARGET_WORDS_BIGENDIAN
|
|
|
|
void mips_uc_init(struct uc_struct* uc)
|
|
|
|
#else
|
|
|
|
void mipsel_uc_init(struct uc_struct* uc)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
register_accel_types(uc);
|
|
|
|
mips_cpu_register_types(uc);
|
|
|
|
mips_machine_init(uc);
|
|
|
|
uc->reg_read = mips_reg_read;
|
|
|
|
uc->reg_write = mips_reg_write;
|
|
|
|
uc->reg_reset = mips_reg_reset;
|
|
|
|
uc->set_pc = mips_set_pc;
|
2015-10-27 09:37:03 +03:00
|
|
|
uc->mem_redirect = mips_mem_redirect;
|
2015-08-21 10:04:50 +03:00
|
|
|
uc_common_init(uc);
|
|
|
|
}
|