Compare commits
10 commits
792d83cad1
...
83a632b1b2
Author | SHA1 | Date | |
---|---|---|---|
83a632b1b2 | |||
4376508c63 | |||
051f910f4d | |||
6e0d8f2ef6 | |||
0ae596828b | |||
ff2783442e | |||
241c068066 | |||
c440b5cd97 | |||
cf57e525c1 | |||
2ae8392a5c |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,3 +14,4 @@ kernel
|
||||||
kernelmemfs
|
kernelmemfs
|
||||||
mkfs
|
mkfs
|
||||||
.gdbinit
|
.gdbinit
|
||||||
|
.vagrant
|
22
Makefile
22
Makefile
|
@ -28,11 +28,7 @@ OBJS = \
|
||||||
vectors.o\
|
vectors.o\
|
||||||
vm.o\
|
vm.o\
|
||||||
|
|
||||||
# Cross-compiling (e.g., on Mac OS X)
|
TOOLPREFIX =
|
||||||
#TOOLPREFIX = i386-jos-elf-
|
|
||||||
|
|
||||||
# Using native tools (e.g., on X86 Linux)
|
|
||||||
#TOOLPREFIX =
|
|
||||||
|
|
||||||
# Try to infer the correct TOOLPREFIX if not set
|
# Try to infer the correct TOOLPREFIX if not set
|
||||||
ifndef TOOLPREFIX
|
ifndef TOOLPREFIX
|
||||||
|
@ -51,7 +47,7 @@ TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/d
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# If the makefile can't find QEMU, specify its path here
|
# If the makefile can't find QEMU, specify its path here
|
||||||
#QEMU =
|
QEMU = qemu-system-i386
|
||||||
|
|
||||||
# Try to infer the correct QEMU
|
# Try to infer the correct QEMU
|
||||||
ifndef QEMU
|
ifndef QEMU
|
||||||
|
@ -146,7 +142,13 @@ _forktest: forktest.o $(ULIB)
|
||||||
$(OBJDUMP) -S _forktest > forktest.asm
|
$(OBJDUMP) -S _forktest > forktest.asm
|
||||||
|
|
||||||
mkfs: mkfs.c fs.h
|
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=\
|
UPROGS=\
|
||||||
_cat\
|
_cat\
|
||||||
|
@ -164,6 +166,8 @@ UPROGS=\
|
||||||
_usertests\
|
_usertests\
|
||||||
_wc\
|
_wc\
|
||||||
_zombie\
|
_zombie\
|
||||||
|
_bigtest\
|
||||||
|
#_getcount\
|
||||||
|
|
||||||
fs.img: mkfs README $(UPROGS)
|
fs.img: mkfs README $(UPROGS)
|
||||||
./mkfs fs.img README $(UPROGS)
|
./mkfs fs.img README $(UPROGS)
|
||||||
|
@ -200,9 +204,9 @@ QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
|
||||||
then echo "-gdb tcp::$(GDBPORT)"; \
|
then echo "-gdb tcp::$(GDBPORT)"; \
|
||||||
else echo "-s -p $(GDBPORT)"; fi)
|
else echo "-s -p $(GDBPORT)"; fi)
|
||||||
ifndef CPUS
|
ifndef CPUS
|
||||||
CPUS := 2
|
CPUS := 1
|
||||||
endif
|
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: fs.img xv6.img
|
||||||
$(QEMU) -serial mon:stdio $(QEMUOPTS)
|
$(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)
|
if(b->dev != 0 && !havedisk1)
|
||||||
panic("iderw: ide disk 1 not present");
|
panic("iderw: ide disk 1 not present");
|
||||||
|
|
||||||
acquire(&idelock); //DOC: acquire-lock
|
acquire(&idelock); //DOC:acquire-lock
|
||||||
|
|
||||||
// Append b to idequeue.
|
// Append b to idequeue.
|
||||||
b->qnext = 0;
|
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;
|
*pp = b;
|
||||||
|
|
||||||
|
|
9
mkfs.c
9
mkfs.c
|
@ -11,10 +11,12 @@
|
||||||
#include "stat.h"
|
#include "stat.h"
|
||||||
#include "param.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 nlog = LOGSIZE;
|
||||||
int ninodes = 200;
|
int ninodes = 200;
|
||||||
int size = 1024;
|
int size = 25045;
|
||||||
|
|
||||||
int fsfd;
|
int fsfd;
|
||||||
struct superblock sb;
|
struct superblock sb;
|
||||||
|
@ -64,6 +66,9 @@ main(int argc, char *argv[])
|
||||||
char buf[512];
|
char buf[512];
|
||||||
struct dinode din;
|
struct dinode din;
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(sizeof(int) == 4, "Integers must be 4 bytes!");
|
||||||
|
|
||||||
if(argc < 2){
|
if(argc < 2){
|
||||||
fprintf(stderr, "Usage: mkfs fs.img files...\n");
|
fprintf(stderr, "Usage: mkfs fs.img files...\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
1
mmu.h
1
mmu.h
|
@ -142,6 +142,7 @@ struct segdesc {
|
||||||
|
|
||||||
// Address in page table or page directory entry
|
// Address in page table or page directory entry
|
||||||
#define PTE_ADDR(pte) ((uint)(pte) & ~0xFFF)
|
#define PTE_ADDR(pte) ((uint)(pte) & ~0xFFF)
|
||||||
|
#define PTE_FLAGS(pte) ((uint)(pte) & 0xFFF)
|
||||||
|
|
||||||
#ifndef __ASSEMBLER__
|
#ifndef __ASSEMBLER__
|
||||||
typedef uint pte_t;
|
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;
|
pde_t *d;
|
||||||
pte_t *pte;
|
pte_t *pte;
|
||||||
uint pa, i;
|
uint pa, i, flags;
|
||||||
char *mem;
|
char *mem;
|
||||||
|
|
||||||
if((d = setupkvm()) == 0)
|
if((d = setupkvm()) == 0)
|
||||||
|
@ -322,10 +322,11 @@ copyuvm(pde_t *pgdir, uint sz)
|
||||||
if(!(*pte & PTE_P))
|
if(!(*pte & PTE_P))
|
||||||
panic("copyuvm: page not present");
|
panic("copyuvm: page not present");
|
||||||
pa = PTE_ADDR(*pte);
|
pa = PTE_ADDR(*pte);
|
||||||
|
flags = PTE_FLAGS(*pte);
|
||||||
if((mem = kalloc()) == 0)
|
if((mem = kalloc()) == 0)
|
||||||
goto bad;
|
goto bad;
|
||||||
memmove(mem, (char*)p2v(pa), PGSIZE);
|
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;
|
goto bad;
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
|
|
Loading…
Reference in a new issue