[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:
Justin C. Miller
2023-05-05 12:04:37 -06:00
parent 3b3857548c
commit b5662bfd25
12 changed files with 135 additions and 9 deletions

View File

@@ -5,6 +5,7 @@
#include <j6/errors.h>
#include <j6/flags.h>
#include <j6/syscalls.h>
#include <j6/syslog.hh>
#include <j6/thread.hh>
#include <j6/types.h>
@@ -17,11 +18,42 @@ extern j6_handle_t __handle_self;
constexpr uintptr_t stack_top = 0xf80000000;
uint32_t flipflop = 0;
bool
test_floats()
{
static constexpr int len = 30;
double as[len];
double bs[len];
double orig = 345.72;
double mult = 3.21;
for (int i = 0; i < len * 100; ++i) {
int idx = i % len;
as[idx] = orig * idx;
}
for (int i = 0; i < len * 100; ++i) {
int idx = i % len;
bs[idx] = as[idx] * mult;
}
for (int i = 0; i < len; ++i) {
if (bs[i] != orig * i * mult) {
j6::syslog("ERROR: floating point discrepency");
return false;
}
}
return true;
}
void
thread_proc(void* channelp)
{
j6_log("sub thread starting");
for (int i = 0; i < 100; ++i)
if (!test_floats()) break;
j6::channel *chan = reinterpret_cast<j6::channel*>(channelp);
char buffer[512];
@@ -86,6 +118,9 @@ main(int argc, const char **argv)
j6_log("main thread created sub thread");
for (int i = 0; i < 100; ++i)
if (!test_floats()) break;
char message[] = "MAIN THREAD SUCCESSFULLY CALLED SEND AND RECEIVE IF THIS IS LOWERCASE";
size_t size = sizeof(message);