提交 eaea18cb 创建 作者: rsc's avatar rsc

PDF at http://am.lcs.mit.edu/~rsc/xv6.pdf

Various changes made while offline. + bwrite sector argument is redundant; use b->sector. + reformatting of files for nicer PDF page breaks + distinguish between locked, unlocked inodes in type signatures + change FD_FILE to FD_INODE + move userinit (nee proc0init) to proc.c + move ROOTDEV to param.h + always parenthesize sizeof argument
上级 3dcf889c
...@@ -4,47 +4,11 @@ proc.c: ...@@ -4,47 +4,11 @@ proc.c:
and be able to break out with an error return. and be able to break out with an error return.
it is better if you check *before* sleep. it is better if you check *before* sleep.
can swap procdump up after proc_kill
and then have proc_exit and proc_wait on same sheet
sched -> switch2scheduler? or just switch?
factor out switching and scheduling code from process code
shuffle for formatting
syscall.c: syscall.c:
cannot convince runoff1 to split the extern lists to fill previous page completely. cannot convince runoff1 to split the extern lists
to fill previous page completely.
fs.c: split all name operations off in name.c? (starting with namei but
wdir keep in fs.c)
locking?
shuffle for formatting
pipe.c:
more comments?
comment how functions get called?
sysfile.c:
is the sys_exec picture upside down?
can sys_open and sys_exec be simplified any?
general:
sizeof parens?
bio.c:
decide odd or even
bwrite doesn't need a second argument
file.c:
move fileincref onto page 1?
L=$HOME/mit/l
(for i in *.c; do xoc -x xgnu -x ./nodecleq.zeta --typesonly $i; done) 2>&1 | grep warning
saw random sharedfd failure.
why does fdalloc consume reference?
why mkdir and create? formatting:
file.c filewrite leaks onto next page
need to fix PAGEBREAK mechanism
...@@ -117,12 +117,11 @@ bread(uint dev, uint sector) ...@@ -117,12 +117,11 @@ bread(uint dev, uint sector)
// Write buf's contents to disk. // Write buf's contents to disk.
// Must be locked. // Must be locked.
void void
bwrite(struct buf *b, uint sector) bwrite(struct buf *b)
{ {
if((b->flags & B_BUSY) == 0) if((b->flags & B_BUSY) == 0)
panic("bwrite"); panic("bwrite");
ide_rw(b->dev & 0xff, b->sector, b->data, 1, 0);
ide_rw(b->dev & 0xff, sector, b->data, 1, 0);
b->flags |= B_VALID; b->flags |= B_VALID;
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
// * cmain() in this file takes over, // * cmain() in this file takes over,
// reads in the kernel and jumps to it. // reads in the kernel and jumps to it.
//PAGEBREAK!
#include "types.h" #include "types.h"
#include "elf.h" #include "elf.h"
#include "x86.h" #include "x86.h"
...@@ -32,7 +33,6 @@ ...@@ -32,7 +33,6 @@
#define SECTSIZE 512 #define SECTSIZE 512
#define ELFHDR ((struct elfhdr*) 0x10000) // scratch space #define ELFHDR ((struct elfhdr*) 0x10000) // scratch space
void readsect(void*, uint);
void readseg(uint, uint, uint); void readseg(uint, uint, uint);
void void
...@@ -64,32 +64,6 @@ bad: ...@@ -64,32 +64,6 @@ bad:
; ;
} }
// Read 'count' bytes at 'offset' from kernel into virtual address 'va'.
// Might copy more than asked
void
readseg(uint va, uint count, uint offset)
{
uint end_va;
va &= 0xFFFFFF;
end_va = va + count;
// round down to sector boundary
va &= ~(SECTSIZE - 1);
// translate from bytes to sectors, and kernel starts at sector 1
offset = (offset / SECTSIZE) + 1;
// If this is too slow, we could read lots of sectors at a time.
// We'd write more to memory than asked, but it doesn't matter --
// we load in increasing order.
while(va < end_va) {
readsect((uchar*) va, offset);
va += SECTSIZE;
offset++;
}
}
void void
waitdisk(void) waitdisk(void)
{ {
...@@ -98,6 +72,7 @@ waitdisk(void) ...@@ -98,6 +72,7 @@ waitdisk(void)
; ;
} }
// Read a single sector at offset into dst.
void void
readsect(void *dst, uint offset) readsect(void *dst, uint offset)
{ {
...@@ -118,3 +93,29 @@ readsect(void *dst, uint offset) ...@@ -118,3 +93,29 @@ readsect(void *dst, uint offset)
insl(0x1F0, dst, SECTSIZE/4); insl(0x1F0, dst, SECTSIZE/4);
} }
// Read 'count' bytes at 'offset' from kernel into virtual address 'va'.
// Might copy more than asked.
void
readseg(uint va, uint count, uint offset)
{
uint end_va;
va &= 0xFFFFFF;
end_va = va + count;
// round down to sector boundary
va &= ~(SECTSIZE - 1);
// translate from bytes to sectors, and kernel starts at sector 1
offset = (offset / SECTSIZE) + 1;
// If this is too slow, we could read lots of sectors at a time.
// We'd write more to memory than asked, but it doesn't matter --
// we load in increasing order.
while(va < end_va) {
readsect((uchar*) va, offset);
va += SECTSIZE;
offset++;
}
}
...@@ -24,6 +24,7 @@ int proc_kill(int); ...@@ -24,6 +24,7 @@ int proc_kill(int);
int proc_wait(void); int proc_wait(void);
void yield(void); void yield(void);
void procdump(void); void procdump(void);
void userinit(void);
// setjmp.S // setjmp.S
struct jmpbuf; struct jmpbuf;
...@@ -117,30 +118,31 @@ void ide_rw(int, uint, void*, uint, int); ...@@ -117,30 +118,31 @@ void ide_rw(int, uint, void*, uint, int);
void binit(void); void binit(void);
struct buf; struct buf;
struct buf* bread(uint, uint); struct buf* bread(uint, uint);
void bwrite(struct buf*, uint); void bwrite(struct buf*);
void brelse(struct buf*); void brelse(struct buf*);
// fs.c // fs.c
struct inode; struct inode;
struct uinode;
void iinit(void); void iinit(void);
void ilock(struct inode*); struct inode* ilock(struct uinode*);
void iunlock(struct inode*); struct uinode* iunlock(struct inode*);
void idecref(struct inode*); void iput(struct uinode*);
struct inode* iincref(struct inode*); struct uinode* idup(struct uinode*);
void iput(struct inode*); struct uinode* namei(char*);
struct inode* namei(char*);
void stati(struct inode*, struct stat*); void stati(struct inode*, struct stat*);
int readi(struct inode*, char*, uint, uint); int readi(struct inode*, char*, uint, uint);
int writei(struct inode*, char*, uint, uint); int writei(struct inode*, char*, uint, uint);
struct inode* mknod(char*, short, short, short); int dirlink(struct inode *dp, char *name, uint ino);
int unlink(char*); struct uinode* dirlookup(struct inode *dp, char *name, uint *poff);
int link(char*, char*); void iupdate(struct inode *ip);
struct inode* igetroot(void); int namecmp(const char *s, const char *t);
int mkdir(char *path); struct uinode* ialloc(uint, short);
struct inode* create(char *path); struct uinode* nameiparent(char *path, char *name);
// exec.c // exec.c
int exec(char*, char**); int exec(char*, char**);
// number of elements in fixed-size array // number of elements in fixed-size array
#define NELEM(x) (sizeof(x)/sizeof((x)[0])) #define NELEM(x) (sizeof(x)/sizeof((x)[0]))
...@@ -19,7 +19,7 @@ int ...@@ -19,7 +19,7 @@ int
exec(char *path, char **argv) exec(char *path, char **argv)
{ {
uint sz, sp, p1, p2; uint sz, sp, p1, p2;
int i, nargs, argbytes, len; int i, nargs, argbytes, len, off;
struct inode *ip; struct inode *ip;
struct elfhdr elf; struct elfhdr elf;
struct proghdr ph; struct proghdr ph;
...@@ -29,7 +29,7 @@ exec(char *path, char **argv) ...@@ -29,7 +29,7 @@ exec(char *path, char **argv)
sz = 0; sz = 0;
mem = 0; mem = 0;
if((ip = namei(path)) == 0) if((ip = ilock(namei(path))) == 0)
return -1; return -1;
if(readi(ip, (char*)&elf, 0, sizeof(elf)) < sizeof(elf)) if(readi(ip, (char*)&elf, 0, sizeof(elf)) < sizeof(elf))
...@@ -38,9 +38,8 @@ exec(char *path, char **argv) ...@@ -38,9 +38,8 @@ exec(char *path, char **argv)
if(elf.magic != ELF_MAGIC) if(elf.magic != ELF_MAGIC)
goto bad; goto bad;
for(i = 0; i < elf.phnum; i++){ for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){
if(readi(ip, (char*)&ph, elf.phoff + i * sizeof(ph), if(readi(ip, (char*)&ph, off, sizeof(ph)) != sizeof(ph))
sizeof(ph)) != sizeof(ph))
goto bad; goto bad;
if(ph.type != ELF_PROG_LOAD) if(ph.type != ELF_PROG_LOAD)
continue; continue;
...@@ -94,7 +93,7 @@ exec(char *path, char **argv) ...@@ -94,7 +93,7 @@ exec(char *path, char **argv)
for(last=s=path; *s; s++) for(last=s=path; *s; s++)
if(*s == '/') if(*s == '/')
last = s+1; last = s+1;
safestrcpy(cp->name, last, sizeof cp->name); safestrcpy(cp->name, last, sizeof(cp->name));
// commit to the new image. // commit to the new image.
kfree(cp->mem, cp->sz); kfree(cp->mem, cp->sz);
...@@ -102,9 +101,8 @@ exec(char *path, char **argv) ...@@ -102,9 +101,8 @@ exec(char *path, char **argv)
cp->mem = mem; cp->mem = mem;
mem = 0; mem = 0;
for(i = 0; i < elf.phnum; i++){ for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){
if(readi(ip, (char*)&ph, elf.phoff + i * sizeof(ph), if(readi(ip, (char*)&ph, off, sizeof(ph)) != sizeof(ph))
sizeof(ph)) != sizeof(ph))
goto bad2; goto bad2;
if(ph.type != ELF_PROG_LOAD) if(ph.type != ELF_PROG_LOAD)
continue; continue;
...@@ -115,7 +113,7 @@ exec(char *path, char **argv) ...@@ -115,7 +113,7 @@ exec(char *path, char **argv)
memset(cp->mem + ph.va + ph.filesz, 0, ph.memsz - ph.filesz); memset(cp->mem + ph.va + ph.filesz, 0, ph.memsz - ph.filesz);
} }
iput(ip); iput(iunlock(ip));
cp->tf->eip = elf.entry; cp->tf->eip = elf.entry;
cp->tf->esp = sp; cp->tf->esp = sp;
...@@ -126,11 +124,11 @@ exec(char *path, char **argv) ...@@ -126,11 +124,11 @@ exec(char *path, char **argv)
bad: bad:
if(mem) if(mem)
kfree(mem, sz); kfree(mem, sz);
iput(ip); iput(iunlock(ip));
return -1; return -1;
bad2: bad2:
iput(ip); iput(iunlock(ip));
proc_exit(); proc_exit();
return 0; return 0;
} }
...@@ -11,9 +11,8 @@ ...@@ -11,9 +11,8 @@
#include "fs.h" #include "fs.h"
#include "fsvar.h" #include "fsvar.h"
struct spinlock file_table_lock;
struct devsw devsw[NDEV]; struct devsw devsw[NDEV];
struct spinlock file_table_lock;
struct file file[NFILE]; struct file file[NFILE];
void void
...@@ -22,7 +21,7 @@ fileinit(void) ...@@ -22,7 +21,7 @@ fileinit(void)
initlock(&file_table_lock, "file_table"); initlock(&file_table_lock, "file_table");
} }
// Allocate a file structure // Allocate a file structure.
struct file* struct file*
filealloc(void) filealloc(void)
{ {
...@@ -57,16 +56,17 @@ int ...@@ -57,16 +56,17 @@ int
fileread(struct file *f, char *addr, int n) fileread(struct file *f, char *addr, int n)
{ {
int r; int r;
struct inode *ip;
if(f->readable == 0) if(f->readable == 0)
return -1; return -1;
if(f->type == FD_PIPE) if(f->type == FD_PIPE)
return pipe_read(f->pipe, addr, n); return pipe_read(f->pipe, addr, n);
if(f->type == FD_FILE){ if(f->type == FD_INODE){
ilock(f->ip); ip = ilock(f->ip);
if((r = readi(f->ip, addr, f->off, n)) > 0) if((r = readi(ip, addr, f->off, n)) > 0)
f->off += r; f->off += r;
iunlock(f->ip); iunlock(ip);
return r; return r;
} }
panic("fileread"); panic("fileread");
...@@ -77,16 +77,17 @@ int ...@@ -77,16 +77,17 @@ int
filewrite(struct file *f, char *addr, int n) filewrite(struct file *f, char *addr, int n)
{ {
int r; int r;
struct inode *ip;
if(f->writable == 0) if(f->writable == 0)
return -1; return -1;
if(f->type == FD_PIPE) if(f->type == FD_PIPE)
return pipe_write(f->pipe, addr, n); return pipe_write(f->pipe, addr, n);
if(f->type == FD_FILE){ if(f->type == FD_INODE){
ilock(f->ip); ip = ilock(f->ip);
if((r = writei(f->ip, addr, f->off, n)) > 0) if((r = writei(ip, addr, f->off, n)) > 0)
f->off += r; f->off += r;
iunlock(f->ip); iunlock(ip);
return r; return r;
} }
panic("filewrite"); panic("filewrite");
...@@ -96,10 +97,12 @@ filewrite(struct file *f, char *addr, int n) ...@@ -96,10 +97,12 @@ filewrite(struct file *f, char *addr, int n)
int int
filestat(struct file *f, struct stat *st) filestat(struct file *f, struct stat *st)
{ {
if(f->type == FD_FILE){ struct inode *ip;
ilock(f->ip);
stati(f->ip, st); if(f->type == FD_INODE){
iunlock(f->ip); ip = ilock(f->ip);
stati(ip, st);
iunlock(ip);
return 0; return 0;
} }
return -1; return -1;
...@@ -110,6 +113,7 @@ void ...@@ -110,6 +113,7 @@ void
fileclose(struct file *f) fileclose(struct file *f)
{ {
struct file ff; struct file ff;
acquire(&file_table_lock); acquire(&file_table_lock);
if(f->ref < 1 || f->type == FD_CLOSED) if(f->ref < 1 || f->type == FD_CLOSED)
...@@ -127,8 +131,8 @@ fileclose(struct file *f) ...@@ -127,8 +131,8 @@ fileclose(struct file *f)
if(ff.type == FD_PIPE) if(ff.type == FD_PIPE)
pipe_close(ff.pipe, ff.writable); pipe_close(ff.pipe, ff.writable);
else if(ff.type == FD_FILE) else if(ff.type == FD_INODE)
idecref(ff.ip); iput(ff.ip);
else else
panic("fileclose"); panic("fileclose");
} }
......
struct file { struct file {
enum { FD_CLOSED, FD_NONE, FD_PIPE, FD_FILE } type; enum { FD_CLOSED, FD_NONE, FD_PIPE, FD_INODE } type;
int ref; // reference count int ref; // reference count
char readable; char readable;
char writable; char writable;
struct pipe *pipe; struct pipe *pipe;
struct inode *ip; struct uinode *ip;
uint off; uint off;
}; };
差异被折叠。
...@@ -14,7 +14,11 @@ struct inode { ...@@ -14,7 +14,11 @@ struct inode {
uint addrs[NADDRS]; uint addrs[NADDRS];
}; };
#define ROOTDEV 1 // Device number of root file system // unlocked inode - only dev and inum are available
struct uinode {
uint dev;
uint inum;
};
#define I_BUSY 0x1 #define I_BUSY 0x1
#define I_VALID 0x2 #define I_VALID 0x2
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
extern char edata[], end[]; extern char edata[], end[];
void proc0init();
// Bootstrap processor starts running C code here. // Bootstrap processor starts running C code here.
// This is called main0 not main so that it can have // This is called main0 not main so that it can have
// a void return type. Gcc can't handle functions named // a void return type. Gcc can't handle functions named
...@@ -35,49 +33,37 @@ main0(void) ...@@ -35,49 +33,37 @@ main0(void)
bcpu = mp_bcpu(); bcpu = mp_bcpu();
// switch to bootstrap processor's stack // switch to bootstrap processor's stack
asm volatile("movl %0, %%esp" : : "r" (cpus[bcpu].mpstack + MPSTACK - 32)); asm volatile("movl %0, %%esp" : : "r" (cpus[bcpu].mpstack+MPSTACK-32));
asm volatile("movl %0, %%ebp" : : "r" (cpus[bcpu].mpstack + MPSTACK)); asm volatile("movl %0, %%ebp" : : "r" (cpus[bcpu].mpstack+MPSTACK));
lapic_init(bcpu); lapic_init(bcpu);
cprintf("\ncpu%d: starting xv6\n\n", cpu()); cprintf("\ncpu%d: starting xv6\n\n", cpu());
pinit(); // process table pinit(); // process table
binit(); // buffer cache binit(); // buffer cache
pic_init(); pic_init(); // interrupt controller
ioapic_init(); ioapic_init(); // another interrupt controller
kinit(); // physical memory allocator kinit(); // physical memory allocator
tvinit(); // trap vectors tvinit(); // trap vectors
idtinit(); // this CPU's interrupt descriptor table idtinit(); // interrupt descriptor table
fileinit(); fileinit(); // file table
iinit(); // i-node table iinit(); // inode cache
setupsegs(0); // segments & TSS
// make sure there's a TSS console_init(); // I/O devices & their interrupts
setupsegs(0); ide_init(); // disk
mp_startthem(); // other CPUs
// initialize I/O devices, let them enable interrupts if(ismp){
console_init(); lapic_timerinit(); // smp timer
ide_init(); lapic_enableintr(); // local interrupts
}else
// start other CPUs pit8253_timerinit(); // uniprocessor timer
mp_startthem(); userinit(); // first user process
// turn on timer
if(ismp)
lapic_timerinit();
else
pit8253_timerinit();
// enable interrupts on the local APIC
lapic_enableintr();
// enable interrupts on this processor. // enable interrupts on this processor.
cpus[cpu()].nlock--; cpus[cpu()].nlock--;
sti(); sti();
// initialize process 0
proc0init();
scheduler(); scheduler();
} }
...@@ -106,29 +92,3 @@ mpmain(void) ...@@ -106,29 +92,3 @@ mpmain(void)
scheduler(); scheduler();
} }
void
proc0init(void)
{
struct proc *p;
extern uchar _binary_initcode_start[], _binary_initcode_size[];
p = copyproc(0);
p->sz = PAGE;
p->mem = kalloc(p->sz);
p->cwd = igetroot();
memset(&p->tf, 0, sizeof p->tf);
p->tf->es = p->tf->ds = p->tf->ss = (SEG_UDATA << 3) | DPL_USER;
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p->tf->eflags = FL_IF;
p->tf->esp = p->sz;
// Push dummy return address to placate gcc.
p->tf->esp -= 4;
*(uint*)(p->mem + p->tf->esp) = 0xefefefef;
p->tf->eip = 0;
memmove(p->mem, _binary_initcode_start, (int)_binary_initcode_size);
safestrcpy(p->name, "initcode", sizeof p->name);
p->state = RUNNABLE;
}
...@@ -8,3 +8,4 @@ ...@@ -8,3 +8,4 @@
#define NBUF 10 // size of disk block cache #define NBUF 10 // size of disk block cache
#define NINODE 100 // maximum number of active i-nodes #define NINODE 100 // maximum number of active i-nodes
#define NDEV 10 // maximum major device number #define NDEV 10 // maximum major device number
#define ROOTDEV 1 // device number of file system root disk
...@@ -11,7 +11,7 @@ struct spinlock proc_table_lock; ...@@ -11,7 +11,7 @@ struct spinlock proc_table_lock;
struct proc proc[NPROC]; struct proc proc[NPROC];
struct proc *curproc[NCPU]; struct proc *curproc[NCPU];
int next_pid = 1; int nextpid = 1;
extern void forkret(void); extern void forkret(void);
extern void forkret1(struct trapframe*); extern void forkret1(struct trapframe*);
...@@ -21,37 +21,27 @@ pinit(void) ...@@ -21,37 +21,27 @@ pinit(void)
initlock(&proc_table_lock, "proc_table"); initlock(&proc_table_lock, "proc_table");
} }
// Set up CPU's segment descriptors and task state for a // Look in the process table for an UNUSED proc.
// given process. // If found, change state to EMBRYO and return it.
// If p==0, set up for "idle" state for when scheduler() // Otherwise return 0.
// is idling, not running any process. static struct proc*
void allocproc(void)
setupsegs(struct proc *p)
{ {
struct cpu *c = &cpus[cpu()]; int i;
struct proc *p;
c->ts.ss0 = SEG_KDATA << 3;
if(p){
c->ts.esp0 = (uint)(p->kstack + KSTACKSIZE);
} else {
c->ts.esp0 = 0xffffffff;
}
c->gdt[0] = SEG_NULL; acquire(&proc_table_lock);
c->gdt[SEG_KCODE] = SEG(STA_X|STA_R, 0, 0x100000 + 64*1024-1, 0); for(i = 0; i < NPROC; i++){
c->gdt[SEG_KDATA] = SEG(STA_W, 0, 0xffffffff, 0); p = &proc[i];
c->gdt[SEG_TSS] = SEG16(STS_T32A, (uint)&c->ts, sizeof(c->ts)-1, 0); if(p->state == UNUSED){
c->gdt[SEG_TSS].s = 0; p->state = EMBRYO;
if(p){ p->pid = nextpid++;
c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz-1, DPL_USER); release(&proc_table_lock);
c->gdt[SEG_UDATA] = SEG(STA_W, (uint)p->mem, p->sz-1, DPL_USER); return p;
} else { }
c->gdt[SEG_UCODE] = SEG_NULL;
c->gdt[SEG_UDATA] = SEG_NULL;
} }
release(&proc_table_lock);
lgdt(c->gdt, sizeof c->gdt); return 0;
ltr(SEG_TSS << 3);
} }
// Grow current process's memory by n bytes. // Grow current process's memory by n bytes.
...@@ -73,29 +63,41 @@ growproc(int n) ...@@ -73,29 +63,41 @@ growproc(int n)
return cp->sz - n; return cp->sz - n;
} }
// Look in the process table for an UNUSED proc. // Set up CPU's segment descriptors and task state for a
// If found, change state to EMBRYO and return it. // given process.
// Otherwise return 0. // If p==0, set up for "idle" state for when scheduler()
struct proc* // is idling, not running any process.
allocproc(void) void
setupsegs(struct proc *p)
{ {
int i; struct cpu *c = &cpus[cpu()];
struct proc *p;
for(i = 0; i < NPROC; i++){ c->ts.ss0 = SEG_KDATA << 3;
p = &proc[i]; if(p)
if(p->state == UNUSED){ c->ts.esp0 = (uint)(p->kstack + KSTACKSIZE);
p->state = EMBRYO; else
return p; c->ts.esp0 = 0xffffffff;
}
c->gdt[0] = SEG_NULL;
c->gdt[SEG_KCODE] = SEG(STA_X|STA_R, 0, 0x100000 + 64*1024-1, 0);
c->gdt[SEG_KDATA] = SEG(STA_W, 0, 0xffffffff, 0);
c->gdt[SEG_TSS] = SEG16(STS_T32A, (uint)&c->ts, sizeof(c->ts)-1, 0);
c->gdt[SEG_TSS].s = 0;
if(p){
c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, (uint)p->mem, p->sz-1, DPL_USER);
c->gdt[SEG_UDATA] = SEG(STA_W, (uint)p->mem, p->sz-1, DPL_USER);
} else {
c->gdt[SEG_UCODE] = SEG_NULL;
c->gdt[SEG_UDATA] = SEG_NULL;
} }
return 0;
lgdt(c->gdt, sizeof(c->gdt));
ltr(SEG_TSS << 3);
} }
// Create a new process copying p as the parent. // Create a new process copying p as the parent.
// Does not copy the kernel stack. // Sets up stack to return as if from system call.
// Instead, sets up stack to return as if from system call. // Caller must set state of returned proc to RUNNABLE.
// Caller must arrange for process to run (set state to RUNNABLE).
struct proc* struct proc*
copyproc(struct proc *p) copyproc(struct proc *p)
{ {
...@@ -103,13 +105,8 @@ copyproc(struct proc *p) ...@@ -103,13 +105,8 @@ copyproc(struct proc *p)
struct proc *np; struct proc *np;
// Allocate process. // Allocate process.
acquire(&proc_table_lock); if((np = allocproc()) == 0)
if((np = allocproc()) == 0){
release(&proc_table_lock);
return 0; return 0;
}
np->pid = next_pid++;
release(&proc_table_lock);
// Allocate kernel stack. // Allocate kernel stack.
if((np->kstack = kalloc(KSTACKSIZE)) == 0){ if((np->kstack = kalloc(KSTACKSIZE)) == 0){
...@@ -120,7 +117,7 @@ copyproc(struct proc *p) ...@@ -120,7 +117,7 @@ copyproc(struct proc *p)
if(p){ // Copy process state from p. if(p){ // Copy process state from p.
np->ppid = p->pid; np->ppid = p->pid;
memmove(np->tf, p->tf, sizeof *np->tf); memmove(np->tf, p->tf, sizeof(*np->tf));
np->sz = p->sz; np->sz = p->sz;
if((np->mem = kalloc(np->sz)) == 0){ if((np->mem = kalloc(np->sz)) == 0){
...@@ -132,24 +129,49 @@ copyproc(struct proc *p) ...@@ -132,24 +129,49 @@ copyproc(struct proc *p)
memmove(np->mem, p->mem, np->sz); memmove(np->mem, p->mem, np->sz);
for(i = 0; i < NOFILE; i++){ for(i = 0; i < NOFILE; i++){
np->ofile[i] = p->ofile[i]; if((np->ofile[i] = p->ofile[i]) != 0)
if(np->ofile[i])
fileincref(np->ofile[i]); fileincref(np->ofile[i]);
} }
np->cwd = iincref(p->cwd); np->cwd = idup(p->cwd);
} }
// Set up new jmpbuf to start executing at forkret (see below). // Set up new jmpbuf to start executing at forkret (see below).
memset(&np->jmpbuf, 0, sizeof np->jmpbuf); memset(&np->jmpbuf, 0, sizeof(np->jmpbuf));
np->jmpbuf.eip = (uint)forkret; np->jmpbuf.eip = (uint)forkret;
np->jmpbuf.esp = (uint)np->tf - 4; np->jmpbuf.esp = (uint)np->tf - 4;
// Clear %eax so that fork system call returns 0 in child. // Clear %eax so that fork system call returns 0 in child.
np->tf->eax = 0; np->tf->eax = 0;
return np; return np;
} }
// Set up first user process.
void
userinit(void)
{
struct proc *p;
extern uchar _binary_initcode_start[], _binary_initcode_size[];
p = copyproc(0);
p->sz = PAGE;
p->mem = kalloc(p->sz);
p->cwd = namei("/");
memset(&p->tf, 0, sizeof(p->tf));
p->tf->es = p->tf->ds = p->tf->ss = (SEG_UDATA << 3) | DPL_USER;
p->tf->cs = (SEG_UCODE << 3) | DPL_USER;
p->tf->eflags = FL_IF;
p->tf->esp = p->sz;
// Push dummy return address to placate gcc.
p->tf->esp -= 4;
*(uint*)(p->mem + p->tf->esp) = 0xefefefef;
p->tf->eip = 0;
memmove(p->mem, _binary_initcode_start, (int)_binary_initcode_size);
safestrcpy(p->name, "initcode", sizeof(p->name));
p->state = RUNNABLE;
}
//PAGEBREAK: 42 //PAGEBREAK: 42
// Per-CPU process scheduler. // Per-CPU process scheduler.
// Each CPU calls scheduler() after setting itself up. // Each CPU calls scheduler() after setting itself up.
...@@ -269,6 +291,7 @@ sleep(void *chan, struct spinlock *lk) ...@@ -269,6 +291,7 @@ sleep(void *chan, struct spinlock *lk)
} }
} }
//PAGEBREAK!
// Wake up all processes sleeping on chan. // Wake up all processes sleeping on chan.
// Proc_table_lock must be held. // Proc_table_lock must be held.
void void
...@@ -334,7 +357,7 @@ proc_exit(void) ...@@ -334,7 +357,7 @@ proc_exit(void)
} }
} }
idecref(cp->cwd); iput(cp->cwd);
cp->cwd = 0; cp->cwd = 0;
acquire(&proc_table_lock); acquire(&proc_table_lock);
......
...@@ -37,7 +37,7 @@ struct proc { ...@@ -37,7 +37,7 @@ struct proc {
void *chan; // If non-zero, sleeping on chan void *chan; // If non-zero, sleeping on chan
int killed; // If non-zero, have been killed int killed; // If non-zero, have been killed
struct file *ofile[NOFILE]; // Open files struct file *ofile[NOFILE]; // Open files
struct inode *cwd; // Current directory struct uinode *cwd; // Current directory
struct jmpbuf jmpbuf; // Jump here to run process struct jmpbuf jmpbuf; // Jump here to run process
struct trapframe *tf; // Trap frame for current interrupt struct trapframe *tf; // Trap frame for current interrupt
char name[16]; // Process name (debugging) char name[16]; // Process name (debugging)
...@@ -49,8 +49,6 @@ struct proc { ...@@ -49,8 +49,6 @@ struct proc {
// fixed-size stack // fixed-size stack
// expandable heap // expandable heap
extern struct proc proc[];
// If xv6 was only for uniprocessors, this could be // If xv6 was only for uniprocessors, this could be
// struct proc *cp; // struct proc *cp;
// Instead we have an array curproc, one per // Instead we have an array curproc, one per
......
...@@ -13,7 +13,7 @@ bootasm.S ...@@ -13,7 +13,7 @@ bootasm.S
bootother.S bootother.S
bootmain.c bootmain.c
main.c main.c
mp.c initcode.S
init.c init.c
# locks # locks
...@@ -27,11 +27,11 @@ setjmp.S ...@@ -27,11 +27,11 @@ setjmp.S
kalloc.c kalloc.c
# system calls # system calls
syscall.h
trapasm.S
traps.h traps.h
trap.c
vectors.pl vectors.pl
trapasm.S
trap.c
syscall.h
syscall.c syscall.c
sysproc.c sysproc.c
...@@ -46,6 +46,7 @@ fsvar.h ...@@ -46,6 +46,7 @@ fsvar.h
ide.c ide.c
bio.c bio.c
fs.c fs.c
exec.c
file.c file.c
sysfile.c sysfile.c
...@@ -56,10 +57,11 @@ pipe.c ...@@ -56,10 +57,11 @@ pipe.c
string.c string.c
# low-level PC # low-level PC
mp.c
ioapic.h ioapic.h
lapic.c lapic.c
ioapic.c ioapic.c
picirq.c picirq.c
kbd.h kbd.h
console.c console.c
8253pit.c 8253pit.c
\ No newline at end of file
even: mmu.h # types.h either
even: bootasm.S # param.h either
even: bootother.S # defs.h either
even: bootmain.c # x86.h either
# asm.h either
# mmu.h either
# elf.h either
# mp.h either
even: bootasm.S # mild preference
even: bootother.S # mild preference
# bootmain.c either
even: main.c even: main.c
even: spinlock.c # mp.c don't care at all
even: proc.h even: initcode.S
even: proc.c odd: init.c
odd: kalloc.c
even: trap.c # spinlock.h either
odd: bio.c # spinlock.c either
even: proc.h # mild preference
even: proc.c # VERY important
# setjmp.S either
# kalloc.c either
# syscall.h either
# trapasm.S either
# traps.h either
even: trap.c # important
# vectors.pl either
# syscall.c either
# sysproc.c either
# buf.h either
# dev.h either
# fcntl.h either
# stat.h either
# file.h either
# fs.h either
# fsvar.h either
# even: ide.c
# odd: bio.c
odd: fs.c # VERY important
# file.c either
# exec.c either
# sysfile.c either
even: pipe.c # mild preference
# string.c either
# even: console.c
...@@ -45,6 +45,12 @@ for($i=0; $i<@lines; ){ ...@@ -45,6 +45,12 @@ for($i=0; $i<@lines; ){
$sawbrace = 0; $sawbrace = 0;
$breaksize = 15; # 15 lines to get to function $breaksize = 15; # 15 lines to get to function
for($j=$i; $j<$i+50 && $j < @lines; $j++){ for($j=$i; $j<$i+50 && $j < @lines; $j++){
if($lines[$j] =~ /PAGEBREAK!/){
$lines[$j] = "";
$breakbefore = $j;
$breaksize = 100;
last;
}
if($lines[$j] =~ /PAGEBREAK:\s*([0-9]+)/){ if($lines[$j] =~ /PAGEBREAK:\s*([0-9]+)/){
$breaksize = $1; $breaksize = $1;
$breakbefore = $j; $breakbefore = $j;
......
...@@ -41,7 +41,7 @@ int _gettoken(char *s, char **p1, char **p2); ...@@ -41,7 +41,7 @@ int _gettoken(char *s, char **p1, char **p2);
int int
main(void) main(void)
{ {
while(getcmd(buf, sizeof buf) >= 0) { while(getcmd(buf, sizeof(buf)) >= 0) {
if(parse(buf) >= 0) if(parse(buf) >= 0)
runcmd(); runcmd();
} }
......
#!/bin/sh #!/bin/sh
runoff1 "$@" | pr.pl -h "xv6/$@" | mpage -m50t50b -o -bLetter -T -t -2 -FCourier -L60 >x.ps; gv --swap x.ps runoff1 "$@" | pr.pl -h "xv6/$@" | mpage -m50t50b -o -bLetter -T -t -2 -FLucidaSans-Typewriter83 -L60 >x.ps; gv --swap x.ps
...@@ -36,6 +36,13 @@ getcallerpcs(void *v, uint pcs[]) ...@@ -36,6 +36,13 @@ getcallerpcs(void *v, uint pcs[])
pcs[i] = 0; pcs[i] = 0;
} }
// Check whether this cpu is holding the lock.
int
holding(struct spinlock *lock)
{
return lock->locked && lock->cpu == cpu() + 10;
}
// Acquire the lock. // Acquire the lock.
// Loops (spins) until the lock is acquired. // Loops (spins) until the lock is acquired.
// (Because contention is handled by spinning, // (Because contention is handled by spinning,
...@@ -83,11 +90,3 @@ release(struct spinlock *lock) ...@@ -83,11 +90,3 @@ release(struct spinlock *lock)
if(--cpus[cpu()].nlock == 0) if(--cpus[cpu()].nlock == 0)
sti(); sti();
} }
// Check whether this cpu is holding the lock.
int
holding(struct spinlock *lock)
{
return lock->locked && lock->cpu == cpu() + 10;
}
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "buf.h" #include "buf.h"
#include "fs.h" #include "fs.h"
#include "fsvar.h" #include "fsvar.h"
#include "elf.h"
#include "file.h" #include "file.h"
#include "fcntl.h" #include "fcntl.h"
...@@ -51,27 +50,15 @@ fdalloc(struct file *f) ...@@ -51,27 +50,15 @@ fdalloc(struct file *f)
} }
int int
sys_pipe(void) sys_read(void)
{ {
int *fd; struct file *f;
struct file *rf, *wf; int n;
int fd0, fd1; char *cp;
if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0) if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &cp, n) < 0)
return -1;
if(pipe_alloc(&rf, &wf) < 0)
return -1;
fd0 = -1;
if((fd0 = fdalloc(rf)) < 0 || (fd1 = fdalloc(wf)) < 0){
if(fd0 >= 0)
cp->ofile[fd0] = 0;
fileclose(rf);
fileclose(wf);
return -1; return -1;
} return fileread(f, cp, n);
fd[0] = fd0;
fd[1] = fd1;
return 0;
} }
int int
...@@ -87,15 +74,14 @@ sys_write(void) ...@@ -87,15 +74,14 @@ sys_write(void)
} }
int int
sys_read(void) sys_fstat(void)
{ {
struct file *f; struct file *f;
int n; struct stat *st;
char *cp;
if(argfd(0, 0, &f) < 0 || argptr(1, (void*)&st, sizeof(*st)) < 0)
if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &cp, n) < 0)
return -1; return -1;
return fileread(f, cp, n); return filestat(f, st);
} }
int int
...@@ -111,6 +97,150 @@ sys_close(void) ...@@ -111,6 +97,150 @@ sys_close(void)
return 0; return 0;
} }
// Create the path new as a link to the same inode as old.
int
sys_link(void)
{
char name[DIRSIZ], *new, *old;
struct inode *dp, *ip;
struct uinode *ipu;
if(argstr(0, &old) < 0 || argstr(1, &new) < 0)
return -1;
if((ip = ilock(namei(old))) == 0)
return -1;
if(ip->type == T_DIR){
iput(iunlock(ip));
return -1;
}
ip->nlink++;
iupdate(ip);
ipu = iunlock(ip); ip = 0;
if((dp = ilock(nameiparent(new, name))) == 0 ||
dp->dev != ipu->dev || dirlink(dp, name, ipu->inum) < 0){
if(dp)
iput(iunlock(dp));
ip = ilock(ipu);
ip->nlink--;
iupdate(ip);
iput(iunlock(ip));
return -1;
}
iput(iunlock(dp));
iput(ipu);
return 0;
}
// Is the directory dp empty except for "." and ".." ?
static int
isdirempty(struct inode *dp)
{
int off;
struct dirent de;
for(off=2*sizeof(de); off<dp->size; off+=sizeof(de)){
if(readi(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
panic("isdirempty: readi");
if(de.inum != 0)
return 0;
}
return 1;
}
int
sys_unlink(void)
{
struct inode *ip, *dp;
struct dirent de;
char name[DIRSIZ], *path;
uint off;
if(argstr(0, &path) < 0)
return -1;
if((dp = ilock(nameiparent(path, name))) == 0)
return -1;
// Cannot unlink "." or "..".
if(namecmp(name, ".") == 0 || namecmp(name, "..") == 0){
iput(iunlock(dp));
return -1;
}
if((ip = ilock(dirlookup(dp, name, &off))) == 0){
iput(iunlock(dp));
return -1;
}
if(ip->nlink < 1)
panic("unlink: nlink < 1");
if(ip->type == T_DIR && !isdirempty(ip)){
iput(iunlock(ip));
iput(iunlock(dp));
return -1;
}
memset(&de, 0, sizeof(de));
if(writei(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
panic("unlink: writei");
iput(iunlock(dp));
ip->nlink--;
iupdate(ip);
iput(iunlock(ip));
return 0;
}
// Create the path and return its unlocked inode structure.
static struct inode*
mkpath(char *path, int canexist, short type, short major, short minor)
{
uint off;
struct inode *ip, *dp;
struct uinode *ipu;
char name[DIRSIZ];
if((dp = ilock(nameiparent(path, name))) == 0)
return 0;
if(canexist && (ipu = dirlookup(dp, name, &off)) != 0){
iput(iunlock(dp));
ip = ilock(ipu);
if(ip->type != type || ip->major != major || ip->minor != minor){
iput(iunlock(ip));
return 0;
}
return ip;
}
if((ip = ilock(ialloc(dp->dev, type))) == 0){
iput(iunlock(dp));
return 0;
}
ip->major = major;
ip->minor = minor;
ip->size = 0;
ip->nlink = 1;
iupdate(ip);
if(dirlink(dp, name, ip->inum) < 0){
ip->nlink = 0;
iput(iunlock(ip));
iput(iunlock(dp));
return 0;
}
if(type == T_DIR){ // Create . and .. entries.
dp->nlink++; // for ".."
iupdate(dp);
// No ip->nlink++ for ".": avoid cyclic ref count.
if(dirlink(ip, ".", ip->inum) < 0 || dirlink(ip, "..", dp->inum) < 0)
panic("mkpath dots");
}
iput(iunlock(dp));
return ip;
}
int int
sys_open(void) sys_open(void)
{ {
...@@ -122,30 +252,28 @@ sys_open(void) ...@@ -122,30 +252,28 @@ sys_open(void)
if(argstr(0, &path) < 0 || argint(1, &omode) < 0) if(argstr(0, &path) < 0 || argint(1, &omode) < 0)
return -1; return -1;
if(omode & O_CREATE) if(omode & O_CREATE){
ip = create(path); if((ip = mkpath(path, 1, T_FILE, 0, 0)) == 0)
else return -1;
ip = namei(path); }else{
if(ip == 0) if((ip = ilock(namei(path))) == 0)
return -1; return -1;
if(ip->type == T_DIR && (omode & (O_RDWR|O_WRONLY))){
if(ip->type == T_DIR && (omode & (O_RDWR|O_WRONLY))){ iput(iunlock(ip));
iput(ip); return -1;
return -1; }
} }
if((f = filealloc()) == 0){ if((f = filealloc()) == 0 || (fd = fdalloc(f)) < 0){
iput(ip); if(f)
return -1; fileclose(f);
} iput(iunlock(ip));
if((fd = fdalloc(f)) < 0){
iput(ip);
fileclose(f);
return -1; return -1;
} }
iunlock(ip); f->type = FD_INODE;
f->type = FD_FILE; f->ip = iunlock(ip);
f->off = 0;
if(omode & O_RDWR) { if(omode & O_RDWR) {
f->readable = 1; f->readable = 1;
f->writable = 1; f->writable = 1;
...@@ -156,8 +284,6 @@ sys_open(void) ...@@ -156,8 +284,6 @@ sys_open(void)
f->readable = 1; f->readable = 1;
f->writable = 0; f->writable = 0;
} }
f->ip = ip;
f->off = 0;
return fd; return fd;
} }
...@@ -165,7 +291,7 @@ sys_open(void) ...@@ -165,7 +291,7 @@ sys_open(void)
int int
sys_mknod(void) sys_mknod(void)
{ {
struct inode *nip; struct inode *ip;
char *path; char *path;
int len; int len;
int type, major, minor; int type, major, minor;
...@@ -173,14 +299,10 @@ sys_mknod(void) ...@@ -173,14 +299,10 @@ sys_mknod(void)
if((len=argstr(0, &path)) < 0 || argint(1, &type) < 0 || if((len=argstr(0, &path)) < 0 || argint(1, &type) < 0 ||
argint(2, &major) < 0 || argint(3, &minor) < 0) argint(2, &major) < 0 || argint(3, &minor) < 0)
return -1; return -1;
// XXX check that type == T_DEV or eliminate type arg?
// XXX why this check? if((ip = mkpath(path, 0, type, major, minor)) == 0)
if(len >= DIRSIZ)
return -1; return -1;
iput(iunlock(ip));
if((nip = mknod(path, type, major, minor)) == 0)
return -1;
iput(nip);
return 0; return 0;
} }
...@@ -188,57 +310,32 @@ int ...@@ -188,57 +310,32 @@ int
sys_mkdir(void) sys_mkdir(void)
{ {
char *path; char *path;
struct inode *ip;
if(argstr(0, &path) < 0) if(argstr(0, &path) < 0 || (ip = mkpath(path, 0, T_DIR, 0, 0)) == 0)
return -1; return -1;
return mkdir(path); iput(iunlock(ip));
return 0;
} }
int int
sys_chdir(void) sys_chdir(void)
{ {
struct inode *ip;
char *path; char *path;
struct inode *ip;
if(argstr(0, &path) < 0) if(argstr(0, &path) < 0 || (ip = ilock(namei(path))) == 0)
return -1;
if((ip = namei(path)) == 0)
return -1; return -1;
if(ip->type != T_DIR) { if(ip->type != T_DIR) {
iput(ip); iput(iunlock(ip));
return -1; return -1;
} }
iput(cp->cwd);
iunlock(ip); cp->cwd = iunlock(ip);
idecref(cp->cwd);
cp->cwd = ip;
return 0; return 0;
} }
int int
sys_unlink(void)
{
char *path;
if(argstr(0, &path) < 0)
return -1;
return unlink(path);
}
int
sys_fstat(void)
{
struct file *f;
struct stat *st;
if(argfd(0, 0, &f) < 0 || argptr(1, (void*)&st, sizeof *st) < 0)
return -1;
return filestat(f, st);
}
int
sys_dup(void) sys_dup(void)
{ {
struct file *f; struct file *f;
...@@ -253,29 +350,17 @@ sys_dup(void) ...@@ -253,29 +350,17 @@ sys_dup(void)
} }
int int
sys_link(void)
{
char *old, *new;
if(argstr(0, &old) < 0 || argstr(1, &new) < 0)
return -1;
return link(old, new);
}
#define MAXARGS 20
int
sys_exec(void) sys_exec(void)
{ {
char *path, *argv[MAXARGS]; char *path, *argv[20];
int i; int i;
uint uargv, uarg; uint uargv, uarg;
if(argstr(0, &path) < 0 || argint(1, (int*)&uargv) < 0) if(argstr(0, &path) < 0 || argint(1, (int*)&uargv) < 0)
return -1; return -1;
memset(argv, 0, sizeof argv); memset(argv, 0, sizeof(argv));
for(i=0;; i++){ for(i=0;; i++){
if(i >= MAXARGS) if(i >= NELEM(argv))
return -1; return -1;
if(fetchint(cp, uargv+4*i, (int*)&uarg) < 0) if(fetchint(cp, uargv+4*i, (int*)&uarg) < 0)
return -1; return -1;
...@@ -289,3 +374,26 @@ sys_exec(void) ...@@ -289,3 +374,26 @@ sys_exec(void)
return exec(path, argv); return exec(path, argv);
} }
int
sys_pipe(void)
{
int *fd;
struct file *rf, *wf;
int fd0, fd1;
if(argptr(0, (void*)&fd, 2*sizeof(fd[0])) < 0)
return -1;
if(pipe_alloc(&rf, &wf) < 0)
return -1;
fd0 = -1;
if((fd0 = fdalloc(rf)) < 0 || (fd1 = fdalloc(wf)) < 0){
if(fd0 >= 0)
cp->ofile[fd0] = 0;
fileclose(rf);
fileclose(wf);
return -1;
}
fd[0] = fd0;
fd[1] = fd1;
return 0;
}
...@@ -17,14 +17,14 @@ tvinit(void) ...@@ -17,14 +17,14 @@ tvinit(void)
int i; int i;
for(i = 0; i < 256; i++) for(i = 0; i < 256; i++)
SETGATE(idt[i], 0, SEG_KCODE << 3, vectors[i], 0); SETGATE(idt[i], 0, SEG_KCODE<<3, vectors[i], 0);
SETGATE(idt[T_SYSCALL], 0, SEG_KCODE << 3, vectors[T_SYSCALL], DPL_USER); SETGATE(idt[T_SYSCALL], 0, SEG_KCODE<<3, vectors[T_SYSCALL], DPL_USER);
} }
void void
idtinit(void) idtinit(void)
{ {
lidt(idt, sizeof idt); lidt(idt, sizeof(idt));
} }
void void
...@@ -80,7 +80,7 @@ trap(struct trapframe *tf) ...@@ -80,7 +80,7 @@ trap(struct trapframe *tf)
default: default:
if(cp) { if(cp) {
// Assume process divided by zero or dereferenced null, etc. // Assume process divided by zero or dereferenced null, etc.
cprintf("pid %d %s: unhandled trap %d err %d on cpu %d eip %x -- kill proc\n", cprintf("pid %d %s: trap %d err %d on cpu %d eip %x -- kill proc\n",
cp->pid, cp->name, tf->trapno, tf->err, cpu(), tf->eip); cp->pid, cp->name, tf->trapno, tf->err, cpu(), tf->eip);
proc_exit(); proc_exit();
} }
......
...@@ -33,6 +33,3 @@ forkret1: ...@@ -33,6 +33,3 @@ forkret1:
movl 4(%esp), %esp movl 4(%esp), %esp
jmp trapret jmp trapret
.globl acpu
acpu:
.long 0
...@@ -100,3 +100,15 @@ atoi(const char *s) ...@@ -100,3 +100,15 @@ atoi(const char *s)
n = n*10 + *s++ - '0'; n = n*10 + *s++ - '0';
return n; return n;
} }
void*
memmove(void *vdst, void *vsrc, int n)
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
*dst++ = *src++;
return vdst;
}
...@@ -23,6 +23,7 @@ char* sbrk(int); ...@@ -23,6 +23,7 @@ char* sbrk(int);
int stat(char*, struct stat*); int stat(char*, struct stat*);
int puts(char*); int puts(char*);
char* strcpy(char*, char*); char* strcpy(char*, char*);
void *memmove(void*, void*, int);
char* strchr(const char*, char c); char* strchr(const char*, char c);
int strcmp(const char*, const char*); int strcmp(const char*, const char*);
void printf(int, char*, ...); void printf(int, char*, ...);
......
...@@ -26,3 +26,24 @@ print "vectors:\n"; ...@@ -26,3 +26,24 @@ print "vectors:\n";
for(my $i = 0; $i < 256; $i++){ for(my $i = 0; $i < 256; $i++){
print " .long vector$i\n"; print " .long vector$i\n";
} }
# sample output:
# # handlers
# .text
# .globl alltraps
# .globl vector0
# vector0:
# pushl $0
# pushl $0
# jmp alltraps
# ...
#
# # vector table
# .data
# .globl vectors
# vectors:
# .long vector0
# .long vector1
# .long vector2
# ...
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论