提交 a38bd10a 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Trap rejiggering.

上级 cdf153d7
...@@ -26,10 +26,12 @@ struct segdesc __attribute__((aligned(16))) bootgdt[NSEGS] = { ...@@ -26,10 +26,12 @@ struct segdesc __attribute__((aligned(16))) bootgdt[NSEGS] = {
[2]=SEGDESC(0, 0, SEG_R|SEG_CODE|SEG_S|SEG_DPL(0)|SEG_P|SEG_L|SEG_G), [2]=SEGDESC(0, 0, SEG_R|SEG_CODE|SEG_S|SEG_DPL(0)|SEG_P|SEG_L|SEG_G),
// kernel data // kernel data
[3]=SEGDESC(0, 0xfffff, SEG_W|SEG_S|SEG_DPL(0)|SEG_P|SEG_D|SEG_G), [3]=SEGDESC(0, 0xfffff, SEG_W|SEG_S|SEG_DPL(0)|SEG_P|SEG_D|SEG_G),
// 64-bit user code // The order of the user data and user code segments is
[6]=SEGDESC(0, 0, SEG_R|SEG_CODE|SEG_S|SEG_DPL(3)|SEG_P|SEG_L|SEG_G), // important for syscall instructions. See initseg.
// 64-bit user data // 64-bit user data
[7]=SEGDESC(0, 0xfffff, SEG_W|SEG_S|SEG_DPL(3)|SEG_P|SEG_D|SEG_G) [6]=SEGDESC(0, 0xfffff, SEG_W|SEG_S|SEG_DPL(3)|SEG_P|SEG_D|SEG_G),
// 64-bit user code
[7]=SEGDESC(0, 0, SEG_R|SEG_CODE|SEG_S|SEG_DPL(3)|SEG_P|SEG_L|SEG_G),
}; };
struct intdesc idt[256] __attribute__((aligned(16))); struct intdesc idt[256] __attribute__((aligned(16)));
...@@ -41,12 +43,15 @@ void ...@@ -41,12 +43,15 @@ void
trap(struct trapframe *tf) trap(struct trapframe *tf)
{ {
// XXX(sbw) eventually these should be moved into trapasm.S // XXX(sbw) eventually these should be moved into trapasm.S
cli();
writegs(KDSEG); writegs(KDSEG);
writemsr(MSR_GS_BASE, (u64)&cpus[cpunum()].cpu); writemsr(MSR_GS_BASE, (u64)&cpus[cpunum()].cpu);
sti();
// XXX(sbw) sysenter/sysexit // XXX(sbw) sysenter/sysexit
#if 0
if(tf->trapno == T_SYSCALL){ if(tf->trapno == T_SYSCALL){
panic("syscall..");
#if 0
if(proc->killed) { if(proc->killed) {
mtrace_kstack_start(trap, proc); mtrace_kstack_start(trap, proc);
exit(); exit();
...@@ -57,9 +62,9 @@ trap(struct trapframe *tf) ...@@ -57,9 +62,9 @@ trap(struct trapframe *tf)
mtrace_kstack_start(trap, proc); mtrace_kstack_start(trap, proc);
exit(); exit();
} }
#endif
return; return;
} }
#endif
if (myproc()->mtrace_stacks.curr >= 0) if (myproc()->mtrace_stacks.curr >= 0)
mtrace_kstack_pause(myproc()); mtrace_kstack_pause(myproc());
...@@ -164,6 +169,8 @@ inittrap(void) ...@@ -164,6 +169,8 @@ inittrap(void)
entry = trapentry[i]; entry = trapentry[i];
idt[i] = INTDESC(KCSEG, entry, bits); idt[i] = INTDESC(KCSEG, entry, bits);
} }
entry = trapentry[T_SYSCALL];
idt[T_SYSCALL] = INTDESC(KCSEG, entry, SEG_DPL(3) | SEG_TRAP64 |INT_P);
} }
void void
......
#include "mmu.h" #include "mmu.h"
#define _TRAP(x, l) \ #define NOEC pushq $0
#define EC
#define _TRAP(x, code) \
.globl trap ## x; \ .globl trap ## x; \
.align 8; \ .align 8; \
trap ## x: \ trap ## x: \
code; \
pushq $x; \ pushq $x; \
jmp l; \ jmp trapcommon; \
.data; \ .data; \
.quad trap ## x; \ .quad trap ## x; \
.previous .previous
#define TRAP(x) _TRAP(x, trappush) #define TRAP(x) _TRAP(x, NOEC)
#define TRAPCODE(x) _TRAP(x, trapcommon) #define TRAPCODE(x) _TRAP(x, EC)
.code64 .code64
.globl sysentry .globl sysentry
...@@ -51,6 +55,7 @@ trapcommon: ...@@ -51,6 +55,7 @@ trapcommon:
movq %rsp, %rdi // first argument to trap movq %rsp, %rdi // first argument to trap
call trap call trap
// Fall through to trapret
.globl trapret .globl trapret
.align 8 .align 8
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论