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
24
|
ICW1_1::CASCADE
25
|
ICW1_2::INTRP_8B
26
|
ICW1_3::EDGE_TRIGGERED
27
|
ICW1_4::USE_ICW1
;
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)
47
out8(
PORTS::PIC1_DATA
,
INTRP::IVT::USER_DEFINED_END
);
48
out8(
PORTS::PIC2_DATA
,
INTRP::IVT::USER_DEFINED_END
);
49
50
UnmaskInterrupt
(
INTRP::IVT::PIC2_CASCADE
);
// enable IRQ2 as cascade on IRQ1
51
}
52
53
}
// namespace PIC
54
PORTS::PIC1_DATA
Definition:
ports.h:14
pic.h
PIC::Remap
void Remap()
Remap default 8259 PIC interrupt number to new range.
Definition:
pic.cpp:20
INTRP::USER_DEFINED_END
0xFF
Definition:
interrupt.h:66
INTRP::PIC1_OFFSET
0x20
Definition:
interrupt.h:45
IrqPort
Definition:
interrupt.h:130
PORTS::PIC2_COMMAND
Definition:
ports.h:15
PIC::EOI
Definition:
pic.h:86
PIC::INTRP_8B
Definition:
pic.h:62
INTRP::PIC2_OFFSET
0x28
Definition:
interrupt.h:56
PIC::CASCADE
Definition:
pic.h:56
PIC::SEQUENTIAL
Definition:
pic.h:92
UnmaskInterrupt
void UnmaskInterrupt(const IrqPort Irq)
Definition:
interrupt.h:156
interrupt.h
PIC::MODE_8086
Definition:
pic.h:81
PIC::USE_ICW1
Definition:
pic.h:75
PIC
8259 Progammable interrupt controller
Definition:
pic.h:46
PORTS::PIC2_DATA
Definition:
ports.h:16
INTRP::USER_DEFINED_START
Definition:
interrupt.h:46
PIC::EDGE_TRIGGERED
Definition:
pic.h:68
INTRP::PIC2_CASCADE
Definition:
interrupt.h:49
PIC::USE_ICW4
Definition:
pic.h:51
PORTS::PIC1_COMMAND
Definition:
ports.h:13
OS
kernel
arch
x86
pic.cpp
Generated by
1.8.13