Skip to content

Commit

Permalink
assorted fixes:
Browse files Browse the repository at this point in the history
 * rename c/cp to cpu/proc
 * rename cpu.context to cpu.scheduler
 * fix some comments
 * formatting for printout
  • Loading branch information
rsc committed Aug 31, 2009
1 parent 0aef891 commit 4875521
Show file tree
Hide file tree
Showing 23 changed files with 155 additions and 156 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump
CFLAGS = -fno-builtin -O2 -Wall -MD -ggdb -m32
CFLAGS = -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASFLAGS = -m32
# FreeBSD ld wants ``elf_i386_fbsd''
Expand Down
6 changes: 3 additions & 3 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cprintf(char *fmt, ...)
if(locking)
acquire(&cons.lock);

argp = (uint*)(void*)&fmt + 1;
argp = (uint*)(void*)(&fmt + 1);
state = 0;
for(i = 0; (c = fmt[i] & 0xff) != 0; i++){
if(c != '%'){
Expand Down Expand Up @@ -106,7 +106,7 @@ panic(char *s)

cli();
cons.locking = 0;
cprintf("cpu%d: panic: ", cpu());
cprintf("cpu%d: panic: ", cpu->id);
cprintf(s);
cprintf("\n");
getcallerpcs(&s, pcs);
Expand Down Expand Up @@ -229,7 +229,7 @@ consoleread(struct inode *ip, char *dst, int n)
acquire(&input.lock);
while(n > 0){
while(input.r == input.w){
if(cp->killed){
if(proc->killed){
release(&input.lock);
ilock(ip);
return -1;
Expand Down
2 changes: 1 addition & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void kinit(void);
void kbdintr(void);

// lapic.c
int cpu(void);
int cpunum(void);
extern volatile uint* lapic;
void lapiceoi(void);
void lapicinit(int);
Expand Down
14 changes: 7 additions & 7 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exec(char *path, char **argv)
{
char *mem, *s, *last;
int i, argc, arglen, len, off;
uint sz, sp, argp, x;
uint sz, sp, argp;
struct elfhdr elf;
struct inode *ip;
struct proghdr ph;
Expand Down Expand Up @@ -103,14 +103,14 @@ exec(char *path, char **argv)
for(last=s=path; *s; s++)
if(*s == '/')
last = s+1;
safestrcpy(cp->name, last, sizeof(cp->name));
safestrcpy(proc->name, last, sizeof(proc->name));

// Commit to the new image.
kfree(cp->mem, cp->sz);
cp->mem = mem;
cp->sz = sz;
cp->tf->eip = elf.entry; // main
cp->tf->esp = sp;
kfree(proc->mem, proc->sz);
proc->mem = mem;
proc->sz = sz;
proc->tf->eip = elf.entry; // main
proc->tf->esp = sp;
usegment();
return 0;

Expand Down
4 changes: 2 additions & 2 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bfree(int dev, uint b)
// to inodes shared between multiple processes.
//
// ip->ref counts the number of pointer references to this cached
// inode; references are typically kept in struct file and in cp->cwd.
// inode; references are typically kept in struct file and in proc->cwd.
// When ip->ref falls to zero, the inode is no longer cached.
// It is an error to use an inode without holding a reference to it.
//
Expand Down Expand Up @@ -578,7 +578,7 @@ namex(char *path, int nameiparent, char *name)
if(*path == '/')
ip = iget(ROOTDEV, ROOTINO);
else
ip = idup(cp->cwd);
ip = idup(proc->cwd);

while((path = skipelem(path, name)) != 0){
ilock(ip);
Expand Down
2 changes: 1 addition & 1 deletion ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ iderw(struct buf *b)
idestart(b);

// Wait for request to finish.
// Assuming will not sleep too long: ignore cp->killed.
// Assuming will not sleep too long: ignore proc->killed.
while((b->flags & (B_VALID|B_DIRTY)) != B_VALID)
sleep(b, &idelock);

Expand Down
2 changes: 1 addition & 1 deletion lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ lapicinit(int c)
}

int
cpu(void)
cpunum(void)
{
// Cannot call cpu when interrupts are enabled:
// result not guaranteed to last long enough to be used!
Expand Down
20 changes: 10 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "proc.h"
#include "x86.h"

__thread struct cpu *c;
__thread struct proc *cp;
__thread struct cpu *cpu;
__thread struct proc *proc;

static void bootothers(void);
static void mpmain(void) __attribute__((noreturn));
Expand All @@ -22,7 +22,7 @@ main(void)
ioapicinit(); // another interrupt controller
consoleinit(); // I/O devices & their interrupts
uartinit(); // serial port
cprintf("\ncpu%d: starting xv6\n\n", cpu());
cprintf("\ncpu%d: starting xv6\n\n", cpu->id);

kinit(); // physical memory allocator
pinit(); // process table
Expand All @@ -45,14 +45,14 @@ main(void)
static void
mpmain(void)
{
if(cpu() != mpbcpu())
lapicinit(cpu());
if(cpunum() != mpbcpu())
lapicinit(cpunum());
ksegment();
cprintf("cpu%d: mpmain\n", cpu());
cprintf("cpu%d: mpmain\n", cpu->id);
idtinit();
xchg(&c->booted, 1);
xchg(&cpu->booted, 1);

cprintf("cpu%d: scheduling\n", cpu());
cprintf("cpu%d: scheduling\n", cpu->id);
scheduler();
}

Expand All @@ -69,14 +69,14 @@ bootothers(void)
memmove(code, _binary_bootother_start, (uint)_binary_bootother_size);

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

// Fill in %esp, %eip and start code on cpu.
stack = kalloc(KSTACKSIZE);
*(void**)(code-4) = stack + KSTACKSIZE;
*(void**)(code-8) = mpmain;
lapicstartap(c->apicid, (uint)code);
lapicstartap(c->id, (uint)code);

// Wait for cpu to get through bootstrap.
while(c->booted == 0)
Expand Down
16 changes: 8 additions & 8 deletions mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ struct segdesc {
};

// Normal segment
#define SEG(type, base, lim, dpl) (struct segdesc) \
{ ((lim) >> 12) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
type, 1, dpl, 1, (uint) (lim) >> 28, 0, 0, 1, 1, \
(uint) (base) >> 24 }
#define SEG(type, base, lim, dpl) (struct segdesc) \
{ ((lim) >> 12) & 0xffff, (uint)(base) & 0xffff, \
((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \
(uint)(lim) >> 28, 0, 0, 1, 1, (uint)(base) >> 24 }

#define SEG16(type, base, lim, dpl) (struct segdesc) \
{ (lim) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
type, 1, dpl, 1, (uint) (lim) >> 16, 0, 0, 1, 0, \
(uint) (base) >> 24 }
#define SEG16(type, base, lim, dpl) (struct segdesc) \
{ (lim) & 0xffff, (uint)(base) & 0xffff, \
((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \
(uint)(lim) >> 16, 0, 0, 1, 0, (uint)(base) >> 24 }

#define DPL_USER 0x3 // User DPL

Expand Down
11 changes: 6 additions & 5 deletions mp.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,22 @@ mpinit(void)
struct mpproc *proc;
struct mpioapic *ioapic;

bcpu = &cpus[ncpu];
bcpu = &cpus[0];
if((conf = mpconfig(&mp)) == 0)
return;

ismp = 1;
lapic = (uint*)conf->lapicaddr;

for(p=(uchar*)(conf+1), e=(uchar*)conf+conf->length; p<e; ){
switch(*p){
case MPPROC:
proc = (struct mpproc*)p;
cpus[ncpu].apicid = proc->apicid;
if(ncpu != proc->apicid) {
cprintf("mpinit: ncpu=%d apicpid=%d", ncpu, proc->apicid);
panic("mpinit");
}
if(proc->flags & MPBOOT)
bcpu = &cpus[ncpu];
cpus[ncpu].id = ncpu;
ncpu++;
p += sizeof(struct mpproc);
continue;
Expand All @@ -135,7 +137,6 @@ mpinit(void)
panic("mpinit");
}
}

if(mp->imcrp){
// Bochs doesn't support IMCR, so this doesn't run on Bochs.
// But it would on real hardware.
Expand Down
4 changes: 2 additions & 2 deletions pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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 || cp->killed){
if(p->readopen == 0 || proc->killed){
release(&p->lock);
return -1;
}
Expand All @@ -103,7 +103,7 @@ piperead(struct pipe *p, char *addr, int n)

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

0 comments on commit 4875521

Please sign in to comment.