xref: /linux/tools/perf/arch/x86/tests/regs_load.S (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/linkage.h>
3
4#define AX	 0
5#define BX	 1 * 8
6#define CX	 2 * 8
7#define DX	 3 * 8
8#define SI	 4 * 8
9#define DI	 5 * 8
10#define BP	 6 * 8
11#define SP	 7 * 8
12#define IP	 8 * 8
13#define FLAGS	 9 * 8
14#define CS	10 * 8
15#define SS	11 * 8
16#define DS	12 * 8
17#define ES	13 * 8
18#define FS	14 * 8
19#define GS	15 * 8
20#define R8	16 * 8
21#define R9	17 * 8
22#define R10	18 * 8
23#define R11	19 * 8
24#define R12	20 * 8
25#define R13	21 * 8
26#define R14	22 * 8
27#define R15	23 * 8
28
29.text
30#ifdef HAVE_ARCH_X86_64_SUPPORT
31SYM_FUNC_START(perf_regs_load)
32	movq %rax, AX(%rdi)
33	movq %rbx, BX(%rdi)
34	movq %rcx, CX(%rdi)
35	movq %rdx, DX(%rdi)
36	movq %rsi, SI(%rdi)
37	movq %rdi, DI(%rdi)
38	movq %rbp, BP(%rdi)
39
40	leaq 8(%rsp), %rax /* exclude this call.  */
41	movq %rax, SP(%rdi)
42
43	movq 0(%rsp), %rax
44	movq %rax, IP(%rdi)
45
46	movq $0, FLAGS(%rdi)
47	movq $0, CS(%rdi)
48	movq $0, SS(%rdi)
49	movq $0, DS(%rdi)
50	movq $0, ES(%rdi)
51	movq $0, FS(%rdi)
52	movq $0, GS(%rdi)
53
54	movq %r8,  R8(%rdi)
55	movq %r9,  R9(%rdi)
56	movq %r10, R10(%rdi)
57	movq %r11, R11(%rdi)
58	movq %r12, R12(%rdi)
59	movq %r13, R13(%rdi)
60	movq %r14, R14(%rdi)
61	movq %r15, R15(%rdi)
62	ret
63SYM_FUNC_END(perf_regs_load)
64#else
65SYM_FUNC_START(perf_regs_load)
66	push %edi
67	movl 8(%esp), %edi
68	movl %eax, AX(%edi)
69	movl %ebx, BX(%edi)
70	movl %ecx, CX(%edi)
71	movl %edx, DX(%edi)
72	movl %esi, SI(%edi)
73	pop %eax
74	movl %eax, DI(%edi)
75	movl %ebp, BP(%edi)
76
77	leal 4(%esp), %eax /* exclude this call.  */
78	movl %eax, SP(%edi)
79
80	movl 0(%esp), %eax
81	movl %eax, IP(%edi)
82
83	movl $0, FLAGS(%edi)
84	movl $0, CS(%edi)
85	movl $0, SS(%edi)
86	movl $0, DS(%edi)
87	movl $0, ES(%edi)
88	movl $0, FS(%edi)
89	movl $0, GS(%edi)
90	ret
91SYM_FUNC_END(perf_regs_load)
92#endif
93
94/*
95 * We need to provide note.GNU-stack section, saying that we want
96 * NOT executable stack. Otherwise the final linking will assume that
97 * the ELF stack should not be restricted at all and set it RWX.
98 */
99.section .note.GNU-stack,"",@progbits
100