aboutsummaryrefslogtreecommitdiff
path: root/target/s390x/misc_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'target/s390x/misc_helper.c')
-rw-r--r--target/s390x/misc_helper.c109
1 files changed, 35 insertions, 74 deletions
diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
index 0b93381188..4afd90b969 100644
--- a/target/s390x/misc_helper.c
+++ b/target/s390x/misc_helper.c
@@ -319,44 +319,14 @@ uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0,
}
uint32_t HELPER(sigp)(CPUS390XState *env, uint64_t order_code, uint32_t r1,
- uint64_t cpu_addr)
+ uint32_t r3)
{
- int cc = SIGP_CC_ORDER_CODE_ACCEPTED;
+ int cc;
- HELPER_LOG("%s: %016" PRIx64 " %08x %016" PRIx64 "\n",
- __func__, order_code, r1, cpu_addr);
-
- /* Remember: Use "R1 or R1 + 1, whichever is the odd-numbered register"
- as parameter (input). Status (output) is always R1. */
-
- switch (order_code & SIGP_ORDER_MASK) {
- case SIGP_SET_ARCH:
- /* switch arch */
- break;
- case SIGP_SENSE:
- /* enumerate CPU status */
- if (cpu_addr) {
- /* XXX implement when SMP comes */
- return 3;
- }
- env->regs[r1] &= 0xffffffff00000000ULL;
- cc = 1;
- break;
-#if !defined(CONFIG_USER_ONLY)
- case SIGP_RESTART:
- qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
- cpu_loop_exit(CPU(s390_env_get_cpu(env)));
- break;
- case SIGP_STOP:
- qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
- cpu_loop_exit(CPU(s390_env_get_cpu(env)));
- break;
-#endif
- default:
- /* unknown sigp */
- fprintf(stderr, "XXX unknown sigp: 0x%" PRIx64 "\n", order_code);
- cc = SIGP_CC_NOT_OPERATIONAL;
- }
+ /* TODO: needed to inject interrupts - push further down */
+ qemu_mutex_lock_iothread();
+ cc = handle_sigp(env, order_code & SIGP_ORDER_MASK, r1, r3);
+ qemu_mutex_unlock_iothread();
return cc;
}
@@ -505,66 +475,57 @@ void HELPER(per_ifetch)(CPUS390XState *env, uint64_t addr)
}
#endif
-/* The maximum bit defined at the moment is 129. */
-#define MAX_STFL_WORDS 3
+static uint8_t stfl_bytes[2048];
+static unsigned int used_stfl_bytes;
-/* Canonicalize the current cpu's features into the 64-bit words required
- by STFLE. Return the index-1 of the max word that is non-zero. */
-static unsigned do_stfle(CPUS390XState *env, uint64_t words[MAX_STFL_WORDS])
+static void prepare_stfl(void)
{
- S390CPU *cpu = s390_env_get_cpu(env);
- const unsigned long *features = cpu->model->features;
- unsigned max_bit = 0;
- S390Feat feat;
+ static bool initialized;
+ int i;
- memset(words, 0, sizeof(uint64_t) * MAX_STFL_WORDS);
-
- if (test_bit(S390_FEAT_ZARCH, features)) {
- /* z/Architecture is always active if around */
- words[0] = 1ull << (63 - 2);
+ /* racy, but we don't care, the same values are always written */
+ if (initialized) {
+ return;
}
- for (feat = find_first_bit(features, S390_FEAT_MAX);
- feat < S390_FEAT_MAX;
- feat = find_next_bit(features, S390_FEAT_MAX, feat + 1)) {
- const S390FeatDef *def = s390_feat_def(feat);
- if (def->type == S390_FEAT_TYPE_STFL) {
- unsigned bit = def->bit;
- if (bit > max_bit) {
- max_bit = bit;
- }
- assert(bit / 64 < MAX_STFL_WORDS);
- words[bit / 64] |= 1ULL << (63 - bit % 64);
+ s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes);
+ for (i = 0; i < sizeof(stfl_bytes); i++) {
+ if (stfl_bytes[i]) {
+ used_stfl_bytes = i + 1;
}
}
-
- return max_bit / 64;
+ initialized = true;
}
#ifndef CONFIG_USER_ONLY
void HELPER(stfl)(CPUS390XState *env)
{
- uint64_t words[MAX_STFL_WORDS];
LowCore *lowcore;
lowcore = cpu_map_lowcore(env);
- do_stfle(env, words);
- lowcore->stfl_fac_list = cpu_to_be32(words[0] >> 32);
+ prepare_stfl();
+ memcpy(&lowcore->stfl_fac_list, stfl_bytes, sizeof(lowcore->stfl_fac_list));
cpu_unmap_lowcore(lowcore);
}
#endif
uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr)
{
- uint64_t words[MAX_STFL_WORDS];
- unsigned count_m1 = env->regs[0] & 0xff;
- unsigned max_m1 = do_stfle(env, words);
- unsigned i;
+ const uintptr_t ra = GETPC();
+ const int count_bytes = ((env->regs[0] & 0xff) + 1) * 8;
+ const int max_bytes = ROUND_UP(used_stfl_bytes, 8);
+ int i;
+
+ if (addr & 0x7) {
+ cpu_restore_state(ENV_GET_CPU(env), ra);
+ program_interrupt(env, PGM_SPECIFICATION, 4);
+ }
- for (i = 0; i <= count_m1; ++i) {
- cpu_stq_data(env, addr + 8 * i, words[i]);
+ prepare_stfl();
+ for (i = 0; i < count_bytes; ++i) {
+ cpu_stb_data_ra(env, addr + i, stfl_bytes[i], ra);
}
- env->regs[0] = deposit64(env->regs[0], 0, 8, max_m1);
- return (count_m1 >= max_m1 ? 0 : 3);
+ env->regs[0] = deposit64(env->regs[0], 0, 8, (max_bytes / 8) - 1);
+ return count_bytes >= max_bytes ? 0 : 3;
}