2 * (c) 2008-2009 Technische Universität Dresden
3 * This file is part of TUD:OS and distributed under the terms of the
4 * GNU General Public License 2.
5 * Please see the COPYING-GPL-2 file for details.
8 * Example to show syscall tracing.
12 #include <l4/sys/ipc.h>
13 #include <l4/sys/thread.h>
14 #include <l4/sys/factory.h>
15 #include <l4/sys/utcb.h>
16 #include <l4/sys/kdebug.h>
17 #include <l4/util/util.h>
18 #include <l4/util/rdtsc.h>
19 #include <l4/re/env.h>
20 #include <l4/re/c/util/cap_alloc.h>
21 #include <l4/sys/debugger.h>
28 static char alien_thread_stack[8 << 10];
29 static l4_cap_idx_t alien;
31 static void alien_thread(void)
33 volatile l4_msgtag_t x;
35 x = l4_ipc_call(0x1234 << L4_CAP_SHIFT, l4_utcb(), l4_msgtag(0, 0, 0, 0), L4_IPC_NEVER);
40 outstring("An int3 -- you should see this\n");
53 l4_utcb_t *u = l4_utcb();
57 printf("Alien feature testing\n");
59 l4_debugger_set_object_name(l4re_env()->main_thread, "alientest");
61 /* Start alien thread */
62 if (l4_is_invalid_cap(alien = l4re_util_cap_alloc()))
65 l4_touch_rw(alien_thread_stack, sizeof(alien_thread_stack));
67 tag = l4_factory_create_thread(l4re_env()->factory, alien);
68 if (l4_msgtag_has_error(tag))
71 l4_debugger_set_object_name(alien, "alienth");
73 l4_thread_control_start();
74 l4_thread_control_pager(l4re_env()->main_thread);
75 l4_thread_control_exc_handler(l4re_env()->main_thread);
76 l4_thread_control_bind((l4_utcb_t *)l4re_env()->first_free_utcb, L4RE_THIS_TASK_CAP);
77 l4_thread_control_alien(1);
78 tag = l4_thread_control_commit(alien);
79 if (l4_msgtag_has_error(tag))
82 tag = l4_thread_ex_regs(alien,
83 (l4_umword_t)alien_thread,
84 (l4_umword_t)alien_thread_stack + sizeof(alien_thread_stack),
86 if (l4_msgtag_has_error(tag))
90 l4_calibrate_tsc(l4re_kip());
93 /* Pager/Exception loop */
94 if (l4_msgtag_has_error(tag = l4_ipc_receive(alien, u, L4_IPC_NEVER)))
96 printf("l4_ipc_receive failed");
100 memcpy(&exc, l4_utcb_exc(), sizeof(exc));
101 mr0 = l4_utcb_mr()->mr[0];
102 mr1 = l4_utcb_mr()->mr[1];
110 if (l4_msgtag_is_exception(tag))
113 printf("PC=%08lx SP=%08lx Err=%08lx Trap=%lx, %s syscall, SC-Nr: %lx\n",
114 l4_utcb_exc_pc(&exc), exc.sp, exc.err,
115 exc.trapno, (exc.err & 4) ? " after" : "before",
118 tag = l4_msgtag((exc.err & 4) ? 0 : L4_PROTO_ALLOW_SYSCALL,
119 L4_UTCB_EXCEPTION_REGS_SIZE, 0, 0);
122 printf("Umm, non-handled request (like PF): %lx %lx\n", mr0, mr1);
124 memcpy(l4_utcb_exc(), &exc, sizeof(exc));
127 if (l4_msgtag_has_error(tag = l4_ipc_call(alien, u, tag, L4_IPC_NEVER)))
129 printf("l4_ipc_call failed\n");
132 memcpy(&exc, l4_utcb_exc(), sizeof(exc));
133 mr0 = l4_utcb_mr()->mr[0];
134 mr1 = l4_utcb_mr()->mr[1];
137 printf("time %lld\n", l4_tsc_to_ns(e - s));