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/sparc/sparc.h"
|
|
|
|
#include "sysemu/cpus.h"
|
|
|
|
#include "unicorn.h"
|
|
|
|
#include "cpu.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)
|
|
|
|
|
|
|
|
|
2015-08-26 10:59:01 +00:00
|
|
|
void sparc_reg_reset(struct uc_struct *uc)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
2015-08-26 10:59:01 +00:00
|
|
|
CPUArchState *env = first_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
|
|
|
}
|
|
|
|
|
2015-08-26 10:59:01 +00:00
|
|
|
int sparc_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:36:33 +00:00
|
|
|
if (regid >= UC_SPARC_REG_G0 && regid <= UC_SPARC_REG_G7)
|
2015-09-11 06:20:52 +00:00
|
|
|
*(int64_t *)value = SPARC_CPU(uc, mycpu)->env.gregs[regid - UC_SPARC_REG_G0];
|
2015-08-21 07:04:50 +00:00
|
|
|
else {
|
|
|
|
switch(regid) {
|
|
|
|
default: break;
|
2015-08-24 04:36:33 +00:00
|
|
|
case UC_SPARC_REG_PC:
|
2015-09-11 06:20:52 +00:00
|
|
|
*(int64_t *)value = SPARC_CPU(uc, mycpu)->env.pc;
|
|
|
|
break;
|
|
|
|
case UC_SPARC_REG_SP:
|
2015-09-12 17:29:35 +00:00
|
|
|
*(int64_t *)value = SPARC_CPU(uc, mycpu)->env.regwptr[6];
|
2015-09-11 06:20:52 +00:00
|
|
|
break;
|
|
|
|
case UC_SPARC_REG_FP:
|
2015-09-12 17:29:35 +00:00
|
|
|
*(int64_t *)value = SPARC_CPU(uc, mycpu)->env.regwptr[22];
|
2015-09-11 06:20:52 +00:00
|
|
|
break;
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 10:59:01 +00:00
|
|
|
int sparc_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:36:33 +00:00
|
|
|
if (regid >= UC_SPARC_REG_G0 && regid <= UC_SPARC_REG_G7)
|
2015-09-11 06:20:52 +00:00
|
|
|
SPARC_CPU(uc, mycpu)->env.gregs[regid - UC_SPARC_REG_G0] = *(uint64_t *)value;
|
2015-08-21 07:04:50 +00:00
|
|
|
else {
|
|
|
|
switch(regid) {
|
|
|
|
default: break;
|
2015-08-24 04:36:33 +00:00
|
|
|
case UC_SPARC_REG_PC:
|
2015-09-11 06:20:52 +00:00
|
|
|
SPARC_CPU(uc, mycpu)->env.pc = *(uint64_t *)value;
|
|
|
|
SPARC_CPU(uc, mycpu)->env.npc = *(uint64_t *)value + 8;
|
|
|
|
break;
|
|
|
|
case UC_SPARC_REG_SP:
|
2015-09-12 17:29:35 +00:00
|
|
|
SPARC_CPU(uc, mycpu)->env.regwptr[6] = *(uint64_t *)value;
|
2015-09-11 06:20:52 +00:00
|
|
|
break;
|
|
|
|
case UC_SPARC_REG_FP:
|
2015-09-12 17:29:35 +00:00
|
|
|
SPARC_CPU(uc, mycpu)->env.regwptr[22] = *(uint64_t *)value;
|
2015-09-11 06:20:52 +00:00
|
|
|
break;
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__ ((visibility ("default")))
|
|
|
|
void sparc64_uc_init(struct uc_struct* uc)
|
|
|
|
{
|
|
|
|
register_accel_types(uc);
|
|
|
|
sparc_cpu_register_types(uc);
|
|
|
|
sun4u_machine_init(uc);
|
|
|
|
uc->reg_read = sparc_reg_read;
|
|
|
|
uc->reg_write = sparc_reg_write;
|
|
|
|
uc->reg_reset = sparc_reg_reset;
|
|
|
|
}
|