xsave_gnu.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. .file "xsave_gnu.S"
  32. #include "linux/linux-regs.h"
  33. .macro DO_XSAVEC
  34. #if defined(LINUX64)
  35. .byte 0x48, 0x0f, 0xc7, 0x21
  36. #else
  37. .byte 0x0f, 0xc7, 0x21
  38. #endif
  39. .endm
  40. .macro DO_XRSTOR
  41. #if defined(LINUX64)
  42. .byte 0x48, 0x0f, 0xae, 0x29
  43. #else
  44. .byte 0x0f, 0xae, 0x29
  45. #endif
  46. .endm
  47. .macro DO_FXSAVE
  48. #if defined(LINUX64)
  49. .byte 0x48, 0x0f, 0xae, 0x01
  50. #else
  51. .byte 0x0f, 0xae, 0x01
  52. #endif
  53. .endm
  54. .macro DO_FXRSTOR
  55. #if defined(LINUX64)
  56. .byte 0x48, 0x0f, 0xae, 0x09
  57. #else
  58. .byte 0x0f, 0xae, 0x09
  59. #endif
  60. .endm
  61. .macro SET_XSAVE_MASK
  62. #ifdef SE_SIM
  63. #if defined(LINUX32)
  64. lea g_xsave_mask_low, %eax
  65. lea g_xsave_mask_high, %edx
  66. #else
  67. mov g_xsave_mask_low@GOTPCREL(%rip), %rax
  68. mov g_xsave_mask_high@GOTPCREL(%rip), %rdx
  69. #endif
  70. movl (%xax), %eax
  71. movl (%xdx), %edx
  72. #else
  73. xor %xax, %xax
  74. xor %xdx, %xdx
  75. mov $0xFFFFFFFF, %eax
  76. mov $0xFFFFFFFF, %edx
  77. #endif
  78. .endm
  79. .section .nipx,"ax",@progbits
  80. DECLARE_LOCAL_FUNC restore_xregs
  81. #if defined(LINUX32)
  82. mov SE_WORDSIZE(%esp), %ecx
  83. lea g_xsave_enabled, %eax
  84. #else
  85. mov %rdi, %rcx
  86. mov g_xsave_enabled@GOTPCREL(%rip), %rax
  87. #endif
  88. movl (%xax), %eax
  89. cmpl $0, %eax
  90. jz 1f
  91. SET_XSAVE_MASK
  92. DO_XRSTOR
  93. jmp 2f
  94. 1:
  95. DO_FXRSTOR
  96. 2:
  97. ret
  98. DECLARE_LOCAL_FUNC save_xregs
  99. #if defined(LINUX32)
  100. mov SE_WORDSIZE(%esp), %ecx
  101. lea g_xsave_enabled, %eax
  102. #else
  103. mov %rdi, %rcx
  104. mov g_xsave_enabled@GOTPCREL(%rip), %rax
  105. #endif
  106. fwait
  107. movl (%xax), %eax
  108. cmpl $0, %eax
  109. jz 1f
  110. SET_XSAVE_MASK
  111. DO_XSAVEC
  112. jmp 2f
  113. 1:
  114. DO_FXSAVE
  115. 2:
  116. ret