3 * \brief Segment handling.
7 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
8 * economic rights: Technische Universität Dresden (Germany)
10 * This file is part of TUD:OS and distributed under the terms of the
11 * GNU General Public License 2.
12 * Please see the COPYING-GPL-2 file for details.
14 * As a special exception, you may use this file as part of a free software
15 * library without restriction. Specifically, if other files instantiate
16 * templates or use macros or inline functions from this file, or you compile
17 * this file and link it with other files to produce an executable, this
18 * file does not by itself cause the resulting executable to be covered by
19 * the GNU General Public License. This exception does not however
20 * invalidate any other reasons why the executable file might be covered by
21 * the GNU General Public License.
23 /*****************************************************************************/
24 #ifndef __L4_SYS__ARCH_X86__SEGMENT_H__
25 #define __L4_SYS__ARCH_X86__SEGMENT_H__
28 #error This header file can only be used with a L4API version!
31 #include <l4/sys/ipc.h>
34 * Set LDT segments descriptors.
35 * \ingroup api_calls_fiasco
37 * \param task Task to set the segment for.
38 * \param ldt Pointer to LDT hardware descriptors.
39 * \param num_desc Number of descriptors.
40 * \param entry_number_start Entry number to start.
41 * \param utcb UTCB of the caller.
44 fiasco_ldt_set(l4_cap_idx_t task, void *ldt, unsigned int size,
45 unsigned int entry_number_start, l4_utcb_t *utcb);
48 * Set GDT segment descriptors. Fiasco supports 3 consecutive entries,
49 * starting at the value returned by fiasco_gdt_get_entry_offset()
50 * \ingroup api_calls_fiasco
52 * \param thread Thread to set the GDT entry for.
53 * \param desc Pointer to GDT descriptors.
54 * \param size Size of the descriptors in bytes
56 * \param entry_number_start Entry number to start (valid values: 0-2).
57 * \param utcb UTCB of the caller.
58 * \return System call error
61 fiasco_gdt_set(l4_cap_idx_t thread, void *desc, unsigned int size,
62 unsigned int entry_number_start, l4_utcb_t *utcb);
65 * Return the offset of the entry in the GDT.
66 * \param thread Thread to get info from.
67 * \param utcb UTCB of the caller.
68 * \ingroup api_calls_fiasco
71 fiasco_gdt_get_entry_offset(l4_cap_idx_t thread, l4_utcb_t *utcb);
74 * \brief Contants for LDT handling.
76 enum L4_task_ldt_x86_consts
78 /** Size of an LDT entry. */
79 L4_TASK_LDT_X86_ENTRY_SIZE = 8,
80 /** Maximum number of LDT entries that can be written with one call. */
81 L4_TASK_LDT_X86_MAX_ENTRIES
82 = (L4_UTCB_GENERIC_DATA_SIZE - 2)
83 / (L4_TASK_LDT_X86_ENTRY_SIZE / (L4_MWORD_BITS / 8)),
87 * Set the FS register.
88 * \param thread Thread to get info from.
89 * \param base Base address.
90 * \param utcb UTCB of the caller.
91 * \return System call error
94 fiasco_amd64_set_fs(l4_cap_idx_t thread, l4_umword_t base, l4_utcb_t *utcb);
98 L4_AMD64_SEGMENT_FS = 0,
99 L4_AMD64_SEGMENT_GS = 1
103 * Set the FS register.
104 * \param thread Thread to get info from.
105 * \param segr Segment register to set (one of L4_sys_segment).
106 * \param base Base address.
107 * \param utcb UTCB of the caller.
108 * \return System call error
111 fiasco_amd64_set_segment_base(l4_cap_idx_t thread, enum L4_sys_segment segr,
112 l4_umword_t base, l4_utcb_t *utcb);
115 /*****************************************************************************
117 *****************************************************************************/
119 #include <l4/sys/task.h>
120 #include <l4/sys/thread.h>
123 fiasco_ldt_set(l4_cap_idx_t task, void *ldt, unsigned int num_desc,
124 unsigned int entry_number_start, l4_utcb_t *utcb)
126 if (num_desc > L4_TASK_LDT_X86_MAX_ENTRIES)
128 l4_utcb_mr_u(utcb)->mr[0] = L4_TASK_LDT_SET_X86_OP;
129 l4_utcb_mr_u(utcb)->mr[1] = entry_number_start;
130 __builtin_memcpy(&l4_utcb_mr_u(utcb)->mr[2], ldt,
131 num_desc * L4_TASK_LDT_X86_ENTRY_SIZE);
132 return l4_error_u(l4_ipc_call(task, utcb, l4_msgtag(L4_PROTO_TASK, 2 + num_desc * 2, 0, 0), L4_IPC_NEVER), utcb);
136 fiasco_gdt_get_entry_offset(l4_cap_idx_t thread, l4_utcb_t *utcb)
138 l4_utcb_mr_u(utcb)->mr[0] = L4_THREAD_X86_GDT_OP;
139 if (l4_error_u(l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 1, 0, 0), L4_IPC_NEVER), utcb))
141 return l4_utcb_mr_u(utcb)->mr[0];
144 #endif /* ! __L4_SYS__ARCH_X86__SEGMENT_H__ */