! Fixed the root Makefile
[lightOS.git] / kernel / x86 / idt.cpp
blob36f76c5f1dbb2978108fa7507224455f26f394f0
1 /*
2 lightOS kernel
3 Copyright (C) 2007-2009 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <kernel/x86_shared/idt.hpp>
20 using namespace kernel;
22 void idt::set_interrupt_gate( uint8_t number,
23 interrupt_handler handler)
25 mIdt[number].offset0 = reinterpret_cast<uintptr_t>(handler) & 0xFFFF;
26 mIdt[number].selector = 0x08;
27 mIdt[number].reserved = 0;
28 mIdt[number].flags = 0x8E;
29 mIdt[number].offset1 = (reinterpret_cast<uintptr_t>(handler) >> 16) & 0xFFFF;
31 idt::interrupt_handler idt::get_interrupt_gate(uint8_t number)
33 uint32_t address = mIdt[number].offset0 | (mIdt[number].offset1 << 16);
34 return reinterpret_cast<interrupt_handler>(address);
36 void idt::set_userspace_interrupt_gate( uint8_t number,
37 interrupt_handler handler)
39 set_interrupt_gate(number, handler);
40 mIdt[number].flags = 0xEE;
42 #ifdef _LIGHTOS_V86
43 void idt::set_task_gate(uint8_t number, uint8_t flags, uint16_t selector)
45 mIdt[number].selector = selector;
46 mIdt[number].flags = flags;
48 #endif
49 void idt::load()
51 struct
53 uint16_t size;
54 uint32_t idt;
55 } __attribute__((packed)) idtr = {2047, reinterpret_cast<uintptr_t>(&mIdt)};
57 asm volatile("lidt %0" :: "m"(idtr));