L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
11 */
12/*****************************************************************************/
13#ifndef __L4_SYS__ARCH_X86__SEGMENT_H__
14#define __L4_SYS__ARCH_X86__SEGMENT_H__
15
16#ifndef L4API_l4f
17#error This header file can only be used with a L4API version!
18#endif
19
20#include <l4/sys/ipc.h>
21
39L4_INLINE long
40fiasco_ldt_set(l4_cap_idx_t task, void *ldt, unsigned int num_desc,
41 unsigned int entry_number_start, l4_utcb_t *utcb);
42
59L4_INLINE long
60fiasco_gdt_set(l4_cap_idx_t thread, void *desc, unsigned int size,
61 unsigned int entry_number_start, l4_utcb_t *utcb);
62
69L4_INLINE unsigned
71
84
100L4_INLINE long
102
113
127L4_INLINE long
129 l4_umword_t base, l4_utcb_t *utcb);
130
140L4_INLINE long
141fiasco_amd64_segment_info(l4_cap_idx_t thread, unsigned *user_ds,
142 unsigned *user_cs, unsigned *user32_cs,
143 l4_utcb_t *utcb);
144
145/*****************************************************************************
146 *** Implementation
147 *****************************************************************************/
148
149#include <l4/sys/task.h>
150#include <l4/sys/thread.h>
151
152L4_INLINE long
153fiasco_ldt_set(l4_cap_idx_t task, void *ldt, unsigned int num_desc,
154 unsigned int entry_number_start, l4_utcb_t *utcb)
155{
156 if (num_desc > L4_TASK_LDT_X86_MAX_ENTRIES)
157 return -L4_EINVAL;
158 l4_utcb_mr_u(utcb)->mr[0] = L4_TASK_LDT_SET_X86_OP;
159 l4_utcb_mr_u(utcb)->mr[1] = entry_number_start;
160 __builtin_memcpy(&l4_utcb_mr_u(utcb)->mr[2], ldt,
161 num_desc * L4_TASK_LDT_X86_ENTRY_SIZE);
162 return l4_error_u(l4_ipc_call(task, utcb, l4_msgtag(L4_PROTO_TASK, 2 + num_desc * 2, 0, 0), L4_IPC_NEVER), utcb);
163}
164
165L4_INLINE unsigned
167{
168 l4_utcb_mr_u(utcb)->mr[0] = L4_THREAD_X86_GDT_OP;
169 if (l4_error_u(l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 1, 0, 0), L4_IPC_NEVER), utcb))
170 return -1;
171 return l4_utcb_mr_u(utcb)->mr[0];
172}
173
174L4_INLINE long
175fiasco_amd64_segment_info(l4_cap_idx_t thread, unsigned *user_ds,
176 unsigned *user_cs, unsigned *user32_cs,
177 l4_utcb_t *utcb)
178{
179 l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
180 int r;
181
183
184 r = l4_error_u(l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 1, 0, 0),
185 L4_IPC_NEVER), utcb);
186 if (r < 0)
187 return r;
188
189 *user_ds = m->mr[0];
190 *user_cs = m->mr[1];
191 *user32_cs = m->mr[2];
192
193 return 0;
194}
195
196#endif /* ! __L4_SYS__ARCH_X86__SEGMENT_H__ */
L4_sys_segment
Constants for identifying segments.
Definition segment.h:107
@ L4_AMD64_SEGMENT_GS
Constant identifying the GS segment.
Definition segment.h:111
@ L4_AMD64_SEGMENT_FS
Constant identifying the FS segment.
Definition segment.h:109
L4_task_ldt_x86_consts
Contants for LDT handling.
Definition segment.h:76
@ L4_TASK_LDT_X86_MAX_ENTRIES
Maximum number of LDT entries that can be written with one call.
Definition segment.h:80
@ L4_TASK_LDT_X86_ENTRY_SIZE
Size of an LDT entry.
Definition segment.h:78
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:175
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:32
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:24
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:153
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:166
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:41
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
#define L4_MWORD_BITS
Size of machine words in bits.
Definition l4int.h:22
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:335
@ L4_EINVAL
Invalid argument.
Definition err.h:46
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:565
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:404
@ L4_PROTO_TASK
Protocol for messages to a task object.
Definition types.h:52
@ L4_PROTO_THREAD
Protocol for messages to a thread object.
Definition types.h:53
@ L4_TASK_LDT_SET_X86_OP
x86: LDT set
Definition task.h:330
@ L4_THREAD_AMD64_GET_SEGMENT_INFO_OP
Get segment information.
Definition thread.h:724
@ L4_THREAD_X86_GDT_OP
Gdt.
Definition thread.h:721
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:68
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:69