Merge branch 'for-4.15/asus' into for-linus
[linux-2.6-microblaze.git] / arch / x86 / include / asm / asm.h
1 #ifndef _ASM_X86_ASM_H
2 #define _ASM_X86_ASM_H
3
4 #ifdef __ASSEMBLY__
5 # define __ASM_FORM(x)  x
6 # define __ASM_FORM_RAW(x)     x
7 # define __ASM_FORM_COMMA(x) x,
8 #else
9 # define __ASM_FORM(x)  " " #x " "
10 # define __ASM_FORM_RAW(x)     #x
11 # define __ASM_FORM_COMMA(x) " " #x ","
12 #endif
13
14 #ifndef __x86_64__
15 /* 32 bit */
16 # define __ASM_SEL(a,b) __ASM_FORM(a)
17 # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
18 #else
19 /* 64 bit */
20 # define __ASM_SEL(a,b) __ASM_FORM(b)
21 # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(b)
22 #endif
23
24 #define __ASM_SIZE(inst, ...)   __ASM_SEL(inst##l##__VA_ARGS__, \
25                                           inst##q##__VA_ARGS__)
26 #define __ASM_REG(reg)         __ASM_SEL_RAW(e##reg, r##reg)
27
28 #define _ASM_PTR        __ASM_SEL(.long, .quad)
29 #define _ASM_ALIGN      __ASM_SEL(.balign 4, .balign 8)
30
31 #define _ASM_MOV        __ASM_SIZE(mov)
32 #define _ASM_INC        __ASM_SIZE(inc)
33 #define _ASM_DEC        __ASM_SIZE(dec)
34 #define _ASM_ADD        __ASM_SIZE(add)
35 #define _ASM_SUB        __ASM_SIZE(sub)
36 #define _ASM_XADD       __ASM_SIZE(xadd)
37 #define _ASM_MUL        __ASM_SIZE(mul)
38
39 #define _ASM_AX         __ASM_REG(ax)
40 #define _ASM_BX         __ASM_REG(bx)
41 #define _ASM_CX         __ASM_REG(cx)
42 #define _ASM_DX         __ASM_REG(dx)
43 #define _ASM_SP         __ASM_REG(sp)
44 #define _ASM_BP         __ASM_REG(bp)
45 #define _ASM_SI         __ASM_REG(si)
46 #define _ASM_DI         __ASM_REG(di)
47
48 /*
49  * Macros to generate condition code outputs from inline assembly,
50  * The output operand must be type "bool".
51  */
52 #ifdef __GCC_ASM_FLAG_OUTPUTS__
53 # define CC_SET(c) "\n\t/* output condition code " #c "*/\n"
54 # define CC_OUT(c) "=@cc" #c
55 #else
56 # define CC_SET(c) "\n\tset" #c " %[_cc_" #c "]\n"
57 # define CC_OUT(c) [_cc_ ## c] "=qm"
58 #endif
59
60 /* Exception table entry */
61 #ifdef __ASSEMBLY__
62 # define _ASM_EXTABLE_HANDLE(from, to, handler)                 \
63         .pushsection "__ex_table","a" ;                         \
64         .balign 4 ;                                             \
65         .long (from) - . ;                                      \
66         .long (to) - . ;                                        \
67         .long (handler) - . ;                                   \
68         .popsection
69
70 # define _ASM_EXTABLE(from, to)                                 \
71         _ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
72
73 # define _ASM_EXTABLE_FAULT(from, to)                           \
74         _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
75
76 # define _ASM_EXTABLE_EX(from, to)                              \
77         _ASM_EXTABLE_HANDLE(from, to, ex_handler_ext)
78
79 # define _ASM_EXTABLE_REFCOUNT(from, to)                        \
80         _ASM_EXTABLE_HANDLE(from, to, ex_handler_refcount)
81
82 # define _ASM_NOKPROBE(entry)                                   \
83         .pushsection "_kprobe_blacklist","aw" ;                 \
84         _ASM_ALIGN ;                                            \
85         _ASM_PTR (entry);                                       \
86         .popsection
87
88 .macro ALIGN_DESTINATION
89         /* check for bad alignment of destination */
90         movl %edi,%ecx
91         andl $7,%ecx
92         jz 102f                         /* already aligned */
93         subl $8,%ecx
94         negl %ecx
95         subl %ecx,%edx
96 100:    movb (%rsi),%al
97 101:    movb %al,(%rdi)
98         incq %rsi
99         incq %rdi
100         decl %ecx
101         jnz 100b
102 102:
103         .section .fixup,"ax"
104 103:    addl %ecx,%edx                  /* ecx is zerorest also */
105         jmp copy_user_handle_tail
106         .previous
107
108         _ASM_EXTABLE(100b,103b)
109         _ASM_EXTABLE(101b,103b)
110         .endm
111
112 #else
113 # define _EXPAND_EXTABLE_HANDLE(x) #x
114 # define _ASM_EXTABLE_HANDLE(from, to, handler)                 \
115         " .pushsection \"__ex_table\",\"a\"\n"                  \
116         " .balign 4\n"                                          \
117         " .long (" #from ") - .\n"                              \
118         " .long (" #to ") - .\n"                                \
119         " .long (" _EXPAND_EXTABLE_HANDLE(handler) ") - .\n"    \
120         " .popsection\n"
121
122 # define _ASM_EXTABLE(from, to)                                 \
123         _ASM_EXTABLE_HANDLE(from, to, ex_handler_default)
124
125 # define _ASM_EXTABLE_FAULT(from, to)                           \
126         _ASM_EXTABLE_HANDLE(from, to, ex_handler_fault)
127
128 # define _ASM_EXTABLE_EX(from, to)                              \
129         _ASM_EXTABLE_HANDLE(from, to, ex_handler_ext)
130
131 # define _ASM_EXTABLE_REFCOUNT(from, to)                        \
132         _ASM_EXTABLE_HANDLE(from, to, ex_handler_refcount)
133
134 /* For C file, we already have NOKPROBE_SYMBOL macro */
135 #endif
136
137 #ifndef __ASSEMBLY__
138 /*
139  * This output constraint should be used for any inline asm which has a "call"
140  * instruction.  Otherwise the asm may be inserted before the frame pointer
141  * gets set up by the containing function.  If you forget to do this, objtool
142  * may print a "call without frame pointer save/setup" warning.
143  */
144 register unsigned long current_stack_pointer asm(_ASM_SP);
145 #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
146 #endif
147
148 #endif /* _ASM_X86_ASM_H */