summaryrefslogtreecommitdiffstats
path: root/arch/x86/PrimaryInit.cpp
blob: bd039040cd073e2723232367ea232f74e96015bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "PrimaryInit.h"

// Test ISRs define start
__attribute__((interrupt)) void isr0(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "Divide error" << '\n';
};

__attribute__((interrupt)) void isr1(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "Debug exception" << '\n';
};

__attribute__((interrupt)) void isr2(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "NMI interrupt" << '\n';
};

__attribute__((interrupt)) void isr3(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "Breakpoint" << '\n';
};

__attribute__((interrupt)) void isr4(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "Overflow" << '\n';
};

__attribute__((interrupt)) void isr5(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "Bound range exceed" << '\n';
};

__attribute__((interrupt)) void isr6(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "Invalid opcode" << '\n';
};

__attribute__((interrupt)) void isr7(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "No math coprocessor" << '\n';
};

__attribute__((interrupt)) void isr8(const struct InterruptFrame *frame, const uword errorCode)
{
    asm("cli\n\t");
    out::display << "Double fault" << '\n';
};

__attribute__((interrupt)) void isr10(const struct InterruptFrame *frame, const uword errorCode)
{
    asm("cli\n\t");
    out::display << "Invalid TSS" << "\n";
};

__attribute__((interrupt)) void isr11(const struct InterruptFrame *frame, const uword errorCode)
{
    asm("cli\n\t");
    out::display << "Segment not present" << "\n";
};

__attribute__((interrupt)) void isr12(const struct InterruptFrame *frame, const uword errorCode)
{
    asm("cli\n\t");
    out::display << "Stack segment fault" << "\n";
};

__attribute__((interrupt)) void isr13(const struct InterruptFrame *frame, const uword errorCode)
{
    asm("cli\n\t");
    out::display << "#GP" << "\n";
};

__attribute__((interrupt)) void isr14(const struct InterruptFrame *frame, const uword errorCode)
{
    asm("cli\n\t");
    out::display << "Page fault" << "\n";
};

__attribute__((interrupt)) void isr16(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "Math fault" << "\n";
};

__attribute__((interrupt)) void isr17(const struct InterruptFrame *frame, const uword errorCode)
{
    asm("cli\n\t");
    out::display << "Alignment check" << "\n";
};

__attribute__((interrupt)) void isr18(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "Machine check" << "\n";
};

__attribute__((interrupt)) void isr19(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "SIMD point exception" << "\n";
};

__attribute__((interrupt)) void isr20(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "Virtualization exception" << "\n";
};

__attribute__((interrupt)) void isr21(const struct InterruptFrame *frame, const uword errorCode)
{
    asm("cli\n\t");
    out::display << "Control protection exception" << "\n";
};

__attribute__((interrupt)) void isrUser(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "User-defined interrupt" << "\n";
};

__attribute__((interrupt)) void isrKeyboard(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "KINT " << (uint32)PortOps::inb(0x60);

    Pic::sendEoi();
};
__attribute__((interrupt)) void isrTimer(const struct InterruptFrame *frame)
{
    asm("cli\n\t");
    out::display << "Timer interrupt" << "\n";

    Pic::sendEoi();
};
//Test ISRs define end -------------------

void isrPerform::perform(null null, DescInterrupt32 &desc) {};

void isrPerform::perform(isr funp, DescInterrupt32 &desc)
{
    desc.setOffset((uint32)funp);
    mngIdt.addDescriptor(desc);
};

void isrPerform::perform(isrExc funp, DescInterrupt32 &desc)
{
    desc.setOffset((uint32)funp);
    mngIdt.addDescriptor(desc);
};

void PrimaryInitialization::processorInitialize()
{
    MngIdt &mngIdt = MngIdt::getInstance();
    MngGdt &mngGdt = MngGdt::getInstance();

    mngGdt.addDescriptor(DescSeg32::flatCodeKernel());
    mngGdt.addDescriptor(DescSeg32::flatDataKernel());
    mngGdt.loadGdt();

    InterruptFuncs intf = InterruptFuncs
                              (
                                isr0, isr1, isr2, isr3,
                                isr4, isr5, isr6, isr7,
                                isr8, nullptr, isr10, isr11,
                                isr12, isr13, isr14, nullptr,
                                isr16, isr17, isr18, isr19,
                                isr20, isr21, nullptr, nullptr,
                                nullptr, nullptr, nullptr, nullptr,
                                nullptr, nullptr, nullptr, nullptr,
                                isrTimer, isrKeyboard
                              );

    DescInterrupt32 descInt = DescInterrupt32::TrapKernelLong
                              (
                                NULL,
                                mngGdt.getCodeSegmentKernel()
                              );
    intf.foreach<isrPerform>(descInt);
    mngIdt.loadIdt();

};

void PrimaryInitialization::devicesInitialize()
{
    out::display = VGADisplay();
    picSingle = SingletonPic();

    Pic *pic = picSingle.getInstance();

    uint8 intn = mngIdt.getIrqInterruptStart();
    while(intn < mngIdt.getIrqInterruptStart() + Pic::numberIrq)
    {
        pic->enableIrq(intn++ - mngIdt.getIrqInterruptStart());
    }
};