Skip to content

Commit

Permalink
Merge branch 'master' of g.csail.mit.edu:xv6-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Morris committed Aug 8, 2017
2 parents aba8423 + 825ce07 commit 1427028
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 172 deletions.
5 changes: 3 additions & 2 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ panic(char *s)

cli();
cons.locking = 0;
cprintf("cpu with apicid %d: panic: ", cpu->apicid);
// use lapiccpunum so that we can call panic from mycpu()
cprintf("lapicid %d: panic: ", lapicid());
cprintf(s);
cprintf("\n");
getcallerpcs(&s, pcs);
Expand Down Expand Up @@ -242,7 +243,7 @@ consoleread(struct inode *ip, char *dst, int n)
acquire(&cons.lock);
while(n > 0){
while(input.r == input.w){
if(proc->killed){
if(myproc()->killed){
release(&cons.lock);
ilock(ip);
return -1;
Expand Down
6 changes: 5 additions & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void kbdintr(void);

// lapic.c
void cmostime(struct rtcdate *r);
int cpunum(void);
int lapicid(void);
extern volatile uint* lapic;
void lapiceoi(void);
void lapicinit(void);
Expand Down Expand Up @@ -103,14 +103,18 @@ int pipewrite(struct pipe*, char*, int);

//PAGEBREAK: 16
// proc.c
int cpuid(void);
void exit(void);
int fork(void);
int growproc(int);
int kill(int);
struct cpu* mycpu(void);
struct proc* myproc();
void pinit(void);
void procdump(void);
void scheduler(void) __attribute__((noreturn));
void sched(void);
void setproc(struct proc*);
void sleep(void*, struct spinlock*);
void userinit(void);
int wait(void);
Expand Down
16 changes: 9 additions & 7 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ exec(char *path, char **argv)
struct inode *ip;
struct proghdr ph;
pde_t *pgdir, *oldpgdir;
struct proc *curproc = myproc();

begin_op();

if((ip = namei(path)) == 0){
end_op();
cprintf("exec: fail\n");
return -1;
}
ilock(ip);
Expand Down Expand Up @@ -89,15 +91,15 @@ exec(char *path, char **argv)
for(last=s=path; *s; s++)
if(*s == '/')
last = s+1;
safestrcpy(proc->name, last, sizeof(proc->name));
safestrcpy(curproc->name, last, sizeof(curproc->name));

// Commit to the user image.
oldpgdir = proc->pgdir;
proc->pgdir = pgdir;
proc->sz = sz;
proc->tf->eip = elf.entry; // main
proc->tf->esp = sp;
switchuvm(proc);
oldpgdir = curproc->pgdir;
curproc->pgdir = pgdir;
curproc->sz = sz;
curproc->tf->eip = elf.entry; // main
curproc->tf->esp = sp;
switchuvm(curproc);
freevm(oldpgdir);
return 0;

Expand Down
11 changes: 2 additions & 9 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ iinit(int dev)
for(i = 0; i < NINODE; i++) {
initsleeplock(&icache.inode[i].lock, "inode");
}

readsb(dev, &sb);
cprintf("sb: size %d nblocks %d ninodes %d nlog %d logstart %d\
inodestart %d bmap start %d\n", sb.size, sb.nblocks,
Expand Down Expand Up @@ -451,13 +451,6 @@ readi(struct inode *ip, char *dst, uint off, uint n)
for(tot=0; tot<n; tot+=m, off+=m, dst+=m){
bp = bread(ip->dev, bmap(ip, off/BSIZE));
m = min(n - tot, BSIZE - off%BSIZE);
/*
cprintf("data off %d:\n", off);
for (int j = 0; j < min(m, 10); j++) {
cprintf("%x ", bp->data[off%BSIZE+j]);
}
cprintf("\n");
*/
memmove(dst, bp->data + off%BSIZE, m);
brelse(bp);
}
Expand Down Expand Up @@ -617,7 +610,7 @@ namex(char *path, int nameiparent, char *name)
if(*path == '/')
ip = iget(ROOTDEV, ROOTINO);
else
ip = idup(proc->cwd);
ip = idup(myproc()->cwd);

while((path = skipelem(path, name)) != 0){
ilock(ip);
Expand Down
3 changes: 2 additions & 1 deletion ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ ideintr(void)

// First queued buffer is the active request.
acquire(&idelock);

if((b = idequeue) == 0){
release(&idelock);
// cprintf("spurious IDE interrupt\n");
return;
}
idequeue = b->qnext;
Expand Down Expand Up @@ -164,5 +164,6 @@ iderw(struct buf *b)
sleep(b, &idelock);
}


release(&idelock);
}
25 changes: 2 additions & 23 deletions lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "traps.h"
#include "mmu.h"
#include "x86.h"
#include "proc.h" // ncpu

// Local APIC registers, divided by 4 for use as uint[] indices.
#define ID (0x0020/4) // ID
Expand Down Expand Up @@ -99,31 +98,11 @@ lapicinit(void)
}

int
cpunum(void)
lapicid(void)
{
int apicid, i;

// Cannot call cpu when interrupts are enabled:
// result not guaranteed to last long enough to be used!
// Would prefer to panic but even printing is chancy here:
// almost everything, including cprintf and panic, calls cpu,
// often indirectly through acquire and release.
if(readeflags()&FL_IF){
static int n;
if(n++ == 0)
cprintf("cpu called from %x with interrupts enabled\n",
__builtin_return_address(0));
}

if (!lapic)
return 0;

apicid = lapic[ID] >> 24;
for (i = 0; i < ncpu; ++i) {
if (cpus[i].apicid == apicid)
return i;
}
panic("unknown apicid\n");
return lapic[ID] >> 24;
}

// Acknowledge interrupt.
Expand Down
9 changes: 4 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ main(void)
mpinit(); // detect other processors
lapicinit(); // interrupt controller
seginit(); // segment descriptors
cprintf("\ncpu%d: starting xv6\n\n", cpunum());
picinit(); // another interrupt controller
ioapicinit(); // another interrupt controller
consoleinit(); // console hardware
Expand All @@ -31,7 +30,7 @@ main(void)
tvinit(); // trap vectors
binit(); // buffer cache
fileinit(); // file table
ideinit(); // disk
ideinit(); // disk
if(!ismp)
timerinit(); // uniprocessor timer
startothers(); // start other processors
Expand All @@ -54,9 +53,9 @@ mpenter(void)
static void
mpmain(void)
{
cprintf("cpu%d: starting\n", cpunum());
cprintf("cpu%d: starting %d\n", cpuid(), cpuid());
idtinit(); // load idt register
xchg(&cpu->started, 1); // tell startothers() we're up
xchg(&(mycpu()->started), 1); // tell startothers() we're up
scheduler(); // start running processes
}

Expand All @@ -78,7 +77,7 @@ startothers(void)
memmove(code, _binary_entryother_start, (uint)_binary_entryother_size);

for(c = cpus; c < cpus+ncpu; c++){
if(c == cpus+cpunum()) // We've started already.
if(c == mycpu()) // We've started already.
continue;

// Tell entryother.S what stack to use, where to enter, and what
Expand Down
9 changes: 4 additions & 5 deletions mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@
// various segment selectors.
#define SEG_KCODE 1 // kernel code
#define SEG_KDATA 2 // kernel data+stack
#define SEG_KCPU 3 // kernel per-cpu data
#define SEG_UCODE 4 // user code
#define SEG_UDATA 5 // user data+stack
#define SEG_TSS 6 // this process's task state
#define SEG_UCODE 3 // user code
#define SEG_UDATA 4 // user data+stack
#define SEG_TSS 5 // this process's task state

// cpu->gdt[NSEGS] holds the above segments.
#define NSEGS 7
#define NSEGS 6

//PAGEBREAK!
#ifndef __ASSEMBLER__
Expand Down
4 changes: 2 additions & 2 deletions pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pipewrite(struct pipe *p, char *addr, int n)
acquire(&p->lock);
for(i = 0; i < n; i++){
while(p->nwrite == p->nread + PIPESIZE){ //DOC: pipewrite-full
if(p->readopen == 0 || proc->killed){
if(p->readopen == 0 || myproc()->killed){
release(&p->lock);
return -1;
}
Expand All @@ -104,7 +104,7 @@ piperead(struct pipe *p, char *addr, int n)

acquire(&p->lock);
while(p->nread == p->nwrite && p->writeopen){ //DOC: pipe-empty
if(proc->killed){
if(myproc()->killed){
release(&p->lock);
return -1;
}
Expand Down
Loading

0 comments on commit 1427028

Please sign in to comment.