mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
scheduler: umask default value and fpu saving in x86_64 context
This commit is contained in:
@@ -40,7 +40,9 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t gsbase;
|
uint64_t gsbase;
|
||||||
uint64_t fsbase;
|
uint64_t fsbase;
|
||||||
} extracontext_t;
|
uint8_t fx[512];
|
||||||
|
uint32_t mxcsr;
|
||||||
|
} extracontext_t __attribute__((aligned(16)));
|
||||||
|
|
||||||
#define CTX_INIT(x,u) \
|
#define CTX_INIT(x,u) \
|
||||||
if (u) { \
|
if (u) { \
|
||||||
@@ -52,6 +54,9 @@ typedef struct {
|
|||||||
} \
|
} \
|
||||||
(x)->rflags = 0x200;
|
(x)->rflags = 0x200;
|
||||||
|
|
||||||
|
#define CTX_XINIT(x, u) \
|
||||||
|
(x)->mxcsr = 0x1F80; // all exceptions masked
|
||||||
|
|
||||||
#define CTX_SP(x) (x)->rsp
|
#define CTX_SP(x) (x)->rsp
|
||||||
#define CTX_IP(x) (x)->rip
|
#define CTX_IP(x) (x)->rip
|
||||||
#define CTX_RET(x) (x)->rax
|
#define CTX_RET(x) (x)->rax
|
||||||
@@ -73,18 +78,24 @@ void arch_context_saveandcall(void (*fn)(context_t *context), void *stack);
|
|||||||
_cpu()->ist.rsp0 = (uint64_t)(x)->kernelstacktop; \
|
_cpu()->ist.rsp0 = (uint64_t)(x)->kernelstacktop; \
|
||||||
wrmsr(MSR_KERNELGSBASE, (x)->extracontext.gsbase); \
|
wrmsr(MSR_KERNELGSBASE, (x)->extracontext.gsbase); \
|
||||||
wrmsr(MSR_FSBASE, (x)->extracontext.fsbase); \
|
wrmsr(MSR_FSBASE, (x)->extracontext.fsbase); \
|
||||||
|
asm("fxrstor (%%rax)" : : "a"(&(x)->extracontext.fx[0])); \
|
||||||
|
asm("ldmxcsr (%%rax)" : : "a"(&(x)->extracontext.mxcsr)); \
|
||||||
arch_context_switch(&thread->context);
|
arch_context_switch(&thread->context);
|
||||||
|
|
||||||
#define ARCH_CONTEXT_THREADSAVE(t, c) \
|
#define ARCH_CONTEXT_THREADSAVE(t, c) \
|
||||||
memcpy(&(t)->context, c, sizeof(context_t)); \
|
memcpy(&(t)->context, c, sizeof(context_t)); \
|
||||||
(t)->extracontext.gsbase = rdmsr(MSR_KERNELGSBASE); \
|
(t)->extracontext.gsbase = rdmsr(MSR_KERNELGSBASE); \
|
||||||
(t)->extracontext.fsbase = rdmsr(MSR_FSBASE);
|
(t)->extracontext.fsbase = rdmsr(MSR_FSBASE); \
|
||||||
|
asm("fxsave (%%rax)" : : "a"(&(t)->extracontext.fx[0])); \
|
||||||
|
asm("stmxcsr (%%rax)" : : "a"(&(t)->extracontext.mxcsr));
|
||||||
|
|
||||||
#define ARCH_CONTEXT_THREADLOAD(t, c) \
|
#define ARCH_CONTEXT_THREADLOAD(t, c) \
|
||||||
memcpy(c, &(t)->context, sizeof(context_t)); \
|
memcpy(c, &(t)->context, sizeof(context_t)); \
|
||||||
_cpu()->ist.rsp0 = (uint64_t)(t)->kernelstacktop; \
|
_cpu()->ist.rsp0 = (uint64_t)(t)->kernelstacktop; \
|
||||||
wrmsr(MSR_KERNELGSBASE, (t)->extracontext.gsbase); \
|
wrmsr(MSR_KERNELGSBASE, (t)->extracontext.gsbase); \
|
||||||
wrmsr(MSR_FSBASE, (t)->extracontext.fsbase);
|
wrmsr(MSR_FSBASE, (t)->extracontext.fsbase); \
|
||||||
|
asm("fxrstor (%%rax)" : : "a"(&(t)->extracontext.fx[0])); \
|
||||||
|
asm("ldmxcsr (%%rax)" : : "a"(&(t)->extracontext.mxcsr));
|
||||||
|
|
||||||
#define ARCH_CONTEXT_INTSTATUS(x) ((x)->rflags & 0x200 ? true : false)
|
#define ARCH_CONTEXT_INTSTATUS(x) ((x)->rflags & 0x200 ? true : false)
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ proc_t *sched_newproc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proc->pid = __atomic_fetch_add(&currpid, 1, __ATOMIC_SEQ_CST);
|
proc->pid = __atomic_fetch_add(&currpid, 1, __ATOMIC_SEQ_CST);
|
||||||
|
proc->umask = 022; // default umask
|
||||||
|
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
@@ -86,6 +87,7 @@ thread_t *sched_newthread(void *ip, size_t kstacksize, int priority, proc_t *pro
|
|||||||
|
|
||||||
|
|
||||||
CTX_INIT(&thread->context, proc != NULL);
|
CTX_INIT(&thread->context, proc != NULL);
|
||||||
|
CTX_XINIT(&thread->extracontext, proc != NULL);
|
||||||
CTX_SP(&thread->context) = proc ? (ctxreg_t)ustack : (ctxreg_t)thread->kernelstacktop;
|
CTX_SP(&thread->context) = proc ? (ctxreg_t)ustack : (ctxreg_t)thread->kernelstacktop;
|
||||||
CTX_IP(&thread->context) = (ctxreg_t)ip;
|
CTX_IP(&thread->context) = (ctxreg_t)ip;
|
||||||
SPINLOCK_INIT(thread->sleeplock);
|
SPINLOCK_INIT(thread->sleeplock);
|
||||||
|
|||||||
Reference in New Issue
Block a user