2 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>,
4 * Björn Döbel <doebel@os.inf.tu-dresden.de>
5 * economic rights: Technische Universität Dresden (Germany)
7 * This file is part of TUD:OS and distributed under the terms of the
8 * GNU General Public License 2.
9 * Please see the COPYING-GPL-2 file for details.
12 * Example to show syscall tracing.
16 #include <l4/sys/ipc.h>
17 #include <l4/sys/thread.h>
18 #include <l4/sys/factory.h>
19 #include <l4/sys/utcb.h>
20 #include <l4/sys/kdebug.h>
21 #include <l4/util/util.h>
22 #include <l4/util/rdtsc.h>
23 #include <l4/re/env.h>
24 #include <l4/re/c/util/cap_alloc.h>
25 #include <l4/sys/debugger.h>
32 static char alien_thread_stack[8 << 10];
33 static l4_cap_idx_t alien;
35 static void alien_thread(void)
37 volatile l4_msgtag_t x;
39 x = l4_ipc_call(0x1234 << L4_CAP_SHIFT, l4_utcb(), l4_msgtag(0, 0, 0, 0), L4_IPC_NEVER);
44 outstring("An int3 -- you should see this\n");
57 l4_utcb_t *u = l4_utcb();
61 printf("Alien feature testing\n");
63 l4_debugger_set_object_name(l4re_env()->main_thread, "alientest");
65 /* Start alien thread */
66 if (l4_is_invalid_cap(alien = l4re_util_cap_alloc()))
69 l4_touch_rw(alien_thread_stack, sizeof(alien_thread_stack));
71 tag = l4_factory_create_thread(l4re_env()->factory, alien);
75 l4_debugger_set_object_name(alien, "alienth");
77 l4_thread_control_start();
78 l4_thread_control_pager(l4re_env()->main_thread);
79 l4_thread_control_exc_handler(l4re_env()->main_thread);
80 l4_thread_control_bind((l4_utcb_t *)l4re_env()->first_free_utcb, L4RE_THIS_TASK_CAP);
81 l4_thread_control_alien(1);
82 tag = l4_thread_control_commit(alien);
86 tag = l4_thread_ex_regs(alien,
87 (l4_umword_t)alien_thread,
88 (l4_umword_t)alien_thread_stack + sizeof(alien_thread_stack),
93 l4_sched_param_t sp = l4_sched_param(1, 0);
94 tag = l4_scheduler_run_thread(l4re_env()->scheduler, alien, &sp);
99 l4_calibrate_tsc(l4re_kip());
102 /* Pager/Exception loop */
103 if (l4_msgtag_has_error(tag = l4_ipc_receive(alien, u, L4_IPC_NEVER)))
105 printf("l4_ipc_receive failed");
109 memcpy(&exc, l4_utcb_exc(), sizeof(exc));
110 mr0 = l4_utcb_mr()->mr[0];
111 mr1 = l4_utcb_mr()->mr[1];
119 if (l4_msgtag_is_exception(tag))
122 printf("PC=%08lx SP=%08lx Err=%08lx Trap=%lx, %s syscall, SC-Nr: %lx\n",
123 l4_utcb_exc_pc(&exc), exc.sp, exc.err,
124 exc.trapno, (exc.err & 4) ? " after" : "before",
127 tag = l4_msgtag((exc.err & 4) ? 0 : L4_PROTO_ALLOW_SYSCALL,
128 L4_UTCB_EXCEPTION_REGS_SIZE, 0, 0);
131 printf("Umm, non-handled request (like PF): %lx %lx\n", mr0, mr1);
133 memcpy(l4_utcb_exc(), &exc, sizeof(exc));
136 if (l4_msgtag_has_error(tag = l4_ipc_call(alien, u, tag, L4_IPC_NEVER)))
138 printf("l4_ipc_call failed\n");
141 memcpy(&exc, l4_utcb_exc(), sizeof(exc));
142 mr0 = l4_utcb_mr()->mr[0];
143 mr1 = l4_utcb_mr()->mr[1];
146 printf("time %lld\n", l4_tsc_to_ns(e - s));