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

101 lines
3.6 KiB
C

//----------------------------------------------------------------------------//
// OS on Kaleid //
// //
// Desc: Interrupt related functions //
// //
// //
// Copyright © 2018-2020 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);
#undef _isr1
#undef _isr0
//----------------------------------------------------------------------------//
#endif