[Zion] Add task switching for SSE registers and enable them in userspace.
This commit is contained in:
parent
2a984a93ec
commit
96063126cb
7 changed files with 43 additions and 5 deletions
|
|
@ -1,5 +1,10 @@
|
|||
.global context_switch
|
||||
context_switch:
|
||||
# %rdi -> Prev Task RSP address
|
||||
# %rsi -> New Task RSP Address
|
||||
# %rdx -> Prev Task FXSAVE Address
|
||||
# %rcx -> New Task FXRSTOR Address
|
||||
|
||||
push %rax
|
||||
push %rcx
|
||||
push %rdx
|
||||
|
|
@ -18,9 +23,25 @@ context_switch:
|
|||
mov %cr3, %rax
|
||||
push %rax
|
||||
|
||||
// For the sleep thread rdx will
|
||||
// be a nullptr.
|
||||
test %rdx, %rdx
|
||||
jz switch
|
||||
|
||||
fxsave (%rdx)
|
||||
|
||||
switch:
|
||||
mov %rsp, (%rdi) # Save rsp to the prev task.
|
||||
mov (%rsi), %rsp # Load the next task's rsp.
|
||||
|
||||
// For the sleep thread rcx will
|
||||
// be a nullptr.
|
||||
test %rcx, %rcx
|
||||
jz restore
|
||||
|
||||
fxrstor (%rcx)
|
||||
|
||||
restore:
|
||||
pop %rax
|
||||
mov %rax, %cr3
|
||||
pop %r15
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
namespace {
|
||||
|
||||
extern "C" void context_switch(uint64_t* current_esp, uint64_t* next_esp);
|
||||
extern "C" void context_switch(uint64_t* current_esp, uint64_t* next_esp,
|
||||
uint8_t* current_fx_data, uint8_t* next_fx_data);
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
@ -26,7 +27,8 @@ void Scheduler::SwapToCurrent(Thread& prev) {
|
|||
current_thread_->SetState(Thread::RUNNING);
|
||||
|
||||
SetRsp0(current_thread_->Rsp0Start());
|
||||
context_switch(prev.Rsp0Ptr(), current_thread_->Rsp0Ptr());
|
||||
context_switch(prev.Rsp0Ptr(), current_thread_->Rsp0Ptr(), prev.FxData(),
|
||||
current_thread_->FxData());
|
||||
|
||||
asm volatile("sti");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue