| 150 | } |
| 151 | |
| 152 | void Initialize() { |
| 153 | idt_ptr.limit = sizeof(idt_entry_t) * 256 - 1; |
| 154 | idt_ptr.base = (uint64_t)&idt; |
| 155 | |
| 156 | for(int i = 0; i < 256; i++){ |
| 157 | SetGate(i, 0, 0x08, 0x8E); |
| 158 | } |
| 159 | |
| 160 | for(unsigned i = 48; i < 256; i++){ |
| 161 | SetGate(i, int_vectors[i - 48], 0x08, 0x8E); |
| 162 | } |
| 163 | |
| 164 | SetGate(0, (uint64_t)isr0,0x08,0x8E); |
| 165 | SetGate(1, (uint64_t)isr1,0x08,0x8E); |
| 166 | SetGate(2, (uint64_t)isr2,0x08,0x8E); |
| 167 | SetGate(3, (uint64_t)isr3,0x08,0x8E); |
| 168 | SetGate(4, (uint64_t)isr4,0x08,0x8E); |
| 169 | SetGate(5, (uint64_t)isr5,0x08,0x8E); |
| 170 | SetGate(6, (uint64_t)isr6,0x08,0x8E); |
| 171 | SetGate(7, (uint64_t)isr7,0x08,0x8E); |
| 172 | SetGate(8, (uint64_t)isr8,0x08,0x8E, 2); // Double Fault |
| 173 | SetGate(9, (uint64_t)isr9,0x08,0x8E); |
| 174 | SetGate(10, (uint64_t)isr10,0x08,0x8E); |
| 175 | SetGate(11, (uint64_t)isr11,0x08,0x8E); |
| 176 | SetGate(12, (uint64_t)isr12,0x08,0x8E); |
| 177 | SetGate(13, (uint64_t)isr13,0x08,0x8E); |
| 178 | SetGate(14, (uint64_t)isr14,0x08,0x8E); |
| 179 | SetGate(15, (uint64_t)isr15,0x08,0x8E); |
| 180 | SetGate(16, (uint64_t)isr16,0x08,0x8E); |
| 181 | SetGate(17, (uint64_t)isr17,0x08,0x8E); |
| 182 | SetGate(18, (uint64_t)isr18,0x08,0x8E); |
| 183 | SetGate(19, (uint64_t)isr19,0x08,0x8E); |
| 184 | SetGate(20, (uint64_t)isr20,0x08,0x8E); |
| 185 | SetGate(21, (uint64_t)isr21,0x08,0x8E); |
| 186 | SetGate(22, (uint64_t)isr22,0x08,0x8E); |
| 187 | SetGate(23, (uint64_t)isr23,0x08,0x8E); |
| 188 | SetGate(24, (uint64_t)isr24,0x08,0x8E); |
| 189 | SetGate(25, (uint64_t)isr25,0x08,0x8E); |
| 190 | SetGate(26, (uint64_t)isr26,0x08,0x8E); |
| 191 | SetGate(27, (uint64_t)isr27,0x08,0x8E); |
| 192 | SetGate(28, (uint64_t)isr28,0x08,0x8E); |
| 193 | SetGate(29, (uint64_t)isr29,0x08,0x8E); |
| 194 | SetGate(30, (uint64_t)isr30,0x08,0x8E); |
| 195 | SetGate(31, (uint64_t)isr31,0x08,0x8E); |
| 196 | SetGate(0x69, (uint64_t)isr0x69, 0x08, 0xEE /* Allow syscalls to be called from user mode*/, 0); // Syscall |
| 197 | |
| 198 | idt_flush(); |
| 199 | |
| 200 | outportb(0x20, 0x11); |
| 201 | outportb(0xA0, 0x11); |
| 202 | outportb(0x21, 0x20); |
| 203 | outportb(0xA1, 0x28); |
| 204 | outportb(0x21, 0x04); |
| 205 | outportb(0xA1, 0x02); |
| 206 | outportb(0x21, 0x01); |
| 207 | outportb(0xA1, 0x01); |
| 208 | outportb(0x21, 0x0); |
| 209 | outportb(0xA1, 0x0); |