1/*
2 * Save registers before calling assembly functions. This avoids
3 * disturbance of register allocation in some inline assembly constructs.
4 * Copyright 2001,2002 by Andi Kleen, SuSE Labs.
5 * Added trace_hardirqs callers - Copyright 2007 Steven Rostedt, Red Hat, Inc.
6 * Subject to the GNU public license, v.2. No warranty of any kind.
7 */
8#include <linux/linkage.h>
9#include <asm/dwarf2.h>
10#include <asm/calling.h>
11#include <asm/asm.h>
12
13	/* rdi:	arg1 ... normal C conventions. rax is saved/restored. */
14	.macro THUNK name, func, put_ret_addr_in_rdi=0
15	.globl \name
16\name:
17	CFI_STARTPROC
18
19	/* this one pushes 9 elems, the next one would be %rIP */
20	pushq_cfi_reg rdi
21	pushq_cfi_reg rsi
22	pushq_cfi_reg rdx
23	pushq_cfi_reg rcx
24	pushq_cfi_reg rax
25	pushq_cfi_reg r8
26	pushq_cfi_reg r9
27	pushq_cfi_reg r10
28	pushq_cfi_reg r11
29
30	.if \put_ret_addr_in_rdi
31	/* 9*8(%rsp) is return addr on stack */
32	movq_cfi_restore 9*8, rdi
33	.endif
34
35	call \func
36	jmp  restore
37	CFI_ENDPROC
38	_ASM_NOKPROBE(\name)
39	.endm
40
41#ifdef CONFIG_TRACE_IRQFLAGS
42	THUNK trace_hardirqs_on_thunk,trace_hardirqs_on_caller,1
43	THUNK trace_hardirqs_off_thunk,trace_hardirqs_off_caller,1
44#endif
45
46#ifdef CONFIG_DEBUG_LOCK_ALLOC
47	THUNK lockdep_sys_exit_thunk,lockdep_sys_exit
48#endif
49
50#ifdef CONFIG_PREEMPT
51	THUNK ___preempt_schedule, preempt_schedule
52#ifdef CONFIG_CONTEXT_TRACKING
53	THUNK ___preempt_schedule_context, preempt_schedule_context
54#endif
55#endif
56
57#if defined(CONFIG_TRACE_IRQFLAGS) \
58 || defined(CONFIG_DEBUG_LOCK_ALLOC) \
59 || defined(CONFIG_PREEMPT)
60	CFI_STARTPROC
61	CFI_ADJUST_CFA_OFFSET 9*8
62restore:
63	popq_cfi_reg r11
64	popq_cfi_reg r10
65	popq_cfi_reg r9
66	popq_cfi_reg r8
67	popq_cfi_reg rax
68	popq_cfi_reg rcx
69	popq_cfi_reg rdx
70	popq_cfi_reg rsi
71	popq_cfi_reg rdi
72	ret
73	CFI_ENDPROC
74	_ASM_NOKPROBE(restore)
75#endif
76