This question is in reference to:
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"
__asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27"
– osgxxsave [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.
– Jesterxsave [something]
, loadedx
andeax
any way you want – harold