unicorn/qemu/target-sparc/unicorn64.c

170 lines
4.9 KiB
C
Raw Normal View History

2015-08-21 10:04:50 +03:00
/* Unicorn Emulator Engine */
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2015 */
2020-06-06 22:53:10 +03:00
/* Modified for Unicorn Engine by Chen Huitao<chenhuitao@hfmrit.com>, 2020 */
2015-08-21 10:04:50 +03:00
2020-06-06 22:53:10 +03:00
#if 0
2015-08-21 10:04:50 +03:00
#include "hw/boards.h"
#include "hw/sparc/sparc.h"
2020-06-06 22:53:10 +03:00
#endif
2015-08-21 10:04:50 +03:00
#include "sysemu/cpus.h"
#include "unicorn.h"
#include "cpu.h"
#include "unicorn_common.h"
#include "uc_priv.h"
2015-08-21 10:04:50 +03:00
const int SPARC64_REGS_STORAGE_SIZE = offsetof(CPUSPARCState, tlb_table);
static bool sparc_stop_interrupt(int intno)
{
switch(intno) {
default:
return false;
case TT_ILL_INSN:
return true;
}
}
static void sparc_set_pc(struct uc_struct *uc, uint64_t address)
{
((CPUSPARCState *)uc->current_cpu->env_ptr)->pc = address;
((CPUSPARCState *)uc->current_cpu->env_ptr)->npc = address + 4;
}
2020-06-06 22:53:10 +03:00
static void sparc_release(void *ctx)
{
int i;
TCGContext *tcg_ctx = (TCGContext *) ctx;
SPARCCPU *cpu = SPARC_CPU(tcg_ctx->uc, tcg_ctx->uc->cpu);
CPUSPARCState *env = &cpu->env;
release_common(ctx);
g_free(tcg_ctx->cpu_wim);
g_free(tcg_ctx->cpu_cond);
g_free(tcg_ctx->cpu_cc_src);
g_free(tcg_ctx->cpu_cc_src2);
g_free(tcg_ctx->cpu_cc_dst);
g_free(tcg_ctx->cpu_fsr);
g_free(tcg_ctx->sparc_cpu_pc);
g_free(tcg_ctx->cpu_npc);
g_free(tcg_ctx->cpu_y);
g_free(tcg_ctx->cpu_tbr);
for (i = 0; i < 8; i++) {
g_free(tcg_ctx->cpu_gregs[i]);
}
for (i = 0; i < 32; i++) {
g_free(tcg_ctx->cpu_gpr[i]);
}
g_free(tcg_ctx->cpu_PC);
g_free(tcg_ctx->btarget);
g_free(tcg_ctx->bcond);
g_free(tcg_ctx->cpu_dspctrl);
g_free(tcg_ctx->tb_ctx.tbs);
g_free(env->def);
}
2015-08-26 13:59:01 +03:00
void sparc_reg_reset(struct uc_struct *uc)
2015-08-21 10:04:50 +03:00
{
2016-09-23 17:38:21 +03:00
CPUArchState *env = uc->cpu->env_ptr;
2015-08-21 10:04:50 +03:00
memset(env->gregs, 0, sizeof(env->gregs));
memset(env->fpr, 0, sizeof(env->fpr));
memset(env->regbase, 0, sizeof(env->regbase));
env->pc = 0;
env->npc = 0;
2015-09-14 04:10:28 +03:00
env->regwptr = env->regbase;
2015-08-21 10:04:50 +03:00
}
2016-04-04 18:25:30 +03:00
int sparc_reg_read(struct uc_struct *uc, unsigned int *regs, void **vals, int count)
2015-08-21 10:04:50 +03:00
{
2016-09-23 17:38:21 +03:00
CPUState *mycpu = uc->cpu;
2016-04-04 18:25:30 +03:00
int i;
2015-08-21 10:04:50 +03:00
2016-04-04 18:25:30 +03:00
for (i = 0; i < count; i++) {
unsigned int regid = regs[i];
void *value = vals[i];
if (regid >= UC_SPARC_REG_G0 && regid <= UC_SPARC_REG_G7)
*(int64_t *)value = SPARC_CPU(uc, mycpu)->env.gregs[regid - UC_SPARC_REG_G0];
else if (regid >= UC_SPARC_REG_O0 && regid <= UC_SPARC_REG_O7)
*(int64_t *)value = SPARC_CPU(uc, mycpu)->env.regwptr[regid - UC_SPARC_REG_O0];
else if (regid >= UC_SPARC_REG_L0 && regid <= UC_SPARC_REG_L7)
*(int64_t *)value = SPARC_CPU(uc, mycpu)->env.regwptr[8 + regid - UC_SPARC_REG_L0];
else if (regid >= UC_SPARC_REG_I0 && regid <= UC_SPARC_REG_I7)
*(int64_t *)value = SPARC_CPU(uc, mycpu)->env.regwptr[16 + regid - UC_SPARC_REG_I0];
else {
switch(regid) {
default: break;
case UC_SPARC_REG_PC:
*(int64_t *)value = SPARC_CPU(uc, mycpu)->env.pc;
break;
}
2015-08-21 10:04:50 +03:00
}
}
return 0;
}
2016-04-04 18:25:30 +03:00
int sparc_reg_write(struct uc_struct *uc, unsigned int *regs, void* const* vals, int count)
2015-08-21 10:04:50 +03:00
{
2016-09-23 17:38:21 +03:00
CPUState *mycpu = uc->cpu;
2016-04-04 18:25:30 +03:00
int i;
2015-08-21 10:04:50 +03:00
2016-04-04 18:25:30 +03:00
for (i = 0; i < count; i++) {
unsigned int regid = regs[i];
const void *value = vals[i];
if (regid >= UC_SPARC_REG_G0 && regid <= UC_SPARC_REG_G7)
SPARC_CPU(uc, mycpu)->env.gregs[regid - UC_SPARC_REG_G0] = *(uint64_t *)value;
else if (regid >= UC_SPARC_REG_O0 && regid <= UC_SPARC_REG_O7)
SPARC_CPU(uc, mycpu)->env.regwptr[regid - UC_SPARC_REG_O0] = *(uint64_t *)value;
else if (regid >= UC_SPARC_REG_L0 && regid <= UC_SPARC_REG_L7)
SPARC_CPU(uc, mycpu)->env.regwptr[8 + regid - UC_SPARC_REG_L0] = *(uint64_t *)value;
else if (regid >= UC_SPARC_REG_I0 && regid <= UC_SPARC_REG_I7)
SPARC_CPU(uc, mycpu)->env.regwptr[16 + regid - UC_SPARC_REG_I0] = *(uint64_t *)value;
else {
switch(regid) {
default: break;
case UC_SPARC_REG_PC:
SPARC_CPU(uc, mycpu)->env.pc = *(uint64_t *)value;
SPARC_CPU(uc, mycpu)->env.npc = *(uint64_t *)value + 4;
break;
}
2015-08-21 10:04:50 +03:00
}
}
return 0;
}
2020-06-06 22:53:10 +03:00
static int sparc_cpus_init(struct uc_struct *uc, const char *cpu_model)
{
SPARCCPU *cpu;
cpu = cpu_sparc_init(uc, cpu_model);
if (cpu == NULL) {
return -1;
}
return 0;
}
DEFAULT_VISIBILITY
2015-08-21 10:04:50 +03:00
void sparc64_uc_init(struct uc_struct* uc)
{
2020-06-06 22:53:10 +03:00
#if 0
2015-08-21 10:04:50 +03:00
register_accel_types(uc);
sparc_cpu_register_types(uc);
sun4u_machine_init(uc);
2020-06-06 22:53:10 +03:00
#endif
uc->release = sparc_release;
2015-08-21 10:04:50 +03:00
uc->reg_read = sparc_reg_read;
uc->reg_write = sparc_reg_write;
uc->reg_reset = sparc_reg_reset;
uc->set_pc = sparc_set_pc;
uc->stop_interrupt = sparc_stop_interrupt;
2020-06-06 22:53:10 +03:00
uc->cpus_init = sparc_cpus_init;
uc_common_init(uc);
2015-08-21 10:04:50 +03:00
}