User swapgs to load the correct GS_BASE

上级 b40a7ea0
......@@ -12,5 +12,6 @@ void
asmdefines(void)
{
DEFINE(PROC_KSTACK_OFFSET, __offsetof(struct proc, kstack));
DEFINE(TF_CS, __offsetof(struct trapframe, cs));
DEFINE(TRAPFRAME_SIZE, sizeof(trapframe));
}
......@@ -20,9 +20,6 @@ extern u64 trapentry[];
u64
sysentry_c(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num)
{
writegs(KDSEG);
writemsr(MSR_GS_BASE, (u64)&cpus[lapicid()].cpu);
sti();
if(myproc()->killed) {
......@@ -45,9 +42,6 @@ sysentry_c(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num)
void
trap(struct trapframe *tf)
{
writegs(KDSEG);
writemsr(MSR_GS_BASE, (u64)&cpus[lapicid()].cpu);
if (tf->trapno == T_NMI) {
// The only locks that we can acquire during NMI are ones
// we acquire only during NMI.
......
......@@ -28,7 +28,6 @@ sysentry:
// blow away %r9: syscalls can take at most 5 args
swapgs
movq %gs:8, %r9 // myproc()
swapgs
movq %ss:PROC_KSTACK_OFFSET(%r9), %r9
addq $(KSTACKSIZE-TRAPFRAME_SIZE), %r9
......@@ -72,6 +71,8 @@ sysentry:
// return using SYSRET
cli
movq %rsp, %r11
swapgs
movw $UDSEG, %cx
movw %cx, %ds
movw %cx, %es
......@@ -110,9 +111,12 @@ trapcommon:
movw $KDSEG, %ax
movw %ax, %ds
movw %ax, %es
// XXX(sbw) we should do something with fs, gs, gs.base
movq %rsp, %rdi // first argument to trap
cmp $KCSEG, TF_CS(%rsp)
jz 1f
swapgs
1: movq %rsp, %rdi // first argument to trap
xor %rbp, %rbp
call trap
// Fall through to trapret
......@@ -120,11 +124,15 @@ trapcommon:
.globl trapret
.align 8
trapret:
addq $0xe, %rsp // padding
cli
cmp $KCSEG, TF_CS(%rsp)
jz 1f
swapgs
1: addq $0xe, %rsp // padding
popw %ax
movw %ax, %ds
movw %ax, %es
// XXX(sbw) we should do something with fs, gs, gs.base
popq %r15
popq %r14
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论