summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/proc
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
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')
-rw-r--r--arch/x86_64/proc/init.c20
-rw-r--r--arch/x86_64/proc/process.c41
-rw-r--r--arch/x86_64/proc/process.h8
-rw-r--r--arch/x86_64/proc/scheduler.c30
-rw-r--r--arch/x86_64/proc/switch.s10
5 files changed, 83 insertions, 26 deletions
diff --git a/arch/x86_64/proc/init.c b/arch/x86_64/proc/init.c
index 155cff6..8003a6d 100644
--- a/arch/x86_64/proc/init.c
+++ b/arch/x86_64/proc/init.c
@@ -5,6 +5,7 @@
#include "jove.h"
#include "hal/obj.h"
#include "lib/string.h"
+#include "sys/message.h"
#include "sys/objdir.h"
#include "panic/panic.h"
#include "lib/printf.h"
@@ -126,20 +127,19 @@ init_setup(void)
//Map the syscall message.
last_base = (last_base + 0xFFF) & ~0xFFF;
jove_owned_obj_t message_frame = init_pop_alloc();
- pagedir_map_frame(pml4, obj_getvalue(&message_frame), last_base,
- PAGE_WRITEABLE | PAGE_USER | PAGE_XD);
+ jove_owned_obj_t *message_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_MESSAGE_I);
+
+ message_new(&message_frame);
+ objdir_swapobj(message_obj, &message_frame);
+ message_map(message_obj, init_pagedir, last_base);
+
+ obj_release(init_pagedir);
- extern struct init_payload _init_payload;
_init_payload.brk = last_base + 0x1000;
+ //Copy init payload into syscall message.
+ extern struct init_payload _init_payload;
memcpy((void*)last_base, &_init_payload, sizeof(struct init_payload));
-
- jove_owned_obj_t *message_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_MESSAGE_I);
- obj_settype(message_obj, JOVE_OBJ_MESSAGE);
- obj_setvalue(message_obj, last_base | 1);
- obj_release(message_obj);
-
- obj_release(init_pagedir);
//Enable syscalls
extern void _syscall_entry(void);
diff --git a/arch/x86_64/proc/process.c b/arch/x86_64/proc/process.c
index 5935303..b10d538 100644
--- a/arch/x86_64/proc/process.c
+++ b/arch/x86_64/proc/process.c
@@ -40,3 +40,44 @@ processing_setup(void (*process_main))
scheduler_init(init_pcb_obj, process_main);
}
+
+inline physaddr_t
+pcb_get_syscall_stack(pcb_t *pcb)
+{
+ return pcb->syscall_page.pfn << 12;
+}
+
+inline physaddr_t
+pcb_get_interrupt_stack(pcb_t *pcb)
+{
+ return pcb->interrupt_page.pfn << 12;
+}
+
+physaddr_t
+pcb_set_syscall_stack(pcb_t *pcb, physaddr_t page)
+{
+ physaddr_t old_page = pcb_get_syscall_stack(pcb);
+ pcb->syscall_page.pfn = page >> 12;
+ pcb->syscall_page.p = 1;
+ pcb->syscall_page.rw = 1;
+ return old_page;
+}
+physaddr_t
+pcb_set_interrupt_stack(pcb_t *pcb, physaddr_t page)
+{
+ physaddr_t old_page = pcb_get_interrupt_stack(pcb);
+ pcb->interrupt_page.pfn = page >> 12;
+ pcb->interrupt_page.p = 1;
+ pcb->interrupt_page.rw = 1;
+ return old_page;
+}
+
+inline void pcb_map_syscall_stack(pcb_t *pcb)
+{
+ *__syscall_stack_mapping = pcb->syscall_page.value;
+}
+
+inline void pcb_map_interrupt_stack(pcb_t *pcb)
+{
+ *__interrupt_stack_mapping = pcb->interrupt_page.value;
+}
diff --git a/arch/x86_64/proc/process.h b/arch/x86_64/proc/process.h
index 5004b49..866184b 100644
--- a/arch/x86_64/proc/process.h
+++ b/arch/x86_64/proc/process.h
@@ -3,16 +3,16 @@
#include "proc/process.h"
#include "lib/rbtree.h"
+#include "arch/x86_64/hal/paging.h"
typedef struct process_control_block
{
struct pcb_header header;
jove_obj_t *iopb;
-
- char kstack[];
-} pcb_t;
-#define PCB_KSTACK_SIZE (0x1000 - sizeof(pcb_t))
+ page_t syscall_page;
+ page_t interrupt_page;
+} pcb_t;
#endif
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)));
+}
diff --git a/arch/x86_64/proc/switch.s b/arch/x86_64/proc/switch.s
index 16b2198..028a949 100644
--- a/arch/x86_64/proc/switch.s
+++ b/arch/x86_64/proc/switch.s
@@ -1,13 +1,3 @@
-.global scheduler_switch
-.type scheduler_switch @function
-
-scheduler_switch:
- movq %rsp, (%rdi)
- movq %rsi, %rsp
- retq
-
-.size scheduler_switch, . - scheduler_switch
-
.global scheduler_savestate
.type scheduler_savestate @function