2009-12-05 19:44:21 +08:00
|
|
|
/*
|
|
|
|
* S/390 helpers
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Ulrich Hecht
|
2011-03-23 17:58:07 +08:00
|
|
|
* Copyright (c) 2011 Alexander Graf
|
2009-12-05 19:44:21 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
2010-03-07 23:48:43 +08:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2009-12-05 19:44:21 +08:00
|
|
|
*/
|
|
|
|
|
2016-01-27 02:17:00 +08:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 16:01:28 +08:00
|
|
|
#include "qapi/error.h"
|
2009-12-05 19:44:21 +08:00
|
|
|
#include "cpu.h"
|
2017-08-18 19:43:49 +08:00
|
|
|
#include "internal.h"
|
2012-12-18 01:19:49 +08:00
|
|
|
#include "exec/gdbstub.h"
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/timer.h"
|
2016-03-15 20:18:37 +08:00
|
|
|
#include "exec/exec-all.h"
|
2015-12-04 19:06:26 +08:00
|
|
|
#include "hw/s390x/ioinst.h"
|
2011-10-07 15:51:50 +08:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2012-12-18 01:20:04 +08:00
|
|
|
#include "sysemu/sysemu.h"
|
2011-10-07 15:51:50 +08:00
|
|
|
#endif
|
2009-12-05 19:44:21 +08:00
|
|
|
|
2011-03-23 17:58:07 +08:00
|
|
|
//#define DEBUG_S390
|
|
|
|
//#define DEBUG_S390_STDOUT
|
|
|
|
|
|
|
|
#ifdef DEBUG_S390
|
|
|
|
#ifdef DEBUG_S390_STDOUT
|
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
do { fprintf(stderr, fmt, ## __VA_ARGS__); \
|
2015-11-13 20:16:27 +08:00
|
|
|
if (qemu_log_separate()) qemu_log(fmt, ##__VA_ARGS__); } while (0)
|
2011-03-23 17:58:07 +08:00
|
|
|
#else
|
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
do { qemu_log(fmt, ## __VA_ARGS__); } while (0)
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
2012-04-02 19:56:29 +08:00
|
|
|
void s390x_tod_timer(void *opaque)
|
2011-03-23 17:58:07 +08:00
|
|
|
{
|
2017-09-29 04:36:39 +08:00
|
|
|
cpu_inject_clock_comparator((S390CPU *) opaque);
|
2011-03-23 17:58:07 +08:00
|
|
|
}
|
|
|
|
|
2012-04-02 19:56:29 +08:00
|
|
|
void s390x_cpu_timer(void *opaque)
|
2011-03-23 17:58:07 +08:00
|
|
|
{
|
2017-09-29 04:36:39 +08:00
|
|
|
cpu_inject_cpu_timer((S390CPU *) opaque);
|
2011-03-23 17:58:07 +08:00
|
|
|
}
|
|
|
|
#endif
|
2009-12-05 19:44:26 +08:00
|
|
|
|
2017-09-13 21:24:15 +08:00
|
|
|
S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, Error **errp)
|
2009-12-05 19:44:21 +08:00
|
|
|
{
|
2017-09-13 21:24:15 +08:00
|
|
|
S390CPU *cpu = S390_CPU(object_new(typename));
|
2016-03-05 01:34:34 +08:00
|
|
|
Error *err = NULL;
|
|
|
|
|
2017-09-13 21:24:08 +08:00
|
|
|
object_property_set_int(OBJECT(cpu), core_id, "core-id", &err);
|
2016-03-05 01:34:34 +08:00
|
|
|
if (err != NULL) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
object_property_set_bool(OBJECT(cpu), true, "realized", &err);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
object_unref(OBJECT(cpu));
|
|
|
|
cpu = NULL;
|
|
|
|
}
|
|
|
|
return cpu;
|
|
|
|
}
|
|
|
|
|
2017-07-24 16:52:49 +08:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2011-03-23 17:58:07 +08:00
|
|
|
|
2013-06-30 00:55:54 +08:00
|
|
|
hwaddr s390_cpu_get_phys_page_debug(CPUState *cs, vaddr vaddr)
|
2011-03-23 17:58:07 +08:00
|
|
|
{
|
2013-06-30 00:55:54 +08:00
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
CPUS390XState *env = &cpu->env;
|
2011-03-23 17:58:07 +08:00
|
|
|
target_ulong raddr;
|
2015-02-13 01:09:22 +08:00
|
|
|
int prot;
|
2011-03-23 17:58:07 +08:00
|
|
|
uint64_t asc = env->psw.mask & PSW_MASK_ASC;
|
|
|
|
|
|
|
|
/* 31-Bit mode */
|
|
|
|
if (!(env->psw.mask & PSW_MASK_64)) {
|
|
|
|
vaddr &= 0x7fffffff;
|
|
|
|
}
|
|
|
|
|
2015-12-09 23:36:42 +08:00
|
|
|
if (mmu_translate(env, vaddr, MMU_INST_FETCH, asc, &raddr, &prot, false)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-03-23 17:58:07 +08:00
|
|
|
return raddr;
|
|
|
|
}
|
|
|
|
|
2012-09-03 19:09:10 +08:00
|
|
|
hwaddr s390_cpu_get_phys_addr_debug(CPUState *cs, vaddr vaddr)
|
|
|
|
{
|
|
|
|
hwaddr phys_addr;
|
|
|
|
target_ulong page;
|
|
|
|
|
|
|
|
page = vaddr & TARGET_PAGE_MASK;
|
|
|
|
phys_addr = cpu_get_phys_page_debug(cs, page);
|
|
|
|
phys_addr += (vaddr & ~TARGET_PAGE_MASK);
|
|
|
|
|
|
|
|
return phys_addr;
|
|
|
|
}
|
|
|
|
|
2012-03-14 08:38:22 +08:00
|
|
|
void load_psw(CPUS390XState *env, uint64_t mask, uint64_t addr)
|
2011-03-23 17:58:07 +08:00
|
|
|
{
|
2015-06-13 06:46:00 +08:00
|
|
|
uint64_t old_mask = env->psw.mask;
|
|
|
|
|
2014-09-30 16:57:29 +08:00
|
|
|
env->psw.addr = addr;
|
|
|
|
env->psw.mask = mask;
|
2015-02-24 21:15:29 +08:00
|
|
|
if (tcg_enabled()) {
|
|
|
|
env->cc_op = (mask >> 44) & 3;
|
|
|
|
}
|
2014-09-30 16:57:29 +08:00
|
|
|
|
2015-06-13 06:46:00 +08:00
|
|
|
if ((old_mask ^ mask) & PSW_MASK_PER) {
|
|
|
|
s390_cpu_recompute_watchpoints(CPU(s390_env_get_cpu(env)));
|
|
|
|
}
|
|
|
|
|
2011-03-23 17:58:07 +08:00
|
|
|
if (mask & PSW_MASK_WAIT) {
|
2013-01-30 20:48:25 +08:00
|
|
|
S390CPU *cpu = s390_env_get_cpu(env);
|
2014-09-30 16:57:29 +08:00
|
|
|
if (s390_cpu_halt(cpu) == 0) {
|
2011-10-07 15:51:50 +08:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2017-05-16 05:41:13 +08:00
|
|
|
qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
|
2011-10-07 15:51:50 +08:00
|
|
|
#endif
|
2011-03-23 17:58:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 16:52:49 +08:00
|
|
|
uint64_t get_psw_mask(CPUS390XState *env)
|
2011-03-23 17:58:07 +08:00
|
|
|
{
|
2015-02-24 21:15:29 +08:00
|
|
|
uint64_t r = env->psw.mask;
|
2011-03-23 17:58:07 +08:00
|
|
|
|
2015-02-24 21:15:29 +08:00
|
|
|
if (tcg_enabled()) {
|
|
|
|
env->cc_op = calc_cc(env, env->cc_op, env->cc_src, env->cc_dst,
|
|
|
|
env->cc_vr);
|
2011-03-23 17:58:07 +08:00
|
|
|
|
2015-02-24 21:15:29 +08:00
|
|
|
r &= ~PSW_MASK_CC;
|
|
|
|
assert(!(env->cc_op & ~3));
|
|
|
|
r |= (uint64_t)env->cc_op << 44;
|
|
|
|
}
|
2011-03-23 17:58:07 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2017-07-24 16:52:49 +08:00
|
|
|
LowCore *cpu_map_lowcore(CPUS390XState *env)
|
2013-01-24 10:28:01 +08:00
|
|
|
{
|
2013-09-03 23:38:47 +08:00
|
|
|
S390CPU *cpu = s390_env_get_cpu(env);
|
2013-01-24 10:28:01 +08:00
|
|
|
LowCore *lowcore;
|
|
|
|
hwaddr len = sizeof(LowCore);
|
|
|
|
|
|
|
|
lowcore = cpu_physical_memory_map(env->psa, &len, 1);
|
|
|
|
|
|
|
|
if (len < sizeof(LowCore)) {
|
2013-09-03 23:38:47 +08:00
|
|
|
cpu_abort(CPU(cpu), "Could not map lowcore\n");
|
2013-01-24 10:28:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return lowcore;
|
|
|
|
}
|
|
|
|
|
2017-07-24 16:52:49 +08:00
|
|
|
void cpu_unmap_lowcore(LowCore *lowcore)
|
2013-01-24 10:28:01 +08:00
|
|
|
{
|
|
|
|
cpu_physical_memory_unmap(lowcore, sizeof(LowCore), 1, sizeof(LowCore));
|
|
|
|
}
|
|
|
|
|
2015-02-24 21:15:29 +08:00
|
|
|
void do_restart_interrupt(CPUS390XState *env)
|
|
|
|
{
|
|
|
|
uint64_t mask, addr;
|
|
|
|
LowCore *lowcore;
|
|
|
|
|
|
|
|
lowcore = cpu_map_lowcore(env);
|
|
|
|
|
|
|
|
lowcore->restart_old_psw.mask = cpu_to_be64(get_psw_mask(env));
|
|
|
|
lowcore->restart_old_psw.addr = cpu_to_be64(env->psw.addr);
|
|
|
|
mask = be64_to_cpu(lowcore->restart_new_psw.mask);
|
|
|
|
addr = be64_to_cpu(lowcore->restart_new_psw.addr);
|
|
|
|
|
|
|
|
cpu_unmap_lowcore(lowcore);
|
|
|
|
|
|
|
|
load_psw(env, mask, addr);
|
|
|
|
}
|
|
|
|
|
2015-06-13 06:46:00 +08:00
|
|
|
void s390_cpu_recompute_watchpoints(CPUState *cs)
|
|
|
|
{
|
|
|
|
const int wp_flags = BP_CPU | BP_MEM_WRITE | BP_STOP_BEFORE_ACCESS;
|
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
|
|
|
|
/* We are called when the watchpoints have changed. First
|
|
|
|
remove them all. */
|
|
|
|
cpu_watchpoint_remove_all(cs, BP_CPU);
|
|
|
|
|
|
|
|
/* Return if PER is not enabled */
|
|
|
|
if (!(env->psw.mask & PSW_MASK_PER)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return if storage-alteration event is not enabled. */
|
|
|
|
if (!(env->cregs[9] & PER_CR9_EVENT_STORE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (env->cregs[10] == 0 && env->cregs[11] == -1LL) {
|
|
|
|
/* We can't create a watchoint spanning the whole memory range, so
|
|
|
|
split it in two parts. */
|
|
|
|
cpu_watchpoint_insert(cs, 0, 1ULL << 63, wp_flags, NULL);
|
|
|
|
cpu_watchpoint_insert(cs, 1ULL << 63, 1ULL << 63, wp_flags, NULL);
|
|
|
|
} else if (env->cregs[10] > env->cregs[11]) {
|
|
|
|
/* The address range loops, create two watchpoints. */
|
|
|
|
cpu_watchpoint_insert(cs, env->cregs[10], -env->cregs[10],
|
|
|
|
wp_flags, NULL);
|
|
|
|
cpu_watchpoint_insert(cs, 0, env->cregs[11] + 1, wp_flags, NULL);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Default case, create a single watchpoint. */
|
|
|
|
cpu_watchpoint_insert(cs, env->cregs[10],
|
|
|
|
env->cregs[11] - env->cregs[10] + 1,
|
|
|
|
wp_flags, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-23 17:58:07 +08:00
|
|
|
#endif /* CONFIG_USER_ONLY */
|
2017-07-24 16:52:46 +08:00
|
|
|
|
|
|
|
void s390_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
CPUS390XState *env = &cpu->env;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (env->cc_op > 3) {
|
|
|
|
cpu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64 " cc %15s\n",
|
|
|
|
env->psw.mask, env->psw.addr, cc_name(env->cc_op));
|
|
|
|
} else {
|
|
|
|
cpu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64 " cc %02x\n",
|
|
|
|
env->psw.mask, env->psw.addr, env->cc_op);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
cpu_fprintf(f, "R%02d=%016" PRIx64, i, env->regs[i]);
|
|
|
|
if ((i % 4) == 3) {
|
|
|
|
cpu_fprintf(f, "\n");
|
|
|
|
} else {
|
|
|
|
cpu_fprintf(f, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
cpu_fprintf(f, "F%02d=%016" PRIx64, i, get_freg(env, i)->ll);
|
|
|
|
if ((i % 4) == 3) {
|
|
|
|
cpu_fprintf(f, "\n");
|
|
|
|
} else {
|
|
|
|
cpu_fprintf(f, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
cpu_fprintf(f, "V%02d=%016" PRIx64 "%016" PRIx64, i,
|
|
|
|
env->vregs[i][0].ll, env->vregs[i][1].ll);
|
|
|
|
cpu_fprintf(f, (i % 2) ? "\n" : " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
cpu_fprintf(f, "C%02d=%016" PRIx64, i, env->cregs[i]);
|
|
|
|
if ((i % 4) == 3) {
|
|
|
|
cpu_fprintf(f, "\n");
|
|
|
|
} else {
|
|
|
|
cpu_fprintf(f, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_INLINE_BRANCHES
|
|
|
|
for (i = 0; i < CC_OP_MAX; i++) {
|
|
|
|
cpu_fprintf(f, " %15s = %10ld\t%10ld\n", cc_name(i),
|
|
|
|
inline_branch_miss[i], inline_branch_hit[i]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cpu_fprintf(f, "\n");
|
|
|
|
}
|
2017-08-18 19:43:44 +08:00
|
|
|
|
|
|
|
const char *cc_name(enum cc_op cc_op)
|
|
|
|
{
|
|
|
|
static const char * const cc_names[] = {
|
|
|
|
[CC_OP_CONST0] = "CC_OP_CONST0",
|
|
|
|
[CC_OP_CONST1] = "CC_OP_CONST1",
|
|
|
|
[CC_OP_CONST2] = "CC_OP_CONST2",
|
|
|
|
[CC_OP_CONST3] = "CC_OP_CONST3",
|
|
|
|
[CC_OP_DYNAMIC] = "CC_OP_DYNAMIC",
|
|
|
|
[CC_OP_STATIC] = "CC_OP_STATIC",
|
|
|
|
[CC_OP_NZ] = "CC_OP_NZ",
|
|
|
|
[CC_OP_LTGT_32] = "CC_OP_LTGT_32",
|
|
|
|
[CC_OP_LTGT_64] = "CC_OP_LTGT_64",
|
|
|
|
[CC_OP_LTUGTU_32] = "CC_OP_LTUGTU_32",
|
|
|
|
[CC_OP_LTUGTU_64] = "CC_OP_LTUGTU_64",
|
|
|
|
[CC_OP_LTGT0_32] = "CC_OP_LTGT0_32",
|
|
|
|
[CC_OP_LTGT0_64] = "CC_OP_LTGT0_64",
|
|
|
|
[CC_OP_ADD_64] = "CC_OP_ADD_64",
|
|
|
|
[CC_OP_ADDU_64] = "CC_OP_ADDU_64",
|
|
|
|
[CC_OP_ADDC_64] = "CC_OP_ADDC_64",
|
|
|
|
[CC_OP_SUB_64] = "CC_OP_SUB_64",
|
|
|
|
[CC_OP_SUBU_64] = "CC_OP_SUBU_64",
|
|
|
|
[CC_OP_SUBB_64] = "CC_OP_SUBB_64",
|
|
|
|
[CC_OP_ABS_64] = "CC_OP_ABS_64",
|
|
|
|
[CC_OP_NABS_64] = "CC_OP_NABS_64",
|
|
|
|
[CC_OP_ADD_32] = "CC_OP_ADD_32",
|
|
|
|
[CC_OP_ADDU_32] = "CC_OP_ADDU_32",
|
|
|
|
[CC_OP_ADDC_32] = "CC_OP_ADDC_32",
|
|
|
|
[CC_OP_SUB_32] = "CC_OP_SUB_32",
|
|
|
|
[CC_OP_SUBU_32] = "CC_OP_SUBU_32",
|
|
|
|
[CC_OP_SUBB_32] = "CC_OP_SUBB_32",
|
|
|
|
[CC_OP_ABS_32] = "CC_OP_ABS_32",
|
|
|
|
[CC_OP_NABS_32] = "CC_OP_NABS_32",
|
|
|
|
[CC_OP_COMP_32] = "CC_OP_COMP_32",
|
|
|
|
[CC_OP_COMP_64] = "CC_OP_COMP_64",
|
|
|
|
[CC_OP_TM_32] = "CC_OP_TM_32",
|
|
|
|
[CC_OP_TM_64] = "CC_OP_TM_64",
|
|
|
|
[CC_OP_NZ_F32] = "CC_OP_NZ_F32",
|
|
|
|
[CC_OP_NZ_F64] = "CC_OP_NZ_F64",
|
|
|
|
[CC_OP_NZ_F128] = "CC_OP_NZ_F128",
|
|
|
|
[CC_OP_ICM] = "CC_OP_ICM",
|
|
|
|
[CC_OP_SLA_32] = "CC_OP_SLA_32",
|
|
|
|
[CC_OP_SLA_64] = "CC_OP_SLA_64",
|
|
|
|
[CC_OP_FLOGR] = "CC_OP_FLOGR",
|
|
|
|
};
|
|
|
|
|
|
|
|
return cc_names[cc_op];
|
|
|
|
}
|