summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/proc/scheduler.c
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-10-13 22:31:43 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-10-13 22:31:43 -0400
commit548506392b789f58b1556a6ffca917441e1d89fd (patch)
tree58e4b747446ea64e7951e523353f58510b3a8b2f /arch/x86_64/proc/scheduler.c
parentc5e3bb7917689bc9ed54fee23a143144fade802d (diff)
downloadjove-kernel-548506392b789f58b1556a6ffca917441e1d89fd.tar.gz
jove-kernel-548506392b789f58b1556a6ffca917441e1d89fd.tar.bz2
jove-kernel-548506392b789f58b1556a6ffca917441e1d89fd.zip
ipc functions. work on process spawning
Diffstat (limited to 'arch/x86_64/proc/scheduler.c')
-rw-r--r--arch/x86_64/proc/scheduler.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/arch/x86_64/proc/scheduler.c b/arch/x86_64/proc/scheduler.c
index 23e54af..49a0c4d 100644
--- a/arch/x86_64/proc/scheduler.c
+++ b/arch/x86_64/proc/scheduler.c
@@ -1,14 +1,16 @@
#include "proc/scheduler.h"
#include "arch/x86_64/hal/gdt.h"
+#include "lib/string.h"
#include "process.h"
#include "../hal/smp.h"
-#include <string.h>
+#include "../proc/process.h"
void
_scheduler_switch_pcb_arch(pcb_t *target)
{
processor_t *proc = processor_current();
- proc->tss.rsp[0] = (uintptr_t)target->header.ksp;
+ proc->syscall_page = target->interrupt_page;
+ proc->interrupt_page = target->interrupt_page;
if(target->iopb) {
proc->tss.iopb = sizeof(struct tss);
@@ -18,3 +20,27 @@ _scheduler_switch_pcb_arch(pcb_t *target)
proc->tss.iopb = 0xff;
}
}
+
+__attribute__((naked))
+void scheduler_switch(void *this_sp, void *other_sp, void *new_cr3)
+{
+ __asm__ volatile("\
+ movq %%rsp, (%%rdi); \
+ movq %%rsi, %%rsp; \
+ movq %%cr3, %%rax; \
+ cmp %%rax, %%rdx; \
+ je .nocr3swap; \
+ movq %%rdx, %%cr3; \
+ .nocr3swap: \
+ movq %%gs:%c[syscall_page], %%rax; \
+ movq %%rax, __syscall_stack_mapping; \
+ movq (__syscall_stack), %%rax; \
+ invlpg (%%rax); \
+ movq %%gs:%c[interrupt_page], %%rax; \
+ movq %%rax, __interrupt_stack_mapping; \
+ movq (__interrupt_stack), %%rax; \
+ invlpg (%%rax); \
+ retq"::
+ [syscall_page] "i"(offsetof(processor_t, syscall_page)),
+ [interrupt_page] "i"(offsetof(processor_t, interrupt_page)));
+}