3 * \brief IDT related functions
7 * \author Frank Mehnert <fm3@os.inf.tu-dresden.de> */
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.
17 #ifndef __L4UTIL_IDT_H
18 #define __L4UTIL_IDT_H
20 #include <l4/sys/l4int.h>
21 #include <l4/sys/compiler.h>
26 * \defgroup l4util_idt Functions to manipulate the local IDT
35 l4_uint32_t a, b; /**< see Intel doc */
36 } __attribute__ ((packed)) l4util_idt_desc_t;
38 /** Header of an IDT table.
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;
47 /** Create an IDT entry.
48 * \param idt pointer to idt table header
49 * \param nr # of exception vector
50 * \param handler exception handler
53 l4util_idt_entry(l4util_idt_header_t *idt, int nr, void(*handler)(void))
55 idt->desc[nr].a = (l4_uint32_t)handler & 0x0000ffff;
56 idt->desc[nr].b = 0x0000ef00 | ((l4_uint32_t)handler & 0xffff0000);
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
64 l4util_idt_init(l4util_idt_header_t *idt, int entries)
67 idt->limit = entries*8 - 1;
68 idt->base = &idt->desc;
70 for (i=0; i<entries; i++)
71 l4util_idt_entry(idt, i, 0);
74 /** Set IDT table for the current thread
75 * \param idt pointer to idt table header
78 l4util_idt_load(l4util_idt_header_t *idt)
80 asm volatile ("lidt (%%eax) \n\t" : : "a" (idt));