Save x87 state on context switch

This commit is contained in:
Santiago Lo Coco 2021-10-27 23:44:01 -03:00
parent 42139b44eb
commit 7ae51a4849
2 changed files with 60 additions and 29 deletions

View File

@ -171,11 +171,14 @@ picSlaveMask:
_irq00Handler: _irq00Handler:
pushState pushState
; mov rsi, rsp mov rsi, rsp
; and rsp, -16 and rsp, -16
; sub rsp, 108 sub rsp, 108
; fsave [rsp] fsave [rsp]
; push rsi and rsp, -16
sub rsp, 512
fxsave [rsp]
push rsi
; push rax ; push rax
; call getFPUaddress ; call getFPUaddress
@ -207,12 +210,15 @@ _irq00Handler:
; fxrstor [rax] ; fxrstor [rax]
; pop rax ; pop rax
; mov rax, rsp pop rsp
; pop rsp mov rax, rsp
; and rsp, -16 and rsp, -16
; sub rsp, 108 sub rsp, 108
; frstor [rsp] frstor [rsp]
; mov rsp, rax and rsp, -16
sub rsp, 512
fxrstor [rsp]
mov rsp, rax
popState popState
iretq iretq
@ -300,20 +306,26 @@ _initialize_stack_frame:
pushState pushState
; mov rsi, rsp mov rsi, rsp
; and rsp, -16 and rsp, -16
; sub rsp, 108 sub rsp, 108
; fsave [rsp] fsave [rsp]
; push rsi and rsp, -16
sub rsp, 512
fxsave [rsp]
push rsi
mov rax, rsp
; fsave [bytesForFPU] ; fsave [bytesForFPU]
; push rax
; mov dword [auxi], 1
; call getFPUaddress
; call getSSEaddress
; pop rax
; fxsave [bytesForSSEAligned] ; fxsave [bytesForSSEAligned]
; push rax
; call getFPUaddress
; fsave [rax]
; call getSSEaddress
; fxsave [rax]
; pop rax
; fsave [r8] ; fsave [r8]
; fxsave [r9] ; fxsave [r9]

View File

@ -2,10 +2,23 @@
#define IDLE_PID 1 #define IDLE_PID 1
// void _initialize_stack_frame(void *, void *, int, char**, void **, void **); // void _initialize_stack_frame(void *, void *, int, char**, void **, void **);
void _initialize_stack_frame(void *, void *, int, char**); // void _initialize_stack_frame(void *, void *, int, char**, void *, void *);
uint64_t * _initialize_stack_frame(void *, void *, int, char**);
enum states {READY = 0, BLOCKED}; enum states {READY = 0, BLOCKED};
// typedef long Align;
// union header {
// struct {
// void * fpuBytes;
// void * sseBytes;
// } s;
// Align x;
// };
// typedef union header Header;
typedef struct processCDT { typedef struct processCDT {
struct processCDT * next; struct processCDT * next;
char * name; char * name;
@ -18,12 +31,12 @@ typedef struct processCDT {
char foreground; char foreground;
enum states state; enum states state;
int * fd; int * fd;
// Header * bytes;
// Header * sse;
// void * sseBytes; // void * sseBytes;
// void * fpuBytes; // void * fpuBytes;
} processCDT; } processCDT;
// typedef long Align;
// typedef union processCDT { // typedef union processCDT {
// struct { // struct {
// struct p * next; // struct p * next;
@ -104,7 +117,7 @@ void enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *
processADT process = pvPortMalloc(sizeof(processCDT)); processADT process = pvPortMalloc(sizeof(processCDT));
uint64_t * auxi = pvPortMalloc(STACK_SIZE); uint64_t * auxi = pvPortMalloc(STACK_SIZE);
uint64_t * rbp = STACK_SIZE + auxi; uint64_t * rbp = STACK_SIZE + auxi;
uint64_t * rsp = rbp - 20; //22 uint64_t * rsp = rbp - 20; // 20 //22
char priority = (foreground == 1) ? DEF_PRIORITY : MAX_PRIORITY/2; char priority = (foreground == 1) ? DEF_PRIORITY : MAX_PRIORITY/2;
@ -127,11 +140,15 @@ void enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *
process->state = READY; process->state = READY;
process->fd = fd; process->fd = fd;
process->next = NULL; process->next = NULL;
// process->bytes->s.fpuBytes = pvPortMalloc(108);
// process->bytes->s.sseBytes = pvPortMalloc(512);
// process->sseBytes = pvPortMalloc(64); // process->sseBytes = pvPortMalloc(64);
// process->fpuBytes = pvPortMalloc(14); // process->fpuBytes = pvPortMalloc(14);
// _initialize_stack_frame(fn, rbp, argc, argv, &(process->fpuBytes), &(process->sseBytes)); // _initialize_stack_frame(fn, rbp, argc, argv, &(process->fpuBytes), &(process->sseBytes));
_initialize_stack_frame(fn, rbp, argc, argv); // _initialize_stack_frame(fn, rbp, argc, argv, &(process->bytes->s.sseBytes), &(process->bytes->s.fpuBytes));
// _initialize_stack_frame(fn, rbp, argc, argv, process->bytes->s.sseBytes, process->bytes->s.fpuBytes);
process->rsp = _initialize_stack_frame(fn, rbp, argc, argv);
if (firstReady == NULL) if (firstReady == NULL)
firstReady = process; firstReady = process;
@ -143,11 +160,13 @@ void enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *
} }
// void * getSSEaddress() { // void * getSSEaddress() {
// return currentProcess->sseBytes; // // return currentProcess->sseBytes;
// return currentProcess->bytes->s.sseBytes;
// } // }
// void * getFPUaddress() { // void * getFPUaddress() {
// return currentProcess->fpuBytes; // // return currentProcess->fpuBytes;
// return currentProcess->bytes->s.fpuBytes;
// } // }
void newProcess(processADT process, char * name, char priority, char foreground, uint64_t rsp, uint64_t rbp) { void newProcess(processADT process, char * name, char priority, char foreground, uint64_t rsp, uint64_t rbp) {