mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +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 {
|
||||
uint64_t gsbase;
|
||||
uint64_t fsbase;
|
||||
} extracontext_t;
|
||||
uint8_t fx[512];
|
||||
uint32_t mxcsr;
|
||||
} extracontext_t __attribute__((aligned(16)));
|
||||
|
||||
#define CTX_INIT(x,u) \
|
||||
if (u) { \
|
||||
@@ -52,6 +54,9 @@ typedef struct {
|
||||
} \
|
||||
(x)->rflags = 0x200;
|
||||
|
||||
#define CTX_XINIT(x, u) \
|
||||
(x)->mxcsr = 0x1F80; // all exceptions masked
|
||||
|
||||
#define CTX_SP(x) (x)->rsp
|
||||
#define CTX_IP(x) (x)->rip
|
||||
#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; \
|
||||
wrmsr(MSR_KERNELGSBASE, (x)->extracontext.gsbase); \
|
||||
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);
|
||||
|
||||
#define ARCH_CONTEXT_THREADSAVE(t, c) \
|
||||
memcpy(&(t)->context, c, sizeof(context_t)); \
|
||||
(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) \
|
||||
memcpy(c, &(t)->context, sizeof(context_t)); \
|
||||
_cpu()->ist.rsp0 = (uint64_t)(t)->kernelstacktop; \
|
||||
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)
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ proc_t *sched_newproc() {
|
||||
}
|
||||
|
||||
proc->pid = __atomic_fetch_add(&currpid, 1, __ATOMIC_SEQ_CST);
|
||||
proc->umask = 022; // default umask
|
||||
|
||||
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_XINIT(&thread->extracontext, proc != NULL);
|
||||
CTX_SP(&thread->context) = proc ? (ctxreg_t)ustack : (ctxreg_t)thread->kernelstacktop;
|
||||
CTX_IP(&thread->context) = (ctxreg_t)ip;
|
||||
SPINLOCK_INIT(thread->sleeplock);
|
||||
|
||||
Reference in New Issue
Block a user