summaryrefslogtreecommitdiff
path: root/sys/include
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-07-02 21:19:49 -0400
committerIan Moffett <ian@osmora.org>2024-07-02 21:25:53 -0400
commit2d7bc823503167276c6d3c40500c3055d4f38938 (patch)
tree2971c86e108f5afa1c622afa511a289d12e7a3e6 /sys/include
parent52760e9c5e677b76c81e921bbab95da26478f425 (diff)
kernel/amd64: Handle the user GS segment register
This commit introduces usage of swapgs to switch out the GS register with the user GS register. An md_td_kick() function is also introduced to start up user threads. The this_cpu() function uses the GS register to read the current CPU structure using a new "self" field. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/include')
-rw-r--r--sys/include/arch/amd64/cpu.h1
-rw-r--r--sys/include/arch/amd64/frameasm.h24
-rw-r--r--sys/include/sys/proc.h2
3 files changed, 23 insertions, 4 deletions
diff --git a/sys/include/arch/amd64/cpu.h b/sys/include/arch/amd64/cpu.h
index 16936e9..2ce363c 100644
--- a/sys/include/arch/amd64/cpu.h
+++ b/sys/include/arch/amd64/cpu.h
@@ -42,6 +42,7 @@ struct cpu_info {
size_t lapic_tmr_freq;
struct tss_entry *tss;
struct proc *curtd;
+ struct cpu_info *self;
};
void cpu_startup(struct cpu_info *ci);
diff --git a/sys/include/arch/amd64/frameasm.h b/sys/include/arch/amd64/frameasm.h
index b8791ba..8983d36 100644
--- a/sys/include/arch/amd64/frameasm.h
+++ b/sys/include/arch/amd64/frameasm.h
@@ -106,11 +106,19 @@
*/
#define INTRENTRY(ENTLABEL, HANDLER) \
ENTLABEL: \
- push_trapframe $0 ; \
+ testq $0x3, 8(%rsp) ; \
+ jz 1f ; \
+ lfence ; \
+ swapgs ; \
+ 1: push_trapframe $0 ; \
mov %rsp, %rdi ; \
call HANDLER ; \
pop_trapframe ; \
- iretq
+ testq $0x3, 8(%rsp) ; \
+ jz 2f ; \
+ lfence ; \
+ swapgs ; \
+ 2: iretq
/*
* Trap entry where an error code is on
@@ -118,10 +126,18 @@
*/
#define TRAPENTRY(ENTLABEL, TRAPNO) \
ENTLABEL: \
- push_trapframe_ec TRAPNO ; \
+ testq $0x3, 8(%rsp) ; \
+ jz 1f ; \
+ lfence ; \
+ swapgs ; \
+ 1: push_trapframe_ec TRAPNO ; \
mov %rsp, %rdi ; \
call trap_handler ; \
pop_trapframe_ec ; \
- iretq
+ testq $0x3, 8(%rsp) ; \
+ jz 2f ; \
+ lfence ; \
+ swapgs ; \
+ 2: iretq
#endif /* !_MACHINE_FRAMEASM_H_ */
diff --git a/sys/include/sys/proc.h b/sys/include/sys/proc.h
index ba931f3..805c4a5 100644
--- a/sys/include/sys/proc.h
+++ b/sys/include/sys/proc.h
@@ -34,6 +34,7 @@
#include <sys/spinlock.h>
#include <sys/queue.h>
#include <sys/param.h>
+#include <sys/cdefs.h>
#if defined(_KERNEL)
#include <machine/frame.h>
#include <machine/pcb.h>
@@ -63,6 +64,7 @@ struct proc *this_td(void);
int md_fork(struct proc *p, struct proc *parent, uintptr_t ip);
void md_td_stackinit(struct proc *td, void *stack_top, struct exec_prog *prog);
+__dead void md_td_kick(struct proc *td);
int fork1(struct proc *cur, int flags, void(*ip)(void), struct proc **newprocp);
int exit1(struct proc *td);