From 28f002cbafb5011ccfec7bbe2452de0b0fbcadb4 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Mon, 26 Feb 2018 04:36:09 -0500 Subject: [PATCH] target-i386: xsave: Helper function to calculate xsave area size Move the xsave area size calculation from cpu_x86_cpuid() inside its own function. While doing it, change it to use the XSAVE area struct sizes for the initial size, instead of the magic 0x240 number. Backports commit 1fda6198e4126af9988754c8824cfc9928649890 from qemu --- qemu/target-i386/cpu.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/qemu/target-i386/cpu.c b/qemu/target-i386/cpu.c index 264eb0fc..544ef548 100644 --- a/qemu/target-i386/cpu.c +++ b/qemu/target-i386/cpu.c @@ -607,6 +607,20 @@ static const ExtSaveArea x86_ext_save_areas[] = { }, }; +static uint32_t xsave_area_size(uint64_t mask) +{ + int i; + uint64_t ret = sizeof(X86LegacyXSaveArea) + sizeof(X86XSaveHeader); + + for (i = 2; i < ARRAY_SIZE(x86_ext_save_areas); i++) { + const ExtSaveArea *esa = &x86_ext_save_areas[i]; + if ((mask >> i) & 1) { + ret = MAX(ret, esa->offset + esa->size); + } + } + return ret; +} + const char *get_register_name_32(unsigned int reg) { if (reg >= CPU_NB_REGS32) { @@ -2546,13 +2560,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } */ if (count == 0) { - *ecx = 0x240; - for (i = 2; i < ARRAY_SIZE(x86_ext_save_areas); i++) { - const ExtSaveArea *esa = &x86_ext_save_areas[i]; - if ((ena_mask >> i) & 1) { - *ecx = MAX(*ecx, esa->offset + esa->size); - } - } + *ecx = xsave_area_size(ena_mask); *eax = ena_mask; *edx = ena_mask >> 32; *ebx = *ecx;