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.
 
 
 
 
 
 

90 line
1.9 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
  4. * 2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
  5. * All Rights Reserved
  6. *
  7. * This library is free software. It comes without any warranty, to
  8. * the extent permitted by applicable law. You can redistribute it
  9. * and/or modify it under the terms of the Do What The Fuck You Want
  10. * To Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. #include "klibc.h"
  14. #define PIC_MASTER_ICW1 0x20
  15. #define PIC_MASTER_ICW2 0x21
  16. #define PIC_SLAVE_ICW1 0xA0
  17. #define PIC_SLAVE_ICW2 0xA1
  18. void init_pic(void)
  19. {
  20. /* MASTER */
  21. outbp(PIC_MASTER_ICW1, 0x11); // Init 8259A-1
  22. /* ICW2 - start vector = 32 */
  23. outbp(PIC_MASTER_ICW2, 0x20); // IRQ 0-7 mapped to 0x20-0x27
  24. /* IICW3 */
  25. outbp(PIC_MASTER_ICW2, 0x04); // 8259A-1 has slave
  26. /* ICW4 */
  27. outbp(PIC_MASTER_ICW2, 0x01);
  28. /* Int mask */
  29. outbp(PIC_MASTER_ICW2, 0xFF);
  30. /* SLAVE */
  31. outbp(PIC_SLAVE_ICW1, 0x11);
  32. /* ICW2 - start vector = 96 */
  33. outbp(PIC_SLAVE_ICW2, 0x70);
  34. /* ICW3 */
  35. outbp(PIC_SLAVE_ICW2, 0x02);
  36. /* ICW4 */
  37. outbp(PIC_SLAVE_ICW2, 0x01);
  38. /* Int Mask */
  39. outbp(PIC_SLAVE_ICW2, 0xFF);
  40. /* Unmask irqs */
  41. outbp(0x21, 0xFD);
  42. }
  43. static unsigned int cached_irq_mask = 0xffff;
  44. #define __byte(x,y) (((unsigned char *)&(y))[x])
  45. #define cached_21 (__byte(0,cached_irq_mask))
  46. #define cached_A1 (__byte(1,cached_irq_mask))
  47. void disable_interrupt(char irq)
  48. {
  49. unsigned int mask = 1 << irq;
  50. cached_irq_mask |= mask;
  51. if (irq & 8)
  52. {
  53. outb(0xA1, cached_A1);
  54. }
  55. else
  56. {
  57. outb(0x21, cached_21);
  58. }
  59. }
  60. void enable_interrupt(char irq)
  61. {
  62. unsigned int mask = ~(1 << irq);
  63. cached_irq_mask &= mask;
  64. if (irq & 8)
  65. {
  66. outb(0xA1, cached_A1);
  67. }
  68. else
  69. {
  70. outb(0x21, cached_21);
  71. }
  72. }