title: x86_64: Can I change the VM flag in the EFLAGS register?
body: <p>Can I change the VM flag in the EFLAGS register? If so, how?</p>
  
  <p>Note that I can't just use <code>pushf</code>, manipulate the value on the stack, and then <code>popf</code>. According to the <a href="https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf" rel="nofollow noreferrer">Intel manual</a>:</p>
  
  <p>Volume 2, Chapter 4.3 PUSHF:</p>
  
  <blockquote>
    <p>"When copying the entire EFLAGS register to the stack, the VM and RF
    flags (bits 16 and 17) are not copied; instead, the values for these
    flags are cleared in the EFLAGS image stored on the stack."</p>
  </blockquote>
  
  <p>Volume 2, Chapter 4.3 POPF:</p>
  
  <blockquote>
    <p>"When operating in protected, compatibility, or 64-bit mode at
    privilege level 0 (or in real-address mode, the equiv- alent to
    privilege level 0), all non-reserved flags in the EFLAGS register
    except RF1, VIP, VIF, and VM may be modi- fied. VIP, VIF and VM remain
    unaffected."</p>
  </blockquote>