Skip to content

Commit 513f595

Browse files
committed
modified & revised xv6 code
0 parents  commit 513f595

File tree

272 files changed

+173927
-0
lines changed

Some content is hidden

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

272 files changed

+173927
-0
lines changed

.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

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+

LICENSE

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
The xv6 software is:
2+
3+
Copyright (c) 2006-2009 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+

Makefile

+270
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
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+
spinlock.o\
19+
string.o\
20+
swtch.o\
21+
syscall.o\
22+
sysfile.o\
23+
sysproc.o\
24+
timer.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 = /usr/bin/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+
else \
61+
qemu=/Applications/Q.app/Contents/MacOS/i386-softmmu.app/Contents/MacOS/i386-softmmu; \
62+
if test -x $$qemu; then echo $$qemu; exit; fi; fi; \
63+
echo "***" 1>&2; \
64+
echo "*** Error: Couldn't find a working QEMU executable." 1>&2; \
65+
echo "*** Is the directory containing the qemu binary in your PATH" 1>&2; \
66+
echo "*** or have you tried setting the QEMU variable in Makefile?" 1>&2; \
67+
echo "***" 1>&2; exit 1)
68+
endif
69+
70+
CC = $(TOOLPREFIX)gcc
71+
AS = $(TOOLPREFIX)gas
72+
LD = $(TOOLPREFIX)ld
73+
OBJCOPY = $(TOOLPREFIX)objcopy
74+
OBJDUMP = $(TOOLPREFIX)objdump
75+
#CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer
76+
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer
77+
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
78+
ASFLAGS = -m32 -gdwarf-2 -Wa,-divide
79+
# FreeBSD ld wants ``elf_i386_fbsd''
80+
LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null)
81+
82+
xv6.img: bootblock kernel fs.img
83+
dd if=/dev/zero of=xv6.img count=10000
84+
dd if=bootblock of=xv6.img conv=notrunc
85+
dd if=kernel of=xv6.img seek=1 conv=notrunc
86+
87+
xv6memfs.img: bootblock kernelmemfs
88+
dd if=/dev/zero of=xv6memfs.img count=10000
89+
dd if=bootblock of=xv6memfs.img conv=notrunc
90+
dd if=kernelmemfs of=xv6memfs.img seek=1 conv=notrunc
91+
92+
bootblock: bootasm.S bootmain.c
93+
$(CC) $(CFLAGS) -fno-pic -O -nostdinc -I. -c bootmain.c
94+
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c bootasm.S
95+
$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o bootmain.o
96+
$(OBJDUMP) -S bootblock.o > bootblock.asm
97+
$(OBJCOPY) -S -O binary -j .text bootblock.o bootblock
98+
./sign.pl bootblock
99+
100+
entryother: entryother.S
101+
$(CC) $(CFLAGS) -fno-pic -nostdinc -I. -c entryother.S
102+
$(LD) $(LDFLAGS) -N -e start -Ttext 0x7000 -o bootblockother.o entryother.o
103+
$(OBJCOPY) -S -O binary -j .text bootblockother.o entryother
104+
$(OBJDUMP) -S bootblockother.o > entryother.asm
105+
106+
initcode: initcode.S
107+
$(CC) $(CFLAGS) -nostdinc -I. -c initcode.S
108+
$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o initcode.out initcode.o
109+
$(OBJCOPY) -S -O binary initcode.out initcode
110+
$(OBJDUMP) -S initcode.o > initcode.asm
111+
112+
kernel: $(OBJS) entry.o entryother initcode kernel.ld
113+
$(LD) $(LDFLAGS) -T kernel.ld -o kernel entry.o $(OBJS) -b binary initcode entryother
114+
$(OBJDUMP) -S kernel > kernel.asm
115+
$(OBJDUMP) -t kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym
116+
117+
# kernelmemfs is a copy of kernel that maintains the
118+
# disk image in memory instead of writing to a disk.
119+
# This is not so useful for testing persistent storage or
120+
# exploring disk buffering implementations, but it is
121+
# great for testing the kernel on real hardware without
122+
# needing a scratch disk.
123+
MEMFSOBJS = $(filter-out ide.o,$(OBJS)) memide.o
124+
kernelmemfs: $(MEMFSOBJS) entry.o entryother initcode fs.img
125+
$(LD) $(LDFLAGS) -Ttext 0x100000 -e main -o kernelmemfs entry.o $(MEMFSOBJS) -b binary initcode entryother fs.img
126+
$(OBJDUMP) -S kernelmemfs > kernelmemfs.asm
127+
$(OBJDUMP) -t kernelmemfs | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernelmemfs.sym
128+
129+
tags: $(OBJS) entryother.S _init
130+
etags *.S *.c
131+
132+
vectors.S: vectors.pl
133+
perl vectors.pl > vectors.S
134+
135+
ULIB = pow.o ulib.o usys.o printf.o umalloc.o libfile.o\
136+
liblog.o exp.o\
137+
138+
_%: %.o $(ULIB)
139+
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^
140+
$(OBJDUMP) -S $@ > $*.asm
141+
$(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym
142+
143+
_forktest: forktest.o $(ULIB)
144+
# forktest has less library code linked in - needs to be small
145+
# in order to be able to max out the proc table.
146+
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o _forktest forktest.o ulib.o usys.o
147+
$(OBJDUMP) -S _forktest > forktest.asm
148+
149+
mkfs: mkfs.c fs.h
150+
gcc -m32 -Werror -Wall -o mkfs mkfs.c
151+
152+
UPROGS=\
153+
_cat\
154+
_echo\
155+
_forktest\
156+
_grep\
157+
_init\
158+
_kill\
159+
_ln\
160+
_ls\
161+
_mkdir\
162+
_rm\
163+
_sh\
164+
_stressfs\
165+
_wc\
166+
_zombie\
167+
_test\
168+
169+
fs.img: mkfs a test1 $(UPROGS)
170+
./mkfs fs.img a test1 $(UPROGS)
171+
172+
-include *.d
173+
174+
clean:
175+
rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
176+
*.o *.d *.asm *.sym vectors.S bootblock entryother \
177+
initcode initcode.out kernel xv6.img fs.img kernelmemfs mkfs \
178+
.gdbinit \
179+
$(UPROGS)
180+
181+
# make a printout
182+
FILES = $(shell grep -v '^\#' runoff.list)
183+
PRINT = runoff.list runoff.spec README toc.hdr toc.ftr $(FILES)
184+
185+
xv6.pdf: $(PRINT)
186+
./runoff
187+
ls -l xv6.pdf
188+
189+
print: xv6.pdf
190+
191+
# run in emulators
192+
193+
bochs : fs.img xv6.img
194+
if [ ! -e .bochsrc ]; then ln -s dot-bochsrc .bochsrc; fi
195+
bochs -q
196+
197+
# try to generate a unique GDB port
198+
GDBPORT = $(shell expr `id -u` % 5000 + 25000)
199+
# QEMU's gdb stub command line changed in 0.11
200+
QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
201+
then echo "-gdb tcp::$(GDBPORT)"; \
202+
else echo "-s -p $(GDBPORT)"; fi)
203+
ifndef CPUS
204+
CPUS := 2
205+
endif
206+
QEMUOPTS = -hdb fs.img xv6.img -smp $(CPUS) -m 512 $(QEMUEXTRA)
207+
208+
qemu: fs.img xv6.img
209+
$(QEMU) -serial mon:stdio $(QEMUOPTS)
210+
211+
qemu-memfs: xv6memfs.img
212+
$(QEMU) xv6memfs.img -smp $(CPUS)
213+
214+
qemu-nox: fs.img xv6.img
215+
$(QEMU) -nographic $(QEMUOPTS)
216+
217+
.gdbinit: .gdbinit.tmpl
218+
sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
219+
220+
qemu-gdb: fs.img xv6.img .gdbinit
221+
@echo "*** Now run 'gdb'." 1>&2
222+
$(QEMU) -serial mon:stdio $(QEMUOPTS) -S $(QEMUGDB)
223+
224+
qemu-nox-gdb: fs.img xv6.img .gdbinit
225+
@echo "*** Now run 'gdb'." 1>&2
226+
$(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB)
227+
228+
# CUT HERE
229+
# prepare dist for students
230+
# after running make dist, probably want to
231+
# rename it to rev0 or rev1 or so on and then
232+
# check in that version.
233+
234+
EXTRA=\
235+
mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\
236+
ln.c ls.c mkdir.c rm.c stressfs.c wc.c zombie.c\
237+
printf.c umalloc.c \
238+
README picoc dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\
239+
.gdbinit.tmpl gdbutil\
240+
241+
dist:
242+
rm -rf dist
243+
mkdir dist
244+
for i in $(FILES); \
245+
do \
246+
grep -v PAGEBREAK $$i >dist/$$i; \
247+
done
248+
sed '/CUT HERE/,$$d' Makefile >dist/Makefile
249+
echo >dist/runoff.spec
250+
cp $(EXTRA) dist
251+
252+
dist-test:
253+
rm -rf dist
254+
make dist
255+
rm -rf dist-test
256+
mkdir dist-test
257+
cp dist/* dist-test
258+
cd dist-test; $(MAKE) print
259+
cd dist-test; $(MAKE) bochs || true
260+
cd dist-test; $(MAKE) qemu
261+
262+
# update this rule (change rev#) when it is time to
263+
# make a new revision.
264+
tar:
265+
rm -rf /tmp/xv6
266+
mkdir -p /tmp/xv6
267+
cp dist/* dist/.gdbinit.tmpl /tmp/xv6
268+
(cd /tmp; tar cf - xv6) | gzip >xv6-rev5.tar.gz
269+
270+
.PHONY: dist-test dist

0 commit comments

Comments
 (0)