]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ppc32/context-ppc32.cpp
update
[l4.git] / kernel / fiasco / src / kern / ppc32 / context-ppc32.cpp
1 IMPLEMENTATION [ppc32]:
2
3 /** Note: TCB pointer is located in sprg1 */
4
5 /*
6 #include <cassert>
7 #include <cstdio>
8
9 #include "l4_types.h"
10 #include "cpu_lock.h"
11 #include "lock_guard.h"
12 #include "space.h"
13 #include "thread_state.h"
14 */
15
16 #include "kmem.h"
17 #include "utcb_support.h"
18
19 IMPLEMENT inline
20 void
21 Context::spill_user_state()
22 {}
23
24 IMPLEMENT inline
25 void
26 Context::fill_user_state()
27 {}
28
29 IMPLEMENT inline
30 void
31 Context::switch_cpu(Context *t)
32 {
33   unsigned long dummy1, dummy2, dummy3;
34
35 //  printf("Switch %p -> %p (sp %p -> %p)\n", this, t, _kernel_sp, t->_kernel_sp);
36 #warning FIXIT: switchin_context_label needs a Context* parameter (old Context *)
37   asm volatile (" lis    %%r5, 1f@ha                \n"
38                 " addi   %%r5, %%r5, 1f@l           \n"
39
40                 //save return addr
41                 " stw    %%r5, 0(%%r1)              \n"
42                 " stw    %%r1, 0(%[kernel_sp])      \n"
43
44                 //switch stack
45                 " mr     %%r1, %[new_sp]            \n"
46                 " mr     %%r3, %[new_thread]        \n"
47
48                 //address space switch
49                 " bl     switchin_context_label     \n"
50                 " lwz    %%r5, 0(%%r1)              \n"
51                 " mtctr  %%r5                       \n"
52                 " bctr                              \n"
53                 "1:                                 \n"
54                 : [new_thread]"=r" (dummy1),
55                   [kernel_sp] "=r" (dummy2),
56                   [new_sp]    "=r" (dummy3)
57                 : "0" (t),
58                   "1" (&_kernel_sp),
59                   "2" (t->_kernel_sp)
60                 : "r0",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
61                   "r8",  "r9",  "r13", "r14", "r15", "r16", "r17", 
62                   "r18", "r19", "r20", "r21", "r22", "r23", "r24",
63                   "r25", "r26", "r27", "r28", "r29", "r30", "r31",
64                   "ctr", "lr",  "cr2", "cr3", "cr4", "xer", "memory"
65                   );
66 }
67
68 /** Thread context switchin.  Called on every re-activation of a
69     thread (switch_exec()).  This method is public only because it is 
70     called by an ``extern "C"'' function that is called
71     from assembly code (call_switchin_context).
72  */
73
74 IMPLEMENT
75 void Context::switchin_context(Context *from)
76 {
77   assert(this == current());
78   assert(state() & Thread_ready);
79   // Set kernel-esp in case we want to return to the user.
80   // kmem::kernel_esp() returns a pointer to the kernel SP (in the
81   // TSS) the CPU uses when next switching from user to kernel mode.  
82   // regs() + 1 returns a pointer to the end of our kernel stack.
83   Kmem::kernel_sp( reinterpret_cast<Mword*>(regs() + 1) );
84 #if 0
85   printf("switch in address space: %p\n",_space);
86 #endif
87
88   // switch to our page directory if nessecary
89   vcpu_aware_space()->switchin_context(from->vcpu_aware_space());
90
91   Utcb_support::current(utcb().usr());
92 }