x86 – Introduction to xv

Introduction to xv

x86 – 这是利用x86进行训练的代写, 对x86的流程进行训练解析, 包括了x86等方面

x86汇编代写 汇编代写 assembly

Introduction

Within this class, we need a model operating system to play with. Well, I say play
with, I really mean make use of to learn operating system concepts by implementing them.
There are many such systems from which you can choose:
Linux
Minix
FreeBSD
EduOS
Xinu
OS/161 (name coincidental, has nothing to do with our CS161)
xv
Each has its advantages and disadvantages. For instance, Linux is feature complete, and
making changes is complex even in building the system. Minix, while an excellent teaching
choice, is out of sync with its textbook. FreeBSD is just like Linux: it’s too complete. EduOS
(from RWTH Aachen University) would be a solid option, as its development is tailored
specifically for teaching. Xinu (from Purdue University), OS/161 (from Harvard University), and
xv6 (from MIT) follow the same pattern — they are tailored to the needs for a teaching operating
system, have educational support, and have at least one significant text that makes use of
them. For our purposes, xv6 is the winner.

xv

So, why xv6? Why not OS/161, with which I learned operating systems? Why not Xinu, which is
industry adopted? Like many decisions, it comes down to inertia and broad appeal. xv6 is used
as the exemplar OS in the popular Operating Systems: Three Easy Pieces (OSTEP) from the
University of Wisconsin. OSTEP is used extensively at the undergraduate level around the
country. OS/161 is more commonly used among graduate programs and is generally more
complex.
xv6 is a reimplementation of Unix Version 6 written by Dennis Ritchie and Ken Thompson.
Unlike v6, xv6 is written in ANSI C, targets the x86 architecture (and RISC-V, but we won’t be
using that due to lack of qemu support on our target machine), and is SMP aware (meaning it
supports multiple CPUs). xv6 is small enough that we can read the entire source but complete
enough you could use it for real tasks. Why you’d want to, I’m not sure, but you could.
There is a free textbook available detailing much of the architecture of xv6. You can either use
the copy I uploaded to Canvas
(https://canvas.oregonstate.edu/courses/1894812/files/92700586?wrap=1) , or you can build your
own from source (https://github.com/mit-pdos/xv6-book) , you have to install an
unmaintained tool to build it, and it hasn’t been updated in a couple of years. For our purposes,
this isn’t a big deal. OSTEP also makes many references to xv6, always the x86 version.

Obtaining source, building, and running

As with almost anything open-source, xv6 is available on GitHub (https://github.com/mit-
pdos/xv6-public) os
foo@bar:~$ mkdir -p ~/clones
foo@bar:~$ cd ~/clones
foo@bar:~$ git clone https://github.com/mit-pdos/xv6-public.git
foo@bar:~$ cd xv6-public
foo@bar:~$ sed -i 's/# QEMU = qemu-system-i386/QEMU = \/usr\/libexec\/qemu-kvm/g' Makefile #only ru
n this line on OS2!
foo@bar:~$ make qemu
The above
1. if one doesn’t already exist, creates a clones directory in your home directory;
2. moves to said directory;
3. clones the repository containing the xv6 source code;
4. moves to the source code directory;
5. sets the QEMU variable in the Makefile to the correct value
6. builds and runs xv6 within a qemu instance
At this point, if you executed each line of the above, you should be in a qemu instance that
looks like
(~/clones/xv6-public)
(dmcgrath@os2:pts/4)
(18:10:45 on master )> make qemu
(Sat,Jan22)
gcc -Werror -Wall -o mkfs mkfs.c
gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-f
rame-pointer -fno-stack-protector -fno-pie -no-pie -c -o ulib.o ulib.c
gcc -m32 -gdwarf-2 -Wa,-divide -c -o usys.o usys.S
#
# ...boring compilation lines skipped...
#
objdump -S kernel > kernel.asm
objdump -t kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > kernel.sym
dd if=/dev/zero of=xv6.img count=
10000 +0 records in
10000 +0 records out
5120000 bytes (5.1 MB) copied, 0 .0535831 s, 95 .6 MB/s
dd if=bootblock of=xv6.img conv=notrunc
1 +0 records in
1 +0 records out
512 bytes (512 B) copied, 0 .00134816 s, 380 kB/s
dd if=kernel of=xv6.img seek=1 conv=notrunc
415 +1 records in
415 +1 records out
212796 bytes (213 kB) copied, 0 .00444484 s, 47 .9 MB/s
/usr/libexec/qemu-kvm -serial mon:stdio -drive file=fs.img,index=1,media=disk,format=raw -drive fil
e=xv6.img,index=0,media=disk,format=raw -smp 2 -m 512
VNC server running on '::1:5900'
xv6...
cpu1: starting 1
cpu0: starting 0
sb: size 1000 nblocks 941 ninodes 200 nlog 30 logstart 2 inodestart 32 bmap start 58
init: starting sh
$
If you see something akin to the above, you’re running in qemu! For future invocations, you just
need to run make qemu from within the ~/clones/xv6-public/ directory.
OK, so now that you have qemu up and running, what now? How do you quit?
The short answer is you can quit by using the chord ctrl-a x (hold control while hitting a, release
both and hit x). What now is more involved, as right this very second the answer is, "quit." As
we move through the course, we’ll be adding functionality to xv6, and you’ll have to run tests.
We will cover that as necessary!