x86: fix assembly constraints in native_save_fl()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / asm-x86 / irqflags.h
blobf57f2fb6c9eae4867cc9e7bfdb7b24c0af5ef197
1 #ifndef _X86_IRQFLAGS_H_
2 #define _X86_IRQFLAGS_H_
4 #include <asm/processor-flags.h>
6 #ifndef __ASSEMBLY__
7 /*
8 * Interrupt control:
9 */
11 static inline unsigned long native_save_fl(void)
13 unsigned long flags;
16 * Note: this needs to be "=r" not "=rm", because we have the
17 * stack offset from what gcc expects at the time the "pop" is
18 * executed, and so a memory reference with respect to the stack
19 * would end up using the wrong address.
21 asm volatile("# __raw_save_flags\n\t"
22 "pushf ; pop %0"
23 : "=r" (flags)
24 : /* no input */
25 : "memory");
27 return flags;
30 static inline void native_restore_fl(unsigned long flags)
32 asm volatile("push %0 ; popf"
33 : /* no output */
34 :"g" (flags)
35 :"memory", "cc");
38 static inline void native_irq_disable(void)
40 asm volatile("cli": : :"memory");
43 static inline void native_irq_enable(void)
45 asm volatile("sti": : :"memory");
48 static inline void native_safe_halt(void)
50 asm volatile("sti; hlt": : :"memory");
53 static inline void native_halt(void)
55 asm volatile("hlt": : :"memory");
58 #endif
60 #ifdef CONFIG_PARAVIRT
61 #include <asm/paravirt.h>
62 #else
63 #ifndef __ASSEMBLY__
65 static inline unsigned long __raw_local_save_flags(void)
67 return native_save_fl();
70 static inline void raw_local_irq_restore(unsigned long flags)
72 native_restore_fl(flags);
75 static inline void raw_local_irq_disable(void)
77 native_irq_disable();
80 static inline void raw_local_irq_enable(void)
82 native_irq_enable();
86 * Used in the idle loop; sti takes one instruction cycle
87 * to complete:
89 static inline void raw_safe_halt(void)
91 native_safe_halt();
95 * Used when interrupts are already enabled or to
96 * shutdown the processor:
98 static inline void halt(void)
100 native_halt();
104 * For spinlocks, etc:
106 static inline unsigned long __raw_local_irq_save(void)
108 unsigned long flags = __raw_local_save_flags();
110 raw_local_irq_disable();
112 return flags;
114 #else
116 #define ENABLE_INTERRUPTS(x) sti
117 #define DISABLE_INTERRUPTS(x) cli
119 #ifdef CONFIG_X86_64
120 #define SWAPGS swapgs
122 * Currently paravirt can't handle swapgs nicely when we
123 * don't have a stack we can rely on (such as a user space
124 * stack). So we either find a way around these or just fault
125 * and emulate if a guest tries to call swapgs directly.
127 * Either way, this is a good way to document that we don't
128 * have a reliable stack. x86_64 only.
130 #define SWAPGS_UNSAFE_STACK swapgs
132 #define PARAVIRT_ADJUST_EXCEPTION_FRAME /* */
134 #define INTERRUPT_RETURN iretq
135 #define USERGS_SYSRET64 \
136 swapgs; \
137 sysretq;
138 #define USERGS_SYSRET32 \
139 swapgs; \
140 sysretl
141 #define ENABLE_INTERRUPTS_SYSEXIT32 \
142 swapgs; \
143 sti; \
144 sysexit
146 #else
147 #define INTERRUPT_RETURN iret
148 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
149 #define GET_CR0_INTO_EAX movl %cr0, %eax
150 #endif
153 #endif /* __ASSEMBLY__ */
154 #endif /* CONFIG_PARAVIRT */
156 #ifndef __ASSEMBLY__
157 #define raw_local_save_flags(flags) \
158 do { (flags) = __raw_local_save_flags(); } while (0)
160 #define raw_local_irq_save(flags) \
161 do { (flags) = __raw_local_irq_save(); } while (0)
163 static inline int raw_irqs_disabled_flags(unsigned long flags)
165 return !(flags & X86_EFLAGS_IF);
168 static inline int raw_irqs_disabled(void)
170 unsigned long flags = __raw_local_save_flags();
172 return raw_irqs_disabled_flags(flags);
176 * makes the traced hardirq state match with the machine state
178 * should be a rarely used function, only in places where its
179 * otherwise impossible to know the irq state, like in traps.
181 static inline void trace_hardirqs_fixup_flags(unsigned long flags)
183 if (raw_irqs_disabled_flags(flags))
184 trace_hardirqs_off();
185 else
186 trace_hardirqs_on();
189 static inline void trace_hardirqs_fixup(void)
191 unsigned long flags = __raw_local_save_flags();
193 trace_hardirqs_fixup_flags(flags);
196 #else
198 #ifdef CONFIG_X86_64
199 #define ARCH_LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk
200 #define ARCH_LOCKDEP_SYS_EXIT_IRQ \
201 TRACE_IRQS_ON; \
202 sti; \
203 SAVE_REST; \
204 LOCKDEP_SYS_EXIT; \
205 RESTORE_REST; \
206 cli; \
207 TRACE_IRQS_OFF;
209 #else
210 #define ARCH_LOCKDEP_SYS_EXIT \
211 pushl %eax; \
212 pushl %ecx; \
213 pushl %edx; \
214 call lockdep_sys_exit; \
215 popl %edx; \
216 popl %ecx; \
217 popl %eax;
219 #define ARCH_LOCKDEP_SYS_EXIT_IRQ
220 #endif
222 #ifdef CONFIG_TRACE_IRQFLAGS
223 # define TRACE_IRQS_ON call trace_hardirqs_on_thunk;
224 # define TRACE_IRQS_OFF call trace_hardirqs_off_thunk;
225 #else
226 # define TRACE_IRQS_ON
227 # define TRACE_IRQS_OFF
228 #endif
229 #ifdef CONFIG_DEBUG_LOCK_ALLOC
230 # define LOCKDEP_SYS_EXIT ARCH_LOCKDEP_SYS_EXIT
231 # define LOCKDEP_SYS_EXIT_IRQ ARCH_LOCKDEP_SYS_EXIT_IRQ
232 # else
233 # define LOCKDEP_SYS_EXIT
234 # define LOCKDEP_SYS_EXIT_IRQ
235 # endif
237 #endif /* __ASSEMBLY__ */
238 #endif