+waitpid()
[meinos.git] / kernel2 / idt.c
blobf83a3fe9e676433ff1265727efd7fcec83eb126f
1 /*
2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <idt.h>
20 #include <isr.h>
21 #include <malloc.h>
22 #include <gdt.h>
23 #include <string.h>
24 #include <debug.h>
25 #include <syscall.h>
27 /**
28 * Initializes IDT
29 * @return 0=Success; -1=Failure
31 int idt_init() {
32 int i;
33 //idt = calloc(ISR_NUM,sizeof(idtdesc_t));
34 memset(idt,0,ISR_NUM*sizeof(idtdesc_t));
36 selector_t selector = {
37 .index = 1,
38 .ti = 0,
39 .priv = PRIV_KERNEL
41 for (i=0;i<ISR_NUM;i++) {
42 idt_set_descriptor(i,isr[i],selector,i==SYSCALL_INT?PRIV_USER:PRIV_KERNEL,IDT_INTGATE32|IDT_PRESENT);
45 idtsel_t idtsel = {
46 .size = ISR_NUM*sizeof(idtdesc_t)-1,
47 .offset = (uint32_t)&idt
49 asm("lidt (%0)"::"r"(&idtsel));
51 return 0;
54 void idt_set_descriptor(int i,void *addr,selector_t selector,priv_t priv,int type) {
55 idt[i].zero = 0;
56 idt[i].address0_15 = ((unsigned int)addr)&0xFFFF;
57 idt[i].address16_31 = (((unsigned int)addr)>>16)&0xFFFF;
58 idt[i].selector = selector;
59 idt[i].type = type|((priv&3)<<5);