Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_X86_ASM_H
0003 #define _ASM_X86_ASM_H
0004 
0005 #ifdef __ASSEMBLY__
0006 # define __ASM_FORM(x, ...)     x,## __VA_ARGS__
0007 # define __ASM_FORM_RAW(x, ...)     x,## __VA_ARGS__
0008 # define __ASM_FORM_COMMA(x, ...)   x,## __VA_ARGS__,
0009 #else
0010 #include <linux/stringify.h>
0011 # define __ASM_FORM(x, ...)     " " __stringify(x,##__VA_ARGS__) " "
0012 # define __ASM_FORM_RAW(x, ...)         __stringify(x,##__VA_ARGS__)
0013 # define __ASM_FORM_COMMA(x, ...)   " " __stringify(x,##__VA_ARGS__) ","
0014 #endif
0015 
0016 #define _ASM_BYTES(x, ...)  __ASM_FORM(.byte x,##__VA_ARGS__ ;)
0017 
0018 #ifndef __x86_64__
0019 /* 32 bit */
0020 # define __ASM_SEL(a,b)     __ASM_FORM(a)
0021 # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
0022 #else
0023 /* 64 bit */
0024 # define __ASM_SEL(a,b)     __ASM_FORM(b)
0025 # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(b)
0026 #endif
0027 
0028 #define __ASM_SIZE(inst, ...)   __ASM_SEL(inst##l##__VA_ARGS__, \
0029                       inst##q##__VA_ARGS__)
0030 #define __ASM_REG(reg)         __ASM_SEL_RAW(e##reg, r##reg)
0031 
0032 #define _ASM_PTR    __ASM_SEL(.long, .quad)
0033 #define _ASM_ALIGN  __ASM_SEL(.balign 4, .balign 8)
0034 
0035 #define _ASM_MOV    __ASM_SIZE(mov)
0036 #define _ASM_INC    __ASM_SIZE(inc)
0037 #define _ASM_DEC    __ASM_SIZE(dec)
0038 #define _ASM_ADD    __ASM_SIZE(add)
0039 #define _ASM_SUB    __ASM_SIZE(sub)
0040 #define _ASM_XADD   __ASM_SIZE(xadd)
0041 #define _ASM_MUL    __ASM_SIZE(mul)
0042 
0043 #define _ASM_AX     __ASM_REG(ax)
0044 #define _ASM_BX     __ASM_REG(bx)
0045 #define _ASM_CX     __ASM_REG(cx)
0046 #define _ASM_DX     __ASM_REG(dx)
0047 #define _ASM_SP     __ASM_REG(sp)
0048 #define _ASM_BP     __ASM_REG(bp)
0049 #define _ASM_SI     __ASM_REG(si)
0050 #define _ASM_DI     __ASM_REG(di)
0051 
0052 #ifndef __x86_64__
0053 /* 32 bit */
0054 
0055 #define _ASM_ARG1   _ASM_AX
0056 #define _ASM_ARG2   _ASM_DX
0057 #define _ASM_ARG3   _ASM_CX
0058 
0059 #define _ASM_ARG1L  eax
0060 #define _ASM_ARG2L  edx
0061 #define _ASM_ARG3L  ecx
0062 
0063 #define _ASM_ARG1W  ax
0064 #define _ASM_ARG2W  dx
0065 #define _ASM_ARG3W  cx
0066 
0067 #define _ASM_ARG1B  al
0068 #define _ASM_ARG2B  dl
0069 #define _ASM_ARG3B  cl
0070 
0071 #else
0072 /* 64 bit */
0073 
0074 #define _ASM_ARG1   _ASM_DI
0075 #define _ASM_ARG2   _ASM_SI
0076 #define _ASM_ARG3   _ASM_DX
0077 #define _ASM_ARG4   _ASM_CX
0078 #define _ASM_ARG5   r8
0079 #define _ASM_ARG6   r9
0080 
0081 #define _ASM_ARG1Q  rdi
0082 #define _ASM_ARG2Q  rsi
0083 #define _ASM_ARG3Q  rdx
0084 #define _ASM_ARG4Q  rcx
0085 #define _ASM_ARG5Q  r8
0086 #define _ASM_ARG6Q  r9
0087 
0088 #define _ASM_ARG1L  edi
0089 #define _ASM_ARG2L  esi
0090 #define _ASM_ARG3L  edx
0091 #define _ASM_ARG4L  ecx
0092 #define _ASM_ARG5L  r8d
0093 #define _ASM_ARG6L  r9d
0094 
0095 #define _ASM_ARG1W  di
0096 #define _ASM_ARG2W  si
0097 #define _ASM_ARG3W  dx
0098 #define _ASM_ARG4W  cx
0099 #define _ASM_ARG5W  r8w
0100 #define _ASM_ARG6W  r9w
0101 
0102 #define _ASM_ARG1B  dil
0103 #define _ASM_ARG2B  sil
0104 #define _ASM_ARG3B  dl
0105 #define _ASM_ARG4B  cl
0106 #define _ASM_ARG5B  r8b
0107 #define _ASM_ARG6B  r9b
0108 
0109 #endif
0110 
0111 /*
0112  * Macros to generate condition code outputs from inline assembly,
0113  * The output operand must be type "bool".
0114  */
0115 #ifdef __GCC_ASM_FLAG_OUTPUTS__
0116 # define CC_SET(c) "\n\t/* output condition code " #c "*/\n"
0117 # define CC_OUT(c) "=@cc" #c
0118 #else
0119 # define CC_SET(c) "\n\tset" #c " %[_cc_" #c "]\n"
0120 # define CC_OUT(c) [_cc_ ## c] "=qm"
0121 #endif
0122 
0123 #ifdef __KERNEL__
0124 
0125 /* Exception table entry */
0126 #ifdef __ASSEMBLY__
0127 # define _ASM_EXTABLE_HANDLE(from, to, handler)         \
0128     .pushsection "__ex_table","a" ;             \
0129     .balign 4 ;                     \
0130     .long (from) - . ;                  \
0131     .long (to) - . ;                    \
0132     .long (handler) - . ;                   \
0133     .popsection
0134 
0135 # define _ASM_EXTABLE(from, to)                 \
0136     _ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
0137 
0138 # define _ASM_EXTABLE_UA(from, to)              \
0139     _ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess)
0140 
0141 # define _ASM_EXTABLE_CPY(from, to)             \
0142     _ASM_EXTABLE_HANDLE(from, to, ex_handler_copy)
0143 
0144 # define _ASM_EXTABLE_FAULT(from, to)               \
0145     _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
0146 
0147 # ifdef CONFIG_KPROBES
0148 #  define _ASM_NOKPROBE(entry)                  \
0149     .pushsection "_kprobe_blacklist","aw" ;         \
0150     _ASM_ALIGN ;                        \
0151     _ASM_PTR (entry);                   \
0152     .popsection
0153 # else
0154 #  define _ASM_NOKPROBE(entry)
0155 # endif
0156 
0157 #else /* ! __ASSEMBLY__ */
0158 # define _EXPAND_EXTABLE_HANDLE(x) #x
0159 # define _ASM_EXTABLE_HANDLE(from, to, handler)         \
0160     " .pushsection \"__ex_table\",\"a\"\n"          \
0161     " .balign 4\n"                      \
0162     " .long (" #from ") - .\n"              \
0163     " .long (" #to ") - .\n"                \
0164     " .long (" _EXPAND_EXTABLE_HANDLE(handler) ") - .\n"    \
0165     " .popsection\n"
0166 
0167 # define _ASM_EXTABLE(from, to)                 \
0168     _ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
0169 
0170 # define _ASM_EXTABLE_UA(from, to)              \
0171     _ASM_EXTABLE_HANDLE(from, to, ex_handler_uaccess)
0172 
0173 # define _ASM_EXTABLE_CPY(from, to)             \
0174     _ASM_EXTABLE_HANDLE(from, to, ex_handler_copy)
0175 
0176 # define _ASM_EXTABLE_FAULT(from, to)               \
0177     _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
0178 
0179 /* For C file, we already have NOKPROBE_SYMBOL macro */
0180 
0181 /*
0182  * This output constraint should be used for any inline asm which has a "call"
0183  * instruction.  Otherwise the asm may be inserted before the frame pointer
0184  * gets set up by the containing function.  If you forget to do this, objtool
0185  * may print a "call without frame pointer save/setup" warning.
0186  */
0187 register unsigned long current_stack_pointer asm(_ASM_SP);
0188 #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
0189 #endif /* __ASSEMBLY__ */
0190 
0191 #endif /* __KERNEL__ */
0192 
0193 #endif /* _ASM_X86_ASM_H */