Thomas Gleixner | 3f520cd2 | 2019-06-04 10:11:07 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andi Kleen | cc1e684 | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 2 | /* |
| 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 Kleen | cc1e684 | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 6 | */ |
Borislav Petkov | 38e6b75 | 2011-05-31 22:21:54 +0200 | [diff] [blame] | 7 | #include <linux/linkage.h> |
Ingo Molnar | d36f947 | 2015-06-03 18:29:26 +0200 | [diff] [blame] | 8 | #include "calling.h" |
Masami Hiramatsu | 98def1d | 2014-04-17 17:17:26 +0900 | [diff] [blame] | 9 | #include <asm/asm.h> |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 10 | #include <asm/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Borislav Petkov | 38e6b75 | 2011-05-31 22:21:54 +0200 | [diff] [blame] | 12 | /* rdi: arg1 ... normal C conventions. rax is saved/restored. */ |
| 13 | .macro THUNK name, func, put_ret_addr_in_rdi=0 |
Jiri Slaby | 76dc6d6 | 2019-10-11 13:50:44 +0200 | [diff] [blame] | 14 | SYM_FUNC_START_NOALIGN(\name) |
Josh Poimboeuf | d4bf707 | 2016-05-17 13:06:06 -0500 | [diff] [blame] | 15 | pushq %rbp |
| 16 | movq %rsp, %rbp |
Borislav Petkov | 38e6b75 | 2011-05-31 22:21:54 +0200 | [diff] [blame] | 17 | |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 18 | 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 Petkov | 38e6b75 | 2011-05-31 22:21:54 +0200 | [diff] [blame] | 27 | |
| 28 | .if \put_ret_addr_in_rdi |
Josh Poimboeuf | d4bf707 | 2016-05-17 13:06:06 -0500 | [diff] [blame] | 29 | /* 8(%rbp) is return addr on stack */ |
| 30 | movq 8(%rbp), %rdi |
Borislav Petkov | 38e6b75 | 2011-05-31 22:21:54 +0200 | [diff] [blame] | 31 | .endif |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | call \func |
Borislav Petkov | 9a7e7b57 | 2016-07-08 16:01:48 +0200 | [diff] [blame] | 34 | jmp .L_restore |
Jiri Slaby | 76dc6d6 | 2019-10-11 13:50:44 +0200 | [diff] [blame] | 35 | SYM_FUNC_END(\name) |
Masami Hiramatsu | 98def1d | 2014-04-17 17:17:26 +0900 | [diff] [blame] | 36 | _ASM_NOKPROBE(\name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | .endm |
| 38 | |
Thomas Gleixner | 4859397 | 2019-07-26 23:19:42 +0200 | [diff] [blame] | 39 | #ifdef CONFIG_PREEMPTION |
Peter Zijlstra | 46db36a | 2020-03-20 12:56:39 +0100 | [diff] [blame] | 40 | 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 Nesterov | 0ad6e3c | 2014-09-21 20:41:53 +0200 | [diff] [blame] | 44 | #endif |
| 45 | |
Thomas Gleixner | 320100a | 2020-05-21 22:05:52 +0200 | [diff] [blame^] | 46 | #ifdef CONFIG_PREEMPTION |
Jiri Slaby | 76dc6d6 | 2019-10-11 13:50:44 +0200 | [diff] [blame] | 47 | SYM_CODE_START_LOCAL_NOALIGN(.L_restore) |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 48 | 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 Poimboeuf | d4bf707 | 2016-05-17 13:06:06 -0500 | [diff] [blame] | 57 | popq %rbp |
Borislav Petkov | 38e6b75 | 2011-05-31 22:21:54 +0200 | [diff] [blame] | 58 | ret |
Borislav Petkov | 9a7e7b57 | 2016-07-08 16:01:48 +0200 | [diff] [blame] | 59 | _ASM_NOKPROBE(.L_restore) |
Jiri Slaby | 76dc6d6 | 2019-10-11 13:50:44 +0200 | [diff] [blame] | 60 | SYM_CODE_END(.L_restore) |
Denys Vlasenko | 69e8544 | 2015-02-26 14:40:24 -0800 | [diff] [blame] | 61 | #endif |