2017-07-24 10:52:49 +02:00
|
|
|
/*
|
|
|
|
* s390x exception / interrupt helpers
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Ulrich Hecht
|
|
|
|
* Copyright (c) 2011 Alexander Graf
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2019-01-29 14:37:47 +01:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2017-07-24 10:52:49 +02:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
2022-02-07 09:27:56 +01:00
|
|
|
#include "qemu/log.h"
|
2017-07-24 10:52:49 +02:00
|
|
|
#include "cpu.h"
|
2021-07-07 12:53:16 +02:00
|
|
|
#include "s390x-internal.h"
|
2018-09-27 15:02:56 +02:00
|
|
|
#include "exec/helper-proto.h"
|
2017-07-24 10:52:49 +02:00
|
|
|
#include "qemu/timer.h"
|
|
|
|
#include "exec/exec-all.h"
|
|
|
|
#include "exec/cpu_ldst.h"
|
|
|
|
#include "hw/s390x/ioinst.h"
|
2017-09-26 20:33:13 +02:00
|
|
|
#include "exec/address-spaces.h"
|
2018-09-27 15:02:55 +02:00
|
|
|
#include "tcg_s390x.h"
|
2017-07-24 10:52:49 +02:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2018-01-29 13:56:13 +01:00
|
|
|
#include "hw/s390x/s390_flic.h"
|
2019-05-18 22:54:24 +02:00
|
|
|
#include "hw/boards.h"
|
2017-07-24 10:52:49 +02:00
|
|
|
#endif
|
|
|
|
|
2022-04-20 15:26:02 +02:00
|
|
|
G_NORETURN void tcg_s390_program_interrupt(CPUS390XState *env,
|
|
|
|
uint32_t code, uintptr_t ra)
|
2018-09-27 15:02:55 +02:00
|
|
|
{
|
2019-03-23 03:21:48 +01:00
|
|
|
CPUState *cs = env_cpu(env);
|
2018-09-27 15:02:55 +02:00
|
|
|
|
|
|
|
cpu_restore_state(cs, ra, true);
|
|
|
|
qemu_log_mask(CPU_LOG_INT, "program interrupt at %#" PRIx64 "\n",
|
|
|
|
env->psw.addr);
|
2019-10-01 19:16:13 +02:00
|
|
|
trigger_pgm_exception(env, code);
|
2018-09-27 15:02:55 +02:00
|
|
|
cpu_loop_exit(cs);
|
|
|
|
}
|
|
|
|
|
2022-04-20 15:26:02 +02:00
|
|
|
G_NORETURN void tcg_s390_data_exception(CPUS390XState *env, uint32_t dxc,
|
|
|
|
uintptr_t ra)
|
2018-09-27 15:02:56 +02:00
|
|
|
{
|
|
|
|
g_assert(dxc <= 0xff);
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
/* Store the DXC into the lowcore */
|
2019-03-23 03:21:48 +01:00
|
|
|
stl_phys(env_cpu(env)->as,
|
2018-09-27 15:02:56 +02:00
|
|
|
env->psa + offsetof(LowCore, data_exc_code), dxc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Store the DXC into the FPC if AFP is enabled */
|
|
|
|
if (env->cregs[0] & CR0_AFP) {
|
|
|
|
env->fpc = deposit32(env->fpc, 8, 8, dxc);
|
|
|
|
}
|
2019-10-01 19:15:58 +02:00
|
|
|
tcg_s390_program_interrupt(env, PGM_DATA, ra);
|
2018-09-27 15:02:56 +02:00
|
|
|
}
|
|
|
|
|
2022-04-20 15:26:02 +02:00
|
|
|
G_NORETURN void tcg_s390_vector_exception(CPUS390XState *env, uint32_t vxc,
|
|
|
|
uintptr_t ra)
|
2019-02-22 11:19:48 +01:00
|
|
|
{
|
|
|
|
g_assert(vxc <= 0xff);
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
/* Always store the VXC into the lowcore, without AFP it is undefined */
|
2019-03-23 03:21:48 +01:00
|
|
|
stl_phys(env_cpu(env)->as,
|
2019-02-22 11:19:48 +01:00
|
|
|
env->psa + offsetof(LowCore, data_exc_code), vxc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Always store the VXC into the FPC, without AFP it is undefined */
|
|
|
|
env->fpc = deposit32(env->fpc, 8, 8, vxc);
|
2019-10-01 19:15:58 +02:00
|
|
|
tcg_s390_program_interrupt(env, PGM_VECTOR_PROCESSING, ra);
|
2019-02-22 11:19:48 +01:00
|
|
|
}
|
|
|
|
|
2018-09-27 15:02:56 +02:00
|
|
|
void HELPER(data_exception)(CPUS390XState *env, uint32_t dxc)
|
|
|
|
{
|
|
|
|
tcg_s390_data_exception(env, dxc, GETPC());
|
|
|
|
}
|
|
|
|
|
2021-10-04 19:40:57 +02:00
|
|
|
/*
|
|
|
|
* Unaligned accesses are only diagnosed with MO_ALIGN. At the moment,
|
|
|
|
* this is only for the atomic operations, for which we want to raise a
|
|
|
|
* specification exception.
|
|
|
|
*/
|
2022-04-20 15:26:02 +02:00
|
|
|
static G_NORETURN
|
|
|
|
void do_unaligned_access(CPUState *cs, uintptr_t retaddr)
|
2021-10-04 19:40:57 +02:00
|
|
|
{
|
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
tcg_s390_program_interrupt(env, PGM_SPECIFICATION, retaddr);
|
|
|
|
}
|
|
|
|
|
2017-07-24 10:52:49 +02:00
|
|
|
#if defined(CONFIG_USER_ONLY)
|
|
|
|
|
|
|
|
void s390_cpu_do_interrupt(CPUState *cs)
|
|
|
|
{
|
|
|
|
cs->exception_index = -1;
|
|
|
|
}
|
|
|
|
|
2021-09-18 19:34:30 +02:00
|
|
|
void s390_cpu_record_sigsegv(CPUState *cs, vaddr address,
|
|
|
|
MMUAccessType access_type,
|
|
|
|
bool maperr, uintptr_t retaddr)
|
2017-07-24 10:52:49 +02:00
|
|
|
{
|
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
|
2021-09-18 19:34:30 +02:00
|
|
|
trigger_pgm_exception(&cpu->env, maperr ? PGM_ADDRESSING : PGM_PROTECTION);
|
|
|
|
/*
|
|
|
|
* On real machines this value is dropped into LowMem. Since this
|
|
|
|
* is userland, simply put this someplace that cpu_loop can find it.
|
|
|
|
* S390 only gives the page of the fault, not the exact address.
|
|
|
|
* C.f. the construction of TEC in mmu_translate().
|
|
|
|
*/
|
|
|
|
cpu->env.__excp_addr = address & TARGET_PAGE_MASK;
|
2019-04-02 13:02:09 +02:00
|
|
|
cpu_loop_exit_restore(cs, retaddr);
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
|
2021-10-04 19:40:57 +02:00
|
|
|
void s390_cpu_record_sigbus(CPUState *cs, vaddr address,
|
|
|
|
MMUAccessType access_type, uintptr_t retaddr)
|
|
|
|
{
|
|
|
|
do_unaligned_access(cs, retaddr);
|
|
|
|
}
|
|
|
|
|
2017-07-24 10:52:49 +02:00
|
|
|
#else /* !CONFIG_USER_ONLY */
|
|
|
|
|
2017-08-18 13:43:45 +02:00
|
|
|
static inline uint64_t cpu_mmu_idx_to_asc(int mmu_idx)
|
|
|
|
{
|
|
|
|
switch (mmu_idx) {
|
|
|
|
case MMU_PRIMARY_IDX:
|
|
|
|
return PSW_ASC_PRIMARY;
|
|
|
|
case MMU_SECONDARY_IDX:
|
|
|
|
return PSW_ASC_SECONDARY;
|
|
|
|
case MMU_HOME_IDX:
|
|
|
|
return PSW_ASC_HOME;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 13:02:09 +02:00
|
|
|
bool s390_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
|
|
|
|
MMUAccessType access_type, int mmu_idx,
|
|
|
|
bool probe, uintptr_t retaddr)
|
2017-07-24 10:52:49 +02:00
|
|
|
{
|
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
target_ulong vaddr, raddr;
|
2019-10-01 19:16:02 +02:00
|
|
|
uint64_t asc, tec;
|
2019-10-01 19:16:07 +02:00
|
|
|
int prot, excp;
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2018-10-05 17:00:01 +02:00
|
|
|
qemu_log_mask(CPU_LOG_MMU, "%s: addr 0x%" VADDR_PRIx " rw %d mmu_idx %d\n",
|
2019-04-02 13:02:09 +02:00
|
|
|
__func__, address, access_type, mmu_idx);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2019-04-02 13:02:09 +02:00
|
|
|
vaddr = address;
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2017-09-26 20:33:14 +02:00
|
|
|
if (mmu_idx < MMU_REAL_IDX) {
|
|
|
|
asc = cpu_mmu_idx_to_asc(mmu_idx);
|
|
|
|
/* 31-Bit mode */
|
|
|
|
if (!(env->psw.mask & PSW_MASK_64)) {
|
|
|
|
vaddr &= 0x7fffffff;
|
|
|
|
}
|
2019-10-01 19:16:05 +02:00
|
|
|
excp = mmu_translate(env, vaddr, access_type, asc, &raddr, &prot, &tec);
|
2017-09-26 20:33:14 +02:00
|
|
|
} else if (mmu_idx == MMU_REAL_IDX) {
|
2018-03-01 13:08:26 +01:00
|
|
|
/* 31-Bit mode */
|
|
|
|
if (!(env->psw.mask & PSW_MASK_64)) {
|
|
|
|
vaddr &= 0x7fffffff;
|
|
|
|
}
|
2019-10-01 19:16:03 +02:00
|
|
|
excp = mmu_translate_real(env, vaddr, access_type, &raddr, &prot, &tec);
|
2017-09-26 20:33:14 +02:00
|
|
|
} else {
|
2019-04-02 13:02:09 +02:00
|
|
|
g_assert_not_reached();
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:54:48 +01:00
|
|
|
env->tlb_fill_exc = excp;
|
|
|
|
env->tlb_fill_tec = tec;
|
|
|
|
|
2019-10-01 19:16:07 +02:00
|
|
|
if (!excp) {
|
2019-04-02 13:02:09 +02:00
|
|
|
qemu_log_mask(CPU_LOG_MMU,
|
|
|
|
"%s: set tlb %" PRIx64 " -> %" PRIx64 " (%x)\n",
|
|
|
|
__func__, (uint64_t)vaddr, (uint64_t)raddr, prot);
|
|
|
|
tlb_set_page(cs, address & TARGET_PAGE_MASK, raddr, prot,
|
|
|
|
mmu_idx, TARGET_PAGE_SIZE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (probe) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2019-10-01 19:16:07 +02:00
|
|
|
if (excp != PGM_ADDRESSING) {
|
|
|
|
stq_phys(env_cpu(env)->as,
|
|
|
|
env->psa + offsetof(LowCore, trans_exc_code), tec);
|
2019-10-01 19:16:01 +02:00
|
|
|
}
|
2019-04-02 13:02:09 +02:00
|
|
|
|
|
|
|
/*
|
2019-10-01 19:16:09 +02:00
|
|
|
* For data accesses, ILEN will be filled in from the unwind info,
|
|
|
|
* within cpu_loop_exit_restore. For code accesses, retaddr == 0,
|
|
|
|
* and so unwinding will not occur. However, ILEN is also undefined
|
|
|
|
* for that case -- we choose to set ILEN = 2.
|
2019-04-02 13:02:09 +02:00
|
|
|
*/
|
2019-10-01 19:16:13 +02:00
|
|
|
env->int_pgm_ilen = 2;
|
|
|
|
trigger_pgm_exception(env, excp);
|
2019-10-01 19:16:09 +02:00
|
|
|
cpu_loop_exit_restore(cs, retaddr);
|
2019-04-02 13:02:09 +02:00
|
|
|
}
|
|
|
|
|
2017-07-24 10:52:49 +02:00
|
|
|
static void do_program_interrupt(CPUS390XState *env)
|
|
|
|
{
|
|
|
|
uint64_t mask, addr;
|
|
|
|
LowCore *lowcore;
|
|
|
|
int ilen = env->int_pgm_ilen;
|
|
|
|
|
|
|
|
assert(ilen == 2 || ilen == 4 || ilen == 6);
|
|
|
|
|
|
|
|
switch (env->int_pgm_code) {
|
|
|
|
case PGM_PER:
|
|
|
|
if (env->per_perc_atmid & PER_CODE_EVENT_NULLIFICATION) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALL THROUGH */
|
|
|
|
case PGM_OPERATION:
|
|
|
|
case PGM_PRIVILEGED:
|
|
|
|
case PGM_EXECUTE:
|
|
|
|
case PGM_PROTECTION:
|
|
|
|
case PGM_ADDRESSING:
|
|
|
|
case PGM_SPECIFICATION:
|
|
|
|
case PGM_DATA:
|
|
|
|
case PGM_FIXPT_OVERFLOW:
|
|
|
|
case PGM_FIXPT_DIVIDE:
|
|
|
|
case PGM_DEC_OVERFLOW:
|
|
|
|
case PGM_DEC_DIVIDE:
|
|
|
|
case PGM_HFP_EXP_OVERFLOW:
|
|
|
|
case PGM_HFP_EXP_UNDERFLOW:
|
|
|
|
case PGM_HFP_SIGNIFICANCE:
|
|
|
|
case PGM_HFP_DIVIDE:
|
|
|
|
case PGM_TRANS_SPEC:
|
|
|
|
case PGM_SPECIAL_OP:
|
|
|
|
case PGM_OPERAND:
|
|
|
|
case PGM_HFP_SQRT:
|
|
|
|
case PGM_PC_TRANS_SPEC:
|
|
|
|
case PGM_ALET_SPEC:
|
|
|
|
case PGM_MONITOR:
|
|
|
|
/* advance the PSW if our exception is not nullifying */
|
|
|
|
env->psw.addr += ilen;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-10-05 17:00:01 +02:00
|
|
|
qemu_log_mask(CPU_LOG_INT,
|
|
|
|
"%s: code=0x%x ilen=%d psw: %" PRIx64 " %" PRIx64 "\n",
|
|
|
|
__func__, env->int_pgm_code, ilen, env->psw.mask,
|
|
|
|
env->psw.addr);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
|
|
|
lowcore = cpu_map_lowcore(env);
|
|
|
|
|
|
|
|
/* Signal PER events with the exception. */
|
|
|
|
if (env->per_perc_atmid) {
|
|
|
|
env->int_pgm_code |= PGM_PER;
|
|
|
|
lowcore->per_address = cpu_to_be64(env->per_address);
|
|
|
|
lowcore->per_perc_atmid = cpu_to_be16(env->per_perc_atmid);
|
|
|
|
env->per_perc_atmid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
lowcore->pgm_ilen = cpu_to_be16(ilen);
|
|
|
|
lowcore->pgm_code = cpu_to_be16(env->int_pgm_code);
|
2021-06-15 05:07:40 +02:00
|
|
|
lowcore->program_old_psw.mask = cpu_to_be64(s390_cpu_get_psw_mask(env));
|
2017-07-24 10:52:49 +02:00
|
|
|
lowcore->program_old_psw.addr = cpu_to_be64(env->psw.addr);
|
|
|
|
mask = be64_to_cpu(lowcore->program_new_psw.mask);
|
|
|
|
addr = be64_to_cpu(lowcore->program_new_psw.addr);
|
|
|
|
lowcore->per_breaking_event_addr = cpu_to_be64(env->gbea);
|
|
|
|
|
|
|
|
cpu_unmap_lowcore(lowcore);
|
|
|
|
|
2021-06-15 05:07:40 +02:00
|
|
|
s390_cpu_set_psw(env, mask, addr);
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_svc_interrupt(CPUS390XState *env)
|
|
|
|
{
|
|
|
|
uint64_t mask, addr;
|
|
|
|
LowCore *lowcore;
|
|
|
|
|
|
|
|
lowcore = cpu_map_lowcore(env);
|
|
|
|
|
|
|
|
lowcore->svc_code = cpu_to_be16(env->int_svc_code);
|
|
|
|
lowcore->svc_ilen = cpu_to_be16(env->int_svc_ilen);
|
2021-06-15 05:07:40 +02:00
|
|
|
lowcore->svc_old_psw.mask = cpu_to_be64(s390_cpu_get_psw_mask(env));
|
2017-07-24 10:52:49 +02:00
|
|
|
lowcore->svc_old_psw.addr = cpu_to_be64(env->psw.addr + env->int_svc_ilen);
|
|
|
|
mask = be64_to_cpu(lowcore->svc_new_psw.mask);
|
|
|
|
addr = be64_to_cpu(lowcore->svc_new_psw.addr);
|
|
|
|
|
|
|
|
cpu_unmap_lowcore(lowcore);
|
|
|
|
|
2021-06-15 05:07:40 +02:00
|
|
|
s390_cpu_set_psw(env, mask, addr);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
|
|
|
/* When a PER event is pending, the PER exception has to happen
|
|
|
|
immediately after the SERVICE CALL one. */
|
|
|
|
if (env->per_perc_atmid) {
|
|
|
|
env->int_pgm_code = PGM_PER;
|
|
|
|
env->int_pgm_ilen = env->int_svc_ilen;
|
|
|
|
do_program_interrupt(env);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VIRTIO_SUBCODE_64 0x0D00
|
|
|
|
|
|
|
|
static void do_ext_interrupt(CPUS390XState *env)
|
|
|
|
{
|
2018-01-29 13:56:13 +01:00
|
|
|
QEMUS390FLICState *flic = QEMU_S390_FLIC(s390_get_flic());
|
2019-03-23 03:21:48 +01:00
|
|
|
S390CPU *cpu = env_archcpu(env);
|
2017-07-24 10:52:49 +02:00
|
|
|
uint64_t mask, addr;
|
2017-09-28 22:36:41 +02:00
|
|
|
uint16_t cpu_addr;
|
2017-07-24 10:52:49 +02:00
|
|
|
LowCore *lowcore;
|
|
|
|
|
|
|
|
if (!(env->psw.mask & PSW_MASK_EXT)) {
|
|
|
|
cpu_abort(CPU(cpu), "Ext int w/o ext mask\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
lowcore = cpu_map_lowcore(env);
|
|
|
|
|
2017-09-28 22:36:43 +02:00
|
|
|
if ((env->pending_int & INTERRUPT_EMERGENCY_SIGNAL) &&
|
|
|
|
(env->cregs[0] & CR0_EMERGENCY_SIGNAL_SC)) {
|
2020-01-21 12:03:44 +01:00
|
|
|
MachineState *ms = MACHINE(qdev_get_machine());
|
|
|
|
unsigned int max_cpus = ms->smp.max_cpus;
|
|
|
|
|
2017-09-28 22:36:41 +02:00
|
|
|
lowcore->ext_int_code = cpu_to_be16(EXT_EMERGENCY);
|
|
|
|
cpu_addr = find_first_bit(env->emergency_signals, S390_MAX_CPUS);
|
|
|
|
g_assert(cpu_addr < S390_MAX_CPUS);
|
|
|
|
lowcore->cpu_addr = cpu_to_be16(cpu_addr);
|
|
|
|
clear_bit(cpu_addr, env->emergency_signals);
|
|
|
|
if (bitmap_empty(env->emergency_signals, max_cpus)) {
|
|
|
|
env->pending_int &= ~INTERRUPT_EMERGENCY_SIGNAL;
|
|
|
|
}
|
2017-09-28 22:36:43 +02:00
|
|
|
} else if ((env->pending_int & INTERRUPT_EXTERNAL_CALL) &&
|
|
|
|
(env->cregs[0] & CR0_EXTERNAL_CALL_SC)) {
|
2017-09-28 22:36:41 +02:00
|
|
|
lowcore->ext_int_code = cpu_to_be16(EXT_EXTERNAL_CALL);
|
|
|
|
lowcore->cpu_addr = cpu_to_be16(env->external_call_addr);
|
|
|
|
env->pending_int &= ~INTERRUPT_EXTERNAL_CALL;
|
2017-09-28 22:36:43 +02:00
|
|
|
} else if ((env->pending_int & INTERRUPT_EXT_CLOCK_COMPARATOR) &&
|
|
|
|
(env->cregs[0] & CR0_CKC_SC)) {
|
2017-09-28 22:36:39 +02:00
|
|
|
lowcore->ext_int_code = cpu_to_be16(EXT_CLOCK_COMP);
|
|
|
|
lowcore->cpu_addr = 0;
|
|
|
|
env->pending_int &= ~INTERRUPT_EXT_CLOCK_COMPARATOR;
|
2017-09-28 22:36:43 +02:00
|
|
|
} else if ((env->pending_int & INTERRUPT_EXT_CPU_TIMER) &&
|
|
|
|
(env->cregs[0] & CR0_CPU_TIMER_SC)) {
|
2017-09-28 22:36:39 +02:00
|
|
|
lowcore->ext_int_code = cpu_to_be16(EXT_CPU_TIMER);
|
|
|
|
lowcore->cpu_addr = 0;
|
|
|
|
env->pending_int &= ~INTERRUPT_EXT_CPU_TIMER;
|
2018-01-29 13:56:13 +01:00
|
|
|
} else if (qemu_s390_flic_has_service(flic) &&
|
2017-09-28 22:36:43 +02:00
|
|
|
(env->cregs[0] & CR0_SERVICE_SC)) {
|
2018-01-29 13:56:13 +01:00
|
|
|
uint32_t param;
|
|
|
|
|
|
|
|
param = qemu_s390_flic_dequeue_service(flic);
|
2017-09-28 22:36:40 +02:00
|
|
|
lowcore->ext_int_code = cpu_to_be16(EXT_SERVICE);
|
2018-01-29 13:56:13 +01:00
|
|
|
lowcore->ext_params = cpu_to_be32(param);
|
2017-09-28 22:36:40 +02:00
|
|
|
lowcore->cpu_addr = 0;
|
2017-09-28 22:36:39 +02:00
|
|
|
} else {
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
2017-07-24 10:52:49 +02:00
|
|
|
mask = be64_to_cpu(lowcore->external_new_psw.mask);
|
|
|
|
addr = be64_to_cpu(lowcore->external_new_psw.addr);
|
2021-06-15 05:07:40 +02:00
|
|
|
lowcore->external_old_psw.mask = cpu_to_be64(s390_cpu_get_psw_mask(env));
|
2017-09-28 22:36:39 +02:00
|
|
|
lowcore->external_old_psw.addr = cpu_to_be64(env->psw.addr);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
|
|
|
cpu_unmap_lowcore(lowcore);
|
|
|
|
|
2021-06-15 05:07:40 +02:00
|
|
|
s390_cpu_set_psw(env, mask, addr);
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_io_interrupt(CPUS390XState *env)
|
|
|
|
{
|
2018-01-29 13:56:13 +01:00
|
|
|
QEMUS390FLICState *flic = QEMU_S390_FLIC(s390_get_flic());
|
|
|
|
uint64_t mask, addr;
|
|
|
|
QEMUS390FlicIO *io;
|
2017-07-24 10:52:49 +02:00
|
|
|
LowCore *lowcore;
|
|
|
|
|
2018-01-29 13:56:13 +01:00
|
|
|
g_assert(env->psw.mask & PSW_MASK_IO);
|
|
|
|
io = qemu_s390_flic_dequeue_io(flic, env->cregs[6]);
|
|
|
|
g_assert(io);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2018-01-29 13:56:13 +01:00
|
|
|
lowcore = cpu_map_lowcore(env);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2018-01-29 13:56:13 +01:00
|
|
|
lowcore->subchannel_id = cpu_to_be16(io->id);
|
|
|
|
lowcore->subchannel_nr = cpu_to_be16(io->nr);
|
|
|
|
lowcore->io_int_parm = cpu_to_be32(io->parm);
|
|
|
|
lowcore->io_int_word = cpu_to_be32(io->word);
|
2021-06-15 05:07:40 +02:00
|
|
|
lowcore->io_old_psw.mask = cpu_to_be64(s390_cpu_get_psw_mask(env));
|
2018-01-29 13:56:13 +01:00
|
|
|
lowcore->io_old_psw.addr = cpu_to_be64(env->psw.addr);
|
|
|
|
mask = be64_to_cpu(lowcore->io_new_psw.mask);
|
|
|
|
addr = be64_to_cpu(lowcore->io_new_psw.addr);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2018-01-29 13:56:13 +01:00
|
|
|
cpu_unmap_lowcore(lowcore);
|
|
|
|
g_free(io);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2021-06-15 05:07:40 +02:00
|
|
|
s390_cpu_set_psw(env, mask, addr);
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 09:11:53 +01:00
|
|
|
typedef struct MchkExtSaveArea {
|
|
|
|
uint64_t vregs[32][2]; /* 0x0000 */
|
|
|
|
uint8_t pad_0x0200[0x0400 - 0x0200]; /* 0x0200 */
|
|
|
|
} MchkExtSaveArea;
|
|
|
|
QEMU_BUILD_BUG_ON(sizeof(MchkExtSaveArea) != 1024);
|
|
|
|
|
|
|
|
static int mchk_store_vregs(CPUS390XState *env, uint64_t mcesao)
|
|
|
|
{
|
|
|
|
hwaddr len = sizeof(MchkExtSaveArea);
|
|
|
|
MchkExtSaveArea *sa;
|
|
|
|
int i;
|
|
|
|
|
2020-02-19 20:20:42 +01:00
|
|
|
sa = cpu_physical_memory_map(mcesao, &len, true);
|
2019-02-22 09:11:53 +01:00
|
|
|
if (!sa) {
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
if (len != sizeof(MchkExtSaveArea)) {
|
|
|
|
cpu_physical_memory_unmap(sa, len, 1, 0);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
2019-05-29 09:15:38 +02:00
|
|
|
sa->vregs[i][0] = cpu_to_be64(env->vregs[i][0]);
|
|
|
|
sa->vregs[i][1] = cpu_to_be64(env->vregs[i][1]);
|
2019-02-22 09:11:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cpu_physical_memory_unmap(sa, len, 1, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-24 10:52:49 +02:00
|
|
|
static void do_mchk_interrupt(CPUS390XState *env)
|
|
|
|
{
|
2018-01-29 13:56:13 +01:00
|
|
|
QEMUS390FLICState *flic = QEMU_S390_FLIC(s390_get_flic());
|
2019-02-22 09:11:53 +01:00
|
|
|
uint64_t mcic = s390_build_validity_mcic() | MCIC_SC_CP;
|
|
|
|
uint64_t mask, addr, mcesao = 0;
|
2017-07-24 10:52:49 +02:00
|
|
|
LowCore *lowcore;
|
|
|
|
int i;
|
|
|
|
|
2018-01-29 13:56:09 +01:00
|
|
|
/* for now we only support channel report machine checks (floating) */
|
|
|
|
g_assert(env->psw.mask & PSW_MASK_MCHECK);
|
|
|
|
g_assert(env->cregs[14] & CR14_CHANNEL_REPORT_SC);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2018-01-29 13:56:13 +01:00
|
|
|
qemu_s390_flic_dequeue_crw_mchk(flic);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
|
|
|
lowcore = cpu_map_lowcore(env);
|
|
|
|
|
2019-02-22 09:11:53 +01:00
|
|
|
/* extended save area */
|
|
|
|
if (mcic & MCIC_VB_VR) {
|
|
|
|
/* length and alignment is 1024 bytes */
|
|
|
|
mcesao = be64_to_cpu(lowcore->mcesad) & ~0x3ffull;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to store vector registers */
|
|
|
|
if (!mcesao || mchk_store_vregs(env, mcesao)) {
|
|
|
|
mcic &= ~MCIC_VB_VR;
|
|
|
|
}
|
|
|
|
|
2017-12-08 17:01:55 +01:00
|
|
|
/* we are always in z/Architecture mode */
|
|
|
|
lowcore->ar_access_id = 1;
|
|
|
|
|
2017-07-24 10:52:49 +02:00
|
|
|
for (i = 0; i < 16; i++) {
|
2019-05-29 09:15:38 +02:00
|
|
|
lowcore->floating_pt_save_area[i] = cpu_to_be64(*get_freg(env, i));
|
2017-07-24 10:52:49 +02:00
|
|
|
lowcore->gpregs_save_area[i] = cpu_to_be64(env->regs[i]);
|
|
|
|
lowcore->access_regs_save_area[i] = cpu_to_be32(env->aregs[i]);
|
|
|
|
lowcore->cregs_save_area[i] = cpu_to_be64(env->cregs[i]);
|
|
|
|
}
|
|
|
|
lowcore->prefixreg_save_area = cpu_to_be32(env->psa);
|
|
|
|
lowcore->fpt_creg_save_area = cpu_to_be32(env->fpc);
|
|
|
|
lowcore->tod_progreg_save_area = cpu_to_be32(env->todpr);
|
2017-12-08 17:01:55 +01:00
|
|
|
lowcore->cpu_timer_save_area = cpu_to_be64(env->cputm);
|
|
|
|
lowcore->clock_comp_save_area = cpu_to_be64(env->ckc >> 8);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2019-02-22 09:11:53 +01:00
|
|
|
lowcore->mcic = cpu_to_be64(mcic);
|
2021-06-15 05:07:40 +02:00
|
|
|
lowcore->mcck_old_psw.mask = cpu_to_be64(s390_cpu_get_psw_mask(env));
|
2017-07-24 10:52:49 +02:00
|
|
|
lowcore->mcck_old_psw.addr = cpu_to_be64(env->psw.addr);
|
|
|
|
mask = be64_to_cpu(lowcore->mcck_new_psw.mask);
|
|
|
|
addr = be64_to_cpu(lowcore->mcck_new_psw.addr);
|
|
|
|
|
|
|
|
cpu_unmap_lowcore(lowcore);
|
|
|
|
|
2021-06-15 05:07:40 +02:00
|
|
|
s390_cpu_set_psw(env, mask, addr);
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void s390_cpu_do_interrupt(CPUState *cs)
|
|
|
|
{
|
2018-01-29 13:56:13 +01:00
|
|
|
QEMUS390FLICState *flic = QEMU_S390_FLIC(s390_get_flic());
|
2017-07-24 10:52:49 +02:00
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
CPUS390XState *env = &cpu->env;
|
2018-01-29 13:56:06 +01:00
|
|
|
bool stopped = false;
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2018-10-05 17:00:01 +02:00
|
|
|
qemu_log_mask(CPU_LOG_INT, "%s: %d at psw=%" PRIx64 ":%" PRIx64 "\n",
|
|
|
|
__func__, cs->exception_index, env->psw.mask, env->psw.addr);
|
2017-07-24 10:52:49 +02:00
|
|
|
|
2018-01-29 13:56:06 +01:00
|
|
|
try_deliver:
|
2017-07-24 10:52:49 +02:00
|
|
|
/* handle machine checks */
|
2017-09-28 22:36:42 +02:00
|
|
|
if (cs->exception_index == -1 && s390_cpu_has_mcck_int(cpu)) {
|
|
|
|
cs->exception_index = EXCP_MCHK;
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
/* handle external interrupts */
|
2017-09-28 22:36:42 +02:00
|
|
|
if (cs->exception_index == -1 && s390_cpu_has_ext_int(cpu)) {
|
2017-09-28 22:36:39 +02:00
|
|
|
cs->exception_index = EXCP_EXT;
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
/* handle I/O interrupts */
|
2017-09-28 22:36:42 +02:00
|
|
|
if (cs->exception_index == -1 && s390_cpu_has_io_int(cpu)) {
|
|
|
|
cs->exception_index = EXCP_IO;
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
2017-09-28 22:37:02 +02:00
|
|
|
/* RESTART interrupt */
|
|
|
|
if (cs->exception_index == -1 && s390_cpu_has_restart_int(cpu)) {
|
|
|
|
cs->exception_index = EXCP_RESTART;
|
|
|
|
}
|
|
|
|
/* STOP interrupt has least priority */
|
|
|
|
if (cs->exception_index == -1 && s390_cpu_has_stop_int(cpu)) {
|
|
|
|
cs->exception_index = EXCP_STOP;
|
|
|
|
}
|
2017-07-24 10:52:49 +02:00
|
|
|
|
|
|
|
switch (cs->exception_index) {
|
|
|
|
case EXCP_PGM:
|
|
|
|
do_program_interrupt(env);
|
|
|
|
break;
|
|
|
|
case EXCP_SVC:
|
|
|
|
do_svc_interrupt(env);
|
|
|
|
break;
|
|
|
|
case EXCP_EXT:
|
|
|
|
do_ext_interrupt(env);
|
|
|
|
break;
|
|
|
|
case EXCP_IO:
|
|
|
|
do_io_interrupt(env);
|
|
|
|
break;
|
|
|
|
case EXCP_MCHK:
|
|
|
|
do_mchk_interrupt(env);
|
|
|
|
break;
|
2017-09-28 22:37:02 +02:00
|
|
|
case EXCP_RESTART:
|
|
|
|
do_restart_interrupt(env);
|
|
|
|
break;
|
|
|
|
case EXCP_STOP:
|
|
|
|
do_stop_interrupt(env);
|
2018-01-29 13:56:06 +01:00
|
|
|
stopped = true;
|
2017-09-28 22:37:02 +02:00
|
|
|
break;
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
2017-09-28 22:36:47 +02:00
|
|
|
|
2018-01-29 13:56:06 +01:00
|
|
|
if (cs->exception_index != -1 && !stopped) {
|
|
|
|
/* check if there are more pending interrupts to deliver */
|
|
|
|
cs->exception_index = -1;
|
|
|
|
goto try_deliver;
|
2017-09-28 22:36:47 +02:00
|
|
|
}
|
2017-07-24 10:52:49 +02:00
|
|
|
cs->exception_index = -1;
|
|
|
|
|
2017-09-28 22:36:42 +02:00
|
|
|
/* we might still have pending interrupts, but not deliverable */
|
2018-01-29 13:56:13 +01:00
|
|
|
if (!env->pending_int && !qemu_s390_flic_has_any(flic)) {
|
2017-07-24 10:52:49 +02:00
|
|
|
cs->interrupt_request &= ~CPU_INTERRUPT_HARD;
|
|
|
|
}
|
2018-01-29 13:56:06 +01:00
|
|
|
|
|
|
|
/* WAIT PSW during interrupt injection or STOP interrupt */
|
|
|
|
if ((env->psw.mask & PSW_MASK_WAIT) || stopped) {
|
|
|
|
/* don't trigger a cpu_loop_exit(), use an interrupt instead */
|
|
|
|
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HALT);
|
|
|
|
} else if (cs->halted) {
|
|
|
|
/* unhalt if we had a WAIT PSW somehwere in our injection chain */
|
|
|
|
s390_cpu_unhalt(cpu);
|
|
|
|
}
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool s390_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
|
|
|
|
{
|
|
|
|
if (interrupt_request & CPU_INTERRUPT_HARD) {
|
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
if (env->ex_value) {
|
|
|
|
/* Execution of the target insn is indivisible from
|
|
|
|
the parent EXECUTE insn. */
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-28 22:36:42 +02:00
|
|
|
if (s390_cpu_has_int(cpu)) {
|
2017-07-24 10:52:49 +02:00
|
|
|
s390_cpu_do_interrupt(cs);
|
|
|
|
return true;
|
|
|
|
}
|
2018-01-29 13:56:12 +01:00
|
|
|
if (env->psw.mask & PSW_MASK_WAIT) {
|
|
|
|
/* Woken up because of a floating interrupt but it has already
|
|
|
|
* been delivered. Go back to sleep. */
|
|
|
|
cpu_interrupt(CPU(cpu), CPU_INTERRUPT_HALT);
|
|
|
|
}
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void s390x_cpu_debug_excp_handler(CPUState *cs)
|
|
|
|
{
|
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
CPUWatchpoint *wp_hit = cs->watchpoint_hit;
|
|
|
|
|
|
|
|
if (wp_hit && wp_hit->flags & BP_CPU) {
|
|
|
|
/* FIXME: When the storage-alteration-space control bit is set,
|
|
|
|
the exception should only be triggered if the memory access
|
|
|
|
is done using an address space with the storage-alteration-event
|
|
|
|
bit set. We have no way to detect that with the current
|
|
|
|
watchpoint code. */
|
|
|
|
cs->watchpoint_hit = NULL;
|
|
|
|
|
|
|
|
env->per_address = env->psw.addr;
|
|
|
|
env->per_perc_atmid |= PER_CODE_EVENT_STORE | get_per_atmid(env);
|
|
|
|
/* FIXME: We currently no way to detect the address space used
|
|
|
|
to trigger the watchpoint. For now just consider it is the
|
|
|
|
current default ASC. This turn to be true except when MVCP
|
|
|
|
and MVCS instrutions are not used. */
|
|
|
|
env->per_perc_atmid |= env->psw.mask & (PSW_MASK_ASC) >> 46;
|
|
|
|
|
2021-06-15 05:07:40 +02:00
|
|
|
/*
|
|
|
|
* Remove all watchpoints to re-execute the code. A PER exception
|
|
|
|
* will be triggered, it will call s390_cpu_set_psw which will
|
|
|
|
* recompute the watchpoints.
|
|
|
|
*/
|
2017-07-24 10:52:49 +02:00
|
|
|
cpu_watchpoint_remove_all(cs, BP_CPU);
|
|
|
|
cpu_loop_exit_noexc(cs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void s390x_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
|
|
|
|
MMUAccessType access_type,
|
|
|
|
int mmu_idx, uintptr_t retaddr)
|
|
|
|
{
|
2021-10-04 19:40:57 +02:00
|
|
|
do_unaligned_access(cs, retaddr);
|
2017-07-24 10:52:49 +02:00
|
|
|
}
|
|
|
|
|
2022-04-20 15:26:02 +02:00
|
|
|
static G_NORETURN
|
|
|
|
void monitor_event(CPUS390XState *env,
|
|
|
|
uint64_t monitor_code,
|
|
|
|
uint8_t monitor_class, uintptr_t ra)
|
2020-09-18 10:51:22 +02:00
|
|
|
{
|
|
|
|
/* Store the Monitor Code and the Monitor Class Number into the lowcore */
|
|
|
|
stq_phys(env_cpu(env)->as,
|
|
|
|
env->psa + offsetof(LowCore, monitor_code), monitor_code);
|
|
|
|
stw_phys(env_cpu(env)->as,
|
|
|
|
env->psa + offsetof(LowCore, mon_class_num), monitor_class);
|
|
|
|
|
|
|
|
tcg_s390_program_interrupt(env, PGM_MONITOR, ra);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(monitor_call)(CPUS390XState *env, uint64_t monitor_code,
|
|
|
|
uint32_t monitor_class)
|
|
|
|
{
|
|
|
|
g_assert(monitor_class <= 0xff);
|
|
|
|
|
|
|
|
if (env->cregs[8] & (0x8000 >> monitor_class)) {
|
|
|
|
monitor_event(env, monitor_code, monitor_class, GETPC());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 17:39:19 +01:00
|
|
|
#endif /* !CONFIG_USER_ONLY */
|