2012-02-29 18:15:28 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2014-01-31 07:19:27 -05:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
|
2012-02-29 18:15:28 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
This file is part of Sortix.
|
2012-02-29 18:15:28 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Sortix is free software: you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
version.
|
2012-02-29 18:15:28 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
2012-02-29 18:15:28 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
2012-02-29 18:15:28 -05:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
x86-family/idt.cpp
|
2013-06-19 18:01:04 -04:00
|
|
|
Initializes and handles the interrupt descriptor table.
|
2012-02-29 18:15:28 -05:00
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2013-06-19 18:01:04 -04:00
|
|
|
#include <stdint.h>
|
2012-09-22 14:38:34 -04:00
|
|
|
#include <string.h>
|
2013-06-19 18:01:04 -04:00
|
|
|
|
2012-02-29 18:15:28 -05:00
|
|
|
#include "idt.h"
|
|
|
|
|
2013-06-19 18:01:04 -04:00
|
|
|
namespace Sortix {
|
|
|
|
namespace IDT {
|
|
|
|
|
2014-01-31 07:19:27 -05:00
|
|
|
void Set(struct idt_entry* table, size_t length)
|
2012-02-29 18:15:28 -05:00
|
|
|
{
|
2014-01-31 07:19:27 -05:00
|
|
|
size_t limit = sizeof(idt_entry) * length - 1;
|
2013-06-19 18:01:04 -04:00
|
|
|
#if defined(__x86_64__)
|
2014-01-31 07:19:27 -05:00
|
|
|
asm volatile ("subq $10, %%rsp\n\t"
|
|
|
|
"movw %w0, 0(%%rsp)\n\t"
|
|
|
|
"movq %1, 2(%%rsp)\n\t"
|
|
|
|
"lidt (%%rsp)\n\t"
|
|
|
|
"addq $10, %%rsp" : : "rN"(limit), "r"(table));
|
2013-06-19 18:01:04 -04:00
|
|
|
#else
|
2014-01-31 07:19:27 -05:00
|
|
|
asm volatile ("subl $6, %%esp\n\t"
|
|
|
|
"movw %w0, 0(%%esp)\n\t"
|
|
|
|
"movl %1, 2(%%esp)\n\t"
|
|
|
|
"lidt (%%esp)\n\t"
|
|
|
|
"addl $6, %%esp" : : "rN"(limit), "r"(table));
|
2012-02-29 18:15:28 -05:00
|
|
|
#endif
|
2013-06-19 18:01:04 -04:00
|
|
|
}
|
|
|
|
|
2014-01-31 07:19:27 -05:00
|
|
|
void SetEntry(struct idt_entry* entry, uintptr_t handler, uint16_t selector, uint8_t flags, uint8_t ist)
|
2013-06-19 18:01:04 -04:00
|
|
|
{
|
2014-01-31 07:19:27 -05:00
|
|
|
entry->flags = flags;
|
|
|
|
entry->ist = ist;
|
|
|
|
entry->selector = selector;
|
|
|
|
entry->handler_low = handler >> 0 & 0xFFFF;
|
|
|
|
entry->handler_high = handler >> 16 & 0xFFFF;
|
2013-06-19 18:01:04 -04:00
|
|
|
#if defined(__x86_64__)
|
2014-01-31 07:19:27 -05:00
|
|
|
entry->handler_highest = handler >> 32 & 0xFFFFFFFFU;
|
|
|
|
entry->reserved1 = 0;
|
2013-06-19 18:01:04 -04:00
|
|
|
#endif
|
2012-02-29 18:15:28 -05:00
|
|
|
}
|
2013-06-19 18:01:04 -04:00
|
|
|
|
|
|
|
} // namespace IDT
|
|
|
|
} // namespace Sortix
|