1 /* 2 * Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _KERNEL_ARCH_x86_INT_H 6 #define _KERNEL_ARCH_x86_INT_H 7 8 9 #define ARCH_INTERRUPT_BASE 0x20 10 #define NUM_IO_VECTORS (256 - ARCH_INTERRUPT_BASE) 11 12 13 static inline void 14 arch_int_enable_interrupts_inline(void) 15 { 16 asm volatile("sti"); 17 } 18 19 20 static inline int 21 arch_int_disable_interrupts_inline(void) 22 { 23 int flags; 24 25 asm volatile("pushfl;\n" 26 "popl %0;\n" 27 "cli" : "=g" (flags)); 28 return (flags & 0x200) != 0; 29 } 30 31 32 static inline void 33 arch_int_restore_interrupts_inline(int oldState) 34 { 35 int flags = oldState ? 0x200 : 0; 36 37 asm volatile("pushfl;\n" 38 "popl %0;\n" 39 "andl $0xfffffdff,%0;\n" 40 "orl %1,%0;\n" 41 "pushl %0;\n" 42 "popfl\n" 43 : "=&r"(flags) : "r"(flags)); 44 } 45 46 47 static inline bool 48 arch_int_are_interrupts_enabled_inline(void) 49 { 50 int flags; 51 52 asm volatile("pushfl;\n" 53 "popl %0;\n" : "=g" (flags)); 54 return (flags & 0x200) != 0; 55 } 56 57 58 // map the functions to the inline versions 59 #define arch_int_enable_interrupts() arch_int_enable_interrupts_inline() 60 #define arch_int_disable_interrupts() arch_int_disable_interrupts_inline() 61 #define arch_int_restore_interrupts(status) \ 62 arch_int_restore_interrupts_inline(status) 63 #define arch_int_are_interrupts_enabled() \ 64 arch_int_are_interrupts_enabled_inline() 65 66 67 #endif /* _KERNEL_ARCH_x86_INT_H */ 68