io.h (1344B)
1 #ifndef _KERNEL_IO_H_ 2 #define _KERNEL_IO_H_ 3 4 #include <stdint.h> 5 6 #define IO_PIC1_CMD 0x20 7 #define IO_PIC2_CMD 0xa0 8 #define IO_PIC1_DATA (IO_PIC1_CMD + 1) 9 #define IO_PIC2_DATA (IO_PIC2_CMD + 1) 10 #define IO_TIMER_CMD 0x43 11 #define IO_TIMER_DATA 0x40 12 #define IO_CURS_CMD 0x3d4 13 #define IO_CURS_DATA 0x3d5 14 #define IO_KBD 0x60 15 16 static inline uint8_t 17 inb(uint16_t port) 18 { 19 uint8_t res; 20 21 __asm__ __volatile__ ("in %%dx, %%al" : "=a" (res) : "d" (port)); 22 return (res); 23 } 24 25 static inline void 26 outb(uint16_t port, uint8_t v) 27 { 28 __asm__ __volatile__ ("out %%al, %%dx" : : "a" (v), "d" (port)); 29 } 30 31 static inline uint16_t 32 inw(uint16_t port) 33 { 34 uint16_t res; 35 36 __asm__ __volatile__ ("in %%dx, %%ax" : "=a" (res) : "d" (port)); 37 return (res); 38 } 39 40 static inline void 41 outw(uint16_t port, uint16_t v) 42 { 43 __asm__ __volatile__ ("out %%ax, %%dx" : : "a" (v), "d" (port)); 44 } 45 46 static inline uint32_t 47 inl(uint16_t port) 48 { 49 uint32_t res; 50 51 __asm__ __volatile__ ("in %%dx, %%eax" : "=a" (res) : "d" (port)); 52 return (res); 53 } 54 55 static inline void 56 outl(uint16_t port, uint32_t v) 57 { 58 __asm__ __volatile__ ("out %%eax, %%dx" : : "a" (v), "d" (port)); 59 } 60 61 static inline void 62 hlt(void) 63 { 64 __asm__ __volatile__ ("hlt"); 65 } 66 67 static inline void 68 cli(void) 69 { 70 __asm__ __volatile__ ("cli"); 71 } 72 73 static inline void 74 sti(void) 75 { 76 __asm__ __volatile__ ("sti"); 77 } 78 79 #endif /* _KERNEL_IO_H_ */