1 IMPLEMENTATION [ppc32]:
3 /** Note: TCB pointer is located in sprg1 */
11 #include "lock_guard.h"
13 #include "thread_state.h"
17 #include "utcb_support.h"
21 Context::spill_user_state()
26 Context::fill_user_state()
31 Context::access_utcb() const
36 Context::access_vcpu(bool = false) const
37 { return vcpu_state(); }
41 Context::switch_cpu(Context *t)
43 unsigned long dummy1, dummy2, dummy3;
45 // printf("Switch %p -> %p (sp %p -> %p)\n", this, t, _kernel_sp, t->_kernel_sp);
46 #warning FIXIT: switchin_context_label needs a Context* parameter (old Context *)
47 asm volatile (" lis %%r5, 1f@ha \n"
48 " addi %%r5, %%r5, 1f@l \n"
51 " stw %%r5, 0(%%r1) \n"
52 " stw %%r1, 0(%[kernel_sp]) \n"
55 " mr %%r1, %[new_sp] \n"
56 " mr %%r3, %[new_thread] \n"
58 //address space switch
59 " bl switchin_context_label \n"
60 " lwz %%r5, 0(%%r1) \n"
64 : [new_thread]"=r" (dummy1),
65 [kernel_sp] "=r" (dummy2),
66 [new_sp] "=r" (dummy3)
70 : "r0", "r2", "r3", "r4", "r5", "r6", "r7",
71 "r8", "r9", "r13", "r14", "r15", "r16", "r17",
72 "r18", "r19", "r20", "r21", "r22", "r23", "r24",
73 "r25", "r26", "r27", "r28", "r29", "r30", "r31",
74 "ctr", "lr", "cr2", "cr3", "cr4", "xer", "memory"
78 /** Thread context switchin. Called on every re-activation of a
79 thread (switch_exec()). This method is public only because it is
80 called by an ``extern "C"'' function that is called
81 from assembly code (call_switchin_context).
85 void Context::switchin_context(Context *from)
87 assert(this == current());
88 assert(state() & Thread_ready);
89 // Set kernel-esp in case we want to return to the user.
90 // kmem::kernel_esp() returns a pointer to the kernel SP (in the
91 // TSS) the CPU uses when next switching from user to kernel mode.
92 // regs() + 1 returns a pointer to the end of our kernel stack.
93 Kmem::kernel_sp( reinterpret_cast<Mword*>(regs() + 1) );
95 printf("switch in address space: %p\n",_space);
98 // switch to our page directory if nessecary
99 vcpu_aware_space()->switchin_context(from->vcpu_aware_space());
101 Utcb_support::current((Utcb*)local_id());