Skip to content

Commit

Permalink
Merge remote-tracking branch 'shorne/tags/pull-or-20170504' into staging
Browse files Browse the repository at this point in the history
Openrisc Features and Fixes for qemu 2.10

# gpg: Signature made Thu 04 May 2017 01:41:45 AM BST
# gpg:                using RSA key 0xC3B31C2D5E6627E4
# gpg: Good signature from "Stafford Horne <[email protected]>"
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: D9C4 7354 AEF8 6C10 3A25  EFF1 C3B3 1C2D 5E66 27E4

* shorne/tags/pull-or-20170504:
  target/openrisc: Support non-busy idle state using PMR SPR
  target/openrisc: Remove duplicate features property
  target/openrisc: Implement full vmstate serialization
  migration: Add VMSTATE_STRUCT_2DARRAY()
  target/openrisc: implement shadow registers
  migration: Add VMSTATE_UINTTL_2DARRAY()
  target/openrisc: add numcores and coreid support
  target/openrisc: Fixes for memory debugging
  target/openrisc: Implement EPH bit
  target/openrisc: Implement EVBAR register
  MAINTAINERS: Add myself as openrisc maintainer

Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
stefanhaRH committed May 5, 2017
2 parents 4f3652b + f4d1414 commit 317134b
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 62 deletions.
4 changes: 2 additions & 2 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ F: hw/nios2/
F: disas/nios2.c

OpenRISC
M: Jia Liu <proljc@gmail.com>
S: Maintained
M: Stafford Horne <shorne@gmail.com>
S: Odd Fixes
F: target/openrisc/
F: hw/openrisc/
F: tests/tcg/openrisc/
Expand Down
1 change: 1 addition & 0 deletions hw/openrisc/cputimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void cpu_openrisc_timer_update(OpenRISCCPU *cpu)
}
next = now + (uint64_t)wait * TIMER_PERIOD;
timer_mod(cpu->env.timer, next);
qemu_cpu_kick(CPU(cpu));
}

void cpu_openrisc_count_start(OpenRISCCPU *cpu)
Expand Down
7 changes: 7 additions & 0 deletions include/migration/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
VMSTATE_UINT64_EQUAL_V(_f, _s, _v)
#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v) \
VMSTATE_UINT64_ARRAY_V(_f, _s, _n, _v)
#define VMSTATE_UINTTL_2DARRAY_V(_f, _s, _n1, _n2, _v) \
VMSTATE_UINT64_2DARRAY_V(_f, _s, _n1, _n2, _v)
#define VMSTATE_UINTTL_TEST(_f, _s, _t) \
VMSTATE_UINT64_TEST(_f, _s, _t)
#define vmstate_info_uinttl vmstate_info_uint64
Expand All @@ -37,6 +39,8 @@
VMSTATE_UINT32_EQUAL_V(_f, _s, _v)
#define VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, _v) \
VMSTATE_UINT32_ARRAY_V(_f, _s, _n, _v)
#define VMSTATE_UINTTL_2DARRAY_V(_f, _s, _n1, _n2, _v) \
VMSTATE_UINT32_2DARRAY_V(_f, _s, _n1, _n2, _v)
#define VMSTATE_UINTTL_TEST(_f, _s, _t) \
VMSTATE_UINT32_TEST(_f, _s, _t)
#define vmstate_info_uinttl vmstate_info_uint32
Expand All @@ -48,5 +52,8 @@
VMSTATE_UINTTL_EQUAL_V(_f, _s, 0)
#define VMSTATE_UINTTL_ARRAY(_f, _s, _n) \
VMSTATE_UINTTL_ARRAY_V(_f, _s, _n, 0)
#define VMSTATE_UINTTL_2DARRAY(_f, _s, _n1, _n2) \
VMSTATE_UINTTL_2DARRAY_V(_f, _s, _n1, _n2, 0)


#endif
18 changes: 18 additions & 0 deletions include/migration/vmstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,19 @@ extern const VMStateInfo vmstate_info_qtailq;
.offset = vmstate_offset_array(_state, _field, _type, _num),\
}

#define VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, _test, \
_version, _vmsd, _type) { \
.name = (stringify(_field)), \
.num = (_n1) * (_n2), \
.field_exists = (_test), \
.version_id = (_version), \
.vmsd = &(_vmsd), \
.size = sizeof(_type), \
.flags = VMS_STRUCT | VMS_ARRAY, \
.offset = vmstate_offset_2darray(_state, _field, _type, \
_n1, _n2), \
}

#define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
.name = (stringify(_field)), \
.num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
Expand Down Expand Up @@ -747,6 +760,11 @@ extern const VMStateInfo vmstate_info_qtailq;
VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, \
_vmsd, _type)

