Skip to content

Commit 10df8c5

Browse files
committed
Boot xv6
1 parent 7693875 commit 10df8c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+12620
-0
lines changed

6.828/xv6-public/.cvsignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.asm
2+
*.d
3+
*.sym
4+
_*
5+
kernel
6+
user1
7+
userfs
8+
usertests
9+
xv6.img
10+
vectors.S
11+
bochsout.txt
12+
bootblock
13+
bootother
14+
bootother.out
15+
parport.out
16+
fmt

6.828/xv6-public/.dir-locals.el

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
((c-mode
2+
(indent-tabs-mode . nil)
3+
(c-file-style . "bsd")
4+
(c-basic-offset . 2)))

6.828/xv6-public/.gdbinit.tmpl

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
set $lastcs = -1
2+
3+
define hook-stop
4+
# There doesn't seem to be a good way to detect if we're in 16- or
5+
# 32-bit mode, but in 32-bit mode we always run with CS == 8 in the
6+
# kernel and CS == 35 in user space
7+
if $cs == 8 || $cs == 35
8+
if $lastcs != 8 && $lastcs != 35
9+
set architecture i386
10+
end
11+
x/i $pc
12+
else
13+
if $lastcs == -1 || $lastcs == 8 || $lastcs == 35
14+
set architecture i8086
15+
end
16+
# Translate the segment:offset into a physical address
17+
printf "[%4x:%4x] ", $cs, $eip
18+
x/i $cs*16+$eip
19+
end
20+
set $lastcs = $cs
21+
end
22+
23+
echo + target remote localhost:1234\n
24+
target remote localhost:1234
25+
26+
echo + symbol-file kernel\n
27+
symbol-file kernel

6.828/xv6-public/.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*~
2+
_*
3+
*.o
4+
*.d
5+
*.asm
6+
*.sym
7+
*.img
8+
vectors.S
9+
bootblock
10+
entryother
11+
initcode
12+
initcode.out
13+
kernel
14+
kernelmemfs
15+
mkfs
16+
.gdbinit

6.828/xv6-public/BUGS

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
formatting:
2+
need to fix PAGEBREAK mechanism
3+
4+
sh:
5+
can't always runcmd in child -- breaks cd.
6+
maybe should hard-code PATH=/ ?
7+

6.828/xv6-public/LICENSE

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
The xv6 software is:
2+
3+
Copyright (c) 2006-2017 Frans Kaashoek, Robert Morris, Russ Cox,
4+
Massachusetts Institute of Technology
5+
6+
Permission is hereby granted, free of charge, to any person obtaining
7+
a copy of this software and associated documentation files (the
8+
"Software"), to deal in the Software without restriction, including
9+
without limitation the rights to use, copy, modify, merge, publish,
10+
distribute, sublicense, and/or sell copies of the Software, and to
11+
permit persons to whom the Software is furnished to do so, subject to
12+
the following conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+

6.828/xv6-public/Makefile

