s390x/tcg: refactor stfl(e) to use s390_get_feat_block()

Refactor it to use s390_get_feat_block(). Directly write into the mapped
lowcore with stfl and make sure it is really only compiled if needed.

While at it, add an alignment check for STFLE and avoid
potential_page_fault() by properly restoring the CPU state.

Due to s390_get_feat_block(), we will now also indicate the
"Configuration-z-architectural-mode", which is with new SIGP code the
right thing to do.

Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20170928203708.9376-30-david@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
This commit is contained in:
David Hildenbrand 2017-09-28 22:37:07 +02:00 committed by Cornelia Huck
parent 0fc60ca58a
commit f74990a5d0
2 changed files with 29 additions and 39 deletions

View File

@ -475,66 +475,57 @@ void HELPER(per_ifetch)(CPUS390XState *env, uint64_t addr)
} }
#endif #endif
/* The maximum bit defined at the moment is 129. */ static uint8_t stfl_bytes[2048];
#define MAX_STFL_WORDS 3 static unsigned int used_stfl_bytes;
/* Canonicalize the current cpu's features into the 64-bit words required static void prepare_stfl(void)
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])
{ {
S390CPU *cpu = s390_env_get_cpu(env); static bool initialized;
const unsigned long *features = cpu->model->features; int i;
unsigned max_bit = 0;
S390Feat feat;
memset(words, 0, sizeof(uint64_t) * MAX_STFL_WORDS); /* racy, but we don't care, the same values are always written */
if (initialized) {
if (test_bit(S390_FEAT_ZARCH, features)) { return;
/* z/Architecture is always active if around */
words[0] = 1ull << (63 - 2);
} }
for (feat = find_first_bit(features, S390_FEAT_MAX); s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes);
feat < S390_FEAT_MAX; for (i = 0; i < sizeof(stfl_bytes); i++) {
feat = find_next_bit(features, S390_FEAT_MAX, feat + 1)) { if (stfl_bytes[i]) {
const S390FeatDef *def = s390_feat_def(feat); used_stfl_bytes = i + 1;
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);
} }
} }
initialized = true;
return max_bit / 64;
} }
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
void HELPER(stfl)(CPUS390XState *env) void HELPER(stfl)(CPUS390XState *env)
{ {
uint64_t words[MAX_STFL_WORDS];
LowCore *lowcore; LowCore *lowcore;
lowcore = cpu_map_lowcore(env); lowcore = cpu_map_lowcore(env);
do_stfle(env, words); prepare_stfl();
lowcore->stfl_fac_list = cpu_to_be32(words[0] >> 32); memcpy(&lowcore->stfl_fac_list, stfl_bytes, sizeof(lowcore->stfl_fac_list));
cpu_unmap_lowcore(lowcore); cpu_unmap_lowcore(lowcore);
} }
#endif #endif
uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr) uint32_t HELPER(stfle)(CPUS390XState *env, uint64_t addr)
{ {
uint64_t words[MAX_STFL_WORDS]; const uintptr_t ra = GETPC();
unsigned count_m1 = env->regs[0] & 0xff; const int count_bytes = ((env->regs[0] & 0xff) + 1) * 8;
unsigned max_m1 = do_stfle(env, words); const int max_bytes = ROUND_UP(used_stfl_bytes, 8);
unsigned i; int i;
for (i = 0; i <= count_m1; ++i) { if (addr & 0x7) {
cpu_stq_data(env, addr + 8 * i, words[i]); cpu_restore_state(ENV_GET_CPU(env), ra);
program_interrupt(env, PGM_SPECIFICATION, 4);
} }
env->regs[0] = deposit64(env->regs[0], 0, 8, max_m1); prepare_stfl();
return (count_m1 >= max_m1 ? 0 : 3); 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_bytes / 8) - 1);
return count_bytes >= max_bytes ? 0 : 3;
} }

View File

@ -4143,7 +4143,6 @@ static ExitStatus op_sturg(DisasContext *s, DisasOps *o)
static ExitStatus op_stfle(DisasContext *s, DisasOps *o) static ExitStatus op_stfle(DisasContext *s, DisasOps *o)
{ {
potential_page_fault(s);
gen_helper_stfle(cc_op, cpu_env, o->in2); gen_helper_stfle(cc_op, cpu_env, o->in2);
set_cc_static(s); set_cc_static(s);
return NO_EXIT; return NO_EXIT;