]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libvcpu/lib/src/vcpu.cc
16d14200ce73843b8c9efe699d2f556bce6c4896
[l4.git] / l4 / pkg / libvcpu / lib / src / vcpu.cc
1 /*
2  * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  *
9  * As a special exception, you may use this file as part of a free software
10  * library without restriction.  Specifically, if other files instantiate
11  * templates or use macros or inline functions from this file, or you compile
12  * this file and link it with other files to produce an executable, this
13  * file does not by itself cause the resulting executable to be covered by
14  * the GNU General Public License.  This exception does not however
15  * invalidate any other reasons why the executable file might be covered by
16  * the GNU General Public License.
17  */
18
19 #include <l4/vcpu/vcpu>
20 #include <l4/re/util/kumem_alloc>
21 #include <cstdio>
22 #include <cstring>
23
24 L4_CV void
25 l4vcpu_print_state(l4_vcpu_state_t *vcpu,
26                    const char *prefix) L4_NOTHROW
27 {
28   printf("%svcpu=%p state=%lx savedstate=%lx label=%lx\n",
29          prefix, vcpu, vcpu->state, vcpu->saved_state, vcpu->i.label);
30   printf("%ssticky=%lx user_task=%lx\n",
31          prefix, vcpu->sticky_flags, vcpu->user_task << L4_CAP_SHIFT);
32   printf("%sentry_sp=%lx entry_ip=%lx\n",
33          prefix, vcpu->entry_sp, vcpu->entry_ip);
34   l4vcpu_print_state_arch(vcpu, prefix);
35 }
36
37 static int
38 do_l4vcpu_ext_alloc(L4vcpu::Vcpu **vcpu,
39                     l4_addr_t *ext_state,
40                     L4::Cap<L4::Task> task,
41                     L4::Cap<L4Re::Rm> rm) L4_NOTHROW
42 {
43   int r;
44   l4_addr_t v;
45
46   if ((r = L4Re::Util::kumem_alloc(&v, 0, task, rm)))
47     return r;
48
49   *vcpu      = L4vcpu::Vcpu::cast(v);
50   *ext_state = v + L4_VCPU_OFFSET_EXT_STATE;
51
52   return 0;
53 }
54
55 L4_CV int
56 l4vcpu_ext_alloc(l4_vcpu_state_t **vcpu, l4_addr_t *ext_state,
57                       l4_cap_idx_t task, l4_cap_idx_t regmgr) L4_NOTHROW
58 {
59   L4::Cap<L4::Task> t(task);
60   L4::Cap<L4Re::Rm> r(regmgr);
61   L4vcpu::Vcpu **v = reinterpret_cast<L4vcpu::Vcpu **>(vcpu);
62   return do_l4vcpu_ext_alloc(v, ext_state, t, r);
63 }
64
65 L4_CV int
66 L4vcpu::Vcpu::ext_alloc(Vcpu **vcpu,
67                         l4_addr_t *ext_state,
68                         L4::Cap<L4::Task> task,
69                         L4::Cap<L4Re::Rm> rm) throw()
70 {
71   return do_l4vcpu_ext_alloc(vcpu, ext_state, task, rm);
72 }