5 EXTENSION class Context
8 Space *_vcpu_user_space;
11 Vcpu_state *_vcpu_state;
19 Context::vcpu_state() const
20 { return _vcpu_state; }
24 Context::vcpu_state(void *s)
25 { _vcpu_state = (Vcpu_state*)s; }
30 Context::vcpu_disable_irqs()
32 if (EXPECT_FALSE(state() & Thread_vcpu_enabled))
34 Vcpu_state *vcpu = access_vcpu();
35 Mword s = vcpu->state;
36 vcpu->state = s & ~Vcpu_state::F_irqs;
37 return s & Vcpu_state::F_irqs;
44 Context::vcpu_save_state_and_upcall()
46 extern char leave_by_vcpu_upcall[];
47 _exc_cont.activate(regs(), leave_by_vcpu_upcall);
50 PUBLIC inline NEEDS["fpu.h"]
52 Context::vcpu_enter_kernel_mode(Vcpu_state *vcpu)
54 if (EXPECT_FALSE(state() & Thread_vcpu_enabled))
56 vcpu->_saved_state = vcpu->state;
57 Mword flags = Vcpu_state::F_traps
58 | Vcpu_state::F_user_mode;
59 vcpu->state &= ~flags;
60 if (state() & Thread_vcpu_user_mode)
62 vcpu->_sp = vcpu->_entry_sp;
63 state_del_dirty(Thread_vcpu_user_mode | Thread_vcpu_fpu_disabled);
65 if (current() == this)
67 if (state() & Thread_fpu_owner)
70 space()->switchin_context(vcpu_user_space());
74 vcpu->_sp = regs()->sp();
82 Context::vcpu_irqs_enabled(Vcpu_state *vcpu) const
84 return EXPECT_FALSE(state() & Thread_vcpu_enabled)
85 && vcpu->state & Vcpu_state::F_irqs;
90 Context::vcpu_pagefaults_enabled(Vcpu_state *vcpu) const
92 return EXPECT_FALSE(state() & Thread_vcpu_enabled)
93 && vcpu->state & Vcpu_state::F_page_faults;
98 Context::vcpu_exceptions_enabled(Vcpu_state *vcpu) const
100 return EXPECT_FALSE(state() & Thread_vcpu_enabled)
101 && vcpu->state & Vcpu_state::F_exceptions;
106 Context::vcpu_set_irq_pending()
108 if (EXPECT_FALSE(state() & Thread_vcpu_enabled))
109 access_vcpu()->sticky_flags |= Vcpu_state::Sf_irq_pending;
112 /** Return the space context.
113 @return space context used for this execution context.
114 Set with set_space_context().
116 PUBLIC inline NEEDS["kdb_ke.h", "cpu_lock.h"]
118 Context::vcpu_user_space() const
120 //assert_kdb (cpu_lock.test());
121 return _vcpu_user_space;
124 PUBLIC inline NEEDS["space.h"]
126 Context::vcpu_set_user_space(Space *t)
128 assert_kdb (current() == this);
132 state_del_dirty(Thread_vcpu_user_mode);
134 Space *old = _vcpu_user_space;
135 _vcpu_user_space = t;
148 // --------------------------------------------------------------------------
151 EXTENSION class Context
153 static unsigned vcpu_log_fmt(Tb_entry *, int, char *)
154 asm ("__context_vcpu_log_fmt");
158 // --------------------------------------------------------------------------
159 IMPLEMENTATION [debug]:
161 #include "kobject_dbg.h"
165 Context::vcpu_log_fmt(Tb_entry *e, int maxlen, char *buf)
167 Vcpu_log *l = e->payload<Vcpu_log>();
173 return snprintf(buf, maxlen, "%sret pc=%lx sp=%lx state=%lx task=D:%lx",
174 l->type == 4 ? "f" : "", l->ip, l->sp, l->state, l->space);
176 return snprintf(buf, maxlen, "ipc from D:%lx task=D:%lx sp=%lx",
177 Kobject_dbg::pointer_to_id((Kobject*)l->ip), l->state, l->sp);
179 return snprintf(buf, maxlen, "exc #%x err=%lx pc=%lx sp=%lx state=%lx task=D:%lx",
180 (unsigned)l->trap, l->err, l->ip, l->sp, l->state, l->space);
182 return snprintf(buf, maxlen, "pf pc=%lx pfa=%lx state=%lx task=D:%lx",
183 l->ip, l->sp, l->state, l->space);
185 return snprintf(buf, maxlen, "unknown");