Intel x86-64 XSAVE/XRSTOR

后端 未结 2 1945
感动是毒
感动是毒 2021-01-04 12:33

I\'m a CS student writing in Intel x86-64 assembly, compiling with nasm, and running on an Core i7 processor with Ubuntu 12.04 as the guest OS. Does anyone hav

2条回答
  •  醉话见心
    2021-01-04 12:54

    Finally, an answer to this question. Thanks to user: harold who helped answer the question for me. A summary of what I've found:

    Set up a memory space in .data and align it on a 64-byte boundary. Then you can use the commands with that memory space. If you want to use the stack, you should be able to do so similarly ensuring that the stack is 64-byte aligned, but this way seems easier to me for this purpose.

    eax: edx is used to set the flags of which registers you WANT to save, restore. This combined is 64-bits and is ANDed with an internal control which knows which registers you CAN save/restore (this allows processors that don't have ymm for example to ignore those registers) I find it easiest to just set all bits on and save / restore everything:

    segment .data

    align   64
    regsave times 1024 dq 0
    

    segment .text

    mov     rdx, 0xFFFFFFFFFFFFFFFF
    mov     rax, 0xFFFFFFFFFFFFFFFF
    xsave   [regsave]
    
    vzeroall
    
    mov     rdx, 0xFFFFFFFFFFFFFFFF
    mov     rax, 0xFFFFFFFFFFFFFFFF
    xrstor  [regsave]
    

提交回复
热议问题