3 * \brief Common thread related definitions.
6 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7 * Alexander Warg <warg@os.inf.tu-dresden.de>,
8 * Björn Döbel <doebel@os.inf.tu-dresden.de>,
9 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
10 * economic rights: Technische Universität Dresden (Germany)
12 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU General Public License 2.
14 * Please see the COPYING-GPL-2 file for details.
16 * As a special exception, you may use this file as part of a free software
17 * library without restriction. Specifically, if other files instantiate
18 * templates or use macros or inline functions from this file, or you compile
19 * this file and link it with other files to produce an executable, this
20 * file does not by itself cause the resulting executable to be covered by
21 * the GNU General Public License. This exception does not however
22 * invalidate any other reasons why the executable file might be covered by
23 * the GNU General Public License.
27 #include <l4/sys/types.h>
28 #include <l4/sys/utcb.h>
29 #include <l4/sys/ipc.h>
32 * \defgroup l4_thread_api Thread
33 * \ingroup l4_kernel_object_api
34 * \brief Thread object.
36 * <c>\#include <l4/sys/thread.h></c>
38 * The thread class defines a thread of execution in the L4 context.
39 * Usually user-level and kernel threads are mapped 1:1 to each other.
40 * Thread kernel objects are created using a Factory, see \ref l4_factory_api
41 * (l4_factory_create_thread()).
43 * An L4 thread encapsulates:
45 * - General-purpose registers
49 * - Scheduling parameters
54 * - Blocked, Runnable, Running
56 * Thread objects provide an API for
57 * - Thread configuration and manipulation
60 * The thread control functions are used to control various aspects of a
61 * thread. See l4_thread_control_start() for more information.
66 * \brief Exchange basic thread registers.
67 * \ingroup l4_thread_api
69 * \param thread Thread to manipulate
70 * \param ip New instruction pointer, use ~0UL to leave the
71 * instruction pointer unchanged
72 * \param sp New stack pointer, use ~0UL to leave the stack
74 * \param flags Ex-regs flags, see #L4_thread_ex_regs_flags
76 * \return System call return tag
78 * This method allows to manipulate and start a thread. The basic
79 * functionality is to set the instruction pointer and the stack pointer of a
80 * thread. Additionally, this method allows also to cancel ongoing IPC
81 * operations and to force the thread to raise an artificial exception (see \a
86 l4_thread_ex_regs(l4_cap_idx_t thread, l4_addr_t ip, l4_addr_t sp,
87 l4_umword_t flags) L4_NOTHROW;
91 * \ingroup l4_thread_api
94 l4_thread_ex_regs_u(l4_cap_idx_t thread, l4_addr_t ip, l4_addr_t sp,
95 l4_umword_t flags, l4_utcb_t *utcb) L4_NOTHROW;
98 * \brief Exchange basic thread registers and return previous values.
99 * \ingroup l4_thread_api
101 * \param[in] thread Thread to manipulate
102 * \param[in,out] ip New instruction pointer, use ~0UL to leave the
103 * instruction pointer unchanged, return previous
104 * instruction pointer
105 * \param[in,out] sp New stack pointer, use ~0UL to leave the stack
106 * pointer unchanged, returns previous stack pointer
107 * \param[in,out] flags Ex-regs flags, see #L4_thread_ex_regs_flags, return
108 * previous CPU flags of the thread.
110 * \return System call return tag
112 * This method allows to manipulate and start a thread. The basic
113 * functionality is to set the instruction pointer and the stack pointer of a
114 * thread. Additionally, this method allows also to cancel ongoing IPC
115 * operations and to force the thread to raise an artificial exception (see \a
118 * Returned values are valid only if function returns successfully.
120 L4_INLINE l4_msgtag_t
121 l4_thread_ex_regs_ret(l4_cap_idx_t thread, l4_addr_t *ip, l4_addr_t *sp,
122 l4_umword_t *flags) L4_NOTHROW;
126 * \ingroup l4_thread_api
128 L4_INLINE l4_msgtag_t
129 l4_thread_ex_regs_ret_u(l4_cap_idx_t thread, l4_addr_t *ip, l4_addr_t *sp,
130 l4_umword_t *flags, l4_utcb_t *utcb) L4_NOTHROW;
135 * \defgroup l4_thread_control_api Thread control
136 * \ingroup l4_thread_api
138 * \brief API for Thread Control method.
141 * The thread control API provides access to almost any parameter of a thread
142 * object. The API is based on a single invocation of the thread object.
143 * However, because of the huge amount of parameters, the API provides a set
144 * of functions to set specific parameters of a thread and a commit function
145 * to commit the thread control call (see l4_thread_control_commit()).
147 * A thread control operation must always start with l4_thread_control_start()
148 * and be committed with l4_thread_control_commit(). All other thread control
149 * parameter setter functions must be called between these two functions.
151 * An example for a sequence of thread control API calls can be found below.
153 * l4_utcb_t *u = l4_utcb(); <br>
154 * \link l4_thread_control_start() l4_thread_control_start(u)\endlink; <br>
155 * \link l4_thread_control_pager() l4_thread_control_pager(u, pager_cap)\endlink; <br>
156 * \link l4_thread_control_bind() l4_thread_control_bind (u, thread_utcb, task)\endlink; <br>
157 * \link l4_thread_control_commit() l4_thread_control_commit(u, thread_cap)\endlink; <br>
162 * \brief Start a thread control API sequence.
163 * \ingroup l4_thread_control_api
165 * This function starts a sequence of thread control API functions.
166 * After this functions any of following functions may be called in any order.
167 * - l4_thread_control_pager()
168 * - l4_thread_control_exc_handler()
169 * - l4_thread_control_bind()
170 * - l4_thread_control_alien()
171 * - l4_thread_control_ux_host_syscall() (Fiasco-UX only)
173 * To commit the changes to the thread l4_thread_control_commit() must be
176 * \note The thread control API calls store the parameters for the thread in
177 * the UTCB of the caller, this means between l4_thread_control_start()
178 * and l4_thread_control_commit() no functions that modify the UTCB
179 * contents must be called.
182 l4_thread_control_start(void) L4_NOTHROW;
186 * \ingroup l4_thread_control_api
189 l4_thread_control_start_u(l4_utcb_t *utcb) L4_NOTHROW;
192 * \brief Set the pager.
193 * \ingroup l4_thread_control_api
195 * \param pager Capability selector invoked to send a page-fault IPC.
197 * \note The pager capability selector is interpreted in the task the thread
198 * is bound to (executes in).
201 l4_thread_control_pager(l4_cap_idx_t pager) L4_NOTHROW;
205 * \ingroup l4_thread_control_api
208 l4_thread_control_pager_u(l4_cap_idx_t pager, l4_utcb_t *utcb) L4_NOTHROW;
211 * \brief Set the exception handler.
212 * \ingroup l4_thread_control_api
214 * \param exc_handler Capability selector invoked to send an exception IPC.
216 * \note The exception-handler capability selector is interpreted in the task
217 * the thread is bound to (executes in).
220 l4_thread_control_exc_handler(l4_cap_idx_t exc_handler) L4_NOTHROW;
224 * \ingroup l4_thread_control_api
227 l4_thread_control_exc_handler_u(l4_cap_idx_t exc_handler,
228 l4_utcb_t *utcb) L4_NOTHROW;
231 * \brief Bind the thread to a task.
232 * \ingroup l4_thread_control_api
234 * \param thread_utcb The address of the UTCB in the target task.
235 * \param task The target task of the thread.
237 * Binding a thread to a task has the effect that the thread
238 * afterwards executes code within that task and has access to the
239 * resources visible within that task.
241 * \note There should not be more than one thread use a UTCB to prevent
246 l4_thread_control_bind(l4_utcb_t *thread_utcb,
247 l4_cap_idx_t task) L4_NOTHROW;
251 * \ingroup l4_thread_control_api
254 l4_thread_control_bind_u(l4_utcb_t *thread_utcb,
255 l4_cap_idx_t task, l4_utcb_t *utcb) L4_NOTHROW;
258 * \brief Enable alien mode.
259 * \ingroup l4_thread_control_api
260 * \param on Boolean value defining the state of the feature.
262 * Alien mode means the thread is not allowed to invoke L4 kernel objects
263 * directly and it is also not allowed to allocate FPU state. All those
264 * operations result in an exception IPC that gets sent through the pager
265 * capability. The responsible pager can then selectively allow an object
266 * invocation or allocate FPU state for the thread.
268 * This feature can be used to attach a debugger to a thread and trace all
269 * object invocations.
272 l4_thread_control_alien(int on) L4_NOTHROW;
276 * \ingroup l4_thread_control_api
279 l4_thread_control_alien_u(l4_utcb_t *utcb, int on) L4_NOTHROW;
282 * \brief Enable pass through of native host (Linux) system calls.
283 * \ingroup l4_thread_control_api
284 * \param on Boolean value defining the state of the feature.
286 * \pre Running on Fiasco-UX
288 * This enables the thread to do host system calls. This feature is only
289 * available in Fiasco-UX and ignored in other environments.
292 l4_thread_control_ux_host_syscall(int on) L4_NOTHROW;
296 * \ingroup l4_thread_control_api
299 l4_thread_control_ux_host_syscall_u(l4_utcb_t *utcb, int on) L4_NOTHROW;
304 * \brief Commit the thread control parameters.
305 * \ingroup l4_thread_control_api
307 * \param thread Capability selector of target thread to commit to.
308 * \return system call return tag
310 L4_INLINE l4_msgtag_t
311 l4_thread_control_commit(l4_cap_idx_t thread) L4_NOTHROW;
315 * \ingroup l4_thread_control_api
317 L4_INLINE l4_msgtag_t
318 l4_thread_control_commit_u(l4_cap_idx_t thread, l4_utcb_t *utcb) L4_NOTHROW;
321 * \brief Yield current time slice.
322 * \ingroup l4_thread_api
324 * \return system call return tag
326 L4_INLINE l4_msgtag_t
327 l4_thread_yield(void) L4_NOTHROW;
330 * \brief Switch to another thread (and donate the remaining time slice).
331 * \ingroup l4_thread_api
333 * \param to_thread The thread to switch to.
335 * \return system call return tag
337 L4_INLINE l4_msgtag_t
338 l4_thread_switch(l4_cap_idx_t to_thread) L4_NOTHROW;
342 * \ingroup l4_thread_api
344 L4_INLINE l4_msgtag_t
345 l4_thread_switch_u(l4_cap_idx_t to_thread, l4_utcb_t *utcb) L4_NOTHROW;
350 * \brief Get consumed timed of thread in µs.
351 * \ingroup l4_thread_api
352 * \param thread Thread to get the consumed time from.
354 * The consumed time is returned as l4_kernel_clock_t at UTCB message
357 L4_INLINE l4_msgtag_t
358 l4_thread_stats_time(l4_cap_idx_t thread) L4_NOTHROW;
362 * \ingroup l4_thread_api
364 L4_INLINE l4_msgtag_t
365 l4_thread_stats_time_u(l4_cap_idx_t thread, l4_utcb_t *utcb) L4_NOTHROW;
369 * \brief vCPU return from event handler.
370 * \ingroup l4_thread_api
372 * \return Message tag to be used for l4_sndfpage_add() and
373 * l4_thread_vcpu_commit()
375 * The vCPU resume functionality is split in multiple functions to allow the
376 * specification of additional send-flex-pages using l4_sndfpage_add().
378 L4_INLINE l4_msgtag_t
379 l4_thread_vcpu_resume_start(void) L4_NOTHROW;
383 * \ingroup l4_thread_api
385 L4_INLINE l4_msgtag_t
386 l4_thread_vcpu_resume_start_u(l4_utcb_t *utcb) L4_NOTHROW;
389 * \brief Commit vCPU resume.
390 * \ingroup l4_thread_api
392 * \param thread Thread to be resumed, using the invalid cap can be used
393 * for the current thread.
394 * \param tag Tag to use, returned by l4_thread_vcpu_resume_start()
396 * \return System call result message tag. In extended vCPU mode and when
397 * the virtual interrupts are cleared, the return code 1 flags an incoming
398 * IPC message, whereas 0 indicates a VM exit.
400 * To resume into another address space the capability to the target task
401 * must be set in the vCPU-state. The task needs to be set only once,
402 * consecutive resumes to the same address space should use an invalid
403 * capability. The kernel resets the field to #L4_INVALID_CAP. To release a
404 * task use a different task or use an invalid capability with
405 * the #L4_SYSF_REPLY flag set.
407 * \see l4_vcpu_state_t
409 L4_INLINE l4_msgtag_t
410 l4_thread_vcpu_resume_commit(l4_cap_idx_t thread,
411 l4_msgtag_t tag) L4_NOTHROW;
415 * \ingroup l4_thread_api
417 L4_INLINE l4_msgtag_t
418 l4_thread_vcpu_resume_commit_u(l4_cap_idx_t thread,
419 l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW;
423 * \brief Enable or disable the vCPU feature for the thread.
424 * \ingroup l4_thread_api
426 * \param thread The thread for which the vCPU feature shall be enabled or
428 * \param vcpu_state The virtual address where the kernel shall store the vCPU
429 * state in case of vCPU exits. The address must be a valid
430 * kernel-user-memory address.
431 * \return Systemcall result message tag.
433 * This function enables the vCPU feature of the \a thread if \a vcpu_state
434 * is set to a valid kernel-user-memory address, or disables the vCPU feature
435 * if \a vcpu_state is 0.
438 L4_INLINE l4_msgtag_t
439 l4_thread_vcpu_control(l4_cap_idx_t thread, l4_addr_t vcpu_state) L4_NOTHROW;
443 * \ingroup l4_thread_api
445 L4_INLINE l4_msgtag_t
446 l4_thread_vcpu_control_u(l4_cap_idx_t thread, l4_addr_t vcpu_state,
447 l4_utcb_t *utcb) L4_NOTHROW;
450 * \brief Enable or disable the extended vCPU feature for the thread.
451 * \ingroup l4_thread_api
453 * \param thread The thread for which the extended vCPU feature shall be
454 * enabled or disabled.
455 * \param vcpu_state The virtual address where the kernel shall store the vCPU
456 * state in case of vCPU exits. The address must be a valid
457 * kernel-user-memory address.
458 * \return Systemcall result message tag.
460 * The extended vCPU feature allows the use of hardware-virtualization
461 * features such as Intel's VT or AMD's SVM.
463 * This function enables the extended vCPU feature of the \a thread
464 * if \a vcpu_state is set to a valid kernel-user-memory address, or disables
465 * the vCPU feature if \a vcpu_state is 0.
468 L4_INLINE l4_msgtag_t
469 l4_thread_vcpu_control_ext(l4_cap_idx_t thread, l4_addr_t ext_vcpu_state) L4_NOTHROW;
473 * \ingroup l4_thread_api
475 L4_INLINE l4_msgtag_t
476 l4_thread_vcpu_control_ext_u(l4_cap_idx_t thread, l4_addr_t ext_vcpu_state,
477 l4_utcb_t *utcb) L4_NOTHROW;
481 * \brief Register an IRQ that will trigger upon deletion events.
482 * \ingroup l4_thread_api
484 * \param thread Thread to register IRQ for.
485 * \param irq Irq to register.
487 * \return System call result message tag.
489 L4_INLINE l4_msgtag_t
490 l4_thread_register_del_irq(l4_cap_idx_t thread, l4_cap_idx_t irq) L4_NOTHROW;
494 * \ingroup l4_thread_api
496 L4_INLINE l4_msgtag_t
497 l4_thread_register_del_irq_u(l4_cap_idx_t thread, l4_cap_idx_t irq,
498 l4_utcb_t *utcb) L4_NOTHROW;
501 * \brief Start a thread sender modifiction sequence.
502 * \ingroup l4_thread_api
504 * Add modification rules with l4_thread_modify_sender_add() and commit with
505 * l4_thread_modify_sender_commit(). Do not touch the UTCB between
506 * l4_thread_modify_sender_start() and l4_thread_modify_sender_commit().
508 * \see l4_thread_modify_sender_add
509 * \see l4_thread_modify_sender_commit
511 L4_INLINE l4_msgtag_t
512 l4_thread_modify_sender_start(void) L4_NOTHROW;
516 * \ingroup l4_thread_api
518 L4_INLINE l4_msgtag_t
519 l4_thread_modify_sender_start_u(l4_utcb_t *u) L4_NOTHROW;
522 * \brief Add a modification pattern to a sender modification sequence.
523 * \ingroup l4_thread_api
525 * \param tag Tag received from l4_thread_modify_sender_start() or
526 * previous l4_thread_modify_sender_add() calls from
528 * \param match_mask Bitmask of bits to match the label.
529 * \param match Bitmask that must be equal to the label after applying
531 * \param del_bits Bits to be deleted from the label.
532 * \param add_bits Bits to be added to the label.
534 * \return 0 on sucess, <0 on error
537 * if ((sender_label & match_mask) == match)
538 * { label = (label & ~del_bits) | add_bits; }
540 * Only the first match is applied.
542 * \see l4_thread_modify_sender_start
543 * \see l4_thread_modify_sender_commit
546 l4_thread_modify_sender_add(l4_umword_t match_mask,
548 l4_umword_t del_bits,
549 l4_umword_t add_bits,
550 l4_msgtag_t *tag) L4_NOTHROW;
554 * \ingroup l4_thread_api
557 l4_thread_modify_sender_add_u(l4_umword_t match_mask,
559 l4_umword_t del_bits,
560 l4_umword_t add_bits,
561 l4_msgtag_t *tag, l4_utcb_t *u) L4_NOTHROW;
564 * \brief Apply (commit) a sender modification sequence.
565 * \ingroup l4_thread_api
567 * \see l4_thread_modify_sender_start
568 * \see l4_thread_modify_sender_add
570 L4_INLINE l4_msgtag_t
571 l4_thread_modify_sender_commit(l4_cap_idx_t thread, l4_msgtag_t tag) L4_NOTHROW;
575 * \ingroup l4_thread_api
577 L4_INLINE l4_msgtag_t
578 l4_thread_modify_sender_commit_u(l4_cap_idx_t thread, l4_msgtag_t tag,
579 l4_utcb_t *u) L4_NOTHROW;
582 * \brief Operations on thread objects.
583 * \ingroup l4_thread_api
589 L4_THREAD_CONTROL_OP = 0UL, /**< Control operation */
590 L4_THREAD_EX_REGS_OP = 1UL, /**< Exchange registers operation */
591 L4_THREAD_SWITCH_OP = 2UL, /**< Do a thread switch */
592 L4_THREAD_STATS_OP = 3UL, /**< Thread statistics */
593 L4_THREAD_VCPU_RESUME_OP = 4UL, /**< VCPU resume */
594 L4_THREAD_REGISTER_DELETE_IRQ_OP = 5UL, /**< Register an IPC-gate deletion IRQ */
595 L4_THREAD_MODIFY_SENDER_OP = 6UL, /**< Modify all senders IDs that match the given pattern */
596 L4_THREAD_VCPU_CONTROL_OP = 7UL, /**< Enable / disable VCPU feature */
597 L4_THREAD_VCPU_CONTROL_EXT_OP = L4_THREAD_VCPU_CONTROL_OP | 0x10000,
598 L4_THREAD_GDT_X86_OP = 0x10UL, /**< Gdt */
599 L4_THREAD_SET_FS_AMD64_OP = 0x12UL, /**< Set FS/TLS */
600 L4_THREAD_OPCODE_MASK = 0xffff, /**< Mask for opcodes */
604 * \brief Flags for the thread control operation.
605 * \ingroup l4_thread_api
609 * Values for the enabled flags need to be given in their appropriate field
611 * \see l4_thread_control
613 enum L4_thread_control_flags
615 /** The pager will be given. */
616 L4_THREAD_CONTROL_SET_PAGER = 0x0010000,
617 /** The task to bind the thread to will be given. */
618 L4_THREAD_CONTROL_BIND_TASK = 0x0200000,
619 /** Alien state of the thread is set. */
620 L4_THREAD_CONTROL_ALIEN = 0x0400000,
621 /** Fiasco-UX only: pass-through of host system calls is set. */
622 L4_THREAD_CONTROL_UX_NATIVE = 0x0800000,
623 /** The exception handler of the thread will be given. */
624 L4_THREAD_CONTROL_SET_EXC_HANDLER = 0x1000000,
628 * \brief Indices for the values in the message register for thread control.
629 * \ingroup l4_thread_api
633 * The values indicate the index in the message registers during
634 * thread-control operation.
636 enum L4_thread_control_mr_indices
638 L4_THREAD_CONTROL_MR_IDX_FLAGS = 0, /**< \see #L4_thread_control_flags. */
639 L4_THREAD_CONTROL_MR_IDX_PAGER = 1, /**< Index for pager cap */
640 L4_THREAD_CONTROL_MR_IDX_EXC_HANDLER = 2, /**< Index for exception handler */
641 L4_THREAD_CONTROL_MR_IDX_FLAG_VALS = 4, /**< Index for feature values */
642 L4_THREAD_CONTROL_MR_IDX_BIND_UTCB = 5, /**< Index for UTCB address for bind */
643 L4_THREAD_CONTROL_MR_IDX_BIND_TASK = 6, /**< Index for task flex-page for bind */
647 * \brief Flags for the thread ex-regs operation.
648 * \ingroup l4_thread_api
651 enum L4_thread_ex_regs_flags
653 L4_THREAD_EX_REGS_CANCEL = 0x10000UL, /**< Cancel ongoing IPC in the thread. */
654 L4_THREAD_EX_REGS_TRIGGER_EXCEPTION = 0x20000UL, /**< Trigger artificial exception in thread. */
658 /* IMPLEMENTATION -----------------------------------------------------------*/
660 #include <l4/sys/ipc.h>
661 #include <l4/sys/types.h>
663 L4_INLINE l4_msgtag_t
664 l4_thread_ex_regs_u(l4_cap_idx_t thread, l4_addr_t ip, l4_addr_t sp,
665 l4_umword_t flags, l4_utcb_t *utcb) L4_NOTHROW
667 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
668 v->mr[0] = L4_THREAD_EX_REGS_OP | flags;
671 return l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 3, 0, 0), L4_IPC_NEVER);
674 L4_INLINE l4_msgtag_t
675 l4_thread_ex_regs_ret_u(l4_cap_idx_t thread, l4_addr_t *ip, l4_addr_t *sp,
676 l4_umword_t *flags, l4_utcb_t *utcb) L4_NOTHROW
678 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
679 l4_msgtag_t ret = l4_thread_ex_regs_u(thread, *ip, *sp, *flags, utcb);
680 if (l4_error_u(ret, utcb))
690 l4_thread_control_start_u(l4_utcb_t *utcb) L4_NOTHROW
692 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
693 v->mr[L4_THREAD_CONTROL_MR_IDX_FLAGS] = L4_THREAD_CONTROL_OP;
697 l4_thread_control_pager_u(l4_cap_idx_t pager, l4_utcb_t *utcb) L4_NOTHROW
699 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
700 v->mr[L4_THREAD_CONTROL_MR_IDX_FLAGS] |= L4_THREAD_CONTROL_SET_PAGER;
701 v->mr[L4_THREAD_CONTROL_MR_IDX_PAGER] = pager;
705 l4_thread_control_exc_handler_u(l4_cap_idx_t exc_handler,
706 l4_utcb_t *utcb) L4_NOTHROW
708 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
709 v->mr[L4_THREAD_CONTROL_MR_IDX_FLAGS] |= L4_THREAD_CONTROL_SET_EXC_HANDLER;
710 v->mr[L4_THREAD_CONTROL_MR_IDX_EXC_HANDLER] = exc_handler;
714 l4_thread_control_bind_u(l4_utcb_t *thread_utcb, l4_cap_idx_t task,
715 l4_utcb_t *utcb) L4_NOTHROW
717 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
718 v->mr[L4_THREAD_CONTROL_MR_IDX_FLAGS] |= L4_THREAD_CONTROL_BIND_TASK;
719 v->mr[L4_THREAD_CONTROL_MR_IDX_BIND_UTCB] = (l4_addr_t)thread_utcb;
720 v->mr[L4_THREAD_CONTROL_MR_IDX_BIND_TASK] = L4_ITEM_MAP;
721 v->mr[L4_THREAD_CONTROL_MR_IDX_BIND_TASK + 1] = l4_obj_fpage(task, 0, L4_FPAGE_RWX).raw;
725 l4_thread_control_alien_u(l4_utcb_t *utcb, int on) L4_NOTHROW
727 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
728 v->mr[L4_THREAD_CONTROL_MR_IDX_FLAGS] |= L4_THREAD_CONTROL_ALIEN;
729 v->mr[L4_THREAD_CONTROL_MR_IDX_FLAG_VALS] |= on ? L4_THREAD_CONTROL_ALIEN : 0;
733 l4_thread_control_ux_host_syscall_u(l4_utcb_t *utcb, int on) L4_NOTHROW
735 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
736 v->mr[L4_THREAD_CONTROL_MR_IDX_FLAGS] |= L4_THREAD_CONTROL_UX_NATIVE;
737 v->mr[L4_THREAD_CONTROL_MR_IDX_FLAG_VALS] |= on ? L4_THREAD_CONTROL_UX_NATIVE : 0;
740 L4_INLINE l4_msgtag_t
741 l4_thread_control_commit_u(l4_cap_idx_t thread, l4_utcb_t *utcb) L4_NOTHROW
744 if (l4_utcb_mr_u(utcb)->mr[L4_THREAD_CONTROL_MR_IDX_FLAGS] & L4_THREAD_CONTROL_BIND_TASK)
746 return l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 6, items, 0), L4_IPC_NEVER);
750 L4_INLINE l4_msgtag_t
751 l4_thread_yield(void) L4_NOTHROW
753 l4_ipc_receive(L4_INVALID_CAP, NULL, L4_IPC_BOTH_TIMEOUT_0);
754 return l4_msgtag(0, 0, 0, 0);
757 /* Preliminary, to be changed */
758 L4_INLINE l4_msgtag_t
759 l4_thread_switch_u(l4_cap_idx_t to_thread, l4_utcb_t *utcb) L4_NOTHROW
761 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
762 v->mr[0] = L4_THREAD_SWITCH_OP;
763 return l4_ipc_call(to_thread, utcb, l4_msgtag(L4_PROTO_THREAD, 1, 0, 0), L4_IPC_NEVER);
767 L4_INLINE l4_msgtag_t
768 l4_thread_stats_time_u(l4_cap_idx_t thread, l4_utcb_t *utcb) L4_NOTHROW
770 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
771 v->mr[0] = L4_THREAD_STATS_OP;
772 return l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 1, 0, 0), L4_IPC_NEVER);
775 L4_INLINE l4_msgtag_t
776 l4_thread_vcpu_resume_start_u(l4_utcb_t *utcb) L4_NOTHROW
778 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
779 v->mr[0] = L4_THREAD_VCPU_RESUME_OP;
780 return l4_msgtag(L4_PROTO_THREAD, 1, 0, 0);
783 L4_INLINE l4_msgtag_t
784 l4_thread_vcpu_resume_commit_u(l4_cap_idx_t thread,
785 l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW
787 return l4_ipc_call(thread, utcb, tag, L4_IPC_NEVER);
790 L4_INLINE l4_msgtag_t
791 l4_thread_ex_regs(l4_cap_idx_t thread, l4_addr_t ip, l4_addr_t sp,
792 l4_umword_t flags) L4_NOTHROW
794 return l4_thread_ex_regs_u(thread, ip, sp, flags, l4_utcb());
797 L4_INLINE l4_msgtag_t
798 l4_thread_ex_regs_ret(l4_cap_idx_t thread, l4_addr_t *ip, l4_addr_t *sp,
799 l4_umword_t *flags) L4_NOTHROW
801 return l4_thread_ex_regs_ret_u(thread, ip, sp, flags, l4_utcb());
805 l4_thread_control_start(void) L4_NOTHROW
807 l4_thread_control_start_u(l4_utcb());
811 l4_thread_control_pager(l4_cap_idx_t pager) L4_NOTHROW
813 l4_thread_control_pager_u(pager, l4_utcb());
817 l4_thread_control_exc_handler(l4_cap_idx_t exc_handler) L4_NOTHROW
819 l4_thread_control_exc_handler_u(exc_handler, l4_utcb());
824 l4_thread_control_bind(l4_utcb_t *thread_utcb, l4_cap_idx_t task) L4_NOTHROW
826 l4_thread_control_bind_u(thread_utcb, task, l4_utcb());
830 l4_thread_control_alien(int on) L4_NOTHROW
832 l4_thread_control_alien_u(l4_utcb(), on);
836 l4_thread_control_ux_host_syscall(int on) L4_NOTHROW
838 l4_thread_control_ux_host_syscall_u(l4_utcb(), on);
841 L4_INLINE l4_msgtag_t
842 l4_thread_control_commit(l4_cap_idx_t thread) L4_NOTHROW
844 return l4_thread_control_commit_u(thread, l4_utcb());
850 L4_INLINE l4_msgtag_t
851 l4_thread_switch(l4_cap_idx_t to_thread) L4_NOTHROW
853 return l4_thread_switch_u(to_thread, l4_utcb());
859 L4_INLINE l4_msgtag_t
860 l4_thread_stats_time(l4_cap_idx_t thread) L4_NOTHROW
862 return l4_thread_stats_time_u(thread, l4_utcb());
865 L4_INLINE l4_msgtag_t
866 l4_thread_vcpu_resume_start(void) L4_NOTHROW
868 return l4_thread_vcpu_resume_start_u(l4_utcb());
871 L4_INLINE l4_msgtag_t
872 l4_thread_vcpu_resume_commit(l4_cap_idx_t thread,
873 l4_msgtag_t tag) L4_NOTHROW
875 return l4_thread_vcpu_resume_commit_u(thread, tag, l4_utcb());
879 L4_INLINE l4_msgtag_t
880 l4_thread_register_del_irq_u(l4_cap_idx_t thread, l4_cap_idx_t irq,
881 l4_utcb_t *u) L4_NOTHROW
883 l4_msg_regs_t *m = l4_utcb_mr_u(u);
884 m->mr[0] = L4_THREAD_REGISTER_DELETE_IRQ_OP;
885 m->mr[1] = l4_map_obj_control(0,0);
886 m->mr[2] = l4_obj_fpage(irq, 0, L4_CAP_FPAGE_RWS).raw;
887 return l4_ipc_call(thread, u, l4_msgtag(L4_PROTO_THREAD, 1, 1, 0), L4_IPC_NEVER);
891 L4_INLINE l4_msgtag_t
892 l4_thread_register_del_irq(l4_cap_idx_t thread, l4_cap_idx_t irq) L4_NOTHROW
894 return l4_thread_register_del_irq_u(thread, irq, l4_utcb());
898 L4_INLINE l4_msgtag_t
899 l4_thread_vcpu_control_u(l4_cap_idx_t thread, l4_addr_t vcpu_state,
900 l4_utcb_t *utcb) L4_NOTHROW
902 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
903 v->mr[0] = L4_THREAD_VCPU_CONTROL_OP;
904 v->mr[1] = vcpu_state;
905 return l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 2, 0, 0), L4_IPC_NEVER);
908 L4_INLINE l4_msgtag_t
909 l4_thread_vcpu_control(l4_cap_idx_t thread, l4_addr_t vcpu_state) L4_NOTHROW
910 { return l4_thread_vcpu_control_u(thread, vcpu_state, l4_utcb()); }
913 L4_INLINE l4_msgtag_t
914 l4_thread_vcpu_control_ext_u(l4_cap_idx_t thread, l4_addr_t ext_vcpu_state,
915 l4_utcb_t *utcb) L4_NOTHROW
917 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
918 v->mr[0] = L4_THREAD_VCPU_CONTROL_EXT_OP;
919 v->mr[1] = ext_vcpu_state;
920 return l4_ipc_call(thread, utcb, l4_msgtag(L4_PROTO_THREAD, 2, 0, 0), L4_IPC_NEVER);
923 L4_INLINE l4_msgtag_t
924 l4_thread_vcpu_control_ext(l4_cap_idx_t thread, l4_addr_t ext_vcpu_state) L4_NOTHROW
925 { return l4_thread_vcpu_control_ext_u(thread, ext_vcpu_state, l4_utcb()); }
927 L4_INLINE l4_msgtag_t
928 l4_thread_modify_sender_start_u(l4_utcb_t *u) L4_NOTHROW
930 l4_msg_regs_t *m = l4_utcb_mr_u(u);
931 m->mr[0] = L4_THREAD_MODIFY_SENDER_OP;
932 return l4_msgtag(L4_PROTO_THREAD, 1, 0, 0);
936 l4_thread_modify_sender_add_u(l4_umword_t match_mask,
938 l4_umword_t del_bits,
939 l4_umword_t add_bits,
940 l4_msgtag_t *tag, l4_utcb_t *u) L4_NOTHROW
942 l4_msg_regs_t *m = l4_utcb_mr_u(u);
943 unsigned w = l4_msgtag_words(*tag);
944 if (w >= L4_UTCB_GENERIC_DATA_SIZE - 4)
947 m->mr[w] = match_mask;
949 m->mr[w+2] = del_bits;
950 m->mr[w+3] = add_bits;
952 *tag = l4_msgtag(l4_msgtag_label(*tag), w + 4, 0, 0);
957 L4_INLINE l4_msgtag_t
958 l4_thread_modify_sender_commit_u(l4_cap_idx_t thread, l4_msgtag_t tag,
959 l4_utcb_t *u) L4_NOTHROW
961 return l4_ipc_call(thread, u, tag, L4_IPC_NEVER);
964 L4_INLINE l4_msgtag_t
965 l4_thread_modify_sender_start(void) L4_NOTHROW
967 return l4_thread_modify_sender_start_u(l4_utcb());
971 l4_thread_modify_sender_add(l4_umword_t match_mask,
973 l4_umword_t del_bits,
974 l4_umword_t add_bits,
975 l4_msgtag_t *tag) L4_NOTHROW
977 return l4_thread_modify_sender_add_u(match_mask, match,
978 del_bits, add_bits, tag, l4_utcb());
981 L4_INLINE l4_msgtag_t
982 l4_thread_modify_sender_commit(l4_cap_idx_t thread, l4_msgtag_t tag) L4_NOTHROW
984 return l4_thread_modify_sender_commit_u(thread, tag, l4_utcb());