2015-08-21 07:04:50 +00:00
|
|
|
/* Unicorn Emulator Engine */
|
|
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2015 */
|
|
|
|
|
|
|
|
#include "hw/boards.h"
|
|
|
|
#include "hw/m68k/m68k.h"
|
|
|
|
#include "sysemu/cpus.h"
|
|
|
|
#include "unicorn.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
|
|
|
|
#include "unicorn_common.h"
|
|
|
|
|
|
|
|
#define READ_QWORD(x) ((uint64)x)
|
|
|
|
#define READ_DWORD(x) (x & 0xffffffff)
|
|
|
|
#define READ_WORD(x) (x & 0xffff)
|
|
|
|
#define READ_BYTE_H(x) ((x & 0xffff) >> 8)
|
|
|
|
#define READ_BYTE_L(x) (x & 0xff)
|
|
|
|
|
|
|
|
|
|
|
|
static void m68k_set_pc(struct uc_struct *uc, uint64_t address)
|
|
|
|
{
|
|
|
|
((CPUM68KState *)uc->current_cpu->env_ptr)->pc = address;
|
|
|
|
}
|
|
|
|
|
2015-08-26 11:11:49 +00:00
|
|
|
void m68k_reg_reset(struct uc_struct *uc)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
2015-08-26 11:11:49 +00:00
|
|
|
CPUArchState *env = first_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;
|
|
|
|
}
|
|
|
|
|
2015-08-26 11:11:49 +00:00
|
|
|
int m68k_reg_read(struct uc_struct *uc, unsigned int regid, void *value)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
|
|
|
CPUState *mycpu = first_cpu;
|
|
|
|
|
2015-08-24 04:56:24 +00:00
|
|
|
if (regid >= UC_M68K_REG_A0 && regid <= UC_M68K_REG_A7)
|
|
|
|
*(int32_t *)value = M68K_CPU(uc, mycpu)->env.aregs[regid - UC_M68K_REG_A0];
|
|
|
|
else if (regid >= UC_M68K_REG_D0 && regid <= UC_M68K_REG_D7)
|
|
|
|
*(int32_t *)value = M68K_CPU(uc, mycpu)->env.dregs[regid - UC_M68K_REG_D0];
|
2015-08-21 07:04:50 +00:00
|
|
|
else {
|
|
|
|
switch(regid) {
|
|
|
|
default: break;
|
2015-08-24 04:56:24 +00:00
|
|
|
case UC_M68K_REG_PC:
|
2015-08-21 07:04:50 +00:00
|
|
|
*(int32_t *)value = M68K_CPU(uc, mycpu)->env.pc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define WRITE_DWORD(x, w) (x = (x & ~0xffffffff) | (w & 0xffffffff))
|
|
|
|
#define WRITE_WORD(x, w) (x = (x & ~0xffff) | (w & 0xffff))
|
|
|
|
#define WRITE_BYTE_H(x, b) (x = (x & ~0xff00) | (b & 0xff))
|
|
|
|
#define WRITE_BYTE_L(x, b) (x = (x & ~0xff) | (b & 0xff))
|
|
|
|
|
2015-08-26 11:11:49 +00:00
|
|
|
int m68k_reg_write(struct uc_struct *uc, unsigned int regid, const void *value)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
|
|
|
CPUState *mycpu = first_cpu;
|
|
|
|
|
2015-08-24 04:56:24 +00:00
|
|
|
if (regid >= UC_M68K_REG_A0 && regid <= UC_M68K_REG_A7)
|
2015-09-04 03:17:08 +00:00
|
|
|
M68K_CPU(uc, mycpu)->env.aregs[regid - UC_M68K_REG_A0] = *(uint32_t *)value;
|
2015-08-24 04:56:24 +00:00
|
|
|
else if (regid >= UC_M68K_REG_D0 && regid <= UC_M68K_REG_D7)
|
2015-09-04 03:17:08 +00:00
|
|
|
M68K_CPU(uc, mycpu)->env.dregs[regid - UC_M68K_REG_D0] = *(uint32_t *)value;
|
2015-08-21 07:04:50 +00:00
|
|
|
else {
|
|
|
|
switch(regid) {
|
|
|
|
default: break;
|
2015-08-24 04:56:24 +00:00
|
|
|
case UC_M68K_REG_PC:
|
2015-08-21 07:04:50 +00:00
|
|
|
M68K_CPU(uc, mycpu)->env.pc = *(uint32_t *)value;
|
2016-01-28 06:06:17 +00:00
|
|
|
// force to quit execution and flush TB
|
|
|
|
uc->quit_request = true;
|
|
|
|
uc_emu_stop(uc);
|
2015-08-21 07:04:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__ ((visibility ("default")))
|
|
|
|
void m68k_uc_init(struct uc_struct* uc)
|
|
|
|
{
|
|
|
|
register_accel_types(uc);
|
|
|
|
m68k_cpu_register_types(uc);
|
|
|
|
dummy_m68k_machine_init(uc);
|
|
|
|
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);
|
|
|
|
}
|