[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 25/30] x86emul: support APX+MOVBE insn


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 11 Nov 2026 15:30:37 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID"
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>
  • Delivery-date: Wed, 11 Nov 2026 14:30:42 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Besides adding table entries and case labels there's very little to do
here; generic map 4 handling takes care of things.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/tools/tests/x86_emulator/evex-disp8.c
+++ b/tools/tests/x86_emulator/evex-disp8.c
@@ -1159,6 +1159,13 @@ static const struct test lzcnt[] = {
     INSN(lzcntw,    66, map4, f5,    el,    w, no),
 };
 
+static const struct test movbe[] = {
+    INSN(movbe,       , map4, 60,    el,   dq, no),
+    INSN(movbe,       , map4, 61,    el,   dq, no),
+    INSN(movbew,    66, map4, 60,    el,    w, no),
+    INSN(movbew,    66, map4, 61,    el,    w, no),
+};
+
 static const struct test popcnt[] = {
     INSN(popcnt,      , map4, 88,    el,   dq, no),
     INSN(popcntw,   66, map4, 88,    el,    w, no),
@@ -1756,6 +1763,7 @@ void evex_disp8_test(void *instr, struct
         RUN(bmi2);
         RUN(cmpccxadd);
         RUN(lzcnt);
+        RUN(movbe);
         RUN(popcnt);
 
 #undef RUN
--- a/tools/tests/x86_emulator/predicates.c
+++ b/tools/tests/x86_emulator/predicates.c
@@ -2202,6 +2202,10 @@ static const struct evex {
     CND(0x40,   2, T, R, pfx_no, Wn, L0, ND ), /* {,cf}cmov<cc> */ \
     CND(0x40,   2, T, R, pfx_66, Wn, L0, ND ), /* {,cf}cmov<cc> */ \
     CND(0x40,   2, T, W, pfx_f2, WIG, L0 ), /* set<cc> */
+    { { 0x60 }, 2, T, R, pfx_no, Wn, L0 }, /* movbe */
+    { { 0x60 }, 2, T, R, pfx_66, Wn, L0 }, /* movbe */
+    { { 0x61 }, 2, T, W, pfx_no, Wn, L0 }, /* movbe */
+    { { 0x61 }, 2, T, W, pfx_66, Wn, L0 }, /* movbe */
     { { 0x66 }, 2, T, R, pfx_66, Wn, L0 }, /* adcx */
     { { 0x66 }, 2, T, R, pfx_f3, Wn, L0 }, /* adox */
     { { 0x69 }, 6, T, R, pfx_no, Wn, L0 }, /* imul */
--- a/tools/tests/x86_emulator/test_x86_emulator.c
+++ b/tools/tests/x86_emulator/test_x86_emulator.c
@@ -2475,6 +2475,35 @@ int main(int argc, char **argv)
         goto fail;
     printf("okay\n");
 
+#ifdef __x86_64__
+    printf("%-40s", "Testing movbe %rax,%rcx...");
+    instr[0] = 0x62; instr[1] = 0xf4; instr[2] = 0xfc; instr[3] = 0x08;
+    instr[4] = 0x60; instr[5] = 0xc8;
+    regs.rip = (unsigned long)&instr[0];
+    rc = x86_emulate(&ctxt, &emulops);
+    if ( (rc != X86EMUL_OKAY) ||
+         (regs.rcx != 0x1234567800000000UL) ||
+         (regs.rip != (unsigned long)&instr[6]) )
+        goto fail;
+    printf("okay\n");
+
+    if ( cpu_has_apx_f )
+    {
+        printf("%-40s", "Testing movbe %r30w,2(%r31)...");
+        instr[1] = 0x4c; instr[2] = 0x7d;
+        instr[4] = 0x61; instr[5] = 0x77; instr[6] = 0x02;
+        regs.rip = (unsigned long)&instr[0];
+        load_egpr(30, 0x12345678);
+        load_egpr(31, (unsigned long)res);
+        rc = x86_emulate(&ctxt, &emulops);
+        if ( (rc != X86EMUL_OKAY) ||
+             (*res != 0x78561234) ||
+             (regs.rip != (unsigned long)&instr[7]) )
+            goto fail;
+        printf("okay\n");
+    }
+#endif
+
     printf("%-40s", "Testing popcnt (%edx),%cx...");
     if ( cpu_has_popcnt )
     {
--- a/tools/tests/x86_emulator/x86-emulate.h
+++ b/tools/tests/x86_emulator/x86-emulate.h
@@ -168,6 +168,7 @@ void wrpkru(unsigned int val);
 #define cpu_has_fma                 (cpu_policy.basic.fma && xcr0_mask(6))
 #define cpu_has_sse4_1               cpu_policy.basic.sse4_1
 #define cpu_has_sse4_2               cpu_policy.basic.sse4_2
+#define cpu_has_movbe                cpu_policy.basic.movbe
 #define cpu_has_popcnt               cpu_policy.basic.popcnt
 #define cpu_has_aesni                cpu_policy.basic.aesni
 #define cpu_has_avx                 (cpu_policy.basic.avx  && xcr0_mask(6))
--- a/xen/arch/x86/x86_emulate/decode.c
+++ b/xen/arch/x86/x86_emulate/decode.c
@@ -691,6 +691,14 @@ static const struct map4_table {
         [vex_f2] = { .to_mem = true, .byte = true, .nd = true,
                      .nci_ndd_nf = true },
     },
+    [0x60] = { /* MOVBE ({,d,q}word) */
+        [vex_np] = { },
+        [vex_66] = { },
+    },
+    [0x61] = { /* MOVBE ({,d,q}word) */
+        [vex_np] = { .to_mem = true },
+        [vex_66] = { .to_mem = true },
+    },
     [0x66] = {
         [vex_66] = { .nd = true }, /* ADCX */
         [vex_f3] = { .nd = true }, /* ADOX */
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -7345,6 +7345,11 @@ x86_emulate(
     case X86EMUL_OPC(0x0f38, 0xf0): /* movbe m,r */
     case X86EMUL_OPC(0x0f38, 0xf1): /* movbe r,m */
         generate_exception_if(ea.type != OP_MEM, X86_EXC_UD);
+        fallthrough;
+    case X86EMUL_OPC_EVEX   (4, 0x60): /* movbe r/m,reg */
+    case X86EMUL_OPC_EVEX_66(4, 0x60): /* movbe r/m,r16 */
+    case X86EMUL_OPC_EVEX   (4, 0x61): /* movbe reg,r/m */
+    case X86EMUL_OPC_EVEX_66(4, 0x61): /* movbe r16,r/m */
         vcpu_must_have(movbe);
         switch ( op_bytes )
         {




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.