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 ; 29 } 30 31 32 static inline void 33 arch_int_restore_interrupts_inline(int oldState) 34 { 35 if (oldState & 0x200) 36 asm("sti"); 37 } 38 39 40 static inline bool 41 arch_int_are_interrupts_enabled_inline(void) 42 { 43 int flags; 44 45 asm volatile("pushfl;\n" 46 "popl %0;\n" : "=g" (flags)); 47 return (flags & 0x200) != 0; 48 } 49 50 51 // map the functions to the inline versions 52 #define arch_int_enable_interrupts() arch_int_enable_interrupts_inline() 53 #define arch_int_disable_interrupts() arch_int_disable_interrupts_inline() 54 #define arch_int_restore_interrupts(status) \ 55 arch_int_restore_interrupts_inline(status) 56 #define arch_int_are_interrupts_enabled() \ 57 arch_int_are_interrupts_enabled_inline() 58 59 60 #ifdef __cplusplus 61 62 typedef struct interrupt_controller_s { 63 const char *name; 64 void (*enable_io_interrupt)(int32 num); 65 void (*disable_io_interrupt)(int32 num); 66 void (*configure_io_interrupt)(int32 num, uint32 config); 67 bool (*is_spurious_interrupt)(int32 num); 68 bool (*is_level_triggered_interrupt)(int32 num); 69 bool (*end_of_interrupt)(int32 num); 70 } interrupt_controller; 71 72 73 void arch_int_set_interrupt_controller(const interrupt_controller &controller); 74 75 #endif // __cplusplus 76 77 #endif /* _KERNEL_ARCH_x86_INT_H */ 78