Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intel x86-64 XSAVE/XRSTOR

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 have an example of how to use XSAVE and XRSTOR? I've read the section on XSAVE in Intel Architectures Software Developers manual several times. I tried to implement xsave in C++ and then disassemble the binary to get an understanding of what it's doing. And of course I've scoured the Internet for examples. Any suggestions would be much obliged.

like image 806
codepoetchris Avatar asked Feb 28 '14 20:02

codepoetchris


People also ask

How many x86 64 instructions are there?

al. states that the current x86-64 design “contains 981 unique mnemonics and a total of 3,684 instruction variants” [2].

What is Xsavec?

XSAVEC writes the logical AND of RFBM and XINUSE to the XSTATE_BV field of the XSAVE header. 2,3. (See Section 13.4. 2, “XSAVE Header” of Intel® 64 and IA-32 Architectures Software Developer's Manual, Volume 1.) XSAVEC sets bit 63 of the XCOMP_BV field and sets bits 62:0 of that field to RFBM[62:0].


1 Answers

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]
like image 138
C_Rod Avatar answered Oct 14 '22 16:10

C_Rod