KernOS
pic.cpp
Go to the documentation of this file.
1 //
2 // Created on 8/15/20.
3 //
4 
5 #include <pic.h>
6 #include <interrupt.h>
7 
8 namespace PIC
9 {
20  void Remap()
21  {
22  // ICW1 - initialize PIC1, PIC2, and tell them to receive ICW 2,3,4 next
23  constexpr uint8_t ICW1_SETTING = ICW1_0::USE_ICW4
28 
29  out8(PORTS::PIC1_COMMAND, ICW1_SETTING); // init flag asks PIC1 to read ICW2,3,4
30  out8(PORTS::PIC2_COMMAND, ICW1_SETTING); // init flag asks PIC2 to read ICW2,3,4
31 
32  // ICW2 - remap IRQ
33  out8(PORTS::PIC1_DATA, INTRP::IVT::PIC1_OFFSET); // PIC1 handles IRQ0-7 (IVT 0x20)
34  out8(PORTS::PIC2_DATA, INTRP::IVT::PIC2_OFFSET); // PIC2 handles IRQ8-15 (IVT 0x28)
35 
36  // ICW3 - inform master/slave about each other
37  out8(PORTS::PIC1_DATA, IrqPort(INTRP::IVT::PIC2_CASCADE).m_IrqNumber); // tells PIC1 position of PIC2 in cascade (use IRQ2)
38  out8(PORTS::PIC2_DATA, INTRP::IVT::PIC2_CASCADE - INTRP::IVT::USER_DEFINED_START); // tells PIC2 its IRQ number assigned on PIC1
39 
40  // ICW4 - set PIC operation
41  constexpr uint8_t ICW4_SETTING = PIC::ICW4_0::MODE_8086 | PIC::ICW4_1::EOI | PIC::ICW4_4::SEQUENTIAL;
42 
43  out8(PORTS::PIC1_DATA, ICW4_SETTING);
44  out8(PORTS::PIC2_DATA, ICW4_SETTING);
45 
46  // disable interrupts (bit set indicates masking of interrupt)
49 
50  UnmaskInterrupt(INTRP::IVT::PIC2_CASCADE); // enable IRQ2 as cascade on IRQ1
51  }
52 
53 } // namespace PIC
54 
void Remap()
Remap default 8259 PIC interrupt number to new range.
Definition: pic.cpp:20
Definition: pic.h:86
void UnmaskInterrupt(const IrqPort Irq)
Definition: interrupt.h:156
8259 Progammable interrupt controller
Definition: pic.h:46