Move popcli, pushcli, and getcallerpcs to trap.c

上级 09e5ba89
...@@ -267,12 +267,9 @@ void sampconf(void); ...@@ -267,12 +267,9 @@ void sampconf(void);
// spinlock.c // spinlock.c
void acquire(struct spinlock*); void acquire(struct spinlock*);
int tryacquire(struct spinlock*); int tryacquire(struct spinlock*);
void getcallerpcs(void*, uptr*);
int holding(struct spinlock*); int holding(struct spinlock*);
void initlock(struct spinlock*, const char*); void initlock(struct spinlock*, const char*);
void release(struct spinlock*); void release(struct spinlock*);
void pushcli(void);
void popcli(void);
// syscall.c // syscall.c
int argint64(int, u64*); int argint64(int, u64*);
...@@ -300,6 +297,9 @@ void swtch(struct context**, struct context*); ...@@ -300,6 +297,9 @@ void swtch(struct context**, struct context*);
// trap.c // trap.c
extern struct segdesc bootgdt[NSEGS]; extern struct segdesc bootgdt[NSEGS];
void pushcli(void);
void popcli(void);
void getcallerpcs(void*, uptr*);
// uart.c // uart.c
void uartputc(char c); void uartputc(char c);
......
...@@ -108,24 +108,6 @@ release(struct spinlock *lk) ...@@ -108,24 +108,6 @@ release(struct spinlock *lk)
popcli(); popcli();
} }
// Record the current call stack in pcs[] by following the %ebp chain.
void
getcallerpcs(void *v, uptr pcs[])
{
uptr *rbp;
int i;
rbp = (uptr*)v;
for(i = 0; i < 10; i++){
if(rbp == 0 || rbp < (uptr*)KBASE || rbp == (uptr*)(~0UL))
break;
pcs[i] = rbp[1]; // saved %rip
rbp = (uptr*)rbp[0]; // saved %rbp
}
for(; i < 10; i++)
pcs[i] = 0;
}
// Check whether this cpu is holding the lock. // Check whether this cpu is holding the lock.
#if SPINLOCK_DEBUG #if SPINLOCK_DEBUG
int int
...@@ -134,30 +116,3 @@ holding(struct spinlock *lock) ...@@ -134,30 +116,3 @@ holding(struct spinlock *lock)
return lock->locked && lock->cpu == mycpu(); return lock->locked && lock->cpu == mycpu();
} }
#endif #endif
// Pushcli/popcli are like cli/sti except that they are matched:
// it takes two popcli to undo two pushcli. Also, if interrupts
// are off, then pushcli, popcli leaves them off.
void
pushcli(void)
{
u64 rflags;
rflags = readrflags();
cli();
if(mycpu()->ncli++ == 0)
mycpu()->intena = rflags & FL_IF;
}
void
popcli(void)
{
if(readrflags()&FL_IF)
panic("popcli - interruptible");
if(--mycpu()->ncli < 0)
panic("popcli");
if(mycpu()->ncli == 0 && mycpu()->intena)
sti();
}
...@@ -206,3 +206,46 @@ initseg(void) ...@@ -206,3 +206,46 @@ initseg(void)
writemsr(MSR_SFMASK, FL_TF); writemsr(MSR_SFMASK, FL_TF);
#endif #endif
} }
// Pushcli/popcli are like cli/sti except that they are matched:
// it takes two popcli to undo two pushcli. Also, if interrupts
// are off, then pushcli, popcli leaves them off.
void
pushcli(void)
{
u64 rflags;
rflags = readrflags();
cli();
if(mycpu()->ncli++ == 0)
mycpu()->intena = rflags & FL_IF;
}
void
popcli(void)
{
if(readrflags()&FL_IF)
panic("popcli - interruptible");
if(--mycpu()->ncli < 0)
panic("popcli");
if(mycpu()->ncli == 0 && mycpu()->intena)
sti();
}
// Record the current call stack in pcs[] by following the %rbp chain.
void
getcallerpcs(void *v, uptr pcs[])
{
uptr *rbp;
int i;
rbp = (uptr*)v;
for(i = 0; i < 10; i++){
if(rbp == 0 || rbp < (uptr*)KBASE || rbp == (uptr*)(~0UL))
break;
pcs[i] = rbp[1]; // saved %rip
rbp = (uptr*)rbp[0]; // saved %rbp
}
for(; i < 10; i++)
pcs[i] = 0;
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论