L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
vcpu
Go to the documentation of this file.
1// vi:se ft=cpp:
2/*
3 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
5 *
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
9 *
10 * As a special exception, you may use this file as part of a free software
11 * library without restriction. Specifically, if other files instantiate
12 * templates or use macros or inline functions from this file, or you compile
13 * this file and link it with other files to produce an executable, this
14 * file does not by itself cause the resulting executable to be covered by
15 * the GNU General Public License. This exception does not however
16 * invalidate any other reasons why the executable file might be covered by
17 * the GNU General Public License.
18 */
24#pragma once
25
26#include <l4/re/env>
27#include <l4/vcpu/vcpu.h>
28
29namespace L4vcpu {
30
35class State
36{
37public:
38 State() {}
39
45 explicit State(unsigned v) : _s(v) {}
46
52 void add(unsigned bits) throw() { _s |= bits; }
53
59 void clear(unsigned bits) throw() { _s &= ~bits; }
60
66 void set(unsigned v) throw() { _s = v; }
67
68private:
69 __typeof__(((l4_vcpu_state_t *)0)->state) _s;
70};
71
76class Vcpu : private l4_vcpu_state_t
77{
78public:
82 void irq_disable() throw()
83 { l4vcpu_irq_disable(this); }
84
89 unsigned irq_disable_save() throw()
90 { return l4vcpu_irq_disable_save(this); }
91
92 l4_vcpu_state_t *s() { return this; }
93 l4_vcpu_state_t const *s() const { return this; }
94
99 State *state() throw()
100 {
101 static_assert(sizeof(State) == sizeof(l4_vcpu_state_t::state),
102 "size mismatch");
103 return reinterpret_cast<State *>(&(l4_vcpu_state_t::state));
104 }
105
110 State state() const throw()
111 { return static_cast<State>(l4_vcpu_state_t::state); }
112
118 {
119 static_assert(sizeof(State) == sizeof(l4_vcpu_state_t::saved_state),
120 "size mismatch");
121 return reinterpret_cast<State *>(&(l4_vcpu_state_t::saved_state));
122 }
127 State saved_state() const throw()
128 { return static_cast<State>(l4_vcpu_state_t::saved_state); }
129
135
146 void irq_enable(l4_utcb_t *utcb, l4vcpu_event_hndl_t do_event_work_cb,
147 l4vcpu_setup_ipc_t setup_ipc) throw()
148 { l4vcpu_irq_enable(this, utcb, do_event_work_cb, setup_ipc); }
149
161 void irq_restore(unsigned s, l4_utcb_t *utcb,
162 l4vcpu_event_hndl_t do_event_work_cb,
163 l4vcpu_setup_ipc_t setup_ipc) throw()
164 { l4vcpu_irq_restore(this, s, utcb, do_event_work_cb, setup_ipc); }
165
177 void wait_for_event(l4_utcb_t *utcb, l4vcpu_event_hndl_t do_event_work_cb,
178 l4vcpu_setup_ipc_t setup_ipc) throw()
179 { l4vcpu_wait_for_event(this, utcb, do_event_work_cb, setup_ipc); }
180
186 { user_task = task.cap(); }
187
193 { return l4vcpu_is_page_fault_entry(this); }
194
199 int is_irq_entry() const
200 { return l4vcpu_is_irq_entry(this); }
201
206 l4_vcpu_regs_t *r() throw()
207 { return &(l4_vcpu_state_t::r); }
208
213 l4_vcpu_regs_t const *r() const throw()
214 { return &(l4_vcpu_state_t::r); }
215
221 { return &(l4_vcpu_state_t::i); }
222
227 l4_vcpu_ipc_regs_t const *i() const throw()
228 { return &(l4_vcpu_state_t::i); }
229
238
245
257 L4_CV static int
259 l4_addr_t *ext_state,
261 L4::Cap<L4Re::Rm> rm = L4Re::Env::env()->rm()) throw();
262
270 static inline Vcpu *cast(void *x) throw()
271 { return reinterpret_cast<Vcpu *>(x); }
272
280 static inline Vcpu *cast(l4_addr_t x) throw()
281 { return reinterpret_cast<Vcpu *>(x); }
282
286 void print_state(const char *prefix = "") const throw()
287 { l4vcpu_print_state(this, prefix); }
288};
289
290
291}
static Env const * env() noexcept
Returns the initial environment for the current task.
Definition env:103
C++ interface for capabilities.
Definition capability.h:222
C++ implementation of state word in the vCPU area.
Definition vcpu:36
void set(unsigned v)
Set flags.
Definition vcpu:66
void add(unsigned bits)
Add flags.
Definition vcpu:52
State(unsigned v)
Initialize state.
Definition vcpu:45
void clear(unsigned bits)
Clear flags.
Definition vcpu:59
C++ implementation of the vCPU save state area.
Definition vcpu:77
unsigned irq_disable_save()
Disable the vCPU for event delivery and return previous state.
Definition vcpu:89
l4_vcpu_ipc_regs_t const * i() const
Return pointer to IPC state.
Definition vcpu:227
State * state()
Get state word.
Definition vcpu:99
static Vcpu * cast(void *x)
Cast a void pointer to a class pointer.
Definition vcpu:270
int is_irq_entry() const
Return whether the entry reason was an IRQ/IPC message.
Definition vcpu:199
static int ext_alloc(Vcpu **vcpu, l4_addr_t *ext_state, L4::Cap< L4::Task > task=L4Re::Env::env() ->task(), L4::Cap< L4Re::Rm > rm=L4Re::Env::env() ->rm())
Allocate state area for an extended vCPU.
void irq_disable()
Disable the vCPU for event delivery.
Definition vcpu:82
State state() const
Get state word.
Definition vcpu:110
l4_vcpu_ipc_regs_t * i()
Return pointer to IPC state.
Definition vcpu:220
static Vcpu * cast(l4_addr_t x)
Cast an address to a class pointer.
Definition vcpu:280
l4_vcpu_regs_t const * r() const
Return pointer to register state.
Definition vcpu:213
l4_vcpu_regs_t * r()
Return pointer to register state.
Definition vcpu:206
void entry_ip(l4_umword_t ip)
Set vCPU entry instruction pointer.
Definition vcpu:243
void irq_enable(l4_utcb_t *utcb, l4vcpu_event_hndl_t do_event_work_cb, l4vcpu_setup_ipc_t setup_ipc)
Enable the vCPU for event delivery.
Definition vcpu:146
void wait_for_event(l4_utcb_t *utcb, l4vcpu_event_hndl_t do_event_work_cb, l4vcpu_setup_ipc_t setup_ipc)
Wait for event.
Definition vcpu:177
void entry_sp(l4_umword_t sp)
Set vCPU entry stack pointer.
Definition vcpu:236
void print_state(const char *prefix="") const
Print the state of the vCPU.
Definition vcpu:286
void task(L4::Cap< L4::Task > const task=L4::Cap< L4::Task >::Invalid)
Set the task of the vCPU.
Definition vcpu:185
l4_uint16_t sticky_flags() const
Get sticky flags.
Definition vcpu:133
void irq_restore(unsigned s, l4_utcb_t *utcb, l4vcpu_event_hndl_t do_event_work_cb, l4vcpu_setup_ipc_t setup_ipc)
Restore a previously saved IRQ/event state.
Definition vcpu:161
State * saved_state()
Get saved_state word.
Definition vcpu:117
int is_page_fault_entry() const
Return whether the entry reason was a page fault.
Definition vcpu:192
State saved_state() const
Get saved_state word.
Definition vcpu:127
Environment interface.
int l4vcpu_is_irq_entry(l4_vcpu_state_t const *vcpu) L4_NOTHROW
Return whether the entry reason was an IRQ/IPC message.
void l4vcpu_irq_enable(l4_vcpu_state_t *vcpu, l4_utcb_t *utcb, l4vcpu_event_hndl_t do_event_work_cb, l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW
Enable a vCPU for event delivery.
Definition vcpu.h:243
void l4vcpu_irq_restore(l4_vcpu_state_t *vcpu, unsigned s, l4_utcb_t *utcb, l4vcpu_event_hndl_t do_event_work_cb, l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW
Restore a previously saved IRQ/event state.
Definition vcpu.h:268
unsigned l4vcpu_irq_disable_save(l4_vcpu_state_t *vcpu) L4_NOTHROW
Disable a vCPU for event delivery and return previous state.
Definition vcpu.h:220
int l4vcpu_is_page_fault_entry(l4_vcpu_state_t const *vcpu) L4_NOTHROW
Return whether the entry reason was a page fault.
void l4vcpu_irq_disable(l4_vcpu_state_t *vcpu) L4_NOTHROW
Disable a vCPU for event delivery.
Definition vcpu.h:212
void l4vcpu_print_state(const l4_vcpu_state_t *vcpu, const char *prefix) L4_NOTHROW
Print the state of a vCPU.
void l4vcpu_wait_for_event(l4_vcpu_state_t *vcpu, l4_utcb_t *utcb, l4vcpu_event_hndl_t do_event_work_cb, l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW
Wait for event.
Definition vcpu.h:281
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
unsigned long l4_addr_t
Address type.
Definition l4int.h:45
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:38
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:67
#define L4_CV
Define calling convention.
Definition linkage.h:44
vCPU message registers.
Definition __vcpu-arch.h:72
vCPU registers.
Definition __vcpu-arch.h:44
State of a vCPU.
Definition vcpu.h:87
l4_umword_t entry_sp
Stack pointer for entry (when coming from user task)
Definition vcpu.h:102
l4_uint16_t sticky_flags
Pending flags. See L4_vcpu_sticky_flags.
Definition vcpu.h:97
l4_uint16_t state
Current vCPU state. See L4_vcpu_state_flags.
Definition vcpu.h:95
l4_vcpu_regs_t r
Register state.
Definition vcpu.h:92
l4_umword_t entry_ip
IP for entry.
Definition vcpu.h:103
l4_cap_idx_t user_task
User task to use.
Definition vcpu.h:100
l4_vcpu_ipc_regs_t i
IPC state.
Definition vcpu.h:93
l4_uint16_t saved_state
Saved vCPU state. See L4_vcpu_state_flags.
Definition vcpu.h:96
vCPU support library (C interface).