#define VMSTATE_STRUCT_2DARRAY(_field, _state, _n1, _n2, _version, \
_vmsd, _type) \
VMSTATE_STRUCT_2DARRAY_TEST(_field, _state, _n1, _n2, NULL, \
_version, _vmsd, _type)

#define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) \
VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \
_size)
Expand Down
2 changes: 1 addition & 1 deletion linux-user/elfload.c
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
int i;

for (i = 0; i < 32; i++) {
(*regs)[i] = tswapreg(env->gpr[i]);
(*regs)[i] = tswapreg(cpu_get_gpr(env, i));
}
(*regs)[32] = tswapreg(env->pc);
(*regs)[33] = tswapreg(cpu_get_sr(env));
Expand Down
18 changes: 9 additions & 9 deletions linux-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2590,17 +2590,17 @@ void cpu_loop(CPUOpenRISCState *env)
case EXCP_SYSCALL:
env->pc += 4; /* 0xc00; */
ret = do_syscall(env,
env->gpr[11], /* return value */
env->gpr[3], /* r3 - r7 are params */
env->gpr[4],
env->gpr[5],
env->gpr[6],
env->gpr[7],
env->gpr[8], 0, 0);
cpu_get_gpr(env, 11), /* return value */
cpu_get_gpr(env, 3), /* r3 - r7 are params */
cpu_get_gpr(env, 4),
cpu_get_gpr(env, 5),
cpu_get_gpr(env, 6),
cpu_get_gpr(env, 7),
cpu_get_gpr(env, 8), 0, 0);
if (ret == -TARGET_ERESTARTSYS) {
env->pc -= 4;
} else if (ret != -TARGET_QEMU_ESIGRETURN) {
env->gpr[11] = ret;
cpu_set_gpr(env, 11, ret);
}
break;
case EXCP_DPF:
Expand Down Expand Up @@ -4765,7 +4765,7 @@ int main(int argc, char **argv, char **envp)
int i;

for (i = 0; i < 32; i++) {
env->gpr[i] = regs->gpr[i];
cpu_set_gpr(env, i, regs->gpr[i]);
}
env->pc = regs->pc;
cpu_set_sr(env, regs->sr);
Expand Down
6 changes: 3 additions & 3 deletions linux-user/openrisc/target_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
static inline void cpu_clone_regs(CPUOpenRISCState *env, target_ulong newsp)
{
if (newsp) {
env->gpr[1] = newsp;
cpu_set_gpr(env, 1, newsp);
}
env->gpr[11] = 0;
cpu_set_gpr(env, 11, 0);
}

static inline void cpu_set_tls(CPUOpenRISCState *env, target_ulong newtls)
{
env->gpr[10] = newtls;
cpu_set_gpr(env, 10, newtls);
}

