]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4util/include/ARCH-x86/idt.h
update
[l4.git] / l4 / pkg / l4util / include / ARCH-x86 / idt.h
1 /**
2  * \file
3  * \brief    IDT related functions
4  * \ingroup  irq
5  *
6  * \date     2003
7  * \author   Frank Mehnert <fm3@os.inf.tu-dresden.de> */
8
9 /*
10  * (c) 2003-2009 Author(s)
11  *     economic rights: Technische Universität Dresden (Germany)
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU Lesser General Public License 2.1.
14  * Please see the COPYING-LGPL-2.1 file for details.
15  */
16
17 #ifndef __L4UTIL_IDT_H
18 #define __L4UTIL_IDT_H
19
20 #include <l4/sys/l4int.h>
21 #include <l4/sys/compiler.h>
22
23 EXTERN_C_BEGIN
24
25 /**
26  * \defgroup l4util_idt Functions to manipulate the local IDT
27  * \ingroup l4util_api
28  */
29 /*@{*/
30
31 /** IDT entry.
32  */
33 typedef struct
34 {
35   l4_uint32_t       a, b;               /**< see Intel doc */
36 } __attribute__ ((packed)) l4util_idt_desc_t;
37
38 /** Header of an IDT table.
39  */
40 typedef struct
41 {
42   l4_uint16_t       limit;              /**< limit field (see Intel doc) */
43   void              *base;              /**< idt base (see Intel doc) */
44   l4util_idt_desc_t desc[0];
45 } __attribute__ ((packed)) l4util_idt_header_t;
46
47 /** Create an IDT entry.
48  * \param idt      pointer to idt table header
49  * \param nr       # of exception vector
50  * \param handler  exception handler
51  */
52 static inline void
53 l4util_idt_entry(l4util_idt_header_t *idt, int nr, void(*handler)(void))
54 {
55   idt->desc[nr].a = (l4_uint32_t)handler & 0x0000ffff;
56   idt->desc[nr].b = 0x0000ef00 | ((l4_uint32_t)handler & 0xffff0000);
57 }
58
59 /** Initializes an IDT.
60  * \param idt      pointer to idt table header
61  * \param entries  # of of exception entries to hold by the idt table
62  */
63 static inline void
64 l4util_idt_init(l4util_idt_header_t *idt, int entries)
65 {
66   int i;
67   idt->limit = entries*8 - 1;
68   idt->base  = &idt->desc;
69
70   for (i=0; i<entries; i++)
71     l4util_idt_entry(idt, i, 0);
72 }
73
74 /** Set IDT table for the current thread 
75  * \param idt      pointer to idt table header
76  */
77 static inline void
78 l4util_idt_load(l4util_idt_header_t *idt)
79 {
80   asm volatile ("lidt (%%eax) \n\t" : : "a" (idt));
81 }
82
83 /*@}*/
84 EXTERN_C_END
85
86 #endif
87