target/s390x: Rework program_interrupt() and related functions

misc_helper.c won't be compiled with --disable-tcg anymore, but we
still need the program_interrupt() function in that case. Move it
to interrupt.c instead, and refactor it to re-use the code from
trigger_pgm_exception() (for TCG) and enter_pgmcheck() (for KVM,
which now got renamed to kvm_s390_program_interrupt() for
clarity).

Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <1500886370-14572-4-git-send-email-thuth@redhat.com>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
This commit is contained in:
Thomas Huth 2017-07-24 10:52:48 +02:00 committed by Cornelia Huck
parent 3d6722051b
commit e3cfd926f7
5 changed files with 52 additions and 48 deletions

View File

@ -474,10 +474,6 @@ static inline bool get_per_in_range(CPUS390XState *env, uint64_t addr)
} }
} }
#ifndef CONFIG_USER_ONLY
void trigger_pgm_exception(CPUS390XState *env, uint32_t code, uint32_t ilen);
#endif
S390CPU *cpu_s390x_init(const char *cpu_model); S390CPU *cpu_s390x_init(const char *cpu_model);
S390CPU *s390x_new_cpu(const char *cpu_model, int64_t id, Error **errp); S390CPU *s390x_new_cpu(const char *cpu_model, int64_t id, Error **errp);
S390CPU *cpu_s390x_create(const char *cpu_model, Error **errp); S390CPU *cpu_s390x_create(const char *cpu_model, Error **errp);
@ -1146,10 +1142,12 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3);
/* automatically detect the instruction length */ /* automatically detect the instruction length */
#define ILEN_AUTO 0xff #define ILEN_AUTO 0xff
void program_interrupt(CPUS390XState *env, uint32_t code, int ilen); void program_interrupt(CPUS390XState *env, uint32_t code, int ilen);
void trigger_pgm_exception(CPUS390XState *env, uint32_t code, uint32_t ilen);
void QEMU_NORETURN runtime_exception(CPUS390XState *env, int excp, void QEMU_NORETURN runtime_exception(CPUS390XState *env, int excp,
uintptr_t retaddr); uintptr_t retaddr);
#ifdef CONFIG_KVM #ifdef CONFIG_KVM
void kvm_s390_program_interrupt(S390CPU *cpu, uint16_t code);
void kvm_s390_io_interrupt(uint16_t subchannel_id, void kvm_s390_io_interrupt(uint16_t subchannel_id,
uint16_t subchannel_nr, uint32_t io_int_parm, uint16_t subchannel_nr, uint32_t io_int_parm,
uint32_t io_int_word); uint32_t io_int_word);
@ -1170,6 +1168,9 @@ int kvm_s390_get_ri(void);
int kvm_s390_get_gs(void); int kvm_s390_get_gs(void);
void kvm_s390_crypto_reset(void); void kvm_s390_crypto_reset(void);
#else #else
static inline void kvm_s390_program_interrupt(S390CPU *cpu, uint16_t code)
{
}
static inline void kvm_s390_io_interrupt(uint16_t subchannel_id, static inline void kvm_s390_io_interrupt(uint16_t subchannel_id,
uint16_t subchannel_nr, uint16_t subchannel_nr,
uint32_t io_int_parm, uint32_t io_int_parm,

View File

@ -165,16 +165,6 @@ int s390_cpu_handle_mmu_fault(CPUState *cs, vaddr address,
#else /* !CONFIG_USER_ONLY */ #else /* !CONFIG_USER_ONLY */
/* Ensure to exit the TB after this call! */
void trigger_pgm_exception(CPUS390XState *env, uint32_t code, uint32_t ilen)
{
CPUState *cs = CPU(s390_env_get_cpu(env));
cs->exception_index = EXCP_PGM;
env->int_pgm_code = code;
env->int_pgm_ilen = ilen;
}
int s390_cpu_handle_mmu_fault(CPUState *cs, vaddr orig_vaddr, int s390_cpu_handle_mmu_fault(CPUState *cs, vaddr orig_vaddr,
int rw, int mmu_idx) int rw, int mmu_idx)
{ {

View File

@ -8,10 +8,49 @@
*/ */
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "qemu/log.h"
#include "cpu.h" #include "cpu.h"
#include "exec/exec-all.h"
#include "sysemu/kvm.h" #include "sysemu/kvm.h"
#include "hw/s390x/ioinst.h" #include "hw/s390x/ioinst.h"
/* Ensure to exit the TB after this call! */
void trigger_pgm_exception(CPUS390XState *env, uint32_t code, uint32_t ilen)
{
CPUState *cs = CPU(s390_env_get_cpu(env));
cs->exception_index = EXCP_PGM;
env->int_pgm_code = code;
env->int_pgm_ilen = ilen;
}
static void tcg_s390_program_interrupt(CPUS390XState *env, uint32_t code,
int ilen)
{
#ifdef CONFIG_TCG
trigger_pgm_exception(env, code, ilen);
cpu_loop_exit(CPU(s390_env_get_cpu(env)));
#else
g_assert_not_reached();
#endif
}
void program_interrupt(CPUS390XState *env, uint32_t code, int ilen)
{
S390CPU *cpu = s390_env_get_cpu(env);
qemu_log_mask(CPU_LOG_INT, "program interrupt at %#" PRIx64 "\n",
env->psw.addr);
if (kvm_enabled()) {
kvm_s390_program_interrupt(cpu, code);
} else if (tcg_enabled()) {
tcg_s390_program_interrupt(env, code, ilen);
} else {
g_assert_not_reached();
}
}
#if !defined(CONFIG_USER_ONLY) #if !defined(CONFIG_USER_ONLY)
void cpu_inject_ext(S390CPU *cpu, uint32_t code, uint32_t param, void cpu_inject_ext(S390CPU *cpu, uint32_t code, uint32_t param,
uint64_t param64) uint64_t param64)

View File

@ -1032,7 +1032,7 @@ void kvm_s390_service_interrupt(uint32_t parm)
kvm_s390_floating_interrupt(&irq); kvm_s390_floating_interrupt(&irq);
} }
static void enter_pgmcheck(S390CPU *cpu, uint16_t code) void kvm_s390_program_interrupt(S390CPU *cpu, uint16_t code)
{ {
struct kvm_s390_irq irq = { struct kvm_s390_irq irq = {
.type = KVM_S390_PROGRAM_INT, .type = KVM_S390_PROGRAM_INT,
@ -1068,7 +1068,7 @@ static int kvm_sclp_service_call(S390CPU *cpu, struct kvm_run *run,
r = sclp_service_call(env, sccb, code); r = sclp_service_call(env, sccb, code);
if (r < 0) { if (r < 0) {
enter_pgmcheck(cpu, -r); kvm_s390_program_interrupt(cpu, -r);
} else { } else {
setcc(cpu, r); setcc(cpu, r);
} }
@ -1236,7 +1236,7 @@ static int kvm_sic_service_call(S390CPU *cpu, struct kvm_run *run)
isc = (env->regs[r3] >> 27) & 0x7; isc = (env->regs[r3] >> 27) & 0x7;
r = css_do_sic(env, isc, mode); r = css_do_sic(env, isc, mode);
if (r) { if (r) {
enter_pgmcheck(cpu, -r); kvm_s390_program_interrupt(cpu, -r);
} }
return 0; return 0;
@ -1357,7 +1357,7 @@ static int handle_hypercall(S390CPU *cpu, struct kvm_run *run)
cpu_synchronize_state(CPU(cpu)); cpu_synchronize_state(CPU(cpu));
ret = s390_virtio_hypercall(env); ret = s390_virtio_hypercall(env);
if (ret == -EINVAL) { if (ret == -EINVAL) {
enter_pgmcheck(cpu, PGM_SPECIFICATION); kvm_s390_program_interrupt(cpu, PGM_SPECIFICATION);
return 0; return 0;
} }
@ -1374,7 +1374,7 @@ static void kvm_handle_diag_288(S390CPU *cpu, struct kvm_run *run)
r3 = run->s390_sieic.ipa & 0x000f; r3 = run->s390_sieic.ipa & 0x000f;
rc = handle_diag_288(&cpu->env, r1, r3); rc = handle_diag_288(&cpu->env, r1, r3);
if (rc) { if (rc) {
enter_pgmcheck(cpu, PGM_SPECIFICATION); kvm_s390_program_interrupt(cpu, PGM_SPECIFICATION);
} }
} }
@ -1431,7 +1431,7 @@ static int handle_diag(S390CPU *cpu, struct kvm_run *run, uint32_t ipb)
break; break;
default: default:
DPRINTF("KVM: unknown DIAG: 0x%x\n", func_code); DPRINTF("KVM: unknown DIAG: 0x%x\n", func_code);
enter_pgmcheck(cpu, PGM_SPECIFICATION); kvm_s390_program_interrupt(cpu, PGM_SPECIFICATION);
break; break;
} }
@ -1899,7 +1899,7 @@ static int handle_instruction(S390CPU *cpu, struct kvm_run *run)
if (r < 0) { if (r < 0) {
r = 0; r = 0;
enter_pgmcheck(cpu, 0x0001); kvm_s390_program_interrupt(cpu, PGM_OPERATION);
} }
return r; return r;
@ -2009,7 +2009,7 @@ static int handle_intercept(S390CPU *cpu)
/* Then check for potential pgm check loops */ /* Then check for potential pgm check loops */
r = handle_oper_loop(cpu, run); r = handle_oper_loop(cpu, run);
if (r == 0) { if (r == 0) {
enter_pgmcheck(cpu, PGM_OPERATION); kvm_s390_program_interrupt(cpu, PGM_OPERATION);
} }
} }
break; break;

View File

@ -68,32 +68,6 @@ void HELPER(exception)(CPUS390XState *env, uint32_t excp)
cpu_loop_exit(cs); cpu_loop_exit(cs);
} }
void program_interrupt(CPUS390XState *env, uint32_t code, int ilen)
{
S390CPU *cpu = s390_env_get_cpu(env);
qemu_log_mask(CPU_LOG_INT, "program interrupt at %#" PRIx64 "\n",
env->psw.addr);
if (kvm_enabled()) {
#ifdef CONFIG_KVM
struct kvm_s390_irq irq = {
.type = KVM_S390_PROGRAM_INT,
.u.pgm.code = code,
};
kvm_s390_vcpu_interrupt(cpu, &irq);
#endif
} else {
CPUState *cs = CPU(cpu);
env->int_pgm_code = code;
env->int_pgm_ilen = ilen;
cs->exception_index = EXCP_PGM;
cpu_loop_exit(cs);
}
}
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
/* SCLP service call */ /* SCLP service call */