1 /*****************************************************************************/
4 * \brief Common L4 ABI Data Types.
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Alexander Warg <warg@os.inf.tu-dresden.de>,
10 * Björn Döbel <doebel@os.inf.tu-dresden.de>,
11 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
12 * economic rights: Technische Universität Dresden (Germany)
14 * This file is part of TUD:OS and distributed under the terms of the
15 * GNU General Public License 2.
16 * Please see the COPYING-GPL-2 file for details.
18 * As a special exception, you may use this file as part of a free software
19 * library without restriction. Specifically, if other files instantiate
20 * templates or use macros or inline functions from this file, or you compile
21 * this file and link it with other files to produce an executable, this
22 * file does not by itself cause the resulting executable to be covered by
23 * the GNU General Public License. This exception does not however
24 * invalidate any other reasons why the executable file might be covered by
25 * the GNU General Public License.
27 /*****************************************************************************/
30 #include <l4/sys/l4int.h>
31 #include <l4/sys/compiler.h>
32 #include <l4/sys/consts.h>
36 * \defgroup l4_msgtag_api Message Tag
38 * \brief API related to the message tag data type.
40 * <c>\#include <l4/sys/types.h></c>
44 * \brief Message tag for IPC operations.
45 * \ingroup l4_msgtag_api
47 * All predefined protocols used by the kernel.
49 enum l4_msgtag_protocol
51 L4_PROTO_NONE = 0, ///< Default protocol tag to reply to kernel
52 L4_PROTO_ALLOW_SYSCALL = 1, ///< Allow an alien the system call
53 L4_PROTO_PF_EXCEPTION = 1, ///< Make an exception out of a page fault
55 L4_PROTO_IRQ = -1L, ///< IRQ message
56 L4_PROTO_PAGE_FAULT = -2L, ///< Page fault message
57 L4_PROTO_PREEMPTION = -3L, ///< Preemption message
58 L4_PROTO_SYS_EXCEPTION = -4L, ///< System exception
59 L4_PROTO_EXCEPTION = -5L, ///< Exception
60 L4_PROTO_SIGMA0 = -6L, ///< Sigma0 protocol
61 L4_PROTO_IO_PAGE_FAULT = -8L, ///< I/O page fault message
62 L4_PROTO_KOBJECT = -10L, ///< Protocol for messages to a a generic kobject
63 L4_PROTO_TASK = -11L, ///< Protocol for messages to a task object
64 L4_PROTO_THREAD = -12L, ///< Protocol for messages to a thread object
65 L4_PROTO_LOG = -13L, ///< Protocol for messages to a log object
66 L4_PROTO_SCHEDULER = -14L, ///< Protocol for messages to a scheduler object
67 L4_PROTO_FACTORY = -15L, ///< Protocol for messages to a factory object
68 L4_PROTO_VM = -16L, ///< Protocol for messages to a virtual machine object
69 L4_PROTO_DEBUGGER = -17L,
70 L4_PROTO_META = -21L, ///< Meta information protocol
75 L4_VARG_TYPE_NIL = 0x00,
76 L4_VARG_TYPE_UMWORD = 0x01,
77 L4_VARG_TYPE_MWORD = 0x81,
78 L4_VARG_TYPE_STRING = 0x02,
79 L4_VARG_TYPE_FPAGE = 0x03,
81 L4_VARG_TYPE_SIGN = 0x80,
86 * \brief Flags for message tags.
87 * \ingroup l4_msgtag_api
91 // flags for received IPC
93 * \brief Error indicator flag.
96 L4_MSGTAG_ERROR = 0x8000,
98 * \brief Cross-CPU invocation indicator flag.
101 L4_MSGTAG_XCPU = 0x4000,
103 // flags for sending IPC
105 * \brief Enable FPU transfer flag for IPC.
108 * By enabling this flag when sending IPC, the sender indicates that the
109 * contents of the FPU shall be transfered to the receiving thread.
110 * However, the receiver has to indicate its willingness to receive
111 * FPU context in its buffer descriptor register (BDR).
113 L4_MSGTAG_TRANSFER_FPU = 0x1000,
115 * \brief Enable schedule in IPC flag.
118 * Usually IPC operations donate the remaining time slice of a thread
119 * to the called thread. Enabling this flag when sending IPC does a real
120 * scheduling decision. However, this flag decreases IPC performance.
122 L4_MSGTAG_SCHEDULE = 0x2000,
124 * \brief Enable IPC propagation.
127 * This flag enables IPC propagation, which means an IPC reply-connection
128 * from the current caller will be propagated to the new IPC receiver.
129 * This makes it possible to propagate an IPC call to a third thread, which
130 * may then directly answer to the caller.
132 L4_MSGTAG_PROPAGATE = 0x4000,
135 * \brief Mask for all flags.
138 L4_MSGTAG_FLAGS = 0xf000,
143 * \brief Message tag data structure.
144 * \ingroup l4_msgtag_api
146 * <c>\#include <l4/sys/types.h></c>
148 * Describes the details of an IPC operation, in particular
149 * which parts of the UTCB have to be transmitted, and also flags
150 * to enable real-time and FPU extensions.
152 * The message tag also contains a user-defined label that could be used
153 * to specify a protocol ID. Some negative values are reserved for kernel
154 * protocols such as page faults and exceptions.
156 * The type must be treated completely opaque.
158 typedef struct l4_msgtag_t
160 l4_mword_t raw; ///< raw value
162 /// Get the protocol value.
163 long label() const throw() { return raw >> 16; }
164 /// Set the protocol value.
165 void label(long v) throw() { raw = (raw & 0x0ffff) | (v << 16); }
166 /// Get the number of untyped words.
167 unsigned words() const throw() { return raw & 0x3f; }
168 /// Get the number of typed items.
169 unsigned items() const throw() { return (raw >> 6) & 0x3f; }
171 * \brief Get the flags value.
173 * The flags are a combination of the flags defined by
176 unsigned flags() const throw() { return raw & 0xf000; }
177 /// Test if protocol indicates page-fault protocol.
178 bool is_page_fault() const throw() { return label() == L4_PROTO_PAGE_FAULT; }
179 /// Test if protocol indicates preemption protocol.
180 bool is_preemption() const throw() { return label() == L4_PROTO_PREEMPTION; }
181 /// Test if protocol indicates system-exception protocol.
182 bool is_sys_exception() const throw() { return label() == L4_PROTO_SYS_EXCEPTION; }
183 /// Test if protocol indicates exception protocol.
184 bool is_exception() const throw() { return label() == L4_PROTO_EXCEPTION; }
185 /// Test if protocol indicates sigma0 protocol.
186 bool is_sigma0() const throw() { return label() == L4_PROTO_SIGMA0; }
187 /// Test if protocol indicates IO-page-fault protocol.
188 bool is_io_page_fault() const throw() { return label() == L4_PROTO_IO_PAGE_FAULT; }
189 /// Test if flags indicate an error.
190 unsigned has_error() const throw() { return raw & L4_MSGTAG_ERROR; }
197 * \brief Create a message tag from the specified values.
198 * \ingroup l4_msgtag_api
200 * \param label the user-defined label
201 * \param words the number of untyped words within the UTCB
202 * \param items the number of typed items (e.g., flex pages) within the UTCB
203 * \param flags the IPC flags for realtime and FPU extensions
205 * \return Message tag
207 L4_INLINE l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items,
208 unsigned flags) L4_NOTHROW;
211 * \brief Get the protocol of tag.
212 * \ingroup l4_msgtag_api
216 L4_INLINE long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW;
219 * \brief Get the number of untyped words.
220 * \ingroup l4_msgtag_api
222 * \return Number of words
224 L4_INLINE unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW;
227 * \brief Get the number of typed items.
228 * \ingroup l4_msgtag_api
230 * \return Number of items.
232 L4_INLINE unsigned l4_msgtag_items(l4_msgtag_t t) L4_NOTHROW;
235 * \brief Get the flags.
236 * \ingroup l4_msgtag_api
238 * The flag are defined by #l4_msgtag_flags.
243 L4_INLINE unsigned l4_msgtag_flags(l4_msgtag_t t) L4_NOTHROW;
246 * \brief Test for error indicator flag.
247 * \ingroup l4_msgtag_api
249 * \return >0 for yes, 0 for no
251 * Return whether the kernel operation caused a communication error, e.g.
253 * if true: utcb->error is valid, otherwise utcb->error is not valid
255 L4_INLINE unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW;
258 * \brief Test for page-fault protocol.
259 * \ingroup l4_msgtag_api
261 * \return Boolean value
263 L4_INLINE unsigned l4_msgtag_is_page_fault(l4_msgtag_t t) L4_NOTHROW;
266 * \brief Test for preemption protocol.
267 * \ingroup l4_msgtag_api
269 * \return Boolean value
271 L4_INLINE unsigned l4_msgtag_is_preemption(l4_msgtag_t t) L4_NOTHROW;
274 * \brief Test for system-exception protocol.
275 * \ingroup l4_msgtag_api
277 * \return Boolean value
279 L4_INLINE unsigned l4_msgtag_is_sys_exception(l4_msgtag_t t) L4_NOTHROW;
282 * \brief Test for exception protocol.
283 * \ingroup l4_msgtag_api
285 * \return Boolean value
287 L4_INLINE unsigned l4_msgtag_is_exception(l4_msgtag_t t) L4_NOTHROW;
290 * \brief Test for sigma0 protocol.
291 * \ingroup l4_msgtag_api
293 * \return Boolean value
295 L4_INLINE unsigned l4_msgtag_is_sigma0(l4_msgtag_t t) L4_NOTHROW;
298 * \brief Test for IO-page-fault protocol.
299 * \ingroup l4_msgtag_api
301 * \return Boolean value
303 L4_INLINE unsigned l4_msgtag_is_io_page_fault(l4_msgtag_t t) L4_NOTHROW;
306 * \defgroup l4_cap_api Capabilities
308 * \brief Functions and definitions related to capabilities.
310 * C interface for capabilities:<br>
311 * <c>\#include <l4/sys/types.h></c>
314 * \brief L4 Capability selector Type.
315 * \ingroup l4_cap_api
317 * <c>\#include <l4/sys/types.h></c>
319 typedef unsigned long l4_cap_idx_t;
322 * \brief Test if a capability selector is the invalid capability.
323 * \ingroup l4_cap_api
324 * \param c Capability selector
325 * \return Boolean value
327 L4_INLINE unsigned l4_is_invalid_cap(l4_cap_idx_t c) L4_NOTHROW;
330 * \brief Test if a capability selector is a valid selector.
331 * \ingroup l4_cap_api
332 * \param c Capability selector
333 * \return Boolean value
335 L4_INLINE unsigned l4_is_valid_cap(l4_cap_idx_t c) L4_NOTHROW;
338 * \brief Test if two capability selectors are equal.
339 * \ingroup l4_cap_api
340 * \param c1 Capability
341 * \param c2 Capability
342 * \return 1 if equal, 0 if not equal
344 L4_INLINE unsigned l4_capability_equal(l4_cap_idx_t c1, l4_cap_idx_t c2) L4_NOTHROW;
346 /* ************************************************************************* */
350 l4_is_invalid_cap(l4_cap_idx_t c) L4_NOTHROW
351 { return c & L4_INVALID_CAP_BIT; }
354 l4_is_valid_cap(l4_cap_idx_t c) L4_NOTHROW
355 { return !(c & L4_INVALID_CAP_BIT); }
358 l4_capability_equal(l4_cap_idx_t c1, l4_cap_idx_t c2) L4_NOTHROW
359 { return (c1 >> L4_CAP_SHIFT) == (c2 >> L4_CAP_SHIFT); }
363 * Message tag functions
366 l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items,
367 unsigned flags) L4_NOTHROW
369 return (l4_msgtag_t){(label << 16) | (l4_mword_t)(words & 0x3f)
370 | (l4_mword_t)((items & 0x3f) << 6)
371 | (l4_mword_t)(flags & 0xf000)};
377 long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
378 { return t.raw >> 16; }
381 unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
382 { return t.raw & 0x3f; }
385 unsigned l4_msgtag_items(l4_msgtag_t t) L4_NOTHROW
386 { return (t.raw >> 6) & 0x3f; }
389 unsigned l4_msgtag_flags(l4_msgtag_t t) L4_NOTHROW
390 { return t.raw & 0xf000; }
394 unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
395 { return t.raw & L4_MSGTAG_ERROR; }
399 L4_INLINE unsigned l4_msgtag_is_page_fault(l4_msgtag_t t) L4_NOTHROW
400 { return l4_msgtag_label(t) == L4_PROTO_PAGE_FAULT; }
402 L4_INLINE unsigned l4_msgtag_is_preemption(l4_msgtag_t t) L4_NOTHROW
403 { return l4_msgtag_label(t) == L4_PROTO_PREEMPTION; }
405 L4_INLINE unsigned l4_msgtag_is_sys_exception(l4_msgtag_t t) L4_NOTHROW
406 { return l4_msgtag_label(t) == L4_PROTO_SYS_EXCEPTION; }
408 L4_INLINE unsigned l4_msgtag_is_exception(l4_msgtag_t t) L4_NOTHROW
409 { return l4_msgtag_label(t) == L4_PROTO_EXCEPTION; }
411 L4_INLINE unsigned l4_msgtag_is_sigma0(l4_msgtag_t t) L4_NOTHROW
412 { return l4_msgtag_label(t) == L4_PROTO_SIGMA0; }
414 L4_INLINE unsigned l4_msgtag_is_io_page_fault(l4_msgtag_t t) L4_NOTHROW
415 { return l4_msgtag_label(t) == L4_PROTO_IO_PAGE_FAULT; }