Due: Fri, 30 Mar 2018 11:00:00 -0700
To compile and run xv6, you need to set up the toolchain as described in the tools guide. If you have a JOS build infrastructure on your own machine for lab 1, then you should be able to use that for building xv6, too.
Fetch the xv6 source:
Build xv6:
Find the address of _start
, the entry point of the xv6 kernel:
In this case, the address is 0010000c
.
i386-jos-elf-
prefixIf you are not using the default ELF toolchain (e.g., on macOS),
you need to add the i386-jos-elf-
prefix to the ELF toolchain commands,
such as i386-jos-elf-nm.
Run the kernel inside QEMU GDB, setting a breakpoint at _start
(i.e., the address you just found).
If you are SSH’d into a remote machine, you may want to use make qemu-nox-gdb. To quit QEMU, type Ctrl-a x.
Leave it running, and in a new terminal, navigate to the same
directory and run the following. If you are trying this by logging into
attu
, check the hostname to make sure that you are running
both the commands on the same physical machine.
The details of what you see are likely to differ from the above output, depending on the version of gdb you are using, but gdb should stop at the breakpoint, and it should be the above mov instruction. Your gdb may also complain that auto-loading isn’t enabled. In that case, it will print instructions on how to enable auto-loading, and you should follow those instructions.
While stopped at the above breakpoint, look at the registers and the stack contents:
Write a short (3-5 word) comment next to each non-zero value on the stack explaining what it is. Which part of the stack printout is actually the stack? (Hint: not all of it.)
You might find it convenient to consult the files bootasm.S
,
bootmain.c
, and bootblock.asm
(which contains the output of the
compiler/assembler). The readings page has pointers to x86 assembly
documentation, if you are wondering about the semantics of a
particular instruction. Your goal is to understand and explain the
contents of the stack that you saw above, just after entering the
xv6 kernel. One way to achieve this would be to observe how and
where the stack gets setup during early boot and then track the
changes to the stack up until the point you are interested in. Here
are some questions to help you along:
Begin by restarting qemu and gdb, and set a breakpoint at 0x7c00
,
the start of the boot block (bootasm.S
). Single step through the
instructions (type si at the gdb prompt). Where in bootasm.S
is the
stack pointer initialized? (Single step until you see an instruction
that moves a value into %esp
, the register for the stack pointer.)
Single step through the call to bootmain
; what is on the stack
now? What do the first assembly instructions of bootmain
do to the
stack? Look for bootmain
in bootblock.asm
.
Continue tracing via gdb (using breakpoints if necessary—see
hint below) and look for the call that changes eip
to 0x10000c
.
What does that call do to the stack? (Hint: Think about what this
call is trying to accomplish in the boot sequence and try to identify
this point in bootmain.c
, and the corresponding instruction in the
bootmain
code in bootblock.asm
. This might help you set suitable
breakpoints to speed things up.)
Write down the output of x/24x $esp with the valid part of the stack
marked, plus your comments, in a file named answers.txt
.
Upload it using Canvas.