User swapgs to load the correct GS_BASE

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