target: e2k: Reorg wd.

This commit is contained in:
Denis Drakhnia 2020-11-26 20:35:07 +02:00
parent f727916e60
commit 7febde65c7
6 changed files with 49 additions and 41 deletions

View File

@ -38,7 +38,7 @@ void cpu_loop(CPUE2KState *env)
switch (trapnr) {
case E2K_EXCP_SYSCALL: {
int offset = env->wd_base + env->syscall_wbs * 2;
int offset = env->wd.base + env->syscall_wbs * 2;
uint64_t *regs = env->wregs;
abi_ulong ret = do_syscall(env,
regs[(0 + offset) % WREGS_SIZE],

View File

@ -48,9 +48,9 @@ static void e2k_cpu_reset(DeviceState *dev)
env->cr1_lo = 0x4dUL << 56; // FIXME: some flags for testing
env->cr1_lo = SET_FIELD(env->cr1_lo, 4, CR1_LO_WPSZ_OFF, CR1_LO_WPSZ_LEN);
env->cr1_lo = SET_FIELD(env->cr1_lo, 4, CR1_LO_WBS_OFF, CR1_LO_WBS_LEN);
env->wd_base = 0;
env->wd_size = 8;
env->wd_psize = 8;
env->wd.base = 0;
env->wd.size = 8;
env->wd.psize = 8;
env->bn.base = 8;
env->bn.size = 8;
env->bn.cur = 0;

View File

@ -269,6 +269,13 @@ typedef struct {
bool fx;
} E2KPshtpState;
typedef struct {
uint32_t base;
uint32_t size;
uint32_t psize;
bool fx;
} E2KWdState;
typedef struct {
/* register file */
uint64_t gregs[GREGS_SIZE]; /* global registers */
@ -283,15 +290,12 @@ typedef struct {
E2KPsState psp;
E2KPshtpState pshtp;
E2KWdState wd;
E2KBnState bn;
E2KBpState bp;
uint64_t lsr; /* loop status register */
uint32_t wd_base;
uint32_t wd_size;
uint32_t wd_psize;
uint64_t usd_lo;
uint64_t usd_hi;
@ -406,6 +410,19 @@ static inline uint64_t e2k_state_pshtp(CPUE2KState *env)
return ret;
}
static inline uint64_t e2k_state_wd(CPUE2KState *env)
{
E2KWdState *wd = &env->wd;
uint64_t ret = 0;
ret = deposit64(ret, WD_BASE_OFF, WD_BASE_LEN, wd->base * 8);
ret = deposit64(ret, WD_SIZE_OFF, WD_SIZE_LEN, wd->size * 8);
ret = deposit64(ret, WD_PSIZE_OFF, WD_PSIZE_LEN, wd->psize * 8);
ret = deposit64(ret, WD_FX_OFF, 1, wd->fx);
return ret;
}
static inline uint32_t e2k_state_br(CPUE2KState *env)
{
E2KBnState *bn = &env->bn;

View File

@ -156,16 +156,7 @@ int e2k_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
case 331: return gdb_get_reg64(mem_buf, 0); // dtcr
case 332: return gdb_get_reg64(mem_buf, 0); // dtarf
case 333: return gdb_get_reg64(mem_buf, 0); // dtart
case 334: {
uint64_t wd = 0;
wd = SET_FIELD(wd, env->wd_base * 8, WD_BASE_OFF, WD_BASE_LEN);
wd = SET_FIELD(wd, env->wd_size * 8, WD_SIZE_OFF, WD_SIZE_LEN);
wd = SET_FIELD(wd, env->wd_psize * 8, WD_PSIZE_OFF, WD_PSIZE_LEN);
wd &= ~WD_FX_BIT; // TODO: wd.fx
return gdb_get_reg64(mem_buf, wd); // wd
}
case 334: return gdb_get_reg64(mem_buf, e2k_state_wd(env)); // wd
case 335: return gdb_get_reg64(mem_buf, 0); // unk
case 336: return gdb_get_reg64(mem_buf, 0); // bgr
case 337: return gdb_get_reg64(mem_buf, 0); // unk

View File

@ -26,7 +26,7 @@ static void pcs_push(CPUE2KState *env, int wbs)
}
e2k_state_cr1_br_set(env, e2k_state_br(env));
e2k_state_cr1_wpsz_set(env, env->wd_psize / 2);
e2k_state_cr1_wpsz_set(env, env->wd.psize / 2);
memcpy(env->pcsp.base + env->pcsp.index, env->proc_chain, size);
e2k_state_cr1_wbs_set(env, wbs);
@ -44,7 +44,7 @@ static void pcs_pop(CPUE2KState *env)
env->pcsp.index -= size;
memcpy(env->proc_chain, env->pcsp.base + env->pcsp.index, size);
env->wd_psize = e2k_state_cr1_wpsz_get(env) * 2;
env->wd.psize = e2k_state_cr1_wpsz_get(env) * 2;
e2k_state_br_set(env, e2k_state_cr1_br_get(env));
}
@ -133,14 +133,14 @@ static void ps_pop_fx(CPUE2KState *env, unsigned int base, size_t len)
static inline void do_call(CPUE2KState *env, int call_wbs)
{
int call_wpsz = env->wd_size / 2 - call_wbs;
int call_wpsz = env->wd.size / 2 - call_wbs;
env->ip = env->nip;
pcs_push(env, call_wbs);
ps_push_nfx(env, env->wd_base, call_wbs * 2);
ps_push_nfx(env, env->wd.base, call_wbs * 2);
env->wd_base = (env->wd_base + call_wbs * 2) % WREGS_SIZE;
env->wd_size = env->wd_psize = call_wpsz * 2;
env->wd.base = (env->wd.base + call_wbs * 2) % WREGS_SIZE;
env->wd.size = env->wd.psize = call_wpsz * 2;
reset_ctprs(env);
}
@ -150,18 +150,18 @@ void helper_return(CPUE2KState *env)
uint32_t new_wd_size, new_wd_base, wbs;
wbs = e2k_state_cr1_wbs_get(env);
new_wd_size = env->wd_psize + wbs * 2;
new_wd_base = (env->wd_base - wbs * 2) % WREGS_SIZE;
new_wd_size = env->wd.psize + wbs * 2;
new_wd_base = (env->wd.base - wbs * 2) % WREGS_SIZE;
if (env->wd_base < new_wd_base) {
env->wd_base += WREGS_SIZE;
if (env->wd.base < new_wd_base) {
env->wd.base += WREGS_SIZE;
}
ps_pop_nfx(env, new_wd_base, env->wd_base - new_wd_base);
ps_pop_nfx(env, new_wd_base, env->wd.base - new_wd_base);
pcs_pop(env);
env->wd_base = new_wd_base;
env->wd_size = new_wd_size;
env->wd.base = new_wd_base;
env->wd.size = new_wd_size;
reset_ctprs(env);
}
@ -204,13 +204,13 @@ static void break_save_state(CPUE2KState *env)
{
int wbs;
wbs = env->wd_size / 2;
ps_push_fx(env, env->wd_base, env->wd_size);
wbs = env->wd.size / 2;
ps_push_fx(env, env->wd.base, env->wd.size);
pcs_push(env, wbs);
env->wd_base = (env->wd_base + env->wd_size) % WREGS_SIZE;
env->wd_size = 0;
env->wd_psize = 0;
env->wd.base = (env->wd.base + env->wd.size) % WREGS_SIZE;
env->wd.size = 0;
env->wd.psize = 0;
env->is_bp = true;
}
@ -221,9 +221,9 @@ void helper_break_restore_state(CPUE2KState *env)
wbs = e2k_state_cr1_wbs_get(env);
pcs_pop(env);
env->wd_size = wbs * 2;
env->wd_base = (env->wd_base - env->wd_size) % WREGS_SIZE;
ps_pop_fx(env, env->wd_base, env->wd_size);
env->wd.size = wbs * 2;
env->wd.base = (env->wd.base - env->wd.size) % WREGS_SIZE;
ps_pop_fx(env, env->wd.base, env->wd.size);
env->is_bp = false;
}

View File

@ -535,8 +535,8 @@ void e2k_tcg_initialize(void) {
char buf[16] = { 0 };
static const struct { TCGv_i32 *ptr; int off; const char *name; } r32[] = {
{ &e2k_cs.wd_base, offsetof(CPUE2KState, wd_base), "woff" },
{ &e2k_cs.wd_size, offsetof(CPUE2KState, wd_size), "wsize" },
{ &e2k_cs.wd_base, offsetof(CPUE2KState, wd.base), "woff" },
{ &e2k_cs.wd_size, offsetof(CPUE2KState, wd.size), "wsize" },
{ &e2k_cs.boff, offsetof(CPUE2KState, bn.base), "boff" },
{ &e2k_cs.bsize, offsetof(CPUE2KState, bn.size), "bsize" },
{ &e2k_cs.bcur, offsetof(CPUE2KState, bn.cur), "bcur" },