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 # define __ASM_REGPFX           %
0010 #else
0011 #include <linux/stringify.h>
0012 # define __ASM_FORM(x, ...)     " " __stringify(x,##__VA_ARGS__) " "
0013 # define __ASM_FORM_RAW(x, ...)         __stringify(x,##__VA_ARGS__)
0014 # define __ASM_FORM_COMMA(x, ...)   " " __stringify(x,##__VA_ARGS__) ","
0015 # define __ASM_REGPFX           %%
0016 #endif
0017 
0018 #define _ASM_BYTES(x, ...)  __ASM_FORM(.byte x,##__VA_ARGS__ ;)
0019 
0020 #ifndef __x86_64__
0021 /* 32 bit */
0022 # define __ASM_SEL(a,b)     __ASM_FORM(a)
0023 # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
0024 #else
0025 /* 64 bit */
0026 # define __ASM_SEL(a,b)     __ASM_FORM(b)
0027 # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(b)
0028 #endif
0029 
0030 #define __ASM_SIZE(inst, ...)   __ASM_SEL(inst##l##__VA_ARGS__, \
0031                       inst##q##__VA_ARGS__)
0032 #define __ASM_REG(reg)         __ASM_SEL_RAW(e##reg, r##reg)
0033 
0034 #define _ASM_PTR    __ASM_SEL(.long, .quad)
0035 #define _ASM_ALIGN  __ASM_SEL(.balign 4, .balign 8)
0036 
0037 #define _ASM_MOV    __ASM_SIZE(mov)
0038 #define _ASM_INC    __ASM_SIZE(inc)
0039 #define _ASM_DEC    __ASM_SIZE(dec)
0040 #define _ASM_ADD    __ASM_SIZE(add)
0041 #define _ASM_SUB    __ASM_SIZE(sub)
0042 #define _ASM_XADD   __ASM_SIZE(xadd)
0043 #define _ASM_MUL    __ASM_SIZE(mul)
0044 
0045 #define _ASM_AX     __ASM_REG(ax)
0046 #define _ASM_BX     __ASM_REG(bx)
0047 #define _ASM_CX     __ASM_REG(cx)
0048 #define _ASM_DX     __ASM_REG(dx)
0049 #define _ASM_SP     __ASM_REG(sp)
0050 #define _ASM_BP     __ASM_REG(bp)
0051 #define _ASM_SI     __ASM_REG(si)
0052 #define _ASM_DI     __ASM_REG(di)
0053 
0054 /* Adds a (%rip) suffix on 64 bits only; for immediate memory references */
0055 #define _ASM_RIP(x) __ASM_SEL_RAW(x, x (__ASM_REGPFX rip))
0056 
0057 #ifndef __x86_64__
0058 /* 32 bit */
0059 
0060 #define _ASM_ARG1   _ASM_AX
0061 #define _ASM_ARG2   _ASM_DX
0062 #define _ASM_ARG3   _ASM_CX
0063 
0064 #define _ASM_ARG1L  eax
0065 #define _ASM_ARG2L  edx
0066 #define _ASM_ARG3L  ecx
0067 
0068 #define _ASM_ARG1W  ax
0069 #define _ASM_ARG2W  dx
0070 #define _ASM_ARG3W  cx
0071 
0072 #define _ASM_ARG1B  al
0073 #define _ASM_ARG2B  dl
0074 #define _ASM_ARG3B  cl
0075 
0076 #else
0077 /* 64 bit */
0078 
0079 #define _ASM_ARG1   _ASM_DI
0080 #define _ASM_ARG2   _ASM_SI
0081 #define _ASM_ARG3   _ASM_DX
0082 #define _ASM_ARG4   _ASM_CX
0083 #define _ASM_ARG5   r8
0084 #define _ASM_ARG6   r9
0085 
0086 #define _ASM_ARG1Q  rdi
0087 #define _ASM_ARG2Q  rsi
0088 #define _ASM_ARG3Q  rdx
0089 #define _ASM_ARG4Q  rcx
0090 #define _ASM_ARG5Q  r8
0091 #define _ASM_ARG6Q  r9
0092 
0093 #define _ASM_ARG1L  edi
0094 #define _ASM_ARG2L  esi
0095 #define _ASM_ARG3L  edx
0096 #define _ASM_ARG4L  ecx
0097 #define _ASM_ARG5L  r8d
0098 #define _ASM_ARG6L  r9d
0099 
0100 #define _ASM_ARG1W  di
0101 #define _ASM_ARG2W  si
0102 #define _ASM_ARG3W  dx
0103 #define _ASM_ARG4W  cx
0104 #define _ASM_ARG5W  r8w
0105 #define _ASM_ARG6W  r9w
0106 
0107 #define _ASM_ARG1B  dil
0108 #define _ASM_ARG2B  sil
0109 #define _ASM_ARG3B  dl
0110 #define _ASM_ARG4B  cl
0111 #define _ASM_ARG5B  r8b
0112 #define _ASM_ARG6B  r9b
0113 
0114 #endif
0115 
0116 /*
0117  * Macros to generate condition code outputs from inline assembly,
0118  * The output operand must be type "bool".
0119  */
0120 #ifdef __GCC_ASM_FLAG_OUTPUTS__
0121 # define CC_SET(c) "\n\t/* output condition code " #c "*/\n"
0122 # define CC_OUT(c) "=@cc" #c
0123 #else
0124 # define CC_SET(c) "\n\tset" #c " %[_cc_" #c "]\n"
0125 # define CC_OUT(c) [_cc_ ## c] "=qm"
0126 #endif
0127 
0128 #ifdef __KERNEL__
0129 
0130 # include <asm/extable_fixup_types.h>
0131 
0132 /* Exception table entry */
0133 #ifdef __ASSEMBLY__
0134 
0135 # define _ASM_EXTABLE_TYPE(from, to, type)          \
0136     .pushsection "__ex_table","a" ;             \
0137     .balign 4 ;                     \
0138     .long (from) - . ;                  \
0139     .long (to) - . ;                    \
0140     .long type ;                        \
0141     .popsection
0142 
0143 # ifdef CONFIG_KPROBES
0144 #  define _ASM_NOKPROBE(entry)                  \
0145     .pushsection "_kprobe_blacklist","aw" ;         \
0146     _ASM_ALIGN ;                        \
0147     _ASM_PTR (entry);                   \
0148     .popsection
0149 # else
0150 #  define _ASM_NOKPROBE(entry)
0151 # endif
0152 
0153 #else /* ! __ASSEMBLY__ */
0154 
0155 # define DEFINE_EXTABLE_TYPE_REG \
0156     ".macro extable_type_reg type:req reg:req\n"                        \
0157     ".set .Lfound, 0\n"                                 \
0158     ".set .Lregnr, 0\n"                                 \
0159     ".irp rs,rax,rcx,rdx,rbx,rsp,rbp,rsi,rdi,r8,r9,r10,r11,r12,r13,r14,r15\n"       \
0160     ".ifc \\reg, %%\\rs\n"                                  \
0161     ".set .Lfound, .Lfound+1\n"                             \
0162     ".long \\type + (.Lregnr << 8)\n"                           \
0163     ".endif\n"                                      \
0164     ".set .Lregnr, .Lregnr+1\n"                             \
0165     ".endr\n"                                       \
0166     ".set .Lregnr, 0\n"                                 \
0167     ".irp rs,eax,ecx,edx,ebx,esp,ebp,esi,edi,r8d,r9d,r10d,r11d,r12d,r13d,r14d,r15d\n"   \
0168     ".ifc \\reg, %%\\rs\n"                                  \
0169     ".set .Lfound, .Lfound+1\n"                             \
0170     ".long \\type + (.Lregnr << 8)\n"                           \
0171     ".endif\n"                                      \
0172     ".set .Lregnr, .Lregnr+1\n"                             \
0173     ".endr\n"                                       \
0174     ".if (.Lfound != 1)\n"                                  \
0175     ".error \"extable_type_reg: bad register argument\"\n"                  \
0176     ".endif\n"                                      \
0177     ".endm\n"
0178 
0179 # define UNDEFINE_EXTABLE_TYPE_REG \
0180     ".purgem extable_type_reg\n"
0181 
0182 # define _ASM_EXTABLE_TYPE(from, to, type)          \
0183     " .pushsection \"__ex_table\",\"a\"\n"          \
0184     " .balign 4\n"                      \
0185     " .long (" #from ") - .\n"              \
0186     " .long (" #to ") - .\n"                \
0187     " .long " __stringify(type) " \n"           \
0188     " .popsection\n"
0189 
0190 # define _ASM_EXTABLE_TYPE_REG(from, to, type, reg)             \
0191     " .pushsection \"__ex_table\",\"a\"\n"                  \
0192     " .balign 4\n"                              \
0193     " .long (" #from ") - .\n"                      \
0194     " .long (" #to ") - .\n"                        \
0195     DEFINE_EXTABLE_TYPE_REG                         \
0196     "extable_type_reg reg=" __stringify(reg) ", type=" __stringify(type) " \n"\
0197     UNDEFINE_EXTABLE_TYPE_REG                       \
0198     " .popsection\n"
0199 
0200 /* For C file, we already have NOKPROBE_SYMBOL macro */
0201 
0202 /*
0203  * This output constraint should be used for any inline asm which has a "call"
0204  * instruction.  Otherwise the asm may be inserted before the frame pointer
0205  * gets set up by the containing function.  If you forget to do this, objtool
0206  * may print a "call without frame pointer save/setup" warning.
0207  */
0208 register unsigned long current_stack_pointer asm(_ASM_SP);
0209 #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
0210 #endif /* __ASSEMBLY__ */
0211 
0212 #define _ASM_EXTABLE(from, to)                  \
0213     _ASM_EXTABLE_TYPE(from, to, EX_TYPE_DEFAULT)
0214 
0215 #define _ASM_EXTABLE_UA(from, to)               \
0216     _ASM_EXTABLE_TYPE(from, to, EX_TYPE_UACCESS)
0217 
0218 #define _ASM_EXTABLE_CPY(from, to)              \
0219     _ASM_EXTABLE_TYPE(from, to, EX_TYPE_COPY)
0220 
0221 #define _ASM_EXTABLE_FAULT(from, to)                \
0222     _ASM_EXTABLE_TYPE(from, to, EX_TYPE_FAULT)
0223 
0224 #endif /* __KERNEL__ */
0225 #endif /* _ASM_X86_ASM_H */