unicorn/qemu/target/sparc/unicorn.c

132 lines
3.9 KiB
C
Raw Normal View History

2015-08-21 07:04:50 +00:00
/* Unicorn Emulator Engine */
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2015 */
#include "qemu/osdep.h"
#include "cpu.h"
2015-08-21 07:04:50 +00:00
#include "hw/boards.h"
#include "hw/sparc/sparc.h"
#include "sysemu/cpus.h"
#include "unicorn.h"
#include "unicorn_common.h"
#include "uc_priv.h"
2015-08-21 07:04:50 +00:00
const int SPARC_REGS_STORAGE_SIZE = offsetof(CPUSPARCState, tlb_table);
2015-08-21 07:04:50 +00:00
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 *state = uc->cpu->env_ptr;
state->pc = address;
state->npc = address + 4;
2015-08-21 07:04:50 +00:00
}
2016-10-03 19:23:27 +00:00
void sparc_release(void *ctx);
void sparc_release(void *ctx)
{
TCGContext *tcg_ctx = (TCGContext *) ctx;
release_common(ctx);
g_free(tcg_ctx->tb_ctx.tbs);
2016-10-03 19:23:27 +00:00
}
2015-08-26 10:59:01 +00:00
void sparc_reg_reset(struct uc_struct *uc)
2015-08-21 07:04:50 +00:00
{
2016-09-23 14:38:21 +00:00
CPUArchState *env = uc->cpu->env_ptr;
2015-08-21 07:04:50 +00: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 01:10:28 +00:00
env->regwptr = env->regbase;
2015-08-21 07:04:50 +00:00
}
2016-04-04 15:25:30 +00:00
int sparc_reg_read(struct uc_struct *uc, unsigned int *regs, void **vals, int count)
2015-08-21 07:04:50 +00:00
{
2016-09-23 14:38:21 +00:00
CPUState *mycpu = uc->cpu;
CPUSPARCState *state = &SPARC_CPU(uc, mycpu)->env;
2016-04-04 15:25:30 +00:00
int i;
2015-08-21 07:04:50 +00:00
2016-04-04 15:25:30 +00: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) {
*(int32_t *)value = state->gregs[regid - UC_SPARC_REG_G0];
} else if (regid >= UC_SPARC_REG_O0 && regid <= UC_SPARC_REG_O7) {
*(int32_t *)value = state->regwptr[regid - UC_SPARC_REG_O0];
} else if (regid >= UC_SPARC_REG_L0 && regid <= UC_SPARC_REG_L7) {
*(int32_t *)value = state->regwptr[8 + regid - UC_SPARC_REG_L0];
} else if (regid >= UC_SPARC_REG_I0 && regid <= UC_SPARC_REG_I7) {
*(int32_t *)value = state->regwptr[16 + regid - UC_SPARC_REG_I0];
} else {
2016-04-04 15:25:30 +00:00
switch(regid) {
default: break;
case UC_SPARC_REG_PC:
*(int32_t *)value = state->pc;
2016-04-04 15:25:30 +00:00
break;
}
2015-08-21 07:04:50 +00:00
}
}
return 0;
}
2016-04-04 15:25:30 +00:00
int sparc_reg_write(struct uc_struct *uc, unsigned int *regs, void *const *vals, int count)
2015-08-21 07:04:50 +00:00
{
2016-09-23 14:38:21 +00:00
CPUState *mycpu = uc->cpu;
CPUSPARCState *state = &SPARC_CPU(uc, mycpu)->env;
2016-04-04 15:25:30 +00:00
int i;
2015-08-21 07:04:50 +00:00
2016-04-04 15:25:30 +00: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) {
state->gregs[regid - UC_SPARC_REG_G0] = *(uint32_t *)value;
} else if (regid >= UC_SPARC_REG_O0 && regid <= UC_SPARC_REG_O7) {
state->regwptr[regid - UC_SPARC_REG_O0] = *(uint32_t *)value;
} else if (regid >= UC_SPARC_REG_L0 && regid <= UC_SPARC_REG_L7) {
state->regwptr[8 + regid - UC_SPARC_REG_L0] = *(uint32_t *)value;
} else if (regid >= UC_SPARC_REG_I0 && regid <= UC_SPARC_REG_I7) {
state->regwptr[16 + regid - UC_SPARC_REG_I0] = *(uint32_t *)value;
} else {
2016-04-04 15:25:30 +00:00
switch(regid) {
default: break;
case UC_SPARC_REG_PC:
state->pc = *(uint32_t *)value;
state->npc = *(uint32_t *)value + 4;
2016-04-04 15:25:30 +00:00
// force to quit execution and flush TB
uc->quit_request = true;
uc_emu_stop(uc);
break;
}
2015-08-21 07:04:50 +00:00
}
}
return 0;
}
DEFAULT_VISIBILITY
2015-08-21 07:04:50 +00:00
void sparc_uc_init(struct uc_struct* uc)
{
register_accel_types(uc);
sparc_cpu_register_types(uc);
leon3_generic_machine_init_register_types(uc);
2016-10-03 19:23:27 +00:00
uc->release = sparc_release;
2015-08-21 07:04:50 +00: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;
uc_common_init(uc);
}