]> Devi Nivas Git - cs3210-lab1.git/commitdiff
add DPL_USER constant
authorrsc <rsc>
Wed, 8 Aug 2007 09:02:42 +0000 (09:02 +0000)
committerrsc <rsc>
Wed, 8 Aug 2007 09:02:42 +0000 (09:02 +0000)
main.c
mmu.h
proc.c
trap.c

diff --git a/main.c b/main.c
index dda3e29be7c6f9d255073d0043aa26c3d73389eb..ad0c9c238ef0a46f9fb99228ca91d735a4291a6b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -138,8 +138,8 @@ process0()
   // process to return to.
   p0->tf = &tf;
   memset(p0->tf, 0, sizeof(struct trapframe));
-  p0->tf->es = p0->tf->ds = p0->tf->ss = (SEG_UDATA << 3) | 3;
-  p0->tf->cs = (SEG_UCODE << 3) | 3;
+  p0->tf->es = p0->tf->ds = p0->tf->ss = (SEG_UDATA << 3) | DPL_USER;
+  p0->tf->cs = (SEG_UCODE << 3) | DPL_USER;
   p0->tf->eflags = FL_IF;
   p0->tf->esp = p0->sz;
 
diff --git a/mmu.h b/mmu.h
index f0eb94d4cd4321e309097dce2e01485806c5adf6..112f4802e25726c71e6e419ed312dc8f3b570e86 100644 (file)
--- a/mmu.h
+++ b/mmu.h
@@ -55,6 +55,8 @@ struct segdesc {
     type, 1, dpl, 1, (uint) (lim) >> 16, 0, 0, 1, 0,            \
     (uint) (base) >> 24 }
 
+#define DPL_USER    0x3     // User DPL
+
 // Application segment type bits
 #define STA_X       0x8     // Executable segment
 #define STA_E       0x4     // Expand down (non-executable segments)
diff --git a/proc.c b/proc.c
index 9eaca99ec26b5c199ebdbac22de50cfa17dd647f..a71aa2f5857a859eae97236773606cb28029662c 100644 (file)
--- a/proc.c
+++ b/proc.c
@@ -43,8 +43,8 @@ setupsegs(struct proc *p)
   c->gdt[SEG_TSS] = SEG16(STS_T32A, (uint) &c->ts, sizeof(c->ts), 0);
   c->gdt[SEG_TSS].s = 0;
   if(p){
-    c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz, 3);
-    c->gdt[SEG_UDATA] = SEG(STA_W, (uint)p->mem, p->sz, 3);
+    c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz, DPL_USER);
+    c->gdt[SEG_UDATA] = SEG(STA_W, (uint)p->mem, p->sz, DPL_USER);
   } else {
     c->gdt[SEG_UCODE] = SEG_NULL;
     c->gdt[SEG_UDATA] = SEG_NULL;
diff --git a/trap.c b/trap.c
index 0625e5609822928feb787b52564b84652d99fba9..0c4a9562e87c94d387beba7767dd3641ad042bd1 100644 (file)
--- a/trap.c
+++ b/trap.c
@@ -18,7 +18,7 @@ tvinit(void)
 
   for(i = 0; i < 256; i++)
     SETGATE(idt[i], 0, SEG_KCODE << 3, vectors[i], 0);
-  SETGATE(idt[T_SYSCALL], 0, SEG_KCODE << 3, vectors[T_SYSCALL], 3);
+  SETGATE(idt[T_SYSCALL], 0, SEG_KCODE << 3, vectors[T_SYSCALL], DPL_USER);
 }
 
 void
@@ -56,7 +56,7 @@ trap(struct trapframe *tf)
       // Force process exit if it has been killed and is in user space.
       // (If it is still executing in the kernel, let it keep running
       // until it gets to the regular system call return.)
-      if((tf->cs&3) == 3 && cp->killed)
+      if((tf->cs&3) == DPL_USER && cp->killed)
         proc_exit();
 
       // Force process to give up CPU and let others run.