summaryrefslogtreecommitdiff
path: root/trap.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-06-05 11:42:03 -0400
committerRobert Morris <[email protected]>2019-06-05 11:42:03 -0400
commitf1a727b971a59bab6025b4c4111342c27356ca40 (patch)
treed22d52c613bfc003e6fb75b5d137aeff9d954201 /trap.c
parentec3d3a1fceee437c640f9c5c05fc517edfb1899e (diff)
downloadxv6-labs-f1a727b971a59bab6025b4c4111342c27356ca40.tar.gz
xv6-labs-f1a727b971a59bab6025b4c4111342c27356ca40.tar.bz2
xv6-labs-f1a727b971a59bab6025b4c4111342c27356ca40.zip
start at support for multiple CPUs
Diffstat (limited to 'trap.c')
-rw-r--r--trap.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/trap.c b/trap.c
index 5f5d4a0..693c596 100644
--- a/trap.c
+++ b/trap.c
@@ -24,8 +24,6 @@ trapinit(void)
// set up to take exceptions and traps while in the kernel.
w_stvec((uint64)kernelvec);
- // time, cycle, instret CSRs
-
initlock(&tickslock, "time");
}
@@ -45,10 +43,6 @@ usertrap(void)
// since we're now in the kernel.
w_stvec((uint64)kernelvec);
- //printf("mtimecmp %x mtime %x\n", *(uint64*)CLINT_MTIMECMP0, *(uint64*)CLINT_MTIME);
-
- *(uint64*)CLINT_MTIMECMP0 = *(uint64*)CLINT_MTIME + 10000;
-
struct proc *p = myproc();
// save user program counter.
@@ -102,6 +96,7 @@ usertrapret(void)
p->tf->kernel_satp = r_satp();
p->tf->kernel_sp = (uint64)p->kstack + PGSIZE;
p->tf->kernel_trap = (uint64)usertrap;
+ p->tf->hartid = r_tp();
// set up the registers that trampoline.S's sret will use
// to get to user space.
@@ -132,9 +127,12 @@ kerneltrap()
{
uint64 sstatus = r_sstatus();
uint64 scause = r_scause();
+ uint64 sepc = r_sepc(); // XXX needed only for check at end?
if((sstatus & SSTATUS_SPP) == 0)
panic("kerneltrap: not from supervisor mode");
+ if(intr_get() != 0)
+ panic("kerneltrap: interrupts enabled");
if(devintr() == 0){
printf("scause 0x%p\n", scause);
@@ -142,12 +140,11 @@ kerneltrap()
panic("kerneltrap");
}
- // turn off interrupts to ensure we
- // return with the correct sstatus.
- intr_off();
-
- // restore previous interrupt status.
- w_sstatus(sstatus);
+ // XXX assert that we don't have to save/restore sstatus or sepc.
+ if(r_sstatus() != sstatus)
+ panic("kerneltrap sstatus");
+ if(r_sepc() != sepc)
+ panic("kerneltrap sepc");
}
// check if it's an external interrupt or software interrupt,