idt.c

来自「一个操作系统的源代码」· C语言 代码 · 共 79 行

C
79
字号
/** idt.c ** ** Original Author: Kasper Verdich Lund ** Date: 10/11/99 ** ** Description: ** Interrupt Descriptor Table functions ** ** This program 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 ** 2 of the License, or (at your option) any later version. ** ** This program is distributed in the hope that it will be ** useful, but WITHOUT ANY WARRANTY; without even the implied ** warranty or 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 this program; if not, write to the ** Free Software Foundation, Inc., 59 Temple Place, Suite 330, ** Boston, MA 02111-1307 USA ** *********************************************************Apostle OS**/#include <idt.h>#include <types.h>#include <io.h>#include <gdt.h>#include <string.h>gate *IDT = (gate *)(GDT_SIZE * sizeof(descriptor));void setupIDT(void){  dword IDTR[2];  memset(IDT, 0, IDT_SIZE * sizeof(gate));  IDTR[0] = ((IDT_SIZE * sizeof(gate)) - 1) << 16;  IDTR[1] = (dword)IDT;  /* load the IDTR - it's only 48-bits and therefore the    * two first bytes are not used */  __asm__("lidt (%0)" : : "r" (((byte *)IDTR) + 2));  }void interruptIDT(gate *g, word selector, dword offset, byte dpl){  g->offset0_15 = offset;  g->offset16_31 = offset >> 16;  g->selector = selector;  g->zero = 0;  g->p = 1;  g->dpl = dpl;  g->type = 0xE; /* assuming 32-bit interrupt gate */ }void trapIDT(gate *g, word selector, dword offset, byte dpl){  g->offset0_15 = offset;  g->offset16_31 = offset >> 16;  g->selector = selector;  g->zero = 0;  g->p = 1;  g->dpl = dpl;  g->type = 0xF; /* assuming 32-bit trap gate */ }void taskIDT(gate *g, word selector, byte dpl){  g->offset0_15 = 0;  g->offset16_31 = 0;  g->selector = selector;  g->zero = 0;  g->p = 1;  g->dpl = dpl;  g->type = 5;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?