L4Re - L4 Runtime Environment
vcpu
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  */
19 
20 #pragma once
21 
22 #include <l4/re/env>
23 #include <l4/vcpu/vcpu.h>
24 
25 namespace L4vcpu {
26 
31 class State
32 {
33 public:
34  State() {}
35 
41  explicit State(unsigned v) : _s(v) {}
42 
48  void add(unsigned bits) throw() { _s |= bits; }
49 
55  void clear(unsigned bits) throw() { _s &= ~bits; }
56 
62  void set(unsigned v) throw() { _s = v; }
63 
64 private:
65  __typeof__(((l4_vcpu_state_t *)0)->state) _s;
66 };
67 
72 class Vcpu : private l4_vcpu_state_t
73 {
74 public:
78  void irq_disable() throw()
79  { l4vcpu_irq_disable(this); }
80 
85  unsigned irq_disable_save() throw()
86  { return l4vcpu_irq_disable_save(this); }
87 
88  l4_vcpu_state_t *s() { return this; }
89  l4_vcpu_state_t const *s() const { return this; }
90 
95  State *state() throw()
96  {
97  static_assert(sizeof(State) == sizeof(l4_vcpu_state_t::state),
98  "size mismatch");
99  return reinterpret_cast<State *>(&(l4_vcpu_state_t::state));
100  }
101 
106  State state() const throw()
107  { return static_cast<State>(l4_vcpu_state_t::state); }
108 
113  State *saved_state() throw()
114  {
115  static_assert(sizeof(State) == sizeof(l4_vcpu_state_t::saved_state),
116  "size mismatch");
117  return reinterpret_cast<State *>(&(l4_vcpu_state_t::saved_state));
118  }
123  State saved_state() const throw()
124  { return static_cast<State>(l4_vcpu_state_t::saved_state); }
125 
129  l4_uint16_t sticky_flags() const throw()
131 
142  void irq_enable(l4_utcb_t *utcb, l4vcpu_event_hndl_t do_event_work_cb,
143  l4vcpu_setup_ipc_t setup_ipc) throw()
144  { l4vcpu_irq_enable(this, utcb, do_event_work_cb, setup_ipc); }
145 
157  void irq_restore(unsigned s, l4_utcb_t *utcb,
158  l4vcpu_event_hndl_t do_event_work_cb,
159  l4vcpu_setup_ipc_t setup_ipc) throw()
160  { l4vcpu_irq_restore(this, s, utcb, do_event_work_cb, setup_ipc); }
161 
173  void wait_for_event(l4_utcb_t *utcb, l4vcpu_event_hndl_t do_event_work_cb,
174  l4vcpu_setup_ipc_t setup_ipc) throw()
175  { l4vcpu_wait_for_event(this, utcb, do_event_work_cb, setup_ipc); }
176 
182  { user_task = task.cap(); }
183 
189  { return l4vcpu_is_page_fault_entry(this); }
190 
195  int is_irq_entry() const
196  { return l4vcpu_is_irq_entry(this); }
197 
202  l4_vcpu_regs_t *r() throw()
203  { return &(l4_vcpu_state_t::r); }
204 
209  l4_vcpu_regs_t const *r() const throw()
210  { return &(l4_vcpu_state_t::r); }
211 
217  { return &(l4_vcpu_state_t::i); }
218 
223  l4_vcpu_ipc_regs_t const *i() const throw()
224  { return &(l4_vcpu_state_t::i); }
225 
233  { l4_vcpu_state_t::entry_sp = sp; }
234 
240  { l4_vcpu_state_t::entry_ip = ip; }
241 
252  L4_CV static int
253  ext_alloc(Vcpu **vcpu,
254  l4_addr_t *ext_state,
255  L4::Cap<L4::Task> task = L4Re::Env::env()->task(),
256  L4::Cap<L4Re::Rm> rm = L4Re::Env::env()->rm()) throw();
257 
265  static inline Vcpu *cast(void *x) throw()
266  { return reinterpret_cast<Vcpu *>(x); }
267 
275  static inline Vcpu *cast(l4_addr_t x) throw()
276  { return reinterpret_cast<Vcpu *>(x); }
277 
281  void print_state(const char *prefix = "") const throw()
282  { l4vcpu_print_state(this, prefix); }
283 };
284 
285 
286 }
State of a vCPU.
Definition: vcpu.h:47
State saved_state() const
Get saved_state word.
Definition: vcpu:123
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition: l4int.h:38
l4_vcpu_ipc_regs_t i
IPC state.
Definition: vcpu.h:52
void l4vcpu_print_state(const l4_vcpu_state_t *vcpu, const char *prefix) L4_NOTHROW
Print the state of a vCPU.
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
Definition: vcpu:25
l4_uint16_t sticky_flags() const
Get sticky flags.
Definition: vcpu:129
l4_vcpu_regs_t const * r() const
Return pointer to register state.
Definition: vcpu:209
void l4vcpu_irq_disable(l4_vcpu_state_t *vcpu) L4_NOTHROW
Disable a vCPU for event delivery.
Definition: vcpu.h:208
int is_irq_entry() const
Return whether the entry reason was an IRQ/IPC message.
Definition: vcpu:195
State * saved_state()
Get saved_state word.
Definition: vcpu:113
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.
static Vcpu * cast(void *x)
Cast a void pointer to a class pointer.
Definition: vcpu:265
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:173
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:239
int is_page_fault_entry() const
Return whether the entry reason was a page fault.
Definition: vcpu:188
State(unsigned v)
Initialize state.
Definition: vcpu:41
unsigned irq_disable_save()
Disable the vCPU for event delivery and return previous state.
Definition: vcpu:85
static Env const * env()
Returns the initial environment for the current task.
Definition: env:103
void entry_ip(l4_umword_t ip)
Set vCPU entry instruction pointer.
Definition: vcpu:239
void task(L4::Cap< L4::Task > const task=L4::Cap< L4::Task >::Invalid)
Set the task of the vCPU.
Definition: vcpu:181
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
l4_umword_t entry_sp
Stack pointer for entry (when coming from user task)
Definition: vcpu.h:61
l4_uint16_t state
Current vCPU state.
Definition: vcpu.h:54
void print_state(const char *prefix="") const
Print the state of the vCPU.
Definition: vcpu:281
#define L4_CV
Define calling convention.
Definition: linkage.h:44
l4_vcpu_regs_t r
Register state.
Definition: vcpu.h:51
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:264
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:157
C++ implementation of the vCPU save state area.
Definition: vcpu:72
State * state()
Get state word.
Definition: vcpu:95
State state() const
Get state word.
Definition: vcpu:106
l4_vcpu_ipc_regs_t const * i() const
Return pointer to IPC state.
Definition: vcpu:223
l4_vcpu_ipc_regs_t * i()
Return pointer to IPC state.
Definition: vcpu:216
void irq_disable()
Disable the vCPU for event delivery.
Definition: vcpu:78
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:277
C++ implementation of state word in the vCPU area.
Definition: vcpu:31
static Vcpu * cast(l4_addr_t x)
Cast an address to a class pointer.
Definition: vcpu:275
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:142
void add(unsigned bits)
Add flags.
Definition: vcpu:48
l4_umword_t entry_ip
IP for entry.
Definition: vcpu.h:62
C++ interface for capabilities.
Definition: capability.h:13
vCPU message registers.
Definition: __vcpu-arch.h:63
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
l4_uint16_t saved_state
Saved vCPU state.
Definition: vcpu.h:55
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:216
int l4vcpu_is_page_fault_entry(l4_vcpu_state_t const *vcpu) L4_NOTHROW
Return whether the entry reason was a page fault.
void entry_sp(l4_umword_t sp)
Set vCPU entry stack pointer.
Definition: vcpu:232
vCPU registers.
Definition: __vcpu-arch.h:39
l4_uint16_t sticky_flags
Pending flags.
Definition: vcpu.h:56
void clear(unsigned bits)
Clear flags.
Definition: vcpu:55
l4_vcpu_regs_t * r()
Return pointer to register state.
Definition: vcpu:202