#endif
2 changes: 1 addition & 1 deletion linux-user/openrisc/target_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef struct target_sigaltstack {

static inline abi_ulong get_sp_from_cpustate(CPUOpenRISCState *state)
{
return state->gpr[1];
return cpu_get_gpr(state, 1);
}


Expand Down
17 changes: 9 additions & 8 deletions linux-user/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -4411,7 +4411,7 @@ static void setup_sigcontext(struct target_sigcontext *sc,
CPUOpenRISCState *regs,
unsigned long mask)
{
unsigned long usp = regs->gpr[1];
unsigned long usp = cpu_get_gpr(regs, 1);

/* copy the regs. they are first in sc so we can use sc directly */

Expand All @@ -4436,7 +4436,7 @@ static inline abi_ulong get_sigframe(struct target_sigaction *ka,
CPUOpenRISCState *regs,
size_t frame_size)
{
unsigned long sp = regs->gpr[1];
unsigned long sp = cpu_get_gpr(regs, 1);
int onsigstack = on_sig_stack(sp);

/* redzone */
Expand Down Expand Up @@ -4489,7 +4489,8 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,
__put_user(0, &frame->uc.tuc_link);
__put_user(target_sigaltstack_used.ss_sp,
&frame->uc.tuc_stack.ss_sp);
__put_user(sas_ss_flags(env->gpr[1]), &frame->uc.tuc_stack.ss_flags);
__put_user(sas_ss_flags(cpu_get_gpr(env, 1)),
&frame->uc.tuc_stack.ss_flags);
__put_user(target_sigaltstack_used.ss_size,
&frame->uc.tuc_stack.ss_size);
setup_sigcontext(&frame->sc, env, set->sig[0]);
Expand All @@ -4512,13 +4513,13 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,

/* Set up registers for signal handler */
env->pc = (unsigned long)ka->_sa_handler; /* what we enter NOW */
env->gpr[9] = (unsigned long)return_ip; /* what we enter LATER */
env->gpr[3] = (unsigned long)sig; /* arg 1: signo */
env->gpr[4] = (unsigned long)&frame->info; /* arg 2: (siginfo_t*) */
env->gpr[5] = (unsigned long)&frame->uc; /* arg 3: ucontext */
cpu_set_gpr(env, 9, (unsigned long)return_ip); /* what we enter LATER */
cpu_set_gpr(env, 3, (unsigned long)sig); /* arg 1: signo */
cpu_set_gpr(env, 4, (unsigned long)&frame->info); /* arg 2: (siginfo_t*) */
cpu_set_gpr(env, 5, (unsigned long)&frame->uc); /* arg 3: ucontext */

/* actually move the usp to reflect the stacked frame */
env->gpr[1] = (unsigned long)frame;
cpu_set_gpr(env, 1, (unsigned long)frame);

return;

Expand Down
16 changes: 5 additions & 11 deletions target/openrisc/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ static void openrisc_cpu_reset(CPUState *s)
cpu->env.lock_addr = -1;
s->exception_index = -1;

cpu->env.upr = UPR_UP | UPR_DMP | UPR_IMP | UPR_PICP | UPR_TTP;
cpu->env.cpucfgr = CPUCFGR_OB32S | CPUCFGR_OF32S;
cpu->env.upr = UPR_UP | UPR_DMP | UPR_IMP | UPR_PICP | UPR_TTP |
UPR_PMP;
cpu->env.dmmucfgr = (DMMUCFGR_NTW & (0 << 2)) | (DMMUCFGR_NTS & (6 << 2));
cpu->env.immucfgr = (IMMUCFGR_NTW & (0 << 2)) | (IMMUCFGR_NTS & (6 << 2));

Expand All @@ -65,12 +65,6 @@ static void openrisc_cpu_reset(CPUState *s)
#endif
}

static inline void set_feature(OpenRISCCPU *cpu, int feature)
{
cpu->feature |= feature;
cpu->env.cpucfgr = cpu->feature;
}

static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp)
{
CPUState *cs = CPU(dev);
Expand Down Expand Up @@ -132,15 +126,15 @@ static void or1200_initfn(Object *obj)
{
OpenRISCCPU *cpu = OPENRISC_CPU(obj);

set_feature(cpu, OPENRISC_FEATURE_OB32S);
set_feature(cpu, OPENRISC_FEATURE_OF32S);
cpu->env.cpucfgr = CPUCFGR_NSGF | CPUCFGR_OB32S | CPUCFGR_OF32S |
CPUCFGR_EVBARP;
}

static void openrisc_any_initfn(Object *obj)
{
OpenRISCCPU *cpu = OPENRISC_CPU(obj);

set_feature(cpu, OPENRISC_FEATURE_OB32S);
cpu->env.cpucfgr = CPUCFGR_NSGF | CPUCFGR_OB32S | CPUCFGR_EVBARP;
}

typedef struct OpenRISCCPUInfo {
Expand Down
46 changes: 31 additions & 15 deletions target/openrisc/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ enum {
CPUCFGR_OF32S = (1 << 7),
CPUCFGR_OF64S = (1 << 8),
CPUCFGR_OV64S = (1 << 9),
/* CPUCFGR_ND = (1 << 10), */
/* CPUCFGR_AVRP = (1 << 11), */
CPUCFGR_EVBARP = (1 << 12),
/* CPUCFGR_ISRP = (1 << 13), */
/* CPUCFGR_AECSRP = (1 << 14), */
};

/* DMMU configure register */
Expand All @@ -135,6 +140,15 @@ enum {
IMMUCFGR_HTR = (1 << 11),
};

/* Power management register */
enum {
PMR_SDF = (15 << 0),
PMR_DME = (1 << 4),
PMR_SME = (1 << 5),
PMR_DCGE = (1 << 6),
PMR_SUME = (1 << 7),
};

/* Float point control status register */
enum {
FPCSR_FPEE = 1,
Expand Down Expand Up @@ -191,17 +205,6 @@ enum {
SR_SCE = (1 << 17),
};

/* OpenRISC Hardware Capabilities */
enum {
OPENRISC_FEATURE_NSGF = (15 << 0),
OPENRISC_FEATURE_CGF = (1 << 4),
OPENRISC_FEATURE_OB32S = (1 << 5),
OPENRISC_FEATURE_OB64S = (1 << 6),
OPENRISC_FEATURE_OF32S = (1 << 7),
OPENRISC_FEATURE_OF64S = (1 << 8),
OPENRISC_FEATURE_OV64S = (1 << 9),
};

/* Tick Timer Mode Register */
enum {
TTMR_TP = (0xfffffff),
Expand Down Expand Up @@ -269,7 +272,8 @@ typedef struct CPUOpenRISCTLBContext {
#endif

typedef struct CPUOpenRISCState {
target_ulong gpr[32]; /* General registers */
target_ulong shadow_gpr[16][32]; /* Shadow registers */

target_ulong pc; /* Program counter */
target_ulong ppc; /* Prev PC */
target_ulong jmp_pc; /* Jump PC */
Expand All @@ -285,10 +289,11 @@ typedef struct CPUOpenRISCState {
uint32_t sr; /* Supervisor register, without SR_{F,CY,OV} */
uint32_t vr; /* Version register */
uint32_t upr; /* Unit presence register */
uint32_t cpucfgr; /* CPU configure register */
uint32_t dmmucfgr; /* DMMU configure register */
uint32_t immucfgr; /* IMMU configure register */
uint32_t esr; /* Exception supervisor register */
uint32_t evbar; /* Exception vector base address register */
uint32_t pmr; /* Power Management Register */
uint32_t fpcsr; /* Float register */
float_status fp_status;

Expand All @@ -303,6 +308,8 @@ typedef struct CPUOpenRISCState {
CPU_COMMON

/* Fields from here on are preserved across CPU reset. */
uint32_t cpucfgr; /* CPU configure register */

#ifndef CONFIG_USER_ONLY
CPUOpenRISCTLBContext * tlb;

Expand All @@ -329,7 +336,6 @@ typedef struct OpenRISCCPU {

CPUOpenRISCState env;

uint32_t feature; /* CPU Capabilities */
} OpenRISCCPU;

static inline OpenRISCCPU *openrisc_env_get_cpu(CPUOpenRISCState *env)
Expand Down Expand Up @@ -392,14 +398,24 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
#define TB_FLAGS_R0_0 2
#define TB_FLAGS_OVE SR_OVE

static inline uint32_t cpu_get_gpr(const CPUOpenRISCState *env, int i)
{
return env->shadow_gpr[0][i];
}

static inline void cpu_set_gpr(CPUOpenRISCState *env, int i, uint32_t val)
{
env->shadow_gpr[0][i] = val;
}

static inline void cpu_get_tb_cpu_state(CPUOpenRISCState *env,
target_ulong *pc,
target_ulong *cs_base, uint32_t *flags)
{
*pc = env->pc;
*cs_base = 0;
*flags = (env->dflag
| (env->gpr[0] == 0 ? TB_FLAGS_R0_0 : 0)
| (cpu_get_gpr(env, 0) == 0 ? TB_FLAGS_R0_0 : 0)
| (env->sr & SR_OVE));
}

Expand Down
4 changes: 2 additions & 2 deletions target/openrisc/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int openrisc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
CPUOpenRISCState *env = &cpu->env;

if (n < 32) {
return gdb_get_reg32(mem_buf, env->gpr[n]);
return gdb_get_reg32(mem_buf, cpu_get_gpr(env, n));
} else {
switch (n) {
case 32: /* PPC */
Expand Down Expand Up @@ -61,7 +61,7 @@ int openrisc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
tmp = ldl_p(mem_buf);

if (n < 32) {
env->gpr[n] = tmp;
cpu_set_gpr(env, n, tmp);
} else {
switch (n) {
case 32: /* PPC */
Expand Down
11 changes: 10 additions & 1 deletion target/openrisc/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,21 @@ void openrisc_cpu_do_interrupt(CPUState *cs)
env->sr |= SR_SM;
env->sr &= ~SR_IEE;
env->sr &= ~SR_TEE;
env->pmr &= ~PMR_DME;
env->pmr &= ~PMR_SME;
env->tlb->cpu_openrisc_map_address_data = &cpu_openrisc_get_phys_nommu;
env->tlb->cpu_openrisc_map_address_code = &cpu_openrisc_get_phys_nommu;
env->lock_addr = -1;

if (cs->exception_index > 0 && cs->exception_index < EXCP_NR) {
env->pc = (cs->exception_index << 8);
hwaddr vect_pc = cs->exception_index << 8;
if (env->cpucfgr & CPUCFGR_EVBARP) {
vect_pc |= env->evbar;
}
if (env->sr & SR_EPH) {
vect_pc |= 0xf0000000;
}
env->pc = vect_pc;
} else {
cpu_abort(cs, "Unhandled exception 0x%x\n", cs->exception_index);
}
Expand Down
Loading

0 comments on commit 317134b

Please sign in to comment.