This commit is contained in:
2026-09-16 05:12:52 +02:00
parent 3e9bdf72c9
commit 6719239036
5 changed files with 344 additions and 310 deletions
+5 -7
View File
@@ -5,7 +5,6 @@
#include <zinnia/pmap.h>
#include <zinnia/sched.h>
#include <zinnia/vas.h>
#include <zinnia/virt.h>
#include <bits/sched.h>
#include <stddef.h>
#include <stdint.h>
@@ -21,7 +20,7 @@ struct task_frame {
};
[[__naked]]
static void perform_switch(uint64_t* old_rsp, uint64_t new_rsp) {
static struct task* perform_switch(uint64_t* old_rsp, uint64_t new_rsp, struct task* prev) {
asm volatile(
"sub rsp, 0x30\n" // Make room for all regs (except RIP).
"mov [rsp + %c0], rbx\n"
@@ -39,7 +38,7 @@ static void perform_switch(uint64_t* old_rsp, uint64_t new_rsp) {
"mov r14, [rsp + %c4]\n"
"mov r15, [rsp + %c5]\n"
"add rsp, 0x30\n"
"call %c6\n"
"mov rax, rdx\n"
"ret" // This will conveniently move us to the RIP we put at this stack entry.
:
: "i"(offsetof(struct task_frame, rbx)),
@@ -47,13 +46,12 @@ static void perform_switch(uint64_t* old_rsp, uint64_t new_rsp) {
"i"(offsetof(struct task_frame, r12)),
"i"(offsetof(struct task_frame, r13)),
"i"(offsetof(struct task_frame, r14)),
"i"(offsetof(struct task_frame, r15)),
"i"(irq_unlock)
"i"(offsetof(struct task_frame, r15))
: "memory"
);
}
void arch_sched_switch(struct task* from, struct task* to) {
struct task* arch_sched_switch(struct task* from, struct task* to) {
struct arch_percpu* cpu = &percpu_get()->arch;
struct arch_task_context* from_ctx = &from->context;
struct arch_task_context* to_ctx = &to->context;
@@ -87,7 +85,7 @@ void arch_sched_switch(struct task* from, struct task* to) {
asm_wrmsr(MSR_KERNEL_GS_BASE, to_ctx->gs_base);
}
perform_switch(&from_ctx->rsp, to_ctx->rsp);
return perform_switch(&from_ctx->rsp, to_ctx->rsp, from);
}
[[__naked]]