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.
 
 
 
 
 
 

93 lines
2.0 KiB

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