$ source /cs/cs134/bin/setup.bashFetch the xv6 source:
$ mkdir cs134 $ cd cs134 $ git clone https://github.com/HMCCS134-Sp2019/xv6.git Cloning into 'xv6'... ... $Build xv6:
$ cd xv6 $ make ... gcc -O -nostdinc -I. -c bootmain.c gcc -nostdinc -I. -c bootasm.S ld -m elf_i386 -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o bootmain.o objdump -S bootblock.o > bootblock.asm objcopy -S -O binary -j .text bootblock.o bootblock ... $
If you are not using Knuth for CS 134 labs, but build on your own machine, see the instructions on the tools page. If you have a build infrastructure on your own machine for lab 1, then you should be able to use that infrastructure for building xv6, too.
Find the address of _start
, the entry point of the kernel:
$ nm kernel | grep _start 8010a48c D _binary_entryother_start 8010a460 D _binary_initcode_start 0010000c T _startIn this case, the address is
0010000c
.
Run the kernel inside QEMU GDB, setting a breakpoint
at _start
(i.e., the address
you just found).
$ make qemu-gdb ... <leave "make qemu-gdb" running, and in a new terminal, navigate to the same directory and run the following.> $ i386-elf-gdb GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word". + target remote localhost:26000 The target architecture is assumed to be i8086 [f000:fff0] 0xffff0: ljmp $0xf000,$0xe05b 0x0000fff0 in ?? () + symbol-file kernel (gdb) br * 0x0010000c Breakpoint 1 at 0x10000c (gdb) c Continuing. The target architecture is assumed to be i386 => 0x10000c: mov %cr4,%eax Breakpoint 1, 0x0010000c in ?? () (gdb)
Note: If you have a problem with getting a message Gtk-WARNING **: 14:17:37.008: cannot open display:, then , run make qemu-nox-gdb instead of make qemu-gdb.
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.
(gdb) info reg ... (gdb) x/24x $esp ... (gdb)
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 reference 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:
If you are having trouble using the nexti command in GDB to single-step while skipping over function calls, a workaround is to use the advance command.
Ways to kill (abort) qemu: