msr-reg.S 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <linux/linkage.h>
  2. #include <linux/errno.h>
  3. #include <asm/asm.h>
  4. #include <asm/msr.h>
  5. #ifdef CONFIG_X86_64
  6. /*
  7. * int {rdmsr,wrmsr}_safe_regs(u32 gprs[8]);
  8. *
  9. * reg layout: u32 gprs[eax, ecx, edx, ebx, esp, ebp, esi, edi]
  10. *
  11. */
  12. .macro op_safe_regs op
  13. ENTRY(\op\()_safe_regs)
  14. pushq %rbx
  15. pushq %r12
  16. movq %rdi, %r10 /* Save pointer */
  17. xorl %r11d, %r11d /* Return value */
  18. movl (%rdi), %eax
  19. movl 4(%rdi), %ecx
  20. movl 8(%rdi), %edx
  21. movl 12(%rdi), %ebx
  22. movl 20(%rdi), %r12d
  23. movl 24(%rdi), %esi
  24. movl 28(%rdi), %edi
  25. 1: \op
  26. 2: movl %eax, (%r10)
  27. movl %r11d, %eax /* Return value */
  28. movl %ecx, 4(%r10)
  29. movl %edx, 8(%r10)
  30. movl %ebx, 12(%r10)
  31. movl %r12d, 20(%r10)
  32. movl %esi, 24(%r10)
  33. movl %edi, 28(%r10)
  34. popq %r12
  35. popq %rbx
  36. ret
  37. 3:
  38. movl $-EIO, %r11d
  39. jmp 2b
  40. _ASM_EXTABLE(1b, 3b)
  41. ENDPROC(\op\()_safe_regs)
  42. .endm
  43. #else /* X86_32 */
  44. .macro op_safe_regs op
  45. ENTRY(\op\()_safe_regs)
  46. pushl %ebx
  47. pushl %ebp
  48. pushl %esi
  49. pushl %edi
  50. pushl $0 /* Return value */
  51. pushl %eax
  52. movl 4(%eax), %ecx
  53. movl 8(%eax), %edx
  54. movl 12(%eax), %ebx
  55. movl 20(%eax), %ebp
  56. movl 24(%eax), %esi
  57. movl 28(%eax), %edi
  58. movl (%eax), %eax
  59. 1: \op
  60. 2: pushl %eax
  61. movl 4(%esp), %eax
  62. popl (%eax)
  63. addl $4, %esp
  64. movl %ecx, 4(%eax)
  65. movl %edx, 8(%eax)
  66. movl %ebx, 12(%eax)
  67. movl %ebp, 20(%eax)
  68. movl %esi, 24(%eax)
  69. movl %edi, 28(%eax)
  70. popl %eax
  71. popl %edi
  72. popl %esi
  73. popl %ebp
  74. popl %ebx
  75. ret
  76. 3:
  77. movl $-EIO, 4(%esp)
  78. jmp 2b
  79. _ASM_EXTABLE(1b, 3b)
  80. ENDPROC(\op\()_safe_regs)
  81. .endm
  82. #endif
  83. op_safe_regs rdmsr
  84. op_safe_regs wrmsr