]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ux/context-ux.cpp
32df20038e13e186455136b600f18bbee3333088
[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 #include "utcb_init.h"
17
18 IMPLEMENT inline
19 void
20 Context::switch_fpu (Context *)
21 {}
22
23 PUBLIC inline
24 bool
25 Context::is_native()
26 { return _is_native; }
27
28 PROTECTED inline NEEDS["utcb_init.h"]
29 void
30 Context::arch_setup_utcb_ptr()
31 {
32   _gs = _fs = Utcb_init::utcb_segment();
33 }
34
35 PROTECTED inline
36 void
37 Context::switch_gdt_user_entries(Context *to)
38 {
39   Mword *trampoline_page = (Mword *) Kmem::phys_to_virt(Mem_layout::Trampoline_frame);
40   Space *tos = to->vcpu_aware_space();
41
42   if (EXPECT_FALSE(!tos))
43     return;
44
45   for (int i = 0; i < 3; i++)
46     if (to == this
47         || _gdt_user_entries[i].v[0] != to->_gdt_user_entries[i].v[0]
48         || _gdt_user_entries[i].v[1] != to->_gdt_user_entries[i].v[1])
49       {
50         memcpy(trampoline_page + 1, &to->_gdt_user_entries[i],
51                sizeof(_gdt_user_entries[0]));
52         Trampoline::syscall(tos->pid(), 243,
53                             Mem_layout::Trampoline_page + sizeof(Mword));
54       }
55
56   // update the global UTCB pointer to make the thread find its UTCB
57   // using fs:[0]
58   Mem_layout::user_utcb_ptr(current_cpu()) = to->utcb().usr();
59 }