summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
add some comments
find out the hard way why user and kernel must have separate segment descriptors
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c9
1 files changed, 6 insertions, 3 deletions
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);