[kernel] Initial XSAVE support implementation
Initial support for XSAVE, but not XSAVEOPT or XSAVEC: - Enable XSAVE and set up xcr0 for all CPUs - Allocate XSAVE area for all non-kernel threads - Call XSAVE and XRSTOR on task switch
This commit is contained in:
@@ -88,6 +88,9 @@ process::create_thread(uintptr_t rsp3, uint8_t priority)
|
||||
if (rsp3)
|
||||
th->tcb()->rsp3 = rsp3;
|
||||
|
||||
if (this != &g_kernel_process)
|
||||
th->init_xsave_area();
|
||||
|
||||
m_threads.append(th);
|
||||
scheduler::get().add_thread(th->tcb());
|
||||
return th;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "objects/process.h"
|
||||
#include "objects/vm_area.h"
|
||||
#include "scheduler.h"
|
||||
#include "xsave.h"
|
||||
|
||||
extern "C" void initialize_user_cpu();
|
||||
extern obj::vm_area_guarded &g_kernel_stacks;
|
||||
@@ -37,6 +38,9 @@ thread::thread(process &parent, uint8_t pri, uintptr_t rsp0) :
|
||||
|
||||
thread::~thread()
|
||||
{
|
||||
if (m_tcb.xsave)
|
||||
delete [] reinterpret_cast<uint8_t*>(m_tcb.xsave);
|
||||
|
||||
g_kernel_stacks.return_section(m_tcb.kernel_stack);
|
||||
m_parent.handle_release();
|
||||
}
|
||||
@@ -158,6 +162,14 @@ thread::add_thunk_user(uintptr_t rip3, uint64_t arg0, uint64_t arg1, uintptr_t r
|
||||
add_thunk_kernel(rip0 ? rip0 : trampoline);
|
||||
}
|
||||
|
||||
void
|
||||
thread::init_xsave_area()
|
||||
{
|
||||
void *xsave_area = new uint8_t [xsave_size];
|
||||
memset(xsave_area, 0, xsave_size);
|
||||
m_tcb.xsave = reinterpret_cast<uintptr_t>(xsave_area);
|
||||
}
|
||||
|
||||
void
|
||||
thread::setup_kernel_stack()
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ struct TCB
|
||||
uintptr_t rsp3;
|
||||
uintptr_t rflags3;
|
||||
uintptr_t pml4;
|
||||
uintptr_t xsave;
|
||||
// End of area used by asembly
|
||||
|
||||
obj::thread* thread;
|
||||
@@ -182,6 +183,9 @@ private:
|
||||
/// \arg rsp0 The existing kernel stack rsp, 0 for none
|
||||
thread(process &parent, uint8_t pri, uintptr_t rsp0 = 0);
|
||||
|
||||
/// Set up the XSAVE saved processor state area for this thread
|
||||
void init_xsave_area();
|
||||
|
||||
/// Set up a new empty kernel stack for this thread.
|
||||
void setup_kernel_stack();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user