3
votes

This question is in reference to:

Intel x86-64 XSAVE/XRSTOR

This question is about how to use XSAVE and XRSTOR. Unfortunately, due to the very odd reputation system on this site, I can't simply ask my question on that thread, I have to make a new question. One person answered this question but did not use the Intel x86 commands XSAVE and XRSTOR. So, really, the question wasn't answered.

Is there some way anyone can put a single example of how to use XSAVE and XRSTOR so that we don't have to copy every register to memory individually to preserve it.

Right now we have to:

copy xmm0 to memory, copy xmm1 to memory... and so on

Then:

right shift ymm0 64 bytes, right shift ymm1 64 bytes... and so on

Then:

repeat 3 times.

So to save the ymm registers, we need about 100 commands.

Then to restore them is about the same.

Now, it seems that Intel x86 assembly has an instruction to do this all at once. The command in Intel x86 syntax is:

xsave [mem], flag

and

xrstor [mem], flag

So, I should be able to (e.g.) just reserve memory in the .data segment like so:

regsave times 1024 dq 0

and then say

xsave [regsave], flag

What is flag? In the huge assembly manual (which has no examples) it says that any registers that can be saved will be ANDed with the flag to determine which ones WILL be saved. It says the flag is 32 bits. So I SHOULD be able to just say:

xsave [regsave], 0xFFFFFFFF

and have it save any registers that it can.

This unfortunately doesn't work. The code will not assemble and gives the error:

"error: invalid combination of opcode and operands"

1
Linux kernel uses explicit byte codes (x86 machine code): lwn.net/Articles/281921 __asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27"osgx
This isn't the right place to complain about Stack Overflow. If you have a grievance, post it on Meta. Keep this post to the point.Kerrek SB
Not sure where you have found that the format of the instruction is xsave [mem], flag and that flag is 32 bits. In fact if you look up the relevant section in the instruction set reference, you can see it says: The implicit EDX:EAX register pair specifies a 64-bit instruction mask. Jester
What is Meta? I found the inability to ask my question a bit annoying, but I also wanted to explain that I wasn't mindlessly copying an existing question, that is, there was a reason for it. @osgx Thanks for the tip. I'll take a look.C_Rod
@C_Rod xsave [something], load edx and eax any way you wantharold

1 Answers

1
votes

XSAVE / XRSTOR doesn't have a parameters for flag, only memory location,

the spec is:

XSAVE mem
XRSTOR mem

the values in EDX:EAX specified which components to save/restore to the memory.