summaryrefslogtreecommitdiff
path: root/src/kernel/arch/amd64/sysenter.c
blob: e42ec7d82d49e324a506e9634e5857188b7be4be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <kernel/arch/generic.h>
#include <kernel/arch/amd64/sysenter.h>
#include <kernel/proc.h>
#include <shared/syscalls.h>

struct registers _sysexit_regs;

void sysexit(struct registers regs) {
	_sysexit_regs = regs;
	_sysexit_regs.ecx = (uintptr_t) regs.esp;
	_sysexit_regs.edx = (uintptr_t) regs.eip;
	_sysexit_real();
	__builtin_unreachable();
}

_Noreturn void sysenter_stage2(void) {
	kprintf("ring0 again!\n");
	struct registers *regs = &process_current->regs;

	*regs = _sysexit_regs; // save the registers
	regs->esp = (userptr_t) regs->ecx; // fix them up
	regs->eip = (userptr_t) regs->edx;

	_syscall(regs->eax, regs->ebx,
	         regs->esi, regs->edi, (uintptr_t)regs->ebp);
	process_switch_any();
}