POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/arch/x86/event.c
Go to the documentation of this file.
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Thu Jan 15 23:34:13 2009 
00015  */
00016 
00017 
00018 #include <libc.h>
00019 
00020 #include <types.h>
00021 #include <errno.h>
00022 #include <core/syscall.h>
00023 
00024 #include "event.h"
00025 #include "sysdesc.h"
00026 
00027 #define IDT_SIZE 256
00028 
00029 idt_entry_t     pok_idt[IDT_SIZE];
00030 
00031 pok_ret_t pok_event_init ()
00032 {
00033    pok_idt_init ();
00034 
00035 #if defined (POK_NEEDS_DEBUG) || defined (POK_NEEDS_ERROR_HANDLING)
00036    pok_exception_init ();
00037 #endif
00038 
00039    pok_syscall_init ();
00040 
00041    return (POK_ERRNO_OK);
00042 }
00043 
00044 pok_ret_t pok_idt_init ()
00045 {
00046    sysdesc_t sysdesc;
00047 
00048    /* Clear table */
00049    memset(pok_idt, 0, sizeof (idt_entry_t) * IDT_SIZE);
00050 
00051    /* Load IDT */
00052    sysdesc.limit = sizeof (pok_idt);
00053    sysdesc.base = (uint32_t)pok_idt;
00054 
00055    asm ("lidt %0"
00056         :
00057         : "m" (sysdesc));
00058 
00059   return (POK_ERRNO_OK);
00060 }
00061 
00062 void pok_idt_set_gate (uint16_t     index,
00063                        uint16_t     segsel,
00064                        uint32_t     offset,
00065                        e_idte_type  t,
00066                        int          dpl)
00067 {
00068    pok_idt[index].offset_low   = (offset) & 0xFFFF;
00069    pok_idt[index].offset_high  = (offset >> 16) & 0xFFFF;
00070    pok_idt[index].segsel       = segsel;
00071    pok_idt[index].dpl          = dpl;
00072    pok_idt[index].type         = t;
00073    pok_idt[index].d            = 1;
00074    pok_idt[index].res0         = 0; /* reserved */
00075    pok_idt[index].res1         = 0; /* reserved */
00076    pok_idt[index].present   = 1;
00077 }
00078