]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libvcpu/lib/src/vcpu.cc
update
[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=%x savedstate=%x label=%lx\n",
29          prefix, vcpu, vcpu->state, vcpu->saved_state, vcpu->i.label);
30   printf("%ssticky=%x user_task=%lx  pfa=%lx\n",
31          prefix, vcpu->sticky_flags, vcpu->user_task << L4_CAP_SHIFT,
32          vcpu->r.pfa);
33   printf("%sentry_sp=%lx entry_ip=%lx\n",
34          prefix, vcpu->entry_sp, vcpu->entry_ip);
35   l4vcpu_print_state_arch(vcpu, prefix);
36 }
37
38 static int
39 do_l4vcpu_ext_alloc(L4vcpu::Vcpu **vcpu,
40                     l4_addr_t *ext_state,
41                     L4::Cap<L4::Task> task,
42                     L4::Cap<L4Re::Rm> rm) L4_NOTHROW
43 {
44   int r;
45   l4_addr_t v;
46
47   if ((r = L4Re::Util::kumem_alloc(&v, 0, task, rm)))
48     return r;
49
50   *vcpu      = L4vcpu::Vcpu::cast(v);
51   *ext_state = v + L4_VCPU_OFFSET_EXT_STATE;
52
53   return 0;
54 }
55
56 L4_CV int
57 l4vcpu_ext_alloc(l4_vcpu_state_t **vcpu, l4_addr_t *ext_state,
58                  l4_cap_idx_t task, l4_cap_idx_t regmgr) L4_NOTHROW
59 {
60   L4::Cap<L4::Task> t(task);
61   L4::Cap<L4Re::Rm> r(regmgr);
62   L4vcpu::Vcpu **v = reinterpret_cast<L4vcpu::Vcpu **>(vcpu);
63   return do_l4vcpu_ext_alloc(v, ext_state, t, r);
64 }
65
66 L4_CV int
67 L4vcpu::Vcpu::ext_alloc(Vcpu **vcpu,
68                         l4_addr_t *ext_state,
69                         L4::Cap<L4::Task> task,
70                         L4::Cap<L4Re::Rm> rm) throw()
71 {
72   return do_l4vcpu_ext_alloc(vcpu, ext_state, task, rm);
73 }