blob: a2b9caa5274c8b16fc4fe93b5d75ebfe0e9c9851 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Borislav Petkov132ec922009-08-31 09:50:09 +02002#include <linux/linkage.h>
3#include <linux/errno.h>
4#include <asm/asm.h>
5#include <asm/msr.h>
6
7#ifdef CONFIG_X86_64
8/*
Andre Przywara1f975f72012-06-01 16:52:35 +02009 * int {rdmsr,wrmsr}_safe_regs(u32 gprs[8]);
Borislav Petkov132ec922009-08-31 09:50:09 +020010 *
11 * reg layout: u32 gprs[eax, ecx, edx, ebx, esp, ebp, esi, edi]
12 *
13 */
H. Peter Anvinf6909f32009-09-01 13:31:52 -070014.macro op_safe_regs op
Jiri Slaby6dcc5622019-10-11 13:51:04 +020015SYM_FUNC_START(\op\()_safe_regs)
Ingo Molnar131484c2015-05-28 12:21:47 +020016 pushq %rbx
Josh Poimboeufc207aee2017-06-28 10:11:06 -050017 pushq %r12
H. Peter Anvin79c5dca2009-08-31 13:59:53 -070018 movq %rdi, %r10 /* Save pointer */
19 xorl %r11d, %r11d /* Return value */
Borislav Petkov132ec922009-08-31 09:50:09 +020020 movl (%rdi), %eax
21 movl 4(%rdi), %ecx
22 movl 8(%rdi), %edx
23 movl 12(%rdi), %ebx
Josh Poimboeufc207aee2017-06-28 10:11:06 -050024 movl 20(%rdi), %r12d
Borislav Petkov132ec922009-08-31 09:50:09 +020025 movl 24(%rdi), %esi
26 movl 28(%rdi), %edi
271: \op
H. Peter Anvin79c5dca2009-08-31 13:59:53 -0700282: movl %eax, (%r10)
29 movl %r11d, %eax /* Return value */
30 movl %ecx, 4(%r10)
31 movl %edx, 8(%r10)
32 movl %ebx, 12(%r10)
Josh Poimboeufc207aee2017-06-28 10:11:06 -050033 movl %r12d, 20(%r10)
H. Peter Anvin79c5dca2009-08-31 13:59:53 -070034 movl %esi, 24(%r10)
35 movl %edi, 28(%r10)
Josh Poimboeufc207aee2017-06-28 10:11:06 -050036 popq %r12
Ingo Molnar131484c2015-05-28 12:21:47 +020037 popq %rbx
Borislav Petkov132ec922009-08-31 09:50:09 +020038 ret
393:
H. Peter Anvin79c5dca2009-08-31 13:59:53 -070040 movl $-EIO, %r11d
Borislav Petkov132ec922009-08-31 09:50:09 +020041 jmp 2b
H. Peter Anvin79c5dca2009-08-31 13:59:53 -070042
43 _ASM_EXTABLE(1b, 3b)
Jiri Slaby6dcc5622019-10-11 13:51:04 +020044SYM_FUNC_END(\op\()_safe_regs)
Borislav Petkov132ec922009-08-31 09:50:09 +020045.endm
46
47#else /* X86_32 */
48
Ingo Molnar8adf65c2009-09-03 21:26:34 +020049.macro op_safe_regs op
Jiri Slaby6dcc5622019-10-11 13:51:04 +020050SYM_FUNC_START(\op\()_safe_regs)
Ingo Molnar131484c2015-05-28 12:21:47 +020051 pushl %ebx
52 pushl %ebp
53 pushl %esi
54 pushl %edi
55 pushl $0 /* Return value */
56 pushl %eax
Borislav Petkov132ec922009-08-31 09:50:09 +020057 movl 4(%eax), %ecx
58 movl 8(%eax), %edx
59 movl 12(%eax), %ebx
60 movl 20(%eax), %ebp
61 movl 24(%eax), %esi
62 movl 28(%eax), %edi
63 movl (%eax), %eax
641: \op
Ingo Molnar131484c2015-05-28 12:21:47 +0200652: pushl %eax
Borislav Petkov132ec922009-08-31 09:50:09 +020066 movl 4(%esp), %eax
Ingo Molnar131484c2015-05-28 12:21:47 +020067 popl (%eax)
Borislav Petkov132ec922009-08-31 09:50:09 +020068 addl $4, %esp
69 movl %ecx, 4(%eax)
70 movl %edx, 8(%eax)
71 movl %ebx, 12(%eax)
72 movl %ebp, 20(%eax)
73 movl %esi, 24(%eax)
74 movl %edi, 28(%eax)
Ingo Molnar131484c2015-05-28 12:21:47 +020075 popl %eax
76 popl %edi
77 popl %esi
78 popl %ebp
79 popl %ebx
Borislav Petkov132ec922009-08-31 09:50:09 +020080 ret
813:
82 movl $-EIO, 4(%esp)
83 jmp 2b
H. Peter Anvin79c5dca2009-08-31 13:59:53 -070084
85 _ASM_EXTABLE(1b, 3b)
Jiri Slaby6dcc5622019-10-11 13:51:04 +020086SYM_FUNC_END(\op\()_safe_regs)
Borislav Petkov132ec922009-08-31 09:50:09 +020087.endm
88
89#endif
90
91op_safe_regs rdmsr
92op_safe_regs wrmsr
93