[Zion] Add task switching for SSE registers and enable them in userspace.

This commit is contained in:
Drew Galbraith 2023-11-21 15:50:31 -08:00
parent 2a984a93ec
commit 96063126cb
7 changed files with 43 additions and 5 deletions

View file

@ -30,7 +30,8 @@ glcr::RefPtr<Thread> Thread::Create(Process& proc, uint64_t tid) {
return glcr::MakeRefCounted<Thread>(proc, tid);
}
Thread::Thread(Process& proc, uint64_t tid) : process_(proc), id_(tid) {
Thread::Thread(Process& proc, uint64_t tid)
: process_(proc), id_(tid), fx_data_(new uint8_t[520]) {
uint64_t* stack_ptr =
reinterpret_cast<uint64_t*>(proc.vmas()->AllocateKernelStack());
// 0: rip
@ -43,6 +44,11 @@ Thread::Thread(Process& proc, uint64_t tid) : process_(proc), id_(tid) {
*(stack_ptr - 16) = proc.vmas()->cr3();
rsp0_ = reinterpret_cast<uint64_t>(stack_ptr - 16);
rsp0_start_ = reinterpret_cast<uint64_t>(stack_ptr);
// Super hacky way to align to 16 bits.
if (reinterpret_cast<uint64_t>(fx_data_) & 0x8) {
fx_data_ += 8;
}
}
uint64_t Thread::pid() const { return process_.id(); }

View file

@ -43,6 +43,8 @@ class Thread : public KernelObject, public glcr::IntrusiveListNode<Thread> {
uint64_t* Rsp0Ptr() { return &rsp0_; }
uint64_t Rsp0Start() { return rsp0_start_; }
uint8_t* FxData() { return fx_data_; }
// Switches the thread's state to runnable and enqueues it.
void Start(uint64_t entry, uint64_t arg1, uint64_t arg2);
@ -86,5 +88,8 @@ class Thread : public KernelObject, public glcr::IntrusiveListNode<Thread> {
// I don't think me mind clobbering the stack here.
uint64_t rsp0_start_;
// Pointer to a 512 byte region for FXSAVE and FXRSTOR
uint8_t* fx_data_ = nullptr;
glcr::IntrusiveList<Thread> blocked_threads_;
};