2015-08-21 07:04:50 +00:00
|
|
|
/* Unicorn Emulator Engine */
|
|
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2015 */
|
|
|
|
|
2018-02-24 06:23:15 +00:00
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "cpu.h"
|
2015-08-21 07:04:50 +00:00
|
|
|
#include "hw/boards.h"
|
|
|
|
#include "hw/m68k/m68k.h"
|
|
|
|
#include "sysemu/cpus.h"
|
|
|
|
#include "unicorn.h"
|
|
|
|
#include "unicorn_common.h"
|
2016-03-02 03:43:02 +00:00
|
|
|
#include "uc_priv.h"
|
2015-08-21 07:04:50 +00:00
|
|
|
|
2016-08-20 11:14:07 +00:00
|
|
|
const int M68K_REGS_STORAGE_SIZE = offsetof(CPUM68KState, tlb_table);
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
static void m68k_set_pc(struct uc_struct *uc, uint64_t address)
|
|
|
|
{
|
2018-03-07 15:37:48 +00:00
|
|
|
CPUM68KState *state = uc->cpu->env_ptr;
|
|
|
|
|
|
|
|
state->pc = address;
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 19:47:03 +00:00
|
|
|
void m68k_release(void* ctx);
|
|
|
|
void m68k_release(void* ctx)
|
|
|
|
{
|
2018-02-21 05:17:01 +00:00
|
|
|
TCGContext *tcg_ctx = ctx;;
|
|
|
|
|
2016-10-03 19:47:03 +00:00
|
|
|
release_common(ctx);
|
2016-12-21 14:28:36 +00:00
|
|
|
g_free(tcg_ctx->tb_ctx.tbs);
|
2016-10-03 19:47:03 +00:00
|
|
|
}
|
|
|
|
|
2015-08-26 11:11:49 +00:00
|
|
|
void m68k_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->aregs, 0, sizeof(env->aregs));
|
|
|
|
memset(env->dregs, 0, sizeof(env->dregs));
|
|
|
|
|
|
|
|
env->pc = 0;
|
|
|
|
}
|
|
|
|
|
2016-04-04 15:25:30 +00:00
|
|
|
int m68k_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;
|
2018-03-07 15:37:48 +00:00
|
|
|
CPUM68KState *state = &M68K_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_M68K_REG_A0 && regid <= UC_M68K_REG_A7)
|
2018-03-07 15:37:48 +00:00
|
|
|
*(int32_t *)value = state->aregs[regid - UC_M68K_REG_A0];
|
2016-04-04 15:25:30 +00:00
|
|
|
else if (regid >= UC_M68K_REG_D0 && regid <= UC_M68K_REG_D7)
|
2018-03-07 15:37:48 +00:00
|
|
|
*(int32_t *)value = state->dregs[regid - UC_M68K_REG_D0];
|
2016-04-04 15:25:30 +00:00
|
|
|
else {
|
|
|
|
switch(regid) {
|
|
|
|
default: break;
|
|
|
|
case UC_M68K_REG_PC:
|
2018-03-07 15:37:48 +00:00
|
|
|
*(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 m68k_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;
|
2018-03-07 15:37:48 +00:00
|
|
|
CPUM68KState *state = &M68K_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_M68K_REG_A0 && regid <= UC_M68K_REG_A7)
|
2018-03-07 15:37:48 +00:00
|
|
|
state->aregs[regid - UC_M68K_REG_A0] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
else if (regid >= UC_M68K_REG_D0 && regid <= UC_M68K_REG_D7)
|
2018-03-07 15:37:48 +00:00
|
|
|
state->dregs[regid - UC_M68K_REG_D0] = *(uint32_t *)value;
|
2016-04-04 15:25:30 +00:00
|
|
|
else {
|
|
|
|
switch(regid) {
|
|
|
|
default: break;
|
|
|
|
case UC_M68K_REG_PC:
|
2018-03-07 15:37:48 +00:00
|
|
|
state->pc = *(uint32_t *)value;
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-19 11:50:28 +00:00
|
|
|
DEFAULT_VISIBILITY
|
2015-08-21 07:04:50 +00:00
|
|
|
void m68k_uc_init(struct uc_struct* uc)
|
|
|
|
{
|
|
|
|
register_accel_types(uc);
|
|
|
|
m68k_cpu_register_types(uc);
|
2018-03-11 18:49:09 +00:00
|
|
|
dummy_m68k_machine_init_register_types(uc);
|
2016-10-03 19:47:03 +00:00
|
|
|
uc->release = m68k_release;
|
2015-08-21 07:04:50 +00:00
|
|
|
uc->reg_read = m68k_reg_read;
|
|
|
|
uc->reg_write = m68k_reg_write;
|
|
|
|
uc->reg_reset = m68k_reg_reset;
|
|
|
|
uc->set_pc = m68k_set_pc;
|
|
|
|
uc_common_init(uc);
|
|
|
|
}
|