Compare commits
10 commits
792d83cad1
...
83a632b1b2
Author | SHA1 | Date | |
---|---|---|---|
|
83a632b1b2 | ||
|
4376508c63 | ||
|
051f910f4d | ||
|
6e0d8f2ef6 | ||
|
0ae596828b | ||
|
ff2783442e | ||
|
241c068066 | ||
|
c440b5cd97 | ||
|
cf57e525c1 | ||
|
2ae8392a5c |
10 changed files with 124 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,3 +14,4 @@ kernel
|
|||
kernelmemfs
|
||||
mkfs
|
||||
.gdbinit
|
||||
.vagrant
|
22
Makefile
22
Makefile
|
@ -28,11 +28,7 @@ OBJS = \
|
|||
vectors.o\
|
||||
vm.o\
|
||||
|
||||
# Cross-compiling (e.g., on Mac OS X)
|
||||
#TOOLPREFIX = i386-jos-elf-
|
||||
|
||||
# Using native tools (e.g., on X86 Linux)
|
||||
#TOOLPREFIX =
|
||||
TOOLPREFIX =
|
||||
|
||||
# Try to infer the correct TOOLPREFIX if not set
|
||||
ifndef TOOLPREFIX
|
||||
|
@ -51,7 +47,7 @@ TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/d
|
|||
endif
|
||||
|
||||
# If the makefile can't find QEMU, specify its path here
|
||||
#QEMU =
|
||||
QEMU = qemu-system-i386
|
||||
|
||||
# Try to infer the correct QEMU
|
||||
ifndef QEMU
|
||||
|
@ -146,7 +142,13 @@ _forktest: forktest.o $(ULIB)
|
|||
$(OBJDUMP) -S _forktest > forktest.asm
|
||||
|
||||
mkfs: mkfs.c fs.h
|
||||
gcc -m32 -Werror -Wall -o mkfs mkfs.c
|
||||
gcc -Werror -Wall -o mkfs mkfs.c
|
||||
|
||||
# Prevent deletion of intermediate files, e.g. cat.o, after first build, so
|
||||
# that disk image changes after first build are persistent until clean. More
|
||||
# details:
|
||||
# http://www.gnu.org/software/make/manual/html_node/Chained-Rules.html
|
||||
.PRECIOUS: %.o
|
||||
|
||||
UPROGS=\
|
||||
_cat\
|
||||
|
@ -164,6 +166,8 @@ UPROGS=\
|
|||
_usertests\
|
||||
_wc\
|
||||
_zombie\
|
||||
_bigtest\
|
||||
#_getcount\
|
||||
|
||||
fs.img: mkfs README $(UPROGS)
|
||||
./mkfs fs.img README $(UPROGS)
|
||||
|
@ -200,9 +204,9 @@ QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
|
|||
then echo "-gdb tcp::$(GDBPORT)"; \
|
||||
else echo "-s -p $(GDBPORT)"; fi)
|
||||
ifndef CPUS
|
||||
CPUS := 2
|
||||
CPUS := 1
|
||||
endif
|
||||
QEMUOPTS = -hdb fs.img xv6.img -smp $(CPUS) -m 512 $(QEMUEXTRA)
|
||||
QEMUOPTS = -hdb fs.img xv6.img -smp $(CPUS) -m 512 $(QEMUEXTRA) -snapshot
|
||||
|
||||
qemu: fs.img xv6.img
|
||||
$(QEMU) -serial mon:stdio $(QEMUOPTS)
|
||||
|
|
21
Vagrantfile
vendored
Normal file
21
Vagrantfile
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
config.vm.box = "ubuntu/trusty64"
|
||||
|
||||
# Share an additional folder to the guest VM. The first argument is
|
||||
# the path on the host to the actual folder. The second argument is
|
||||
# the path on the guest to mount the folder. And the optional third
|
||||
# argument is a set of non-required options.
|
||||
# config.vm.synced_folder "../data", "/vagrant_data"
|
||||
|
||||
config.vm.provider "virtualbox" do |vb|
|
||||
vb.customize ["modifyvm", :id, "--memory", "1024"]
|
||||
end
|
||||
|
||||
config.vm.provision :shell, path: "vagrantprov.sh"
|
||||
end
|
51
bigtest.c
Normal file
51
bigtest.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "types.h"
|
||||
#include "stat.h"
|
||||
#include "user.h"
|
||||
#include "fcntl.h"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
char buf[512];
|
||||
int fd, i, sectors;
|
||||
|
||||
fd = open("big.file", O_CREATE | O_WRONLY);
|
||||
if(fd < 0){
|
||||
printf(2, "big: cannot open big.file for writing\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
sectors = 0;
|
||||
while(1){
|
||||
*(int*)buf = sectors;
|
||||
int cc = write(fd, buf, sizeof(buf));
|
||||
if(cc <= 0)
|
||||
break;
|
||||
sectors++;
|
||||
if (sectors % 100 == 0)
|
||||
printf(2, ".");
|
||||
}
|
||||
|
||||
printf(1, "\nwrote %d sectors\n", sectors);
|
||||
|
||||
close(fd);
|
||||
fd = open("big.file", O_RDONLY);
|
||||
if(fd < 0){
|
||||
printf(2, "big: cannot re-open big.file for reading\n");
|
||||
exit();
|
||||
}
|
||||
for(i = 0; i < sectors; i++){
|
||||
int cc = read(fd, buf, sizeof(buf));
|
||||
if(cc <= 0){
|
||||
printf(2, "big: read error at sector %d\n", i);
|
||||
exit();
|
||||
}
|
||||
if(*(int*)buf != i){
|
||||
printf(2, "big: read the wrong data (%d) for sector %d\n",
|
||||
*(int*)buf, i);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
exit();
|
||||
}
|
19
getcount.c
Normal file
19
getcount.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "types.h"
|
||||
#include "user.h"
|
||||
#include "syscall.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
printf(1, "initial fork count %d\n", getcount(SYS_fork));
|
||||
if (fork() == 0) {
|
||||
printf(1, "child fork count %d\n", getcount(SYS_fork));
|
||||
printf(1, "child write count %d\n", getcount(SYS_write));
|
||||
} else {
|
||||
wait();
|
||||
printf(1, "parent fork count %d\n", getcount(SYS_fork));
|
||||
printf(1, "parent write count %d\n", getcount(SYS_write));
|
||||
}
|
||||
printf(1, "wait count %d\n", getcount(SYS_wait));
|
||||
exit();
|
||||
}
|
4
ide.c
4
ide.c
|
@ -134,11 +134,11 @@ iderw(struct buf *b)
|
|||
if(b->dev != 0 && !havedisk1)
|
||||
panic("iderw: ide disk 1 not present");
|
||||
|
||||
acquire(&idelock); //DOC: acquire-lock
|
||||
acquire(&idelock); //DOC:acquire-lock
|
||||
|
||||
// Append b to idequeue.
|
||||
b->qnext = 0;
|
||||
for(pp=&idequeue; *pp; pp=&(*pp)->qnext) //DOC: insert-queue
|
||||
for(pp=&idequeue; *pp; pp=&(*pp)->qnext) //DOC:insert-queue
|
||||
;
|
||||
*pp = b;
|
||||
|
||||
|
|
9
mkfs.c
9
mkfs.c
|
@ -11,10 +11,12 @@
|
|||
#include "stat.h"
|
||||
#include "param.h"
|
||||
|
||||
int nblocks = 985;
|
||||
#define static_assert(a, b) do { switch (0) case 0: case (a): ; } while (0)
|
||||
|
||||
int nblocks = 25000;
|
||||
int nlog = LOGSIZE;
|
||||
int ninodes = 200;
|
||||
int size = 1024;
|
||||
int size = 25045;
|
||||
|
||||
int fsfd;
|
||||
struct superblock sb;
|
||||
|
@ -64,6 +66,9 @@ main(int argc, char *argv[])
|
|||
char buf[512];
|
||||
struct dinode din;
|
||||
|
||||
|
||||
static_assert(sizeof(int) == 4, "Integers must be 4 bytes!");
|
||||
|
||||
if(argc < 2){
|
||||
fprintf(stderr, "Usage: mkfs fs.img files...\n");
|
||||
exit(1);
|
||||
|
|
1
mmu.h
1
mmu.h
|
@ -142,6 +142,7 @@ struct segdesc {
|
|||
|
||||
// Address in page table or page directory entry
|
||||
#define PTE_ADDR(pte) ((uint)(pte) & ~0xFFF)
|
||||
#define PTE_FLAGS(pte) ((uint)(pte) & 0xFFF)
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
typedef uint pte_t;
|
||||
|
|
6
vagrantprov.sh
Executable file
6
vagrantprov.sh
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
apt-get update
|
||||
apt-get install -y qemu-system-x86
|
||||
apt-get install -y gdb
|
||||
echo "set auto-load safe-path /" > /home/vagrant/.gdbinit
|
5
vm.c
5
vm.c
|
@ -311,7 +311,7 @@ copyuvm(pde_t *pgdir, uint sz)
|
|||
{
|
||||
pde_t *d;
|
||||
pte_t *pte;
|
||||
uint pa, i;
|
||||
uint pa, i, flags;
|
||||
char *mem;
|
||||
|
||||
if((d = setupkvm()) == 0)
|
||||
|
@ -322,10 +322,11 @@ copyuvm(pde_t *pgdir, uint sz)
|
|||
if(!(*pte & PTE_P))
|
||||
panic("copyuvm: page not present");
|
||||
pa = PTE_ADDR(*pte);
|
||||
flags = PTE_FLAGS(*pte);
|
||||
if((mem = kalloc()) == 0)
|
||||
goto bad;
|
||||
memmove(mem, (char*)p2v(pa), PGSIZE);
|
||||
if(mappages(d, (void*)i, PGSIZE, v2p(mem), PTE_W|PTE_U) < 0)
|
||||
if(mappages(d, (void*)i, PGSIZE, v2p(mem), flags) < 0)
|
||||
goto bad;
|
||||
}
|
||||
return d;
|
||||
|
|
Loading…
Reference in a new issue