5 EXTENSION class Context
8 Ku_mem_ptr<Vcpu_state> _vcpu_state;
15 Context::Ku_mem_ptr<Vcpu_state> const &
16 Context::vcpu_state() const
17 { return _vcpu_state; }
22 Context::vcpu_disable_irqs()
24 if (EXPECT_FALSE(state() & Thread_vcpu_enabled))
26 Vcpu_state *vcpu = vcpu_state().access();
27 Mword s = vcpu->state;
28 vcpu->state = s & ~Vcpu_state::F_irqs;
29 return s & Vcpu_state::F_irqs;
36 Context::vcpu_save_state_and_upcall()
38 extern char leave_by_vcpu_upcall[];
39 _exc_cont.activate(regs(), leave_by_vcpu_upcall);
42 PUBLIC inline NEEDS["fpu.h"]
44 Context::vcpu_enter_kernel_mode(Vcpu_state *vcpu)
46 if (EXPECT_FALSE(state() & Thread_vcpu_enabled))
48 vcpu->_saved_state = vcpu->state;
49 Mword flags = Vcpu_state::F_traps
50 | Vcpu_state::F_user_mode;
51 vcpu->state &= ~flags;
53 if (vcpu->_saved_state & Vcpu_state::F_user_mode)
54 vcpu->_sp = vcpu->_entry_sp;
56 vcpu->_sp = regs()->sp();
58 if (_space.user_mode())
60 _space.user_mode(false);
61 state_del_dirty(Thread_vcpu_fpu_disabled);
63 if (current() == this)
65 if (state() & Thread_fpu_owner)
68 space()->switchin_context(vcpu_user_space());
78 Context::vcpu_irqs_enabled(Vcpu_state *vcpu) const
80 return EXPECT_FALSE(state() & Thread_vcpu_enabled)
81 && vcpu->state & Vcpu_state::F_irqs;
86 Context::vcpu_pagefaults_enabled(Vcpu_state *vcpu) const
88 return EXPECT_FALSE(state() & Thread_vcpu_enabled)
89 && vcpu->state & Vcpu_state::F_page_faults;
94 Context::vcpu_exceptions_enabled(Vcpu_state *vcpu) const
96 return EXPECT_FALSE(state() & Thread_vcpu_enabled)
97 && vcpu->state & Vcpu_state::F_exceptions;
102 Context::vcpu_set_irq_pending()
104 if (EXPECT_FALSE(state() & Thread_vcpu_enabled))
105 vcpu_state().access()->sticky_flags |= Vcpu_state::Sf_irq_pending;
108 /** Return the space context.
109 @return space context used for this execution context.
110 Set with set_space_context().
114 Context::vcpu_user_space() const
115 { return _space.vcpu_user(); }
118 // --------------------------------------------------------------------------
121 EXTENSION class Context
123 static unsigned vcpu_log_fmt(Tb_entry *, int, char *)
124 asm ("__context_vcpu_log_fmt");
128 // --------------------------------------------------------------------------
129 IMPLEMENTATION [debug]:
131 #include "kobject_dbg.h"
135 Context::vcpu_log_fmt(Tb_entry *e, int maxlen, char *buf)
137 Vcpu_log *l = e->payload<Vcpu_log>();
143 return snprintf(buf, maxlen, "%sret pc=%lx sp=%lx state=%lx task=D:%lx",
144 l->type == 4 ? "f" : "", l->ip, l->sp, l->state, l->space);
146 return snprintf(buf, maxlen, "ipc from D:%lx task=D:%lx sp=%lx",
147 Kobject_dbg::pointer_to_id((Kobject*)l->ip), l->state, l->sp);
149 return snprintf(buf, maxlen, "exc #%x err=%lx pc=%lx sp=%lx state=%lx task=D:%lx",
150 (unsigned)l->trap, l->err, l->ip, l->sp, l->state, l->space);
152 return snprintf(buf, maxlen, "pf pc=%lx pfa=%lx state=%lx task=D:%lx",
153 l->ip, l->sp, l->state, l->space);
155 return snprintf(buf, maxlen, "unknown");