blob: ccd32877a3c4141faaf97ad4dfec58217ac2cf48 [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.
Andi Kleencc1e6842006-09-26 10:52:29 +02006 */
Borislav Petkov38e6b752011-05-31 22:21:54 +02007#include <linux/linkage.h>
Ingo Molnard36f9472015-06-03 18:29:26 +02008#include "calling.h"
Masami Hiramatsu98def1d2014-04-17 17:17:26 +09009#include <asm/asm.h>
Al Viro784d5692016-01-11 11:04:34 -050010#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Borislav Petkov38e6b752011-05-31 22:21:54 +020012 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
13 .macro THUNK name, func, put_ret_addr_in_rdi=0
Jiri Slaby76dc6d62019-10-11 13:50:44 +020014SYM_FUNC_START_NOALIGN(\name)
Josh Poimboeufd4bf7072016-05-17 13:06:06 -050015 pushq %rbp
16 movq %rsp, %rbp
Borislav Petkov38e6b752011-05-31 22:21:54 +020017
Ingo Molnar131484c2015-05-28 12:21:47 +020018 pushq %rdi
19 pushq %rsi
20 pushq %rdx
21 pushq %rcx
22 pushq %rax
23 pushq %r8
24 pushq %r9
25 pushq %r10
26 pushq %r11
Borislav Petkov38e6b752011-05-31 22:21:54 +020027
28 .if \put_ret_addr_in_rdi
Josh Poimboeufd4bf7072016-05-17 13:06:06 -050029 /* 8(%rbp) is return addr on stack */
30 movq 8(%rbp), %rdi
Borislav Petkov38e6b752011-05-31 22:21:54 +020031 .endif
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 call \func
Borislav Petkov9a7e7b572016-07-08 16:01:48 +020034 jmp .L_restore
Jiri Slaby76dc6d62019-10-11 13:50:44 +020035SYM_FUNC_END(\name)
Masami Hiramatsu98def1d2014-04-17 17:17:26 +090036 _ASM_NOKPROBE(\name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 .endm
38
Thomas Gleixner48593972019-07-26 23:19:42 +020039#ifdef CONFIG_PREEMPTION
Peter Zijlstra46db36a2020-03-20 12:56:39 +010040 THUNK preempt_schedule_thunk, preempt_schedule
41 THUNK preempt_schedule_notrace_thunk, preempt_schedule_notrace
42 EXPORT_SYMBOL(preempt_schedule_thunk)
43 EXPORT_SYMBOL(preempt_schedule_notrace_thunk)
Oleg Nesterov0ad6e3c2014-09-21 20:41:53 +020044#endif
45
Thomas Gleixner320100a2020-05-21 22:05:52 +020046#ifdef CONFIG_PREEMPTION
Jiri Slaby76dc6d62019-10-11 13:50:44 +020047SYM_CODE_START_LOCAL_NOALIGN(.L_restore)
Ingo Molnar131484c2015-05-28 12:21:47 +020048 popq %r11
49 popq %r10
50 popq %r9
51 popq %r8
52 popq %rax
53 popq %rcx
54 popq %rdx
55 popq %rsi
56 popq %rdi
Josh Poimboeufd4bf7072016-05-17 13:06:06 -050057 popq %rbp
Borislav Petkov38e6b752011-05-31 22:21:54 +020058 ret
Borislav Petkov9a7e7b572016-07-08 16:01:48 +020059 _ASM_NOKPROBE(.L_restore)
Jiri Slaby76dc6d62019-10-11 13:50:44 +020060SYM_CODE_END(.L_restore)
Denys Vlasenko69e85442015-02-26 14:40:24 -080061#endif