]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ux/context-ux.cpp
update
[l4.git] / kernel / fiasco / src / kern / ux / context-ux.cpp
1 INTERFACE[ux]:
2
3 EXTENSION class Context
4 {
5 protected:
6   enum { Gdt_user_entries = 3 };
7   struct { Unsigned64 v[2]; } _gdt_user_entries[Gdt_user_entries]; // type struct Ldt_user_desc
8
9   bool _is_native; // thread can call Linux host system calls
10   Unsigned32                  _es, _fs, _gs;
11 };
12
13 // ---------------------------------------------------------------------
14 IMPLEMENTATION[ux]:
15
16 IMPLEMENT inline
17 void
18 Context::switch_fpu (Context *)
19 {}
20
21 PUBLIC inline
22 bool
23 Context::is_native()
24 { return _is_native; }
25
26 PROTECTED inline
27 void
28 Context::switch_gdt_user_entries(Context *to)
29 {
30   Mword *trampoline_page = (Mword *) Kmem::phys_to_virt(Mem_layout::Trampoline_frame);
31   Space *tos = to->vcpu_aware_space();
32
33   if (EXPECT_FALSE(!tos))
34     return;
35
36   for (int i = 0; i < 3; i++)
37     if (to == this
38         || _gdt_user_entries[i].v[0] != to->_gdt_user_entries[i].v[0]
39         || _gdt_user_entries[i].v[1] != to->_gdt_user_entries[i].v[1])
40       {
41         memcpy(trampoline_page + 1, &to->_gdt_user_entries[i],
42                sizeof(_gdt_user_entries[0]));
43         Trampoline::syscall(tos->pid(), 243,
44                             Mem_layout::Trampoline_page + sizeof(Mword));
45       }
46 }