blob: cfdca8b42c707de3c07e3363250ef9ba260574f2 [file] [log] [blame]
Thomas Gleixner3f520cd22019-06-04 10:11:07 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Andi Kleencc1e6842006-09-26 10:52:29 +02002/*
3 * Save registers before calling assembly functions. This avoids
4 * disturbance of register allocation in some inline assembly constructs.
5 * Copyright 2001,2002 by Andi Kleen, SuSE Labs.
Steven Rostedt81d68a92008-05-12 21:20:42 +02006 * Added trace_hardirqs callers - Copyright 2007 Steven Rostedt, Red Hat, Inc.
Andi Kleencc1e6842006-09-26 10:52:29 +02007 */
Borislav Petkov38e6b752011-05-31 22:21:54 +02008#include <linux/linkage.h>
Ingo Molnard36f9472015-06-03 18:29:26 +02009#include "calling.h"
Masami Hiramatsu98def1d2014-04-17 17:17:26 +090010#include <asm/asm.h>
Al Viro784d5692016-01-11 11:04:34 -050011#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Borislav Petkov38e6b752011-05-31 22:21:54 +020013 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
14 .macro THUNK name, func, put_ret_addr_in_rdi=0
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 .globl \name
Josh Poimboeuf058fb732016-01-21 16:49:20 -060016 .type \name, @function
Borislav Petkov38e6b752011-05-31 22:21:54 +020017\name:
Josh Poimboeufd4bf7072016-05-17 13:06:06 -050018 pushq %rbp
19 movq %rsp, %rbp
Borislav Petkov38e6b752011-05-31 22:21:54 +020020
Ingo Molnar131484c2015-05-28 12:21:47 +020021 pushq %rdi
22 pushq %rsi
23 pushq %rdx
24 pushq %rcx
25 pushq %rax
26 pushq %r8
27 pushq %r9
28 pushq %r10
29 pushq %r11
Borislav Petkov38e6b752011-05-31 22:21:54 +020030
31 .if \put_ret_addr_in_rdi
Josh Poimboeufd4bf7072016-05-17 13:06:06 -050032 /* 8(%rbp) is return addr on stack */
33 movq 8(%rbp), %rdi
Borislav Petkov38e6b752011-05-31 22:21:54 +020034 .endif
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 call \func
Borislav Petkov9a7e7b572016-07-08 16:01:48 +020037 jmp .L_restore
Masami Hiramatsu98def1d2014-04-17 17:17:26 +090038 _ASM_NOKPROBE(\name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 .endm
40
Ingo Molnar6375e2b2006-07-03 00:24:45 -070041#ifdef CONFIG_TRACE_IRQFLAGS
Borislav Petkov38e6b752011-05-31 22:21:54 +020042 THUNK trace_hardirqs_on_thunk,trace_hardirqs_on_caller,1
43 THUNK trace_hardirqs_off_thunk,trace_hardirqs_off_caller,1
Ingo Molnar6375e2b2006-07-03 00:24:45 -070044#endif
Peter Zijlstra10cd7062007-10-11 22:11:12 +020045
46#ifdef CONFIG_DEBUG_LOCK_ALLOC
Borislav Petkov38e6b752011-05-31 22:21:54 +020047 THUNK lockdep_sys_exit_thunk,lockdep_sys_exit
Peter Zijlstra10cd7062007-10-11 22:11:12 +020048#endif
Borislav Petkov38e6b752011-05-31 22:21:54 +020049
Oleg Nesterov0ad6e3c2014-09-21 20:41:53 +020050#ifdef CONFIG_PREEMPT
51 THUNK ___preempt_schedule, preempt_schedule
Frederic Weisbecker4eaca0a2015-06-04 17:39:08 +020052 THUNK ___preempt_schedule_notrace, preempt_schedule_notrace
Al Viro784d5692016-01-11 11:04:34 -050053 EXPORT_SYMBOL(___preempt_schedule)
54 EXPORT_SYMBOL(___preempt_schedule_notrace)
Oleg Nesterov0ad6e3c2014-09-21 20:41:53 +020055#endif
56
Denys Vlasenko69e85442015-02-26 14:40:24 -080057#if defined(CONFIG_TRACE_IRQFLAGS) \
58 || defined(CONFIG_DEBUG_LOCK_ALLOC) \
59 || defined(CONFIG_PREEMPT)
Borislav Petkov9a7e7b572016-07-08 16:01:48 +020060.L_restore:
Ingo Molnar131484c2015-05-28 12:21:47 +020061 popq %r11
62 popq %r10
63 popq %r9
64 popq %r8
65 popq %rax
66 popq %rcx
67 popq %rdx
68 popq %rsi
69 popq %rdi
Josh Poimboeufd4bf7072016-05-17 13:06:06 -050070 popq %rbp
Borislav Petkov38e6b752011-05-31 22:21:54 +020071 ret
Borislav Petkov9a7e7b572016-07-08 16:01:48 +020072 _ASM_NOKPROBE(.L_restore)
Denys Vlasenko69e85442015-02-26 14:40:24 -080073#endif