L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
segment.h
Go to the documentation of this file.
1
6/*
7 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
8 * economic rights: Technische Universität Dresden (Germany)
9 *
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.
13 *
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.
22 */
23/*****************************************************************************/
24#ifndef __L4_SYS__ARCH_X86__SEGMENT_H__
25#define __L4_SYS__ARCH_X86__SEGMENT_H__
26
27#ifndef L4API_l4f
28#error This header file can only be used with a L4API version!
29#endif
30
31#include <l4/sys/ipc.h>
32
50L4_INLINE long
51fiasco_ldt_set(l4_cap_idx_t task, void *ldt, unsigned int num_desc,
52 unsigned int entry_number_start, l4_utcb_t *utcb);
53
70L4_INLINE long
71fiasco_gdt_set(l4_cap_idx_t thread, void *desc, unsigned int size,
72 unsigned int entry_number_start, l4_utcb_t *utcb);
73
80L4_INLINE unsigned
82
95
111L4_INLINE long
113
124
138L4_INLINE long
140 l4_umword_t base, l4_utcb_t *utcb);
141
151L4_INLINE long
152fiasco_amd64_segment_info(l4_cap_idx_t thread, unsigned *user_ds,
153 unsigned *user_cs, unsigned *user32_cs,
154 l4_utcb_t *utcb);
155
156/*****************************************************************************
157 *** Implementation
158 *****************************************************************************/
159
160#include <l4/sys/task.h>
161#include <l4/sys/thread.h>
162
163L4_INLINE long
164fiasco_ldt_set(l4_cap_idx_t task, void *ldt, unsigned int num_desc,
165 unsigned int entry_number_start, l4_utcb_t *utcb)
166{
167 if (num_desc > L4_TASK_LDT_X86_MAX_ENTRIES)
168 return -L4_EINVAL;
169 l4_utcb_mr_u(utcb)->mr[0] = L4_TASK_LDT_SET_X86_OP;
170 l4_utcb_mr_u(utcb)->mr[1] = entry_number_start;
171 __builtin_memcpy(&l4_utcb_mr_u(utcb)->mr[2], ldt,
172 num_desc * L4_TASK_LDT_X86_ENTRY_SIZE);
173 return l4_error_u(l4_ipc_call(task, utcb, l4_msgtag(L4_PROTO_TASK, 2 + num_desc * 2, 0, 0), L4_IPC_NEVER), utcb);
174}
175
176L4_INLINE unsigned
178{
179 l4_utcb_mr_u(utcb)->mr[0] = L4_THREAD_X86_GDT_OP;
180 if (l4_error_u(l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 1, 0, 0), L4_IPC_NEVER), utcb))
181 return -1;
182 return l4_utcb_mr_u(utcb)->mr[0];
183}
184
185L4_INLINE long
186fiasco_amd64_segment_info(l4_cap_idx_t thread, unsigned *user_ds,
187 unsigned *user_cs, unsigned *user32_cs,
188 l4_utcb_t *utcb)
189{
190 l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
191 int r;
192
194
195 r = l4_error_u(l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 1, 0, 0),
196 L4_IPC_NEVER), utcb);
197 if (r < 0)
198 return r;
199
200 *user_ds = m->mr[0];
201 *user_cs = m->mr[1];
202 *user32_cs = m->mr[2];
203
204 return 0;
205}
206
207#endif /* ! __L4_SYS__ARCH_X86__SEGMENT_H__ */
L4_sys_segment
Constants for identifying segments.
Definition segment.h:118
@ L4_AMD64_SEGMENT_GS
Constant identifying the GS segment.
Definition segment.h:122
@ L4_AMD64_SEGMENT_FS
Constant identifying the FS segment.
Definition segment.h:120
L4_task_ldt_x86_consts
Contants for LDT handling.
Definition segment.h:87
@ L4_TASK_LDT_X86_MAX_ENTRIES
Maximum number of LDT entries that can be written with one call.
Definition segment.h:91
@ L4_TASK_LDT_X86_ENTRY_SIZE
Size of an LDT entry.
Definition segment.h:89
long fiasco_amd64_segment_info(l4_cap_idx_t thread, unsigned *user_ds, unsigned *user_cs, unsigned *user32_cs, l4_utcb_t *utcb)
Get segment information.
Definition segment.h:186
long fiasco_amd64_set_segment_base(l4_cap_idx_t thread, enum L4_sys_segment segr, l4_umword_t base, l4_utcb_t *utcb)
Set the base address for a segment.
Definition segment.h:43
long fiasco_amd64_set_fs(l4_cap_idx_t thread, l4_umword_t base, l4_utcb_t *utcb)
Set the base address for the FS segment.
Definition segment.h:35
long fiasco_ldt_set(l4_cap_idx_t task, void *ldt, unsigned int num_desc, unsigned int entry_number_start, l4_utcb_t *utcb)
Set LDT segments descriptors.
Definition segment.h:164
unsigned fiasco_gdt_get_entry_offset(l4_cap_idx_t thread, l4_utcb_t *utcb)
Return the offset of the entry in the GDT.
Definition segment.h:177
long fiasco_gdt_set(l4_cap_idx_t thread, void *desc, unsigned int size, unsigned int entry_number_start, l4_utcb_t *utcb)
Set GDT segment descriptors.
Definition segment.h:52
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
#define L4_MWORD_BITS
Size of machine words in bits.
Definition l4int.h:33
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:359
@ L4_EINVAL
Invalid argument.
Definition err.h:57
l4_msgtag_t l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Object call (usual invocation).
Definition ipc.h:576
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition types.h:428
@ L4_PROTO_TASK
Protocol for messages to a task object.
Definition types.h:63
@ L4_PROTO_THREAD
Protocol for messages to a thread object.
Definition types.h:64
@ L4_TASK_LDT_SET_X86_OP
x86: LDT set
Definition task.h:318
@ L4_THREAD_AMD64_GET_SEGMENT_INFO_OP
Get segment information.
Definition thread.h:707
@ L4_THREAD_X86_GDT_OP
Gdt.
Definition thread.h:704
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:84
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:67
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:79
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:80