tweak some comments.
This commit is contained in:
parent
2f22a3ed6a
commit
9981bb2270
|
@ -6,20 +6,16 @@
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
struct proc proc[NPROC];
|
|
||||||
|
|
||||||
struct cpu cpus[NCPU];
|
struct cpu cpus[NCPU];
|
||||||
|
|
||||||
|
struct proc proc[NPROC];
|
||||||
|
|
||||||
struct proc *initproc;
|
struct proc *initproc;
|
||||||
|
|
||||||
struct spinlock pid_lock;
|
|
||||||
int nextpid = 1;
|
int nextpid = 1;
|
||||||
|
struct spinlock pid_lock;
|
||||||
|
|
||||||
extern void forkret(void);
|
extern void forkret(void);
|
||||||
|
|
||||||
// for returning out of the kernel
|
|
||||||
extern void sysexit(void);
|
|
||||||
|
|
||||||
static void wakeup1(struct proc *chan);
|
static void wakeup1(struct proc *chan);
|
||||||
|
|
||||||
extern char trampout[]; // trampoline.S
|
extern char trampout[]; // trampoline.S
|
||||||
|
@ -287,8 +283,8 @@ fork(void)
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass p's abandoned children to init. p and p's parent
|
// Pass p's abandoned children to init.
|
||||||
// are locked.
|
// Caller must hold p->lock and parent->lock.
|
||||||
void
|
void
|
||||||
reparent(struct proc *p, struct proc *parent) {
|
reparent(struct proc *p, struct proc *parent) {
|
||||||
struct proc *pp;
|
struct proc *pp;
|
||||||
|
@ -536,7 +532,7 @@ sleep(void *chan, struct spinlock *lk)
|
||||||
|
|
||||||
//PAGEBREAK!
|
//PAGEBREAK!
|
||||||
// Wake up p, used by exit()
|
// Wake up p, used by exit()
|
||||||
// Caller should lock p.
|
// Caller must hold p->lock.
|
||||||
static void
|
static void
|
||||||
wakeup1(struct proc *p)
|
wakeup1(struct proc *p)
|
||||||
{
|
{
|
||||||
|
@ -545,8 +541,8 @@ wakeup1(struct proc *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wake up all processes sleeping on chan. Never
|
// Wake up all processes sleeping on chan.
|
||||||
// called when holding a p->lock
|
// Must be called without any p->lock.
|
||||||
void
|
void
|
||||||
wakeup(void *chan)
|
wakeup(void *chan)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,33 +18,37 @@ struct context {
|
||||||
uint64 s11;
|
uint64 s11;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Per-CPU state
|
// Per-CPU state.
|
||||||
struct cpu {
|
struct cpu {
|
||||||
struct proc *proc; // The process running on this cpu or null
|
struct proc *proc; // The process running on this cpu, or null.
|
||||||
struct context scheduler; // swtch() here to enter scheduler
|
struct context scheduler; // swtch() here to enter scheduler().
|
||||||
int noff; // Depth of push_off() nesting.
|
int noff; // Depth of push_off() nesting.
|
||||||
int intena; // Were interrupts enabled before push_off()?
|
int intena; // Were interrupts enabled before push_off()?
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct cpu cpus[NCPU];
|
extern struct cpu cpus[NCPU];
|
||||||
|
|
||||||
//PAGEBREAK: 17
|
//PAGEBREAK: 17
|
||||||
|
|
||||||
// per-process data for the early trap handling code in trampoline.S.
|
// per-process data for the trap handling code in trampoline.S.
|
||||||
// sits in a page by itself just under the trampoline page in the
|
// sits in a page by itself just under the trampoline page in the
|
||||||
// user page table. not specially mapped in the kernel page table.
|
// user page table. not specially mapped in the kernel page table.
|
||||||
// the sscratch register points here.
|
// the sscratch register points here.
|
||||||
// trampoline.S saves user registers, then restores kernel_sp and
|
// trampin in trampoline.S saves user registers in the trapframe,
|
||||||
// kernel_satp.
|
// then initializes registers from the trapframe's
|
||||||
// includes callee-saved registers like s0-s11 because the
|
// kernel_sp, kernel_hartid, kernel_satp, and jumps to kernel_trap.
|
||||||
|
// usertrapret() and trampout in trampoline.S set up
|
||||||
|
// the trapframe's kernel_*, restore user registers from the
|
||||||
|
// trapframe, switch to the user page table, and enter user space.
|
||||||
|
// the trapframe includes callee-saved user registers like s0-s11 because the
|
||||||
// return-to-user path via usertrapret() doesn't return through
|
// return-to-user path via usertrapret() doesn't return through
|
||||||
// the entire kernel call stack.
|
// the entire kernel call stack.
|
||||||
struct trapframe {
|
struct trapframe {
|
||||||
/* 0 */ uint64 kernel_satp;
|
/* 0 */ uint64 kernel_satp; // kernel page table
|
||||||
/* 8 */ uint64 kernel_sp;
|
/* 8 */ uint64 kernel_sp; // top of process's kernel stack
|
||||||
/* 16 */ uint64 kernel_trap; // usertrap()
|
/* 16 */ uint64 kernel_trap; // usertrap()
|
||||||
/* 24 */ uint64 epc; // saved user program counter
|
/* 24 */ uint64 epc; // saved user program counter
|
||||||
/* 32 */ uint64 hartid;
|
/* 32 */ uint64 kernel_hartid; // saved kernel tp
|
||||||
/* 40 */ uint64 ra;
|
/* 40 */ uint64 ra;
|
||||||
/* 48 */ uint64 sp;
|
/* 48 */ uint64 sp;
|
||||||
/* 56 */ uint64 gp;
|
/* 56 */ uint64 gp;
|
||||||
|
|
|
@ -120,7 +120,7 @@ trampin:
|
||||||
# restore kernel stack pointer from p->tf->kernel_sp
|
# restore kernel stack pointer from p->tf->kernel_sp
|
||||||
ld sp, 8(a0)
|
ld sp, 8(a0)
|
||||||
|
|
||||||
# make tp hold the current hartid, from p->tf->hartid
|
# make tp hold the current hartid, from p->tf->kernel_hartid
|
||||||
ld tp, 32(a0)
|
ld tp, 32(a0)
|
||||||
|
|
||||||
# remember the address of usertrap(), p->tf->kernel_trap
|
# remember the address of usertrap(), p->tf->kernel_trap
|
||||||
|
|
|
@ -100,7 +100,7 @@ usertrapret(void)
|
||||||
p->tf->kernel_satp = r_satp();
|
p->tf->kernel_satp = r_satp();
|
||||||
p->tf->kernel_sp = (uint64)p->kstack + PGSIZE;
|
p->tf->kernel_sp = (uint64)p->kstack + PGSIZE;
|
||||||
p->tf->kernel_trap = (uint64)usertrap;
|
p->tf->kernel_trap = (uint64)usertrap;
|
||||||
p->tf->hartid = r_tp();
|
p->tf->kernel_hartid = r_tp();
|
||||||
|
|
||||||
// set up the registers that trampoline.S's sret will use
|
// set up the registers that trampoline.S's sret will use
|
||||||
// to get to user space.
|
// to get to user space.
|
||||||
|
|
Loading…
Reference in a new issue