blob: 7e020782ade22adbef8dd4ad2ddae555a74dcb7c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_LINKAGE_H
3#define _LINUX_LINKAGE_H
4
Will Deacond1515582017-10-24 11:22:46 +01005#include <linux/compiler_types.h>
Al Viroe1b5bb62013-01-21 17:16:07 -05006#include <linux/stringify.h>
Linus Torvaldsf8ce1fa2013-05-05 10:58:06 -07007#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/linkage.h>
9
Chen Gang9df62f02014-01-12 09:59:13 +080010/* Some toolchains use other characters (e.g. '`') to mark new line in macro */
11#ifndef ASM_NL
12#define ASM_NL ;
13#endif
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#ifdef __cplusplus
Andi Kleen3adc1be2014-05-02 00:44:36 +020016#define CPP_ASMLINKAGE extern "C"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#else
Andi Kleen3adc1be2014-05-02 00:44:36 +020018#define CPP_ASMLINKAGE
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#endif
20
21#ifndef asmlinkage
22#define asmlinkage CPP_ASMLINKAGE
23#endif
24
Al Viroe1b5bb62013-01-21 17:16:07 -050025#ifndef cond_syscall
Linus Torvaldsf8ce1fa2013-05-05 10:58:06 -070026#define cond_syscall(x) asm( \
Masahiro Yamada00979ce2018-06-11 11:35:26 +090027 ".weak " __stringify(x) "\n\t" \
28 ".set " __stringify(x) "," \
29 __stringify(sys_ni_syscall))
Al Viroe1b5bb62013-01-21 17:16:07 -050030#endif
31
32#ifndef SYSCALL_ALIAS
Linus Torvaldsf8ce1fa2013-05-05 10:58:06 -070033#define SYSCALL_ALIAS(alias, name) asm( \
Masahiro Yamada00979ce2018-06-11 11:35:26 +090034 ".globl " __stringify(alias) "\n\t" \
35 ".set " __stringify(alias) "," \
36 __stringify(name))
Al Viroe1b5bb62013-01-21 17:16:07 -050037#endif
38
Tim Abbott75b13482010-02-20 01:03:37 +010039#define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
Tim Abbott7c74df02010-02-20 01:03:38 +010040#define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
Jeremy Fitzhardingea7bf0bd2008-05-28 15:02:14 +010041
Linus Torvaldsd10d89e2008-04-10 17:35:23 -070042/*
Tim Abbottd2af12a2009-06-23 19:59:35 -040043 * For assembly routines.
44 *
45 * Note when using these that you must specify the appropriate
46 * alignment directives yourself
47 */
Tim Abbott75b13482010-02-20 01:03:37 +010048#define __PAGE_ALIGNED_DATA .section ".data..page_aligned", "aw"
Tim Abbott7c74df02010-02-20 01:03:38 +010049#define __PAGE_ALIGNED_BSS .section ".bss..page_aligned", "aw"
Tim Abbottd2af12a2009-06-23 19:59:35 -040050
51/*
Linus Torvaldsd10d89e2008-04-10 17:35:23 -070052 * This is used by architectures to keep arguments on the stack
53 * untouched by the compiler by keeping them live until the end.
54 * The argument stack may be owned by the assembly-language
55 * caller, not the callee, and gcc doesn't always understand
56 * that.
57 *
58 * We have the return value, and a maximum of six arguments.
59 *
60 * This should always be followed by a "return ret" for the
61 * protection to work (ie no more work that the compiler might
62 * end up needing stack temporaries for).
63 */
Heiko Carstensb0fac022008-04-11 13:46:54 +020064/* Assembly files may be compiled with -traditional .. */
65#ifndef __ASSEMBLY__
Roland McGrath54a01512008-04-10 15:37:38 -070066#ifndef asmlinkage_protect
67# define asmlinkage_protect(n, ret, args...) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#endif
Heiko Carstensb0fac022008-04-11 13:46:54 +020069#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#ifndef __ALIGN
72#define __ALIGN .align 4,0x90
73#define __ALIGN_STR ".align 4,0x90"
74#endif
75
76#ifdef __ASSEMBLY__
77
Tim Abbott42f29a22009-09-20 18:14:12 -040078#ifndef LINKER_SCRIPT
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#define ALIGN __ALIGN
80#define ALIGN_STR __ALIGN_STR
81
Mark Rutlandad697a12018-11-15 22:41:58 +000082#ifndef GLOBAL
83#define GLOBAL(name) \
84 .globl name ASM_NL \
85 name:
86#endif
87
Jan Beulichab7efcc2006-03-24 03:16:17 -080088#ifndef ENTRY
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#define ENTRY(name) \
Chen Gang9df62f02014-01-12 09:59:13 +080090 .globl name ASM_NL \
91 ALIGN ASM_NL \
92 name:
Jan Beulichab7efcc2006-03-24 03:16:17 -080093#endif
Tim Abbott42f29a22009-09-20 18:14:12 -040094#endif /* LINKER_SCRIPT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Rusty Russell214541d2007-10-21 16:41:34 -070096#ifndef WEAK
97#define WEAK(name) \
Chen Gang9df62f02014-01-12 09:59:13 +080098 .weak name ASM_NL \
Andrey Ryabinin74f213e2018-10-26 15:02:27 -070099 ALIGN ASM_NL \
Rusty Russell214541d2007-10-21 16:41:34 -0700100 name:
101#endif
102
Jan Beulichab7efcc2006-03-24 03:16:17 -0800103#ifndef END
104#define END(name) \
Chen Gang9df62f02014-01-12 09:59:13 +0800105 .size name, .-name
Jan Beulichab7efcc2006-03-24 03:16:17 -0800106#endif
107
John Reiser6b8be6d2008-01-30 13:33:13 +0100108/* If symbol 'name' is treated as a subroutine (gets called, and returns)
109 * then please use ENDPROC to mark 'name' as STT_FUNC for the benefit of
110 * static analysis tools such as stack depth analyzer.
111 */
Jan Beulichab7efcc2006-03-24 03:16:17 -0800112#ifndef ENDPROC
113#define ENDPROC(name) \
Chen Gang9df62f02014-01-12 09:59:13 +0800114 .type name, @function ASM_NL \
115 END(name)
Jan Beulichab7efcc2006-03-24 03:16:17 -0800116#endif
Prasanna S Panchamukhid0aaff92005-09-06 15:19:26 -0700117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#endif
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#endif