]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/context-ia32.cpp
update
[l4.git] / kernel / fiasco / src / kern / ia32 / context-ia32.cpp
1 IMPLEMENTATION [ia32,amd64,ux]:
2
3 #include <cassert>
4 #include <cstdio>
5
6 #include "cpu.h"
7 #include "globals.h"            // current()
8 #include "kmem.h"
9 #include "lock_guard.h"
10 #include "space.h"
11 #include "thread_state.h"
12
13
14 IMPLEMENT inline
15 void
16 Context::spill_user_state()
17 {}
18
19 IMPLEMENT inline
20 void
21 Context::fill_user_state()
22 {}
23
24 PUBLIC inline
25 Utcb *
26 Context::access_utcb() const
27 { return utcb(); }
28
29 PUBLIC inline
30 Vcpu_state *
31 Context::access_vcpu(bool = false) const
32 { return vcpu_state(); }
33
34 /** Thread context switchin.  Called on every re-activation of a thread
35     (switch_exec()).  This method is public only because it is called from
36     from assembly code in switch_cpu().
37  */
38 IMPLEMENT
39 void
40 Context::switchin_context(Context *from)
41 {
42   assert_kdb (this == current());
43   assert_kdb (state() & Thread_ready_mask);
44
45   // Set kernel-esp in case we want to return to the user.
46   // kmem::kernel_sp() returns a pointer to the kernel SP (in the
47   // TSS) the CPU uses when next switching from user to kernel mode.
48   // regs() + 1 returns a pointer to the end of our kernel stack.
49   Cpu::cpus.cpu(cpu()).kernel_sp() = reinterpret_cast<Address>(regs() + 1);
50
51   // switch to our page directory if necessary
52   vcpu_aware_space()->switchin_context(from->vcpu_aware_space());
53
54   // load new segment selectors
55   load_segments();
56
57   // update the global UTCB pointer to make the thread find its UTCB
58   // using gs:[0]
59   Mem_layout::user_utcb_ptr(current_cpu()) = local_id();
60 }
61
62 //---------------------------------------------------------------------------
63 IMPLEMENTATION [ia32 || ux]:
64
65 PROTECTED inline NEEDS["cpu.h"]
66 void
67 Context::load_segments()
68 {
69   Cpu::set_es((Unsigned32)_es);
70   Cpu::set_fs((Unsigned32)_fs);
71   Cpu::set_gs((Unsigned32)_gs);
72 }
73
74 PROTECTED inline NEEDS["cpu.h"]
75 void
76 Context::store_segments()
77 {
78   _es = Cpu::get_es();
79   _fs = Cpu::get_fs();
80   _gs = Cpu::get_gs();
81 }
82
83
84 //---------------------------------------------------------------------------
85 IMPLEMENTATION [amd64]:
86
87 PROTECTED inline
88 void
89 Context::load_segments()
90 {}
91
92 PROTECTED inline
93 void
94 Context::store_segments()
95 {}
96
97 PROTECTED inline
98 void
99 Context::switch_gdt_user_entries(Context *)
100 {}