From 1afc9d3fcaa7c5992659bb8b69f639b746dda2bc Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Thu, 5 Aug 2010 21:16:55 -0400 Subject: add some comments find out the hard way why user and kernel must have separate segment descriptors --- vm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index c94e9a3..9ea5e92 100644 --- a/vm.c +++ b/vm.c @@ -93,12 +93,15 @@ ksegment(void) { struct cpu *c; - // Map once virtual addresses to linear addresses using identity map + // Map virtual addresses to linear addresses using identity map. + // Cannot share a CODE descriptor for both kernel and user + // because it would have to have DPL_USR, but the CPU forbids + // an interrupt from CPL=0 to DPL=3. c = &cpus[cpunum()]; c->gdt[SEG_KCODE] = SEG(STA_X|STA_R, 0, 0xffffffff, 0); c->gdt[SEG_KDATA] = SEG(STA_W, 0, 0xffffffff, 0); - c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, 0x0, 0xffffffff, DPL_USER); - c->gdt[SEG_UDATA] = SEG(STA_W, 0x0, 0xffffffff, DPL_USER); + c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, 0, 0xffffffff, DPL_USER); + c->gdt[SEG_UDATA] = SEG(STA_W, 0, 0xffffffff, DPL_USER); // map cpu, and curproc c->gdt[SEG_KCPU] = SEG(STA_W, &c->cpu, 8, 0); -- cgit v1.2.3