+279
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
OBJS = \
2+
bio.o\
3+
console.o\
4+
exec.o\
5+
file.o\
6+
fs.o\
7+
ide.o\
8+
ioapic.o\
9+
kalloc.o\
10+
kbd.o\
11+
lapic.o\
12+
log.o\
13+
main.o\
14+
mp.o\
15+
picirq.o\
16+
pipe.o\
17+
proc.o\
18+
sleeplock.o\
19+
spinlock.o\
20+
string.o\
21+
swtch.o\
22+
syscall.o\
23+
sysfile.o\
24+
sysproc.o\
25+
trapasm.o\
26+
trap.o\
27+
uart.o\
28+
vectors.o\
29+
vm.o\
30+
31+
# Cross-compiling (e.g., on Mac OS X)
32+
TOOLPREFIX = i386-jos-elf-
33+
34+
# Using native tools (e.g., on X86 Linux)
35+
#TOOLPREFIX =
36+
37+
# Try to infer the correct TOOLPREFIX if not set
38+
ifndef TOOLPREFIX
39+
TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
40+
then echo 'i386-jos-elf-'; \
41+
elif objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \
42+
then echo ''; \
43+
else echo "***" 1>&2; \
44+
echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \
45+
echo "*** Is the directory with i386-jos-elf-gcc in your PATH?" 1>&2; \
46+
echo "*** If your i386-*-elf toolchain is installed with a command" 1>&2; \
47+
echo "*** prefix other than 'i386-jos-elf-', set your TOOLPREFIX" 1>&2; \
48+
echo "*** environment variable to that prefix and run 'make' again." 1>&2; \
49+
echo "*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \
50+
echo "***" 1>&2; exit 1; fi)
51+
endif
52+
53+
# If the makefile can't find QEMU, specify its path here
54+
QEMU = qemu-system-i386
55+
56+
# Try to infer the correct QEMU
57+
ifndef QEMU
58+
QEMU = $(shell if which qemu > /dev/null; \
59+
then echo qemu; exit; \
60+
elif which qemu-system-i386 > /dev/null; \
61+
then echo qemu-system-i386; exit; \
62+
elif which qemu-system-x86_64 > /dev/null; \
63+
then echo qemu-system-x86_64; exit; \
64+
else \
65+
qemu=/Applications/Q.app/Contents/MacOS/i386-softmmu.app/Contents/MacOS/i386-softmmu; \
66+
if test -x $$qemu; then echo $$qemu; exit; fi; fi; \
67+
echo "***" 1>&2; \
68+
echo "*** Error: Couldn't find a working QEMU executable." 1>&2; \
69+
echo "*** Is the directory containing the qemu binary in your PATH" 1>&2; \
70+
echo "*** or have you tried setting the QEMU variable in Makefile?" 1>&2; \
71+
echo "***" 1>&2; exit 1)
72+
endif
73+
74+
CC = $(TOOLPREFIX)gcc
75+
AS = $(TOOLPREFIX)gas
76+
LD = $(TOOLPREFIX)ld
77+
OBJCOPY = $(TOOLPREFIX)objcopy
78+
OBJDUMP = $(TOOLPREFIX)objdump
79+
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer
80+
#CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -fvar-tracking -fvar-tracking-assignments -O0 -g -Wall -MD -gdwarf-2 -m32 -Werror -fno-omit-frame-pointer
81+
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
82+
ASFLAGS = -m32 -gdwarf-2 -Wa,-divide
83+
# FreeBSD ld wants ``elf_i386_fbsd''
84+
LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null | head -n 1)
85+
86+
xv6.img: bootblock kernel fs.img
87+
dd if=/dev/zero of=xv6.img count=10000
88+
dd if=bootblock of=xv6.img conv=notrunc
89+
dd if=kernel of=xv6.img seek=1 conv=notrunc
90+
91+
xv6memfs.img: bootblock kernelmemfs
92+
dd if=/dev/zero of=xv6memfs.img count=10000
93+
dd if=bootblock of=xv6memfs.img conv=notrunc
94+
dd if=kernelmemfs of=xv6memfs.img seek=1 conv=notrunc
95+
96+
bootblock: bootasm.S bootmain.c
97+
$(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c bootmain.c
98+
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c bootasm.S
99+
$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o bootmain.o
100+
$(OBJDUMP) -S bootblock.o > bootblock.asm
101+
$(OBJCOPY) -S -O binary -j .text bootblock.o bootblock
102+
./sign.pl bootblock
103+
104+
entryother: entryother.S
105+
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c entryother.S
106+
$(LD) $(LDFLAGS) -N -e start -Ttext 0x7000 -o bootblockother.o entryother.o
107+
$(OBJCOPY) -S -O binary -j .text bootblockother.o entryother
108+
$(OBJDUMP) -S bootblockother.o > entryother.asm
109+
110+
initcode: initcode.S
111+
$(CC) $(CFLAGS) -nostdinc -I. -c initcode.S
112+
$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o initcode.out initcode.o
113+
$(OBJCOPY) -S -O binary initcode.out initcode
114+
$(OBJDUMP) -S initcode.o > initcode.asm
115+
116+
kernel: $(OBJS) entry.o entryother initcode kernel.ld
117+
$(LD) $(LDFLAGS) -T kernel.ld -o kernel entry.o $(OBJS) -b binary initcode entryother
118+
$(OBJDUMP) -S kernel > kernel.asm
119+
$(OBJDUMP) -t kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym
120+
121+
# kernelmemfs is a copy of kernel that maintains the
122+
# disk image in memory instead of writing to a disk.
123+
# This is not so useful for testing persistent storage or
124+
# exploring disk buffering implementations, but it is
125+
# great for testing the kernel on real hardware without
126+
# needing a scratch disk.
127+
MEMFSOBJS = $(filter-out ide.o,$(OBJS)) memide.o
128+
kernelmemfs: $(MEMFSOBJS) entry.o entryother initcode kernel.ld fs.img
129+
$(LD) $(LDFLAGS) -T kernel.ld -o kernelmemfs entry.o $(MEMFSOBJS) -b binary initcode entryother fs.img
130+
$(OBJDUMP) -S kernelmemfs > kernelmemfs.asm
131+
$(OBJDUMP) -t kernelmemfs | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernelmemfs.sym
132+
133+
tags: $(OBJS) entryother.S _init
134+
etags *.S *.c
135+
136+
vectors.S: vectors.pl
137+
perl vectors.pl > vectors.S
138+
139+
ULIB = ulib.o usys.o printf.o umalloc.o
140+
141+
_%: %.o $(ULIB)
142+
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^
143+
$(OBJDUMP) -S $@ > $*.asm
144+
$(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym
145+
146+
_forktest: forktest.o $(ULIB)
147+
# forktest has less library code linked in - needs to be small
148+
# in order to be able to max out the proc table.
149+
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o _forktest forktest.o ulib.o usys.o
150+
$(OBJDUMP) -S _forktest > forktest.asm
151+
152+
mkfs: mkfs.c fs.h
153+
gcc -Werror -Wall -o mkfs mkfs.c
154+
155+
# Prevent deletion of intermediate files, e.g. cat.o, after first build, so
156+
# that disk image changes after first build are persistent until clean. More
157+
# details:
158+
# http://www.gnu.org/software/make/manual/html_node/Chained-Rules.html
159+
.PRECIOUS: %.o
160+
161+
UPROGS=\
162+
_cat\
163+
_echo\
164+
_forktest\
165+
_grep\
166+
_init\
167+
_kill\
168+
_ln\
169+
_ls\
170+
_mkdir\
171+
_rm\
172+
_sh\
173+
_stressfs\
174+
_usertests\
175+
_wc\
176+
_zombie\
177+
178+
fs.img: mkfs README $(UPROGS)
179+
./mkfs fs.img README $(UPROGS)
180+
181+
-include *.d
182+
183+
clean:
184+
rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
185+
*.o *.d *.asm *.sym vectors.S bootblock entryother \
186+
initcode initcode.out kernel xv6.img fs.img kernelmemfs mkfs \
187+
.gdbinit \
188+
$(UPROGS)
189+
190+
# make a printout
191+
FILES = $(shell grep -v '^\#' runoff.list)
192+
PRINT = runoff.list runoff.spec README toc.hdr toc.ftr $(FILES)
193+
194+
xv6.pdf: $(PRINT)
195+
./runoff
196+
ls -l xv6.pdf
197+
198+
print: xv6.pdf
199+
200+
# run in emulators
201+
202+
bochs : fs.img xv6.img
203+
if [ ! -e .bochsrc ]; then ln -s dot-bochsrc .bochsrc; fi
204+
bochs -q
205+
206+
# try to generate a unique GDB port
207+
GDBPORT = $(shell expr `id -u` % 5000 + 25000)
208+
# QEMU's gdb stub command line changed in 0.11
209+
QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
210+
then echo "-gdb tcp::$(GDBPORT)"; \
211+
else echo "-s -p $(GDBPORT)"; fi)
212+
ifndef CPUS
213+
CPUS := 2
214+
endif
215+
QEMUOPTS = -drive file=fs.img,index=1,media=disk,format=raw -drive file=xv6.img,index=0,media=disk,format=raw -smp $(CPUS) -m 512 $(QEMUEXTRA)
216+
217+
qemu: fs.img xv6.img
218+
$(QEMU) -serial mon:stdio $(QEMUOPTS)
219+
220+
qemu-memfs: xv6memfs.img
221+
$(QEMU) -drive file=xv6memfs.img,index=0,media=disk,format=raw -smp $(CPUS) -m 256
222+
223+
qemu-nox: fs.img xv6.img
224+
$(QEMU) -nographic $(QEMUOPTS)
225+
226+
.gdbinit: .gdbinit.tmpl
227+
sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
228+
229+
qemu-gdb: fs.img xv6.img .gdbinit
230+
@echo "*** Now run 'gdb'." 1>&2
231+
$(QEMU) -serial mon:stdio $(QEMUOPTS) -S $(QEMUGDB)
232+
233+
qemu-nox-gdb: fs.img xv6.img .gdbinit
234+
@echo "*** Now run 'gdb'." 1>&2
235+
$(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB)
236+
237+
# CUT HERE
238+
# prepare dist for students
239+
# after running make dist, probably want to
240+
# rename it to rev0 or rev1 or so on and then
241+
# check in that version.
242+
243+
EXTRA=\
244+
mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\
245+
ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\
246+
printf.c umalloc.c\
247+
README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\
248+
.gdbinit.tmpl gdbutil\
249+
250+
dist:
251+
rm -rf dist
252+
mkdir dist
253+
for i in $(FILES); \
254+
do \
255+
grep -v PAGEBREAK $$i >dist/$$i; \
256+
done
257+
sed '/CUT HERE/,$$d' Makefile >dist/Makefile
258+
echo >dist/runoff.spec
259+
cp $(EXTRA) dist
260+
261+
dist-test:
262+
rm -rf dist
263+
make dist
264+
rm -rf dist-test
265+
mkdir dist-test
266+
cp dist/* dist-test
267+
cd dist-test; $(MAKE) print
268+
cd dist-test; $(MAKE) bochs || true
269+
cd dist-test; $(MAKE) qemu
270+
271+
# update this rule (change rev#) when it is time to
272+
# make a new revision.
273+
tar:
274+
rm -rf /tmp/xv6
275+
mkdir -p /tmp/xv6
276+
cp dist/* dist/.gdbinit.tmpl /tmp/xv6
277+
(cd /tmp; tar cf - xv6) | gzip >xv6-rev10.tar.gz # the next one will be 10 (9/17)
278+
279+
.PHONY: dist-test dist

0 commit comments

Comments
 (0)