You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

74 lines
1.3 KiB

  1. #include "klibc.h"
  2. #define PIC_MASTER_ICW1 0x20
  3. #define PIC_MASTER_ICW2 0x21
  4. #define PIC_SLAVE_ICW1 0xA0
  5. #define PIC_SLAVE_ICW2 0xA1
  6. void init_pic(void)
  7. {
  8. /* MASTER */
  9. outbp(PIC_MASTER_ICW1,0x11); // Init 8259A-1
  10. /* ICW2 - start vector = 32 */
  11. outbp(PIC_MASTER_ICW2,0x20); // IRQ 0-7 mapped to 0x20-0x27
  12. /* IICW3 */
  13. outbp(PIC_MASTER_ICW2,0x04); // 8259A-1 has slave
  14. /* ICW4 */
  15. outbp(PIC_MASTER_ICW2,0x01);
  16. /* Int mask */
  17. outbp(PIC_MASTER_ICW2,0xFF);
  18. /* SLAVE */
  19. outbp(PIC_SLAVE_ICW1,0x11);
  20. /* ICW2 - start vector = 96 */
  21. outbp(PIC_SLAVE_ICW2,0x70);
  22. /* ICW3 */
  23. outbp(PIC_SLAVE_ICW2,0x02);
  24. /* ICW4 */
  25. outbp(PIC_SLAVE_ICW2,0x01);
  26. /* Int Mask */
  27. outbp(PIC_SLAVE_ICW2,0xFF);
  28. /* Unmask irqs */
  29. outbp(0x21,0xFD);
  30. }
  31. static unsigned int cached_irq_mask = 0xffff;
  32. #define __byte(x,y) (((unsigned char *)&(y))[x])
  33. #define cached_21 (__byte(0,cached_irq_mask))
  34. #define cached_A1 (__byte(1,cached_irq_mask))
  35. void disable_interrupt(char irq)
  36. {
  37. unsigned int mask = 1 << irq;
  38. cached_irq_mask |= mask;
  39. if (irq & 8) {
  40. outb(0xA1, cached_A1);
  41. } else {
  42. outb(0x21, cached_21);
  43. }
  44. }
  45. void enable_interrupt(char irq)
  46. {
  47. unsigned int mask = ~(1 << irq);
  48. cached_irq_mask &= mask;
  49. if (irq & 8) {
  50. outb(0xA1, cached_A1);
  51. } else {
  52. outb(0x21, cached_21);
  53. }
  54. }