os-k/include/kernel/ke/idt.h

120 lines
4.5 KiB
C

//----------------------------------------------------------------------------//
// OS on Kaleid //
// //
// Desc: Interrupt related functions //
// //
// //
// Copyright © 2018-2021 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K 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 //
// any later version. //
// //
// OS/K 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. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KERNEL_H
#include <kernel.h>
#endif
#ifndef _KALKERN_IDT_H
#define _KALKERN_IDT_H
//----------------------------------------------------------------------------//
struct IdtDescriptor_t
{
ushort limit;
ulong base;
} __attribute__((packed));
struct IdtEntry_t
{
ushort baseLow;
ushort selector;
uchar ist;
uchar flags;
ushort baseMid;
uint baseHigh;
uint reserved;
} __attribute__((packed));
struct IdtPtr_t
{
ushort limit;
void *base;
} __attribute__((packed));
struct ISRList_t
{
uchar n; //number of entries in the list
struct entry {
void (*isr)(ISRFrame_t *regs);
uchar isrNo;
uchar flags;
} entry[255];
};
//----------------------------------------------------------------------------//
void KeLoadIDT(void);
void KeSetupIDT(void);
void KeUnmaskIRQ(uchar IRQline);
void KeMaskIRQ(uchar IRQline);
void KeSendEOItoPIC(uchar isr);
void KeSetIDTGate(uchar rank,
ulong base,
ushort selector,
uchar flags,
uchar ist);
error_t KeRegisterISR(void (*isr)(ISRFrame_t *regs), uchar isrNo);
void KeBrkDumpRegisters(ISRFrame_t *regs);
//----------------------------------------------------------------------------//
#define _isr0(a,b,c,d,e) \
void isr##a(); void isr##b(); void isr##c(); void isr##d(); void isr##e()
#define _isr1(a,b,c,d,e,f,g,h,i,j) _isr0(a,b,c,d,e); _isr0(f,g,h,i,j)
_isr1(0,1,2,3,4,5,6,7,8,9); _isr1(10,11,12,13,14,15,16,17,18,19);
_isr1(20,21,22,23,24,25,26,27,28,29); _isr1(30,31,32,33,34,35,36,37,38,39);
_isr1(40,41,42,43,44,45,46,47,48,49); _isr1(50,51,52,53,54,55,56,57,58,59);
_isr1(60,61,62,63,64,65,66,67,68,69); _isr1(70,71,72,73,74,75,76,77,78,79);
_isr1(80,81,82,83,84,85,86,87,88,89); _isr1(90,91,92,93,94,95,96,97,98,99);
_isr1(100,101,102,103,104,105,106,107,108,109);
_isr1(110,111,112,113,114,115,116,117,118,119);
_isr1(120,121,122,123,124,125,126,127,128,129);
_isr1(130,131,132,133,134,135,136,137,138,139);
_isr1(140,141,142,143,144,145,146,147,148,149);
_isr1(150,151,152,153,154,155,156,157,158,159);
_isr1(160,161,162,163,164,165,166,167,168,169);
_isr1(170,171,172,173,174,175,176,177,178,179);
_isr1(180,181,182,183,184,185,186,187,188,189);
_isr1(190,191,192,193,194,195,196,197,198,199);
_isr1(200,201,202,203,204,205,206,207,208,209);
_isr1(210,211,212,213,214,215,216,217,218,219);
_isr1(220,221,222,223,224,225,226,227,228,229);
_isr1(230,231,232,233,234,235,236,237,238,239);
_isr1(240,241,242,243,244,245,246,247,248,249);
_isr0(250,251,252,253,254);
void isr255();
#undef _isr1
#undef _isr0
//----------------------------------------------------------------------------//
#endif