sched: add kernel-mode context switching
This commit is contained in:
20
arch/x86_64/thread.c
Normal file
20
arch/x86_64/thread.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <socks/machine/thread.h>
|
||||
|
||||
struct thread_ctx {
|
||||
uint64_t r15, r14, r13, r12, r11, r10, r9, r8;
|
||||
uint64_t rdi, rsi, rbp, unused_rsp, rbx, rdx, rcx, rax;
|
||||
uint64_t rfl;
|
||||
} __packed;
|
||||
|
||||
void prepare_stack(uintptr_t ip, uintptr_t *sp)
|
||||
{
|
||||
(*sp) -= sizeof(uintptr_t);
|
||||
uintptr_t *dest_ip = (uintptr_t *)(*sp);
|
||||
*dest_ip = ip;
|
||||
|
||||
(*sp) -= sizeof(struct thread_ctx);
|
||||
struct thread_ctx *ctx = (struct thread_ctx *)(*sp);
|
||||
memset(ctx, 0x0, sizeof *ctx);
|
||||
|
||||
ctx->rfl = 0x202;
|
||||
}
|
||||
Reference in New Issue
Block a user