Remove trailing white space with:
for f in *.{h,c}; do sed -i .sed 's/[[:blank:]]*$//' $f; done (Thanks to Nicolás Wolovick)
This commit is contained in:
parent
6de6a3c952
commit
7894fcd217
6
bio.c
6
bio.c
|
@ -4,7 +4,7 @@
|
||||||
// cached copies of disk block contents. Caching disk blocks
|
// cached copies of disk block contents. Caching disk blocks
|
||||||
// in memory reduces the number of disk reads and also provides
|
// in memory reduces the number of disk reads and also provides
|
||||||
// a synchronization point for disk blocks used by multiple processes.
|
// a synchronization point for disk blocks used by multiple processes.
|
||||||
//
|
//
|
||||||
// Interface:
|
// Interface:
|
||||||
// * To get a buffer for a particular disk block, call bread.
|
// * To get a buffer for a particular disk block, call bread.
|
||||||
// * After changing buffer data, call bwrite to write it to disk.
|
// * After changing buffer data, call bwrite to write it to disk.
|
||||||
|
@ -12,10 +12,10 @@
|
||||||
// * Do not use the buffer after calling brelse.
|
// * Do not use the buffer after calling brelse.
|
||||||
// * Only one process at a time can use a buffer,
|
// * Only one process at a time can use a buffer,
|
||||||
// so do not keep them longer than necessary.
|
// so do not keep them longer than necessary.
|
||||||
//
|
//
|
||||||
// The implementation uses three state flags internally:
|
// The implementation uses three state flags internally:
|
||||||
// * B_BUSY: the block has been returned from bread
|
// * B_BUSY: the block has been returned from bread
|
||||||
// and has not been passed back to brelse.
|
// and has not been passed back to brelse.
|
||||||
// * B_VALID: the buffer data has been read from the disk.
|
// * B_VALID: the buffer data has been read from the disk.
|
||||||
// * B_DIRTY: the buffer data has been modified
|
// * B_DIRTY: the buffer data has been modified
|
||||||
// and needs to be written to disk.
|
// and needs to be written to disk.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Boot loader.
|
// Boot loader.
|
||||||
//
|
//
|
||||||
// Part of the boot block, along with bootasm.S, which calls bootmain().
|
// Part of the boot block, along with bootasm.S, which calls bootmain().
|
||||||
// bootasm.S has put the processor into protected 32-bit mode.
|
// bootasm.S has put the processor into protected 32-bit mode.
|
||||||
// bootmain() loads an ELF kernel image from the disk starting at
|
// bootmain() loads an ELF kernel image from the disk starting at
|
||||||
|
|
|
@ -107,7 +107,7 @@ panic(char *s)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint pcs[10];
|
uint pcs[10];
|
||||||
|
|
||||||
cli();
|
cli();
|
||||||
cons.locking = 0;
|
cons.locking = 0;
|
||||||
cprintf("cpu%d: panic: ", cpu->id);
|
cprintf("cpu%d: panic: ", cpu->id);
|
||||||
|
@ -130,7 +130,7 @@ static void
|
||||||
cgaputc(int c)
|
cgaputc(int c)
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
// Cursor position: col + 80*row.
|
// Cursor position: col + 80*row.
|
||||||
outb(CRTPORT, 14);
|
outb(CRTPORT, 14);
|
||||||
pos = inb(CRTPORT+1) << 8;
|
pos = inb(CRTPORT+1) << 8;
|
||||||
|
@ -146,13 +146,13 @@ cgaputc(int c)
|
||||||
|
|
||||||
if(pos < 0 || pos > 25*80)
|
if(pos < 0 || pos > 25*80)
|
||||||
panic("pos under/overflow");
|
panic("pos under/overflow");
|
||||||
|
|
||||||
if((pos/80) >= 24){ // Scroll up.
|
if((pos/80) >= 24){ // Scroll up.
|
||||||
memmove(crt, crt+80, sizeof(crt[0])*23*80);
|
memmove(crt, crt+80, sizeof(crt[0])*23*80);
|
||||||
pos -= 80;
|
pos -= 80;
|
||||||
memset(crt+pos, 0, sizeof(crt[0])*(24*80 - pos));
|
memset(crt+pos, 0, sizeof(crt[0])*(24*80 - pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
outb(CRTPORT, 14);
|
outb(CRTPORT, 14);
|
||||||
outb(CRTPORT+1, pos>>8);
|
outb(CRTPORT+1, pos>>8);
|
||||||
outb(CRTPORT, 15);
|
outb(CRTPORT, 15);
|
||||||
|
|
2
file.c
2
file.c
|
@ -68,7 +68,7 @@ fileclose(struct file *f)
|
||||||
f->ref = 0;
|
f->ref = 0;
|
||||||
f->type = FD_NONE;
|
f->type = FD_NONE;
|
||||||
release(&ftable.lock);
|
release(&ftable.lock);
|
||||||
|
|
||||||
if(ff.type == FD_PIPE)
|
if(ff.type == FD_PIPE)
|
||||||
pipeclose(ff.pipe, ff.writable);
|
pipeclose(ff.pipe, ff.writable);
|
||||||
else if(ff.type == FD_INODE){
|
else if(ff.type == FD_INODE){
|
||||||
|
|
|
@ -27,24 +27,24 @@ forktest(void)
|
||||||
if(pid == 0)
|
if(pid == 0)
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n == N){
|
if(n == N){
|
||||||
printf(1, "fork claimed to work N times!\n", N);
|
printf(1, "fork claimed to work N times!\n", N);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(; n > 0; n--){
|
for(; n > 0; n--){
|
||||||
if(wait() < 0){
|
if(wait() < 0){
|
||||||
printf(1, "wait stopped early\n");
|
printf(1, "wait stopped early\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wait() != -1){
|
if(wait() != -1){
|
||||||
printf(1, "wait got too many\n");
|
printf(1, "wait got too many\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(1, "fork test OK\n");
|
printf(1, "fork test OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
fs.c
14
fs.c
|
@ -5,7 +5,7 @@
|
||||||
// + Directories: inode with special contents (list of other inodes!)
|
// + Directories: inode with special contents (list of other inodes!)
|
||||||
// + Names: paths like /usr/rtm/xv6/fs.c for convenient naming.
|
// + Names: paths like /usr/rtm/xv6/fs.c for convenient naming.
|
||||||
//
|
//
|
||||||
// This file contains the low-level file system manipulation
|
// This file contains the low-level file system manipulation
|
||||||
// routines. The (higher-level) system call implementations
|
// routines. The (higher-level) system call implementations
|
||||||
// are in sysfile.c.
|
// are in sysfile.c.
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ void
|
||||||
readsb(int dev, struct superblock *sb)
|
readsb(int dev, struct superblock *sb)
|
||||||
{
|
{
|
||||||
struct buf *bp;
|
struct buf *bp;
|
||||||
|
|
||||||
bp = bread(dev, 1);
|
bp = bread(dev, 1);
|
||||||
memmove(sb, bp->data, sizeof(*sb));
|
memmove(sb, bp->data, sizeof(*sb));
|
||||||
brelse(bp);
|
brelse(bp);
|
||||||
|
@ -40,14 +40,14 @@ static void
|
||||||
bzero(int dev, int bno)
|
bzero(int dev, int bno)
|
||||||
{
|
{
|
||||||
struct buf *bp;
|
struct buf *bp;
|
||||||
|
|
||||||
bp = bread(dev, bno);
|
bp = bread(dev, bno);
|
||||||
memset(bp->data, 0, BSIZE);
|
memset(bp->data, 0, BSIZE);
|
||||||
log_write(bp);
|
log_write(bp);
|
||||||
brelse(bp);
|
brelse(bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blocks.
|
// Blocks.
|
||||||
|
|
||||||
// Allocate a zeroed disk block.
|
// Allocate a zeroed disk block.
|
||||||
static uint
|
static uint
|
||||||
|
@ -348,7 +348,7 @@ iunlockput(struct inode *ip)
|
||||||
//
|
//
|
||||||
// The content (data) associated with each inode is stored
|
// The content (data) associated with each inode is stored
|
||||||
// in blocks on the disk. The first NDIRECT block numbers
|
// in blocks on the disk. The first NDIRECT block numbers
|
||||||
// are listed in ip->addrs[]. The next NINDIRECT blocks are
|
// are listed in ip->addrs[]. The next NINDIRECT blocks are
|
||||||
// listed in block ip->addrs[NDIRECT].
|
// listed in block ip->addrs[NDIRECT].
|
||||||
|
|
||||||
// Return the disk block address of the nth block in inode ip.
|
// Return the disk block address of the nth block in inode ip.
|
||||||
|
@ -401,7 +401,7 @@ itrunc(struct inode *ip)
|
||||||
ip->addrs[i] = 0;
|
ip->addrs[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ip->addrs[NDIRECT]){
|
if(ip->addrs[NDIRECT]){
|
||||||
bp = bread(ip->dev, ip->addrs[NDIRECT]);
|
bp = bread(ip->dev, ip->addrs[NDIRECT]);
|
||||||
a = (uint*)bp->data;
|
a = (uint*)bp->data;
|
||||||
|
@ -554,7 +554,7 @@ dirlink(struct inode *dp, char *name, uint inum)
|
||||||
de.inum = inum;
|
de.inum = inum;
|
||||||
if(writei(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
|
if(writei(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
|
||||||
panic("dirlink");
|
panic("dirlink");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
fs.h
2
fs.h
|
@ -1,4 +1,4 @@
|
||||||
// On-disk file system format.
|
// On-disk file system format.
|
||||||
// Both the kernel and user programs use this header file.
|
// Both the kernel and user programs use this header file.
|
||||||
|
|
||||||
|
|
||||||
|
|
6
grep.c
6
grep.c
|
@ -12,7 +12,7 @@ grep(char *pattern, int fd)
|
||||||
{
|
{
|
||||||
int n, m;
|
int n, m;
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
|
|
||||||
m = 0;
|
m = 0;
|
||||||
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
|
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
|
||||||
m += n;
|
m += n;
|
||||||
|
@ -40,13 +40,13 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd, i;
|
int fd, i;
|
||||||
char *pattern;
|
char *pattern;
|
||||||
|
|
||||||
if(argc <= 1){
|
if(argc <= 1){
|
||||||
printf(2, "usage: grep pattern [file ...]\n");
|
printf(2, "usage: grep pattern [file ...]\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
pattern = argv[1];
|
pattern = argv[1];
|
||||||
|
|
||||||
if(argc <= 2){
|
if(argc <= 2){
|
||||||
grep(pattern, 0);
|
grep(pattern, 0);
|
||||||
exit();
|
exit();
|
||||||
|
|
22
ide.c
22
ide.c
|
@ -39,7 +39,7 @@ idewait(int checkerr)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
while(((r = inb(0x1f7)) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY)
|
while(((r = inb(0x1f7)) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY)
|
||||||
;
|
;
|
||||||
if(checkerr && (r & (IDE_DF|IDE_ERR)) != 0)
|
if(checkerr && (r & (IDE_DF|IDE_ERR)) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -50,12 +50,12 @@ void
|
||||||
ideinit(void)
|
ideinit(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
initlock(&idelock, "ide");
|
initlock(&idelock, "ide");
|
||||||
picenable(IRQ_IDE);
|
picenable(IRQ_IDE);
|
||||||
ioapicenable(IRQ_IDE, ncpu - 1);
|
ioapicenable(IRQ_IDE, ncpu - 1);
|
||||||
idewait(0);
|
idewait(0);
|
||||||
|
|
||||||
// Check if disk 1 is present
|
// Check if disk 1 is present
|
||||||
outb(0x1f6, 0xe0 | (1<<4));
|
outb(0x1f6, 0xe0 | (1<<4));
|
||||||
for(i=0; i<1000; i++){
|
for(i=0; i<1000; i++){
|
||||||
|
@ -64,7 +64,7 @@ ideinit(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch back to disk 0.
|
// Switch back to disk 0.
|
||||||
outb(0x1f6, 0xe0 | (0<<4));
|
outb(0x1f6, 0xe0 | (0<<4));
|
||||||
}
|
}
|
||||||
|
@ -81,9 +81,9 @@ idestart(struct buf *b)
|
||||||
int sector = b->blockno * sector_per_block;
|
int sector = b->blockno * sector_per_block;
|
||||||
int read_cmd = (sector_per_block == 1) ? IDE_CMD_READ : IDE_CMD_RDMUL;
|
int read_cmd = (sector_per_block == 1) ? IDE_CMD_READ : IDE_CMD_RDMUL;
|
||||||
int write_cmd = (sector_per_block == 1) ? IDE_CMD_WRITE : IDE_CMD_WRMUL;
|
int write_cmd = (sector_per_block == 1) ? IDE_CMD_WRITE : IDE_CMD_WRMUL;
|
||||||
|
|
||||||
if (sector_per_block > 7) panic("idestart");
|
if (sector_per_block > 7) panic("idestart");
|
||||||
|
|
||||||
idewait(0);
|
idewait(0);
|
||||||
outb(0x3f6, 0); // generate interrupt
|
outb(0x3f6, 0); // generate interrupt
|
||||||
outb(0x1f2, sector_per_block); // number of sectors
|
outb(0x1f2, sector_per_block); // number of sectors
|
||||||
|
@ -117,12 +117,12 @@ ideintr(void)
|
||||||
// Read data if needed.
|
// Read data if needed.
|
||||||
if(!(b->flags & B_DIRTY) && idewait(1) >= 0)
|
if(!(b->flags & B_DIRTY) && idewait(1) >= 0)
|
||||||
insl(0x1f0, b->data, BSIZE/4);
|
insl(0x1f0, b->data, BSIZE/4);
|
||||||
|
|
||||||
// Wake process waiting for this buf.
|
// Wake process waiting for this buf.
|
||||||
b->flags |= B_VALID;
|
b->flags |= B_VALID;
|
||||||
b->flags &= ~B_DIRTY;
|
b->flags &= ~B_DIRTY;
|
||||||
wakeup(b);
|
wakeup(b);
|
||||||
|
|
||||||
// Start disk on next buf in queue.
|
// Start disk on next buf in queue.
|
||||||
if(idequeue != 0)
|
if(idequeue != 0)
|
||||||
idestart(idequeue);
|
idestart(idequeue);
|
||||||
|
@ -131,7 +131,7 @@ ideintr(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
//PAGEBREAK!
|
//PAGEBREAK!
|
||||||
// Sync buf with disk.
|
// Sync buf with disk.
|
||||||
// If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID.
|
// If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID.
|
||||||
// Else if B_VALID is not set, read buf from disk, set B_VALID.
|
// Else if B_VALID is not set, read buf from disk, set B_VALID.
|
||||||
void
|
void
|
||||||
|
@ -153,11 +153,11 @@ iderw(struct buf *b)
|
||||||
for(pp=&idequeue; *pp; pp=&(*pp)->qnext) //DOC:insert-queue
|
for(pp=&idequeue; *pp; pp=&(*pp)->qnext) //DOC:insert-queue
|
||||||
;
|
;
|
||||||
*pp = b;
|
*pp = b;
|
||||||
|
|
||||||
// Start disk if necessary.
|
// Start disk if necessary.
|
||||||
if(idequeue == b)
|
if(idequeue == b)
|
||||||
idestart(b);
|
idestart(b);
|
||||||
|
|
||||||
// Wait for request to finish.
|
// Wait for request to finish.
|
||||||
while((b->flags & (B_VALID|B_DIRTY)) != B_VALID){
|
while((b->flags & (B_VALID|B_DIRTY)) != B_VALID){
|
||||||
sleep(b, &idelock);
|
sleep(b, &idelock);
|
||||||
|
|
2
ioapic.c
2
ioapic.c
|
@ -13,7 +13,7 @@
|
||||||
#define REG_TABLE 0x10 // Redirection table base
|
#define REG_TABLE 0x10 // Redirection table base
|
||||||
|
|
||||||
// The redirection table starts at REG_TABLE and uses
|
// The redirection table starts at REG_TABLE and uses
|
||||||
// two registers to configure each interrupt.
|
// two registers to configure each interrupt.
|
||||||
// The first (low) register in a pair contains configuration bits.
|
// The first (low) register in a pair contains configuration bits.
|
||||||
// The second (high) register contains a bitmask telling which
|
// The second (high) register contains a bitmask telling which
|
||||||
// CPUs can serve that interrupt.
|
// CPUs can serve that interrupt.
|
||||||
|
|
14
log.c
14
log.c
|
@ -31,7 +31,7 @@
|
||||||
// Contents of the header block, used for both the on-disk header block
|
// Contents of the header block, used for both the on-disk header block
|
||||||
// and to keep track in memory of logged block# before commit.
|
// and to keep track in memory of logged block# before commit.
|
||||||
struct logheader {
|
struct logheader {
|
||||||
int n;
|
int n;
|
||||||
int block[LOGSIZE];
|
int block[LOGSIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ initlog(int dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy committed blocks from log to their home location
|
// Copy committed blocks from log to their home location
|
||||||
static void
|
static void
|
||||||
install_trans(void)
|
install_trans(void)
|
||||||
{
|
{
|
||||||
int tail;
|
int tail;
|
||||||
|
@ -75,7 +75,7 @@ install_trans(void)
|
||||||
struct buf *dbuf = bread(log.dev, log.lh.block[tail]); // read dst
|
struct buf *dbuf = bread(log.dev, log.lh.block[tail]); // read dst
|
||||||
memmove(dbuf->data, lbuf->data, BSIZE); // copy block to dst
|
memmove(dbuf->data, lbuf->data, BSIZE); // copy block to dst
|
||||||
bwrite(dbuf); // write dst to disk
|
bwrite(dbuf); // write dst to disk
|
||||||
brelse(lbuf);
|
brelse(lbuf);
|
||||||
brelse(dbuf);
|
brelse(dbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ write_head(void)
|
||||||
static void
|
static void
|
||||||
recover_from_log(void)
|
recover_from_log(void)
|
||||||
{
|
{
|
||||||
read_head();
|
read_head();
|
||||||
install_trans(); // if committed, copy from log to disk
|
install_trans(); // if committed, copy from log to disk
|
||||||
log.lh.n = 0;
|
log.lh.n = 0;
|
||||||
write_head(); // clear the log
|
write_head(); // clear the log
|
||||||
|
@ -171,7 +171,7 @@ end_op(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy modified blocks from cache to log.
|
// Copy modified blocks from cache to log.
|
||||||
static void
|
static void
|
||||||
write_log(void)
|
write_log(void)
|
||||||
{
|
{
|
||||||
int tail;
|
int tail;
|
||||||
|
@ -181,7 +181,7 @@ write_log(void)
|
||||||
struct buf *from = bread(log.dev, log.lh.block[tail]); // cache block
|
struct buf *from = bread(log.dev, log.lh.block[tail]); // cache block
|
||||||
memmove(to->data, from->data, BSIZE);
|
memmove(to->data, from->data, BSIZE);
|
||||||
bwrite(to); // write the log
|
bwrite(to); // write the log
|
||||||
brelse(from);
|
brelse(from);
|
||||||
brelse(to);
|
brelse(to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ commit()
|
||||||
write_log(); // Write modified blocks from cache to log
|
write_log(); // Write modified blocks from cache to log
|
||||||
write_head(); // Write header to disk -- the real commit
|
write_head(); // Write header to disk -- the real commit
|
||||||
install_trans(); // Now install writes to home locations
|
install_trans(); // Now install writes to home locations
|
||||||
log.lh.n = 0;
|
log.lh.n = 0;
|
||||||
write_head(); // Erase the transaction from the log
|
write_head(); // Erase the transaction from the log
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
ls.c
12
ls.c
|
@ -8,12 +8,12 @@ fmtname(char *path)
|
||||||
{
|
{
|
||||||
static char buf[DIRSIZ+1];
|
static char buf[DIRSIZ+1];
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
// Find first character after last slash.
|
// Find first character after last slash.
|
||||||
for(p=path+strlen(path); p >= path && *p != '/'; p--)
|
for(p=path+strlen(path); p >= path && *p != '/'; p--)
|
||||||
;
|
;
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
// Return blank-padded name.
|
// Return blank-padded name.
|
||||||
if(strlen(p) >= DIRSIZ)
|
if(strlen(p) >= DIRSIZ)
|
||||||
return p;
|
return p;
|
||||||
|
@ -29,23 +29,23 @@ ls(char *path)
|
||||||
int fd;
|
int fd;
|
||||||
struct dirent de;
|
struct dirent de;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if((fd = open(path, 0)) < 0){
|
if((fd = open(path, 0)) < 0){
|
||||||
printf(2, "ls: cannot open %s\n", path);
|
printf(2, "ls: cannot open %s\n", path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fstat(fd, &st) < 0){
|
if(fstat(fd, &st) < 0){
|
||||||
printf(2, "ls: cannot stat %s\n", path);
|
printf(2, "ls: cannot stat %s\n", path);
|
||||||
close(fd);
|
close(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(st.type){
|
switch(st.type){
|
||||||
case T_FILE:
|
case T_FILE:
|
||||||
printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
|
printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_DIR:
|
case T_DIR:
|
||||||
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
|
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
|
||||||
printf(1, "ls: path too long\n");
|
printf(1, "ls: path too long\n");
|
||||||
|
|
6
main.c
6
main.c
|
@ -44,7 +44,7 @@ main(void)
|
||||||
static void
|
static void
|
||||||
mpenter(void)
|
mpenter(void)
|
||||||
{
|
{
|
||||||
switchkvm();
|
switchkvm();
|
||||||
seginit();
|
seginit();
|
||||||
lapicinit();
|
lapicinit();
|
||||||
mpmain();
|
mpmain();
|
||||||
|
@ -81,7 +81,7 @@ startothers(void)
|
||||||
if(c == cpus+cpunum()) // We've started already.
|
if(c == cpus+cpunum()) // We've started already.
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Tell entryother.S what stack to use, where to enter, and what
|
// Tell entryother.S what stack to use, where to enter, and what
|
||||||
// pgdir to use. We cannot use kpgdir yet, because the AP processor
|
// pgdir to use. We cannot use kpgdir yet, because the AP processor
|
||||||
// is running in low memory, so we use entrypgdir for the APs too.
|
// is running in low memory, so we use entrypgdir for the APs too.
|
||||||
stack = kalloc();
|
stack = kalloc();
|
||||||
|
@ -99,7 +99,7 @@ startothers(void)
|
||||||
|
|
||||||
// The boot page table used in entry.S and entryother.S.
|
// The boot page table used in entry.S and entryother.S.
|
||||||
// Page directories (and page tables) must start on page boundaries,
|
// Page directories (and page tables) must start on page boundaries,
|
||||||
// hence the __aligned__ attribute.
|
// hence the __aligned__ attribute.
|
||||||
// PTE_PS in a page directory entry enables 4Mbyte pages.
|
// PTE_PS in a page directory entry enables 4Mbyte pages.
|
||||||
|
|
||||||
__attribute__((__aligned__(PGSIZE)))
|
__attribute__((__aligned__(PGSIZE)))
|
||||||
|
|
4
memide.c
4
memide.c
|
@ -31,7 +31,7 @@ ideintr(void)
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync buf with disk.
|
// Sync buf with disk.
|
||||||
// If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID.
|
// If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID.
|
||||||
// Else if B_VALID is not set, read buf from disk, set B_VALID.
|
// Else if B_VALID is not set, read buf from disk, set B_VALID.
|
||||||
void
|
void
|
||||||
|
@ -49,7 +49,7 @@ iderw(struct buf *b)
|
||||||
panic("iderw: block out of range");
|
panic("iderw: block out of range");
|
||||||
|
|
||||||
p = memdisk + b->blockno*BSIZE;
|
p = memdisk + b->blockno*BSIZE;
|
||||||
|
|
||||||
if(b->flags & B_DIRTY){
|
if(b->flags & B_DIRTY){
|
||||||
b->flags &= ~B_DIRTY;
|
b->flags &= ~B_DIRTY;
|
||||||
memmove(p, b->data, BSIZE);
|
memmove(p, b->data, BSIZE);
|
||||||
|
|
4
mkfs.c
4
mkfs.c
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
int nbitmap = FSSIZE/(BSIZE*8) + 1;
|
int nbitmap = FSSIZE/(BSIZE*8) + 1;
|
||||||
int ninodeblocks = NINODES / IPB + 1;
|
int ninodeblocks = NINODES / IPB + 1;
|
||||||
int nlog = LOGSIZE;
|
int nlog = LOGSIZE;
|
||||||
int nmeta; // Number of meta blocks (boot, sb, nlog, inode, bitmap)
|
int nmeta; // Number of meta blocks (boot, sb, nlog, inode, bitmap)
|
||||||
int nblocks; // Number of data blocks
|
int nblocks; // Number of data blocks
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ main(int argc, char *argv[])
|
||||||
perror(argv[i]);
|
perror(argv[i]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip leading _ in name when writing to file system.
|
// Skip leading _ in name when writing to file system.
|
||||||
// The binaries are named _rm, _cat, etc. to keep the
|
// The binaries are named _rm, _cat, etc. to keep the
|
||||||
// build operating system from trying to execute them
|
// build operating system from trying to execute them
|
||||||
|
|
4
mmu.h
4
mmu.h
|
@ -1,4 +1,4 @@
|
||||||
// This file contains definitions for the
|
// This file contains definitions for the
|
||||||
// x86 memory management unit (MMU).
|
// x86 memory management unit (MMU).
|
||||||
|
|
||||||
// Eflags register
|
// Eflags register
|
||||||
|
@ -110,7 +110,7 @@ struct segdesc {
|
||||||
// | Page Directory | Page Table | Offset within Page |
|
// | Page Directory | Page Table | Offset within Page |
|
||||||
// | Index | Index | |
|
// | Index | Index | |
|
||||||
// +----------------+----------------+---------------------+
|
// +----------------+----------------+---------------------+
|
||||||
// \--- PDX(va) --/ \--- PTX(va) --/
|
// \--- PDX(va) --/ \--- PTX(va) --/
|
||||||
|
|
||||||
// page directory index
|
// page directory index
|
||||||
#define PDX(va) (((uint)(va) >> PDXSHIFT) & 0x3FF)
|
#define PDX(va) (((uint)(va) >> PDXSHIFT) & 0x3FF)
|
||||||
|
|
18
proc.c
18
proc.c
|
@ -53,11 +53,11 @@ found:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
sp = p->kstack + KSTACKSIZE;
|
sp = p->kstack + KSTACKSIZE;
|
||||||
|
|
||||||
// Leave room for trap frame.
|
// Leave room for trap frame.
|
||||||
sp -= sizeof *p->tf;
|
sp -= sizeof *p->tf;
|
||||||
p->tf = (struct trapframe*)sp;
|
p->tf = (struct trapframe*)sp;
|
||||||
|
|
||||||
// Set up new context to start executing at forkret,
|
// Set up new context to start executing at forkret,
|
||||||
// which returns to trapret.
|
// which returns to trapret.
|
||||||
sp -= 4;
|
sp -= 4;
|
||||||
|
@ -78,7 +78,7 @@ userinit(void)
|
||||||
{
|
{
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
extern char _binary_initcode_start[], _binary_initcode_size[];
|
extern char _binary_initcode_start[], _binary_initcode_size[];
|
||||||
|
|
||||||
acquire(&ptable.lock);
|
acquire(&ptable.lock);
|
||||||
|
|
||||||
p = allocproc();
|
p = allocproc();
|
||||||
|
@ -110,7 +110,7 @@ int
|
||||||
growproc(int n)
|
growproc(int n)
|
||||||
{
|
{
|
||||||
uint sz;
|
uint sz;
|
||||||
|
|
||||||
sz = proc->sz;
|
sz = proc->sz;
|
||||||
if(n > 0){
|
if(n > 0){
|
||||||
if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0)
|
if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0)
|
||||||
|
@ -162,13 +162,13 @@ fork(void)
|
||||||
np->cwd = idup(proc->cwd);
|
np->cwd = idup(proc->cwd);
|
||||||
|
|
||||||
safestrcpy(np->name, proc->name, sizeof(proc->name));
|
safestrcpy(np->name, proc->name, sizeof(proc->name));
|
||||||
|
|
||||||
pid = np->pid;
|
pid = np->pid;
|
||||||
|
|
||||||
np->state = RUNNABLE;
|
np->state = RUNNABLE;
|
||||||
|
|
||||||
release(&ptable.lock);
|
release(&ptable.lock);
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,13 +342,13 @@ forkret(void)
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
// Some initialization functions must be run in the context
|
// Some initialization functions must be run in the context
|
||||||
// of a regular process (e.g., they call sleep), and thus cannot
|
// of a regular process (e.g., they call sleep), and thus cannot
|
||||||
// be run from main().
|
// be run from main().
|
||||||
first = 0;
|
first = 0;
|
||||||
iinit(ROOTDEV);
|
iinit(ROOTDEV);
|
||||||
initlog(ROOTDEV);
|
initlog(ROOTDEV);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return to "caller", actually trapret (see allocproc).
|
// Return to "caller", actually trapret (see allocproc).
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +453,7 @@ procdump(void)
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
char *state;
|
char *state;
|
||||||
uint pc[10];
|
uint pc[10];
|
||||||
|
|
||||||
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
|
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
|
||||||
if(p->state == UNUSED)
|
if(p->state == UNUSED)
|
||||||
continue;
|
continue;
|
||||||
|
|
2
proc.h
2
proc.h
|
@ -7,7 +7,7 @@ struct cpu {
|
||||||
volatile uint started; // Has the CPU started?
|
volatile uint started; // Has the CPU started?
|
||||||
int ncli; // Depth of pushcli nesting.
|
int ncli; // Depth of pushcli nesting.
|
||||||
int intena; // Were interrupts enabled before pushcli?
|
int intena; // Were interrupts enabled before pushcli?
|
||||||
|
|
||||||
// Cpu-local storage variables; see below
|
// Cpu-local storage variables; see below
|
||||||
struct cpu *cpu;
|
struct cpu *cpu;
|
||||||
struct proc *proc; // The currently-running process.
|
struct proc *proc; // The currently-running process.
|
||||||
|
|
22
sh.c
22
sh.c
|
@ -66,7 +66,7 @@ runcmd(struct cmd *cmd)
|
||||||
|
|
||||||
if(cmd == 0)
|
if(cmd == 0)
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
switch(cmd->type){
|
switch(cmd->type){
|
||||||
default:
|
default:
|
||||||
panic("runcmd");
|
panic("runcmd");
|
||||||
|
@ -120,7 +120,7 @@ runcmd(struct cmd *cmd)
|
||||||
wait();
|
wait();
|
||||||
wait();
|
wait();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BACK:
|
case BACK:
|
||||||
bcmd = (struct backcmd*)cmd;
|
bcmd = (struct backcmd*)cmd;
|
||||||
if(fork1() == 0)
|
if(fork1() == 0)
|
||||||
|
@ -146,7 +146,7 @@ main(void)
|
||||||
{
|
{
|
||||||
static char buf[100];
|
static char buf[100];
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
// Ensure that three file descriptors are open.
|
// Ensure that three file descriptors are open.
|
||||||
while((fd = open("console", O_RDWR)) >= 0){
|
while((fd = open("console", O_RDWR)) >= 0){
|
||||||
if(fd >= 3){
|
if(fd >= 3){
|
||||||
|
@ -154,7 +154,7 @@ main(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read and run input commands.
|
// Read and run input commands.
|
||||||
while(getcmd(buf, sizeof(buf)) >= 0){
|
while(getcmd(buf, sizeof(buf)) >= 0){
|
||||||
if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
|
if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){
|
||||||
|
@ -182,7 +182,7 @@ int
|
||||||
fork1(void)
|
fork1(void)
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if(pid == -1)
|
if(pid == -1)
|
||||||
panic("fork");
|
panic("fork");
|
||||||
|
@ -267,7 +267,7 @@ gettoken(char **ps, char *es, char **q, char **eq)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
s = *ps;
|
s = *ps;
|
||||||
while(s < es && strchr(whitespace, *s))
|
while(s < es && strchr(whitespace, *s))
|
||||||
s++;
|
s++;
|
||||||
|
@ -300,7 +300,7 @@ gettoken(char **ps, char *es, char **q, char **eq)
|
||||||
}
|
}
|
||||||
if(eq)
|
if(eq)
|
||||||
*eq = s;
|
*eq = s;
|
||||||
|
|
||||||
while(s < es && strchr(whitespace, *s))
|
while(s < es && strchr(whitespace, *s))
|
||||||
s++;
|
s++;
|
||||||
*ps = s;
|
*ps = s;
|
||||||
|
@ -311,7 +311,7 @@ int
|
||||||
peek(char **ps, char *es, char *toks)
|
peek(char **ps, char *es, char *toks)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
s = *ps;
|
s = *ps;
|
||||||
while(s < es && strchr(whitespace, *s))
|
while(s < es && strchr(whitespace, *s))
|
||||||
s++;
|
s++;
|
||||||
|
@ -419,7 +419,7 @@ parseexec(char **ps, char *es)
|
||||||
int tok, argc;
|
int tok, argc;
|
||||||
struct execcmd *cmd;
|
struct execcmd *cmd;
|
||||||
struct cmd *ret;
|
struct cmd *ret;
|
||||||
|
|
||||||
if(peek(ps, es, "("))
|
if(peek(ps, es, "("))
|
||||||
return parseblock(ps, es);
|
return parseblock(ps, es);
|
||||||
|
|
||||||
|
@ -458,7 +458,7 @@ nulterminate(struct cmd *cmd)
|
||||||
|
|
||||||
if(cmd == 0)
|
if(cmd == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch(cmd->type){
|
switch(cmd->type){
|
||||||
case EXEC:
|
case EXEC:
|
||||||
ecmd = (struct execcmd*)cmd;
|
ecmd = (struct execcmd*)cmd;
|
||||||
|
@ -477,7 +477,7 @@ nulterminate(struct cmd *cmd)
|
||||||
nulterminate(pcmd->left);
|
nulterminate(pcmd->left);
|
||||||
nulterminate(pcmd->right);
|
nulterminate(pcmd->right);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIST:
|
case LIST:
|
||||||
lcmd = (struct listcmd*)cmd;
|
lcmd = (struct listcmd*)cmd;
|
||||||
nulterminate(lcmd->left);
|
nulterminate(lcmd->left);
|
||||||
|
|
|
@ -71,7 +71,7 @@ getcallerpcs(void *v, uint pcs[])
|
||||||
{
|
{
|
||||||
uint *ebp;
|
uint *ebp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
ebp = (uint*)v - 2;
|
ebp = (uint*)v - 2;
|
||||||
for(i = 0; i < 10; i++){
|
for(i = 0; i < 10; i++){
|
||||||
if(ebp == 0 || ebp < (uint*)KERNBASE || ebp == (uint*)0xffffffff)
|
if(ebp == 0 || ebp < (uint*)KERNBASE || ebp == (uint*)0xffffffff)
|
||||||
|
@ -99,7 +99,7 @@ void
|
||||||
pushcli(void)
|
pushcli(void)
|
||||||
{
|
{
|
||||||
int eflags;
|
int eflags;
|
||||||
|
|
||||||
eflags = readeflags();
|
eflags = readeflags();
|
||||||
cli();
|
cli();
|
||||||
if(cpu->ncli++ == 0)
|
if(cpu->ncli++ == 0)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Mutual exclusion lock.
|
// Mutual exclusion lock.
|
||||||
struct spinlock {
|
struct spinlock {
|
||||||
uint locked; // Is the lock held?
|
uint locked; // Is the lock held?
|
||||||
|
|
||||||
// For debugging:
|
// For debugging:
|
||||||
char *name; // Name of lock.
|
char *name; // Name of lock.
|
||||||
struct cpu *cpu; // The cpu holding the lock.
|
struct cpu *cpu; // The cpu holding the lock.
|
||||||
|
|
|
@ -44,6 +44,6 @@ main(int argc, char *argv[])
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
wait();
|
wait();
|
||||||
|
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
6
string.c
6
string.c
|
@ -16,7 +16,7 @@ int
|
||||||
memcmp(const void *v1, const void *v2, uint n)
|
memcmp(const void *v1, const void *v2, uint n)
|
||||||
{
|
{
|
||||||
const uchar *s1, *s2;
|
const uchar *s1, *s2;
|
||||||
|
|
||||||
s1 = v1;
|
s1 = v1;
|
||||||
s2 = v2;
|
s2 = v2;
|
||||||
while(n-- > 0){
|
while(n-- > 0){
|
||||||
|
@ -69,7 +69,7 @@ char*
|
||||||
strncpy(char *s, const char *t, int n)
|
strncpy(char *s, const char *t, int n)
|
||||||
{
|
{
|
||||||
char *os;
|
char *os;
|
||||||
|
|
||||||
os = s;
|
os = s;
|
||||||
while(n-- > 0 && (*s++ = *t++) != 0)
|
while(n-- > 0 && (*s++ = *t++) != 0)
|
||||||
;
|
;
|
||||||
|
@ -83,7 +83,7 @@ char*
|
||||||
safestrcpy(char *s, const char *t, int n)
|
safestrcpy(char *s, const char *t, int n)
|
||||||
{
|
{
|
||||||
char *os;
|
char *os;
|
||||||
|
|
||||||
os = s;
|
os = s;
|
||||||
if(n <= 0)
|
if(n <= 0)
|
||||||
return os;
|
return os;
|
||||||
|
|
|
@ -55,7 +55,7 @@ int
|
||||||
argptr(int n, char **pp, int size)
|
argptr(int n, char **pp, int size)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(argint(n, &i) < 0)
|
if(argint(n, &i) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if((uint)i >= proc->sz || (uint)i+size > proc->sz)
|
if((uint)i >= proc->sz || (uint)i+size > proc->sz)
|
||||||
|
|
|
@ -61,7 +61,7 @@ sys_sleep(void)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
uint ticks0;
|
uint ticks0;
|
||||||
|
|
||||||
if(argint(0, &n) < 0)
|
if(argint(0, &n) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
acquire(&tickslock);
|
acquire(&tickslock);
|
||||||
|
@ -83,7 +83,7 @@ int
|
||||||
sys_uptime(void)
|
sys_uptime(void)
|
||||||
{
|
{
|
||||||
uint xticks;
|
uint xticks;
|
||||||
|
|
||||||
acquire(&tickslock);
|
acquire(&tickslock);
|
||||||
xticks = ticks;
|
xticks = ticks;
|
||||||
release(&tickslock);
|
release(&tickslock);
|
||||||
|
|
8
trap.c
8
trap.c
|
@ -22,7 +22,7 @@ tvinit(void)
|
||||||
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], 1, SEG_KCODE<<3, vectors[T_SYSCALL], DPL_USER);
|
SETGATE(idt[T_SYSCALL], 1, SEG_KCODE<<3, vectors[T_SYSCALL], DPL_USER);
|
||||||
|
|
||||||
initlock(&tickslock, "time");
|
initlock(&tickslock, "time");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ trap(struct trapframe *tf)
|
||||||
cpu->id, tf->cs, tf->eip);
|
cpu->id, tf->cs, tf->eip);
|
||||||
lapiceoi();
|
lapiceoi();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//PAGEBREAK: 13
|
//PAGEBREAK: 13
|
||||||
default:
|
default:
|
||||||
if(proc == 0 || (tf->cs&3) == 0){
|
if(proc == 0 || (tf->cs&3) == 0){
|
||||||
|
@ -89,13 +89,13 @@ trap(struct trapframe *tf)
|
||||||
// In user space, assume process misbehaved.
|
// In user space, assume process misbehaved.
|
||||||
cprintf("pid %d %s: trap %d err %d on cpu %d "
|
cprintf("pid %d %s: trap %d err %d on cpu %d "
|
||||||
"eip 0x%x addr 0x%x--kill proc\n",
|
"eip 0x%x addr 0x%x--kill proc\n",
|
||||||
proc->pid, proc->name, tf->trapno, tf->err, cpu->id, tf->eip,
|
proc->pid, proc->name, tf->trapno, tf->err, cpu->id, tf->eip,
|
||||||
rcr2());
|
rcr2());
|
||||||
proc->killed = 1;
|
proc->killed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force process exit if it has been killed and is in user space.
|
// Force process exit if it has been killed and is in user space.
|
||||||
// (If it is still executing in the kernel, let it keep running
|
// (If it is still executing in the kernel, let it keep running
|
||||||
// until it gets to the regular system call return.)
|
// until it gets to the regular system call return.)
|
||||||
if(proc && proc->killed && (tf->cs&3) == DPL_USER)
|
if(proc && proc->killed && (tf->cs&3) == DPL_USER)
|
||||||
exit();
|
exit();
|
||||||
|
|
4
uart.c
4
uart.c
|
@ -22,7 +22,7 @@ uartinit(void)
|
||||||
|
|
||||||
// Turn off the FIFO
|
// Turn off the FIFO
|
||||||
outb(COM1+2, 0);
|
outb(COM1+2, 0);
|
||||||
|
|
||||||
// 9600 baud, 8 data bits, 1 stop bit, parity off.
|
// 9600 baud, 8 data bits, 1 stop bit, parity off.
|
||||||
outb(COM1+3, 0x80); // Unlock divisor
|
outb(COM1+3, 0x80); // Unlock divisor
|
||||||
outb(COM1+0, 115200/9600);
|
outb(COM1+0, 115200/9600);
|
||||||
|
@ -42,7 +42,7 @@ uartinit(void)
|
||||||
inb(COM1+0);
|
inb(COM1+0);
|
||||||
picenable(IRQ_COM1);
|
picenable(IRQ_COM1);
|
||||||
ioapicenable(IRQ_COM1, 0);
|
ioapicenable(IRQ_COM1, 0);
|
||||||
|
|
||||||
// Announce that we're here.
|
// Announce that we're here.
|
||||||
for(p="xv6...\n"; *p; p++)
|
for(p="xv6...\n"; *p; p++)
|
||||||
uartputc(*p);
|
uartputc(*p);
|
||||||
|
|
2
ulib.c
2
ulib.c
|
@ -96,7 +96,7 @@ void*
|
||||||
memmove(void *vdst, void *vsrc, int n)
|
memmove(void *vdst, void *vsrc, int n)
|
||||||
{
|
{
|
||||||
char *dst, *src;
|
char *dst, *src;
|
||||||
|
|
||||||
dst = vdst;
|
dst = vdst;
|
||||||
src = vsrc;
|
src = vsrc;
|
||||||
while(n-- > 0)
|
while(n-- > 0)
|
||||||
|
|
20
usertests.c
20
usertests.c
|
@ -539,7 +539,7 @@ fourfiles(void)
|
||||||
printf(1, "create failed\n");
|
printf(1, "create failed\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buf, '0'+pi, 512);
|
memset(buf, '0'+pi, 512);
|
||||||
for(i = 0; i < 12; i++){
|
for(i = 0; i < 12; i++){
|
||||||
if((n = write(fd, buf, 500)) != 500){
|
if((n = write(fd, buf, 500)) != 500){
|
||||||
|
@ -882,7 +882,7 @@ linkunlink()
|
||||||
|
|
||||||
if(pid)
|
if(pid)
|
||||||
wait();
|
wait();
|
||||||
else
|
else
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
printf(1, "linkunlink ok\n");
|
printf(1, "linkunlink ok\n");
|
||||||
|
@ -951,7 +951,7 @@ subdir(void)
|
||||||
}
|
}
|
||||||
write(fd, "ff", 2);
|
write(fd, "ff", 2);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if(unlink("dd") >= 0){
|
if(unlink("dd") >= 0){
|
||||||
printf(1, "unlink dd (non-empty dir) succeeded!\n");
|
printf(1, "unlink dd (non-empty dir) succeeded!\n");
|
||||||
exit();
|
exit();
|
||||||
|
@ -1390,24 +1390,24 @@ forktest(void)
|
||||||
if(pid == 0)
|
if(pid == 0)
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n == 1000){
|
if(n == 1000){
|
||||||
printf(1, "fork claimed to work 1000 times!\n");
|
printf(1, "fork claimed to work 1000 times!\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(; n > 0; n--){
|
for(; n > 0; n--){
|
||||||
if(wait() < 0){
|
if(wait() < 0){
|
||||||
printf(1, "wait stopped early\n");
|
printf(1, "wait stopped early\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wait() != -1){
|
if(wait() != -1){
|
||||||
printf(1, "wait got too many\n");
|
printf(1, "wait got too many\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(1, "fork test OK\n");
|
printf(1, "fork test OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1424,7 +1424,7 @@ sbrktest(void)
|
||||||
// can one sbrk() less than a page?
|
// can one sbrk() less than a page?
|
||||||
a = sbrk(0);
|
a = sbrk(0);
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < 5000; i++){
|
for(i = 0; i < 5000; i++){
|
||||||
b = sbrk(1);
|
b = sbrk(1);
|
||||||
if(b != a){
|
if(b != a){
|
||||||
printf(stdout, "sbrk test failed %d %x %x\n", i, a, b);
|
printf(stdout, "sbrk test failed %d %x %x\n", i, a, b);
|
||||||
|
@ -1453,7 +1453,7 @@ sbrktest(void)
|
||||||
a = sbrk(0);
|
a = sbrk(0);
|
||||||
amt = (BIG) - (uint)a;
|
amt = (BIG) - (uint)a;
|
||||||
p = sbrk(amt);
|
p = sbrk(amt);
|
||||||
if (p != a) {
|
if (p != a) {
|
||||||
printf(stdout, "sbrk test failed to grow big address space; enough phys mem?\n");
|
printf(stdout, "sbrk test failed to grow big address space; enough phys mem?\n");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -1492,7 +1492,7 @@ sbrktest(void)
|
||||||
printf(stdout, "sbrk downsize failed, a %x c %x\n", a, c);
|
printf(stdout, "sbrk downsize failed, a %x c %x\n", a, c);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// can we read the kernel's memory?
|
// can we read the kernel's memory?
|
||||||
for(a = (char*)(KERNBASE); a < (char*) (KERNBASE+2000000); a += 50000){
|
for(a = (char*)(KERNBASE); a < (char*) (KERNBASE+2000000); a += 50000){
|
||||||
ppid = getpid();
|
ppid = getpid();
|
||||||
|
|
14
vm.c
14
vm.c
|
@ -32,7 +32,7 @@ seginit(void)
|
||||||
|
|
||||||
lgdt(c->gdt, sizeof(c->gdt));
|
lgdt(c->gdt, sizeof(c->gdt));
|
||||||
loadgs(SEG_KCPU << 3);
|
loadgs(SEG_KCPU << 3);
|
||||||
|
|
||||||
// Initialize cpu-local storage.
|
// Initialize cpu-local storage.
|
||||||
cpu = c;
|
cpu = c;
|
||||||
proc = 0;
|
proc = 0;
|
||||||
|
@ -56,7 +56,7 @@ walkpgdir(pde_t *pgdir, const void *va, int alloc)
|
||||||
// Make sure all those PTE_P bits are zero.
|
// Make sure all those PTE_P bits are zero.
|
||||||
memset(pgtab, 0, PGSIZE);
|
memset(pgtab, 0, PGSIZE);
|
||||||
// The permissions here are overly generous, but they can
|
// The permissions here are overly generous, but they can
|
||||||
// be further restricted by the permissions in the page table
|
// be further restricted by the permissions in the page table
|
||||||
// entries, if necessary.
|
// entries, if necessary.
|
||||||
*pde = V2P(pgtab) | PTE_P | PTE_W | PTE_U;
|
*pde = V2P(pgtab) | PTE_P | PTE_W | PTE_U;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ mappages(pde_t *pgdir, void *va, uint size, uint pa, int perm)
|
||||||
{
|
{
|
||||||
char *a, *last;
|
char *a, *last;
|
||||||
pte_t *pte;
|
pte_t *pte;
|
||||||
|
|
||||||
a = (char*)PGROUNDDOWN((uint)va);
|
a = (char*)PGROUNDDOWN((uint)va);
|
||||||
last = (char*)PGROUNDDOWN(((uint)va) + size - 1);
|
last = (char*)PGROUNDDOWN(((uint)va) + size - 1);
|
||||||
for(;;){
|
for(;;){
|
||||||
|
@ -93,7 +93,7 @@ mappages(pde_t *pgdir, void *va, uint size, uint pa, int perm)
|
||||||
// current process's page table during system calls and interrupts;
|
// current process's page table during system calls and interrupts;
|
||||||
// page protection bits prevent user code from using the kernel's
|
// page protection bits prevent user code from using the kernel's
|
||||||
// mappings.
|
// mappings.
|
||||||
//
|
//
|
||||||
// setupkvm() and exec() set up every page table like this:
|
// setupkvm() and exec() set up every page table like this:
|
||||||
//
|
//
|
||||||
// 0..KERNBASE: user memory (text+data+stack+heap), mapped to
|
// 0..KERNBASE: user memory (text+data+stack+heap), mapped to
|
||||||
|
@ -101,7 +101,7 @@ mappages(pde_t *pgdir, void *va, uint size, uint pa, int perm)
|
||||||
// KERNBASE..KERNBASE+EXTMEM: mapped to 0..EXTMEM (for I/O space)
|
// KERNBASE..KERNBASE+EXTMEM: mapped to 0..EXTMEM (for I/O space)
|
||||||
// KERNBASE+EXTMEM..data: mapped to EXTMEM..V2P(data)
|
// KERNBASE+EXTMEM..data: mapped to EXTMEM..V2P(data)
|
||||||
// for the kernel's instructions and r/o data
|
// for the kernel's instructions and r/o data
|
||||||
// data..KERNBASE+PHYSTOP: mapped to V2P(data)..PHYSTOP,
|
// data..KERNBASE+PHYSTOP: mapped to V2P(data)..PHYSTOP,
|
||||||
// rw data + free physical memory
|
// rw data + free physical memory
|
||||||
// 0xfe000000..0: mapped direct (devices such as ioapic)
|
// 0xfe000000..0: mapped direct (devices such as ioapic)
|
||||||
//
|
//
|
||||||
|
@ -136,7 +136,7 @@ setupkvm(void)
|
||||||
if (P2V(PHYSTOP) > (void*)DEVSPACE)
|
if (P2V(PHYSTOP) > (void*)DEVSPACE)
|
||||||
panic("PHYSTOP too high");
|
panic("PHYSTOP too high");
|
||||||
for(k = kmap; k < &kmap[NELEM(kmap)]; k++)
|
for(k = kmap; k < &kmap[NELEM(kmap)]; k++)
|
||||||
if(mappages(pgdir, k->virt, k->phys_end - k->phys_start,
|
if(mappages(pgdir, k->virt, k->phys_end - k->phys_start,
|
||||||
(uint)k->phys_start, k->perm) < 0)
|
(uint)k->phys_start, k->perm) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
return pgdir;
|
return pgdir;
|
||||||
|
@ -181,7 +181,7 @@ void
|
||||||
inituvm(pde_t *pgdir, char *init, uint sz)
|
inituvm(pde_t *pgdir, char *init, uint sz)
|
||||||
{
|
{
|
||||||
char *mem;
|
char *mem;
|
||||||
|
|
||||||
if(sz >= PGSIZE)
|
if(sz >= PGSIZE)
|
||||||
panic("inituvm: more than a page");
|
panic("inituvm: more than a page");
|
||||||
mem = kalloc();
|
mem = kalloc();
|
||||||
|
|
4
x86.h
4
x86.h
|
@ -121,7 +121,7 @@ static inline uint
|
||||||
xchg(volatile uint *addr, uint newval)
|
xchg(volatile uint *addr, uint newval)
|
||||||
{
|
{
|
||||||
uint result;
|
uint result;
|
||||||
|
|
||||||
// The + in "+m" denotes a read-modify-write operand.
|
// The + in "+m" denotes a read-modify-write operand.
|
||||||
asm volatile("lock; xchgl %0, %1" :
|
asm volatile("lock; xchgl %0, %1" :
|
||||||
"+m" (*addr), "=a" (result) :
|
"+m" (*addr), "=a" (result) :
|
||||||
|
@ -139,7 +139,7 @@ rcr2(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
lcr3(uint val)
|
lcr3(uint val)
|
||||||
{
|
{
|
||||||
asm volatile("movl %0,%%cr3" : : "r" (val));
|
asm volatile("movl %0,%%cr3" : : "r" (val));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue