Refactored the interrupt code to make it cleaner and more flexible.
Added support for hooking directly into an interrupt with your own interrupt handler.
This commit is contained in:
parent
7ebed6dd6a
commit
0e48b23429
|
@ -1,6 +1,6 @@
|
||||||
/******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -14,13 +14,13 @@
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
details.
|
details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License along with
|
||||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
descriptor_tables.cpp
|
descriptor_tables.cpp
|
||||||
Initializes and handles the GDT, TSS and IDT.
|
Initializes and handles the GDT, TSS and IDT.
|
||||||
|
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
@ -183,57 +183,10 @@ namespace Sortix
|
||||||
CPU::OutPortB(0xA1, 0x01);
|
CPU::OutPortB(0xA1, 0x01);
|
||||||
CPU::OutPortB(0x21, 0x0);
|
CPU::OutPortB(0x21, 0x0);
|
||||||
CPU::OutPortB(0xA1, 0x0);
|
CPU::OutPortB(0xA1, 0x0);
|
||||||
|
}
|
||||||
|
|
||||||
SetGate( 0, (addr_t) isr0 , 0x08, 0x8E);
|
void Flush()
|
||||||
SetGate( 1, (addr_t) isr1 , 0x08, 0x8E);
|
{
|
||||||
SetGate( 2, (addr_t) isr2 , 0x08, 0x8E);
|
|
||||||
SetGate( 3, (addr_t) isr3 , 0x08, 0x8E);
|
|
||||||
SetGate( 4, (addr_t) isr4 , 0x08, 0x8E);
|
|
||||||
SetGate( 5, (addr_t) isr5 , 0x08, 0x8E);
|
|
||||||
SetGate( 6, (addr_t) isr6 , 0x08, 0x8E);
|
|
||||||
SetGate( 7, (addr_t) isr7 , 0x08, 0x8E);
|
|
||||||
SetGate( 8, (addr_t) isr8 , 0x08, 0x8E);
|
|
||||||
SetGate( 9, (addr_t) isr9 , 0x08, 0x8E);
|
|
||||||
SetGate(10, (addr_t) isr10, 0x08, 0x8E);
|
|
||||||
SetGate(11, (addr_t) isr11, 0x08, 0x8E);
|
|
||||||
SetGate(12, (addr_t) isr12, 0x08, 0x8E);
|
|
||||||
SetGate(13, (addr_t) isr13, 0x08, 0x8E);
|
|
||||||
SetGate(14, (addr_t) isr14, 0x08, 0x8E);
|
|
||||||
SetGate(15, (addr_t) isr15, 0x08, 0x8E);
|
|
||||||
SetGate(16, (addr_t) isr16, 0x08, 0x8E);
|
|
||||||
SetGate(17, (addr_t) isr17, 0x08, 0x8E);
|
|
||||||
SetGate(18, (addr_t) isr18, 0x08, 0x8E);
|
|
||||||
SetGate(19, (addr_t) isr19, 0x08, 0x8E);
|
|
||||||
SetGate(20, (addr_t) isr20, 0x08, 0x8E);
|
|
||||||
SetGate(21, (addr_t) isr21, 0x08, 0x8E);
|
|
||||||
SetGate(22, (addr_t) isr22, 0x08, 0x8E);
|
|
||||||
SetGate(23, (addr_t) isr23, 0x08, 0x8E);
|
|
||||||
SetGate(24, (addr_t) isr24, 0x08, 0x8E);
|
|
||||||
SetGate(25, (addr_t) isr25, 0x08, 0x8E);
|
|
||||||
SetGate(26, (addr_t) isr26, 0x08, 0x8E);
|
|
||||||
SetGate(27, (addr_t) isr27, 0x08, 0x8E);
|
|
||||||
SetGate(28, (addr_t) isr28, 0x08, 0x8E);
|
|
||||||
SetGate(29, (addr_t) isr29, 0x08, 0x8E);
|
|
||||||
SetGate(30, (addr_t) isr30, 0x08, 0x8E);
|
|
||||||
SetGate(31, (addr_t) isr31, 0x08, 0x8E);
|
|
||||||
SetGate(32, (addr_t) irq0, 0x08, 0x8E);
|
|
||||||
SetGate(33, (addr_t) irq1, 0x08, 0x8E);
|
|
||||||
SetGate(34, (addr_t) irq2, 0x08, 0x8E);
|
|
||||||
SetGate(35, (addr_t) irq3, 0x08, 0x8E);
|
|
||||||
SetGate(36, (addr_t) irq4, 0x08, 0x8E);
|
|
||||||
SetGate(37, (addr_t) irq5, 0x08, 0x8E);
|
|
||||||
SetGate(38, (addr_t) irq6, 0x08, 0x8E);
|
|
||||||
SetGate(39, (addr_t) irq7, 0x08, 0x8E);
|
|
||||||
SetGate(40, (addr_t) irq8, 0x08, 0x8E);
|
|
||||||
SetGate(41, (addr_t) irq9, 0x08, 0x8E);
|
|
||||||
SetGate(42, (addr_t) irq10, 0x08, 0x8E);
|
|
||||||
SetGate(43, (addr_t) irq11, 0x08, 0x8E);
|
|
||||||
SetGate(44, (addr_t) irq12, 0x08, 0x8E);
|
|
||||||
SetGate(45, (addr_t) irq13, 0x08, 0x8E);
|
|
||||||
SetGate(46, (addr_t) irq14, 0x08, 0x8E);
|
|
||||||
SetGate(47, (addr_t) irq15, 0x08, 0x8E);
|
|
||||||
SetGate(128, (addr_t) syscall_handler, 0x08, 0x8E | 0x60); // System Calls
|
|
||||||
|
|
||||||
idt_flush((addr_t) &idt_ptr);
|
idt_flush((addr_t) &idt_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -14,13 +14,13 @@
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
details.
|
details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License along with
|
||||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
descriptor_tables.cpp
|
descriptor_tables.h
|
||||||
Initializes and handles the GDT, TSS and IDT.
|
Initializes and handles the GDT, TSS and IDT.
|
||||||
|
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#ifndef SORTIX_DESCRIPTOR_TABLES_H
|
#ifndef SORTIX_DESCRIPTOR_TABLES_H
|
||||||
#define SORTIX_DESCRIPTOR_TABLES_H
|
#define SORTIX_DESCRIPTOR_TABLES_H
|
||||||
|
@ -125,7 +125,6 @@ namespace Sortix
|
||||||
|
|
||||||
namespace IDT
|
namespace IDT
|
||||||
{
|
{
|
||||||
|
|
||||||
// A struct describing an interrupt gate.
|
// A struct describing an interrupt gate.
|
||||||
struct idt_entry32_struct
|
struct idt_entry32_struct
|
||||||
{
|
{
|
||||||
|
@ -168,59 +167,9 @@ namespace Sortix
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void SetGate(uint8_t num, addr_t base, uint16_t sel, uint8_t flags);
|
void SetGate(uint8_t num, addr_t base, uint16_t sel, uint8_t flags);
|
||||||
|
void Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// These extern directives let us access the addresses of our ASM ISR handlers.
|
|
||||||
extern "C" void isr0 ();
|
|
||||||
extern "C" void isr1 ();
|
|
||||||
extern "C" void isr2 ();
|
|
||||||
extern "C" void isr3 ();
|
|
||||||
extern "C" void isr4 ();
|
|
||||||
extern "C" void isr5 ();
|
|
||||||
extern "C" void isr6 ();
|
|
||||||
extern "C" void isr7 ();
|
|
||||||
extern "C" void isr8 ();
|
|
||||||
extern "C" void isr9 ();
|
|
||||||
extern "C" void isr10();
|
|
||||||
extern "C" void isr11();
|
|
||||||
extern "C" void isr12();
|
|
||||||
extern "C" void isr13();
|
|
||||||
extern "C" void isr14();
|
|
||||||
extern "C" void isr15();
|
|
||||||
extern "C" void isr16();
|
|
||||||
extern "C" void isr17();
|
|
||||||
extern "C" void isr18();
|
|
||||||
extern "C" void isr19();
|
|
||||||
extern "C" void isr20();
|
|
||||||
extern "C" void isr21();
|
|
||||||
extern "C" void isr22();
|
|
||||||
extern "C" void isr23();
|
|
||||||
extern "C" void isr24();
|
|
||||||
extern "C" void isr25();
|
|
||||||
extern "C" void isr26();
|
|
||||||
extern "C" void isr27();
|
|
||||||
extern "C" void isr28();
|
|
||||||
extern "C" void isr29();
|
|
||||||
extern "C" void isr30();
|
|
||||||
extern "C" void isr31();
|
|
||||||
extern "C" void isr128();
|
|
||||||
extern "C" void irq0 ();
|
|
||||||
extern "C" void irq1 ();
|
|
||||||
extern "C" void irq2 ();
|
|
||||||
extern "C" void irq3 ();
|
|
||||||
extern "C" void irq4 ();
|
|
||||||
extern "C" void irq5 ();
|
|
||||||
extern "C" void irq6 ();
|
|
||||||
extern "C" void irq7 ();
|
|
||||||
extern "C" void irq8 ();
|
|
||||||
extern "C" void irq9 ();
|
|
||||||
extern "C" void irq10();
|
|
||||||
extern "C" void irq11();
|
|
||||||
extern "C" void irq12();
|
|
||||||
extern "C" void irq13();
|
|
||||||
extern "C" void irq14();
|
|
||||||
extern "C" void irq15();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -14,18 +14,17 @@
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
details.
|
details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License along with
|
||||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
interrupt.cpp
|
interrupt.cpp
|
||||||
High level interrupt service routines and interrupt request handlers.
|
High level interrupt service routines and interrupt request handlers.
|
||||||
|
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "log.h"
|
#include "descriptor_tables.h"
|
||||||
#include "interrupt.h"
|
#include "interrupt.h"
|
||||||
#include "panic.h"
|
|
||||||
|
|
||||||
#include "process.h" // Hack for SIGSEGV
|
#include "process.h" // Hack for SIGSEGV
|
||||||
#include "sound.h" // Hack for SIGSEGV
|
#include "sound.h" // Hack for SIGSEGV
|
||||||
|
@ -33,18 +32,18 @@
|
||||||
#include "syscall.h" // HACK FOR SIGSEGV
|
#include "syscall.h" // HACK FOR SIGSEGV
|
||||||
#include "scheduler.h" // HACK FOR SIGSEGV
|
#include "scheduler.h" // HACK FOR SIGSEGV
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix {
|
||||||
{
|
void SysExit(int status); // HACK
|
||||||
void SysExit(int status); // HACK
|
|
||||||
|
|
||||||
namespace Interrupt
|
namespace Interrupt {
|
||||||
{
|
|
||||||
const bool DEBUG_EXCEPTION = false;
|
|
||||||
const bool DEBUG_IRQ = false;
|
|
||||||
|
|
||||||
size_t numknownexceptions = 20;
|
const bool DEBUG_EXCEPTION = false;
|
||||||
const char* exceptions[] =
|
const bool DEBUG_IRQ = false;
|
||||||
{ "Divide by zero", "Debug", "Non maskable interrupt", "Breakpoint",
|
bool initialized;
|
||||||
|
|
||||||
|
const size_t numknownexceptions = 20;
|
||||||
|
const char* exceptions[] =
|
||||||
|
{ "Divide by zero", "Debug", "Non maskable interrupt", "Breakpoint",
|
||||||
"Into detected overflow", "Out of bounds", "Invalid opcode",
|
"Into detected overflow", "Out of bounds", "Invalid opcode",
|
||||||
"No coprocessor", "Double fault", "Coprocessor segment overrun",
|
"No coprocessor", "Double fault", "Coprocessor segment overrun",
|
||||||
"Bad TSS", "Segment not present", "Stack fault",
|
"Bad TSS", "Segment not present", "Stack fault",
|
||||||
|
@ -52,29 +51,105 @@ namespace Sortix
|
||||||
"Coprocessor fault", "Alignment check", "Machine check",
|
"Coprocessor fault", "Alignment check", "Machine check",
|
||||||
"SIMD Floating-Point" };
|
"SIMD Floating-Point" };
|
||||||
|
|
||||||
const size_t NUM_INTERRUPTS = 256UL;
|
const size_t NUM_INTERRUPTS = 256UL;
|
||||||
|
|
||||||
Handler interrupthandlers[NUM_INTERRUPTS];
|
Handler interrupthandlers[NUM_INTERRUPTS];
|
||||||
void* interrupthandlerptr[NUM_INTERRUPTS];
|
void* interrupthandlerptr[NUM_INTERRUPTS];
|
||||||
|
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
initialized = false;
|
||||||
|
IDT::Init();
|
||||||
|
|
||||||
void Init()
|
|
||||||
{
|
|
||||||
for ( size_t i = 0; i < NUM_INTERRUPTS; i++ )
|
for ( size_t i = 0; i < NUM_INTERRUPTS; i++ )
|
||||||
{
|
{
|
||||||
interrupthandlers[i] = NULL;
|
interrupthandlers[i] = NULL;
|
||||||
interrupthandlerptr[i] = NULL;
|
interrupthandlerptr[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegisterRawHandler(0, isr0, false);
|
||||||
|
RegisterRawHandler(1, isr1, false);
|
||||||
|
RegisterRawHandler(2, isr2, false);
|
||||||
|
RegisterRawHandler(3, isr3, false);
|
||||||
|
RegisterRawHandler(4, isr4, false);
|
||||||
|
RegisterRawHandler(5, isr5, false);
|
||||||
|
RegisterRawHandler(6, isr6, false);
|
||||||
|
RegisterRawHandler(7, isr7, false);
|
||||||
|
RegisterRawHandler(8, isr8, false);
|
||||||
|
RegisterRawHandler(9, isr9, false);
|
||||||
|
RegisterRawHandler(10, isr10, false);
|
||||||
|
RegisterRawHandler(11, isr11, false);
|
||||||
|
RegisterRawHandler(12, isr12, false);
|
||||||
|
RegisterRawHandler(13, isr13, false);
|
||||||
|
RegisterRawHandler(14, isr14, false);
|
||||||
|
RegisterRawHandler(15, isr15, false);
|
||||||
|
RegisterRawHandler(16, isr16, false);
|
||||||
|
RegisterRawHandler(17, isr17, false);
|
||||||
|
RegisterRawHandler(18, isr18, false);
|
||||||
|
RegisterRawHandler(19, isr19, false);
|
||||||
|
RegisterRawHandler(20, isr20, false);
|
||||||
|
RegisterRawHandler(21, isr21, false);
|
||||||
|
RegisterRawHandler(22, isr22, false);
|
||||||
|
RegisterRawHandler(23, isr23, false);
|
||||||
|
RegisterRawHandler(24, isr24, false);
|
||||||
|
RegisterRawHandler(25, isr25, false);
|
||||||
|
RegisterRawHandler(26, isr26, false);
|
||||||
|
RegisterRawHandler(27, isr27, false);
|
||||||
|
RegisterRawHandler(28, isr28, false);
|
||||||
|
RegisterRawHandler(29, isr29, false);
|
||||||
|
RegisterRawHandler(30, isr30, false);
|
||||||
|
RegisterRawHandler(31, isr31, false);
|
||||||
|
RegisterRawHandler(32, irq0, false);
|
||||||
|
RegisterRawHandler(33, irq1, false);
|
||||||
|
RegisterRawHandler(34, irq2, false);
|
||||||
|
RegisterRawHandler(35, irq3, false);
|
||||||
|
RegisterRawHandler(36, irq4, false);
|
||||||
|
RegisterRawHandler(37, irq5, false);
|
||||||
|
RegisterRawHandler(38, irq6, false);
|
||||||
|
RegisterRawHandler(39, irq7, false);
|
||||||
|
RegisterRawHandler(40, irq8, false);
|
||||||
|
RegisterRawHandler(41, irq9, false);
|
||||||
|
RegisterRawHandler(42, irq10, false);
|
||||||
|
RegisterRawHandler(43, irq11, false);
|
||||||
|
RegisterRawHandler(44, irq12, false);
|
||||||
|
RegisterRawHandler(45, irq13, false);
|
||||||
|
RegisterRawHandler(46, irq14, false);
|
||||||
|
RegisterRawHandler(47, irq15, false);
|
||||||
|
|
||||||
|
for ( unsigned i = 48; i < 256; i++ )
|
||||||
|
{
|
||||||
|
RegisterRawHandler(48, interrupt_handler_null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterHandler(uint8_t n, Interrupt::Handler handler, void* user)
|
// TODO: Let the syscall.cpp code register this.
|
||||||
{
|
RegisterRawHandler(128, syscall_handler, true);
|
||||||
|
|
||||||
|
IDT::Flush();
|
||||||
|
initialized = true;
|
||||||
|
|
||||||
|
Interrupt::Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegisterHandler(uint8_t n, Interrupt::Handler handler, void* user)
|
||||||
|
{
|
||||||
interrupthandlers[n] = handler;
|
interrupthandlers[n] = handler;
|
||||||
interrupthandlerptr[n] = user;
|
interrupthandlerptr[n] = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This gets called from our ASM interrupt handler stub.
|
// TODO: This function contains magic IDT-related values!
|
||||||
extern "C" void ISRHandler(Sortix::CPU::InterruptRegisters* regs)
|
void RegisterRawHandler(uint8_t index, RawHandler handler, bool userspace)
|
||||||
{
|
{
|
||||||
|
addr_t handlerentry = (addr_t) handler;
|
||||||
|
uint16_t sel = 0x08;
|
||||||
|
uint8_t flags = 0x8E;
|
||||||
|
if ( userspace ) { flags |= 0x60; }
|
||||||
|
IDT::SetGate(index, handlerentry, sel, flags);
|
||||||
|
if ( initialized ) { IDT::Flush(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// This gets called from our ASM interrupt handler stub.
|
||||||
|
extern "C" void ISRHandler(Sortix::CPU::InterruptRegisters* regs)
|
||||||
|
{
|
||||||
if ( regs->int_no < 32 )
|
if ( regs->int_no < 32 )
|
||||||
{
|
{
|
||||||
const char* message = ( regs->int_no < numknownexceptions )
|
const char* message = ( regs->int_no < numknownexceptions )
|
||||||
|
@ -113,11 +188,11 @@ namespace Sortix
|
||||||
void* user = interrupthandlerptr[regs->int_no];
|
void* user = interrupthandlerptr[regs->int_no];
|
||||||
interrupthandlers[regs->int_no](regs, user);
|
interrupthandlers[regs->int_no](regs, user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This gets called from our ASM interrupt handler stub.
|
// This gets called from our ASM interrupt handler stub.
|
||||||
extern "C" void IRQHandler(Sortix::CPU::InterruptRegisters* regs)
|
extern "C" void IRQHandler(Sortix::CPU::InterruptRegisters* regs)
|
||||||
{
|
{
|
||||||
// TODO! IRQ 7 and 15 might be spurious and might need to be ignored.
|
// TODO! IRQ 7 and 15 might be spurious and might need to be ignored.
|
||||||
// See http://wiki.osdev.org/PIC for details (section Spurious IRQs).
|
// See http://wiki.osdev.org/PIC for details (section Spurious IRQs).
|
||||||
if ( regs->int_no == 32 + 7 || regs->int_no == 32 + 15 ) { return; }
|
if ( regs->int_no == 32 + 7 || regs->int_no == 32 + 15 ) { return; }
|
||||||
|
@ -142,13 +217,15 @@ namespace Sortix
|
||||||
void* user = interrupthandlerptr[regs->int_no];
|
void* user = interrupthandlerptr[regs->int_no];
|
||||||
interrupthandlers[regs->int_no](regs, user);
|
interrupthandlers[regs->int_no](regs, user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void interrupt_handler(Sortix::CPU::InterruptRegisters* regs)
|
extern "C" void interrupt_handler(Sortix::CPU::InterruptRegisters* regs)
|
||||||
{
|
{
|
||||||
size_t int_no = regs->int_no;
|
size_t int_no = regs->int_no;
|
||||||
if ( 32 <= int_no && int_no < 48 ) { IRQHandler(regs); }
|
if ( 32 <= int_no && int_no < 48 ) { IRQHandler(regs); }
|
||||||
else { ISRHandler(regs); }
|
else { ISRHandler(regs); }
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Interrupt
|
||||||
|
} // namespace Sortix
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -14,44 +14,101 @@
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
details.
|
details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License along with
|
||||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
interrupt.h
|
interrupt.h
|
||||||
High level interrupt service routines and interrupt request handlers.
|
High level interrupt service routines and interrupt request handlers.
|
||||||
|
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#ifndef SORTIX_ISR_H
|
#ifndef SORTIX_INTERRUPT_H
|
||||||
#define SORTIX_ISR_H
|
#define SORTIX_INTERRUPT_H
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix {
|
||||||
{
|
namespace Interrupt {
|
||||||
namespace Interrupt
|
|
||||||
{
|
|
||||||
const unsigned IRQ0 = 32;
|
|
||||||
const unsigned IRQ1 = 33;
|
|
||||||
const unsigned IRQ2 = 34;
|
|
||||||
const unsigned IRQ3 = 35;
|
|
||||||
const unsigned IRQ4 = 36;
|
|
||||||
const unsigned IRQ5 = 37;
|
|
||||||
const unsigned IRQ6 = 38;
|
|
||||||
const unsigned IRQ7 = 39;
|
|
||||||
const unsigned IRQ8 = 30;
|
|
||||||
const unsigned IRQ9 = 41;
|
|
||||||
const unsigned IRQ10 = 42;
|
|
||||||
const unsigned IRQ11 = 43;
|
|
||||||
const unsigned IRQ12 = 44;
|
|
||||||
const unsigned IRQ13 = 45;
|
|
||||||
const unsigned IRQ14 = 46;
|
|
||||||
const unsigned IRQ15 = 47;
|
|
||||||
|
|
||||||
typedef void (*Handler)(CPU::InterruptRegisters* regs, void* user);
|
const unsigned IRQ0 = 32;
|
||||||
|
const unsigned IRQ1 = 33;
|
||||||
|
const unsigned IRQ2 = 34;
|
||||||
|
const unsigned IRQ3 = 35;
|
||||||
|
const unsigned IRQ4 = 36;
|
||||||
|
const unsigned IRQ5 = 37;
|
||||||
|
const unsigned IRQ6 = 38;
|
||||||
|
const unsigned IRQ7 = 39;
|
||||||
|
const unsigned IRQ8 = 30;
|
||||||
|
const unsigned IRQ9 = 41;
|
||||||
|
const unsigned IRQ10 = 42;
|
||||||
|
const unsigned IRQ11 = 43;
|
||||||
|
const unsigned IRQ12 = 44;
|
||||||
|
const unsigned IRQ13 = 45;
|
||||||
|
const unsigned IRQ14 = 46;
|
||||||
|
const unsigned IRQ15 = 47;
|
||||||
|
|
||||||
void RegisterHandler(uint8_t n, Handler handler, void* user);
|
inline void Enable() { asm volatile("sti"); }
|
||||||
|
inline void Disable() { asm volatile("cli"); }
|
||||||
|
|
||||||
void Init();
|
typedef void (*Handler)(CPU::InterruptRegisters* regs, void* user);
|
||||||
}
|
void RegisterHandler(uint8_t index, Handler handler, void* user);
|
||||||
}
|
|
||||||
|
typedef void (*RawHandler)(void);
|
||||||
|
void RegisterRawHandler(uint8_t index, RawHandler handler, bool userspace);
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
|
||||||
|
} // namespace Interrupt
|
||||||
|
} // namespace Sortix
|
||||||
|
|
||||||
|
extern "C" void isr0();
|
||||||
|
extern "C" void isr1();
|
||||||
|
extern "C" void isr2();
|
||||||
|
extern "C" void isr3();
|
||||||
|
extern "C" void isr4();
|
||||||
|
extern "C" void isr5();
|
||||||
|
extern "C" void isr6();
|
||||||
|
extern "C" void isr7();
|
||||||
|
extern "C" void isr8();
|
||||||
|
extern "C" void isr9();
|
||||||
|
extern "C" void isr10();
|
||||||
|
extern "C" void isr11();
|
||||||
|
extern "C" void isr12();
|
||||||
|
extern "C" void isr13();
|
||||||
|
extern "C" void isr14();
|
||||||
|
extern "C" void isr15();
|
||||||
|
extern "C" void isr16();
|
||||||
|
extern "C" void isr17();
|
||||||
|
extern "C" void isr18();
|
||||||
|
extern "C" void isr19();
|
||||||
|
extern "C" void isr20();
|
||||||
|
extern "C" void isr21();
|
||||||
|
extern "C" void isr22();
|
||||||
|
extern "C" void isr23();
|
||||||
|
extern "C" void isr24();
|
||||||
|
extern "C" void isr25();
|
||||||
|
extern "C" void isr26();
|
||||||
|
extern "C" void isr27();
|
||||||
|
extern "C" void isr28();
|
||||||
|
extern "C" void isr29();
|
||||||
|
extern "C" void isr30();
|
||||||
|
extern "C" void isr31();
|
||||||
|
extern "C" void isr128();
|
||||||
|
extern "C" void irq0();
|
||||||
|
extern "C" void irq1();
|
||||||
|
extern "C" void irq2();
|
||||||
|
extern "C" void irq3();
|
||||||
|
extern "C" void irq4();
|
||||||
|
extern "C" void irq5();
|
||||||
|
extern "C" void irq6();
|
||||||
|
extern "C" void irq7();
|
||||||
|
extern "C" void irq8();
|
||||||
|
extern "C" void irq9();
|
||||||
|
extern "C" void irq10();
|
||||||
|
extern "C" void irq11();
|
||||||
|
extern "C" void irq12();
|
||||||
|
extern "C" void irq13();
|
||||||
|
extern "C" void irq14();
|
||||||
|
extern "C" void irq15();
|
||||||
|
extern "C" void interrupt_handler_null();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -14,13 +14,14 @@
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
details.
|
details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU General Public License along with
|
||||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
kernel.cpp
|
kernel.cpp
|
||||||
A common interface shared by all devices that can be printed text to.
|
The main kernel initialization routine. Configures hardware and starts an
|
||||||
|
initial process from the init ramdisk, allowing a full operating system.
|
||||||
|
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
|
@ -205,7 +206,7 @@ namespace Sortix
|
||||||
initrdsize = 0x280000; // 2 MiB 512 KiB
|
initrdsize = 0x280000; // 2 MiB 512 KiB
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Memory::RegisterInitRDSize(initrdsize);;
|
Memory::RegisterInitRDSize(initrdsize);
|
||||||
|
|
||||||
// Initialize the paging and virtual memory.
|
// Initialize the paging and virtual memory.
|
||||||
Memory::Init(BootInfo);
|
Memory::Init(BootInfo);
|
||||||
|
@ -213,12 +214,9 @@ namespace Sortix
|
||||||
// Initialize the GDT and TSS structures.
|
// Initialize the GDT and TSS structures.
|
||||||
GDT::Init();
|
GDT::Init();
|
||||||
|
|
||||||
// Initialize the interrupt handler table to zeroes.
|
// Initialize the interrupt handler table and enable interrupts.
|
||||||
Interrupt::Init();
|
Interrupt::Init();
|
||||||
|
|
||||||
// Initialize the interrupt descriptor tables (enabling interrupts).
|
|
||||||
IDT::Init();
|
|
||||||
|
|
||||||
// Initialize the kernel heap.
|
// Initialize the kernel heap.
|
||||||
Maxsi::Memory::Init();
|
Maxsi::Memory::Init();
|
||||||
|
|
||||||
|
|
|
@ -49,9 +49,6 @@ gdt_flush_postjmp:
|
||||||
idt_flush:
|
idt_flush:
|
||||||
# Load the IDT pointer.
|
# Load the IDT pointer.
|
||||||
lidt (%rdi)
|
lidt (%rdi)
|
||||||
|
|
||||||
# Enable interrupts
|
|
||||||
sti
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.global tss_flush
|
.global tss_flush
|
||||||
|
|
|
@ -438,3 +438,8 @@ interrupt_handler_prepare:
|
||||||
# Return to where we came from.
|
# Return to where we came from.
|
||||||
iretq
|
iretq
|
||||||
|
|
||||||
|
.global interrupt_handler_null
|
||||||
|
.type interrupt_handler_null, @function
|
||||||
|
interrupt_handler_null:
|
||||||
|
iretq
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ gdt_flush:
|
||||||
idt_flush:
|
idt_flush:
|
||||||
mov eax, [esp+4] ; Get the pointer to the IDT, passed as a parameter.
|
mov eax, [esp+4] ; Get the pointer to the IDT, passed as a parameter.
|
||||||
lidt [eax] ; Load the IDT pointer.
|
lidt [eax] ; Load the IDT pointer.
|
||||||
sti
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
[GLOBAL tss_flush] ; Allows our C code to call tss_flush().
|
[GLOBAL tss_flush] ; Allows our C code to call tss_flush().
|
||||||
|
|
|
@ -157,5 +157,9 @@ irq_common_stub:
|
||||||
;sti
|
;sti
|
||||||
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
|
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
|
||||||
|
|
||||||
|
global
|
||||||
|
|
||||||
|
global interrupt_handler_null
|
||||||
|
interrupt_handler_null:
|
||||||
|
iret
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue