xv6: a simple, Unix-like teaching operating system

Running and Debugging xv6

Installing and Running xv6 under QEMU

  • Update Ubuntu build Environment
  • 
      sudo apt install build-essential git gdb qemu-system gcc-riscv64-linux-gnu g++-riscv64-linux-gnu binutils-riscv64-linux-gnu
      
  • Download the source cod eof xv6
  • 
    git clone https://github.com/mit-pdos/xv6-riscv.git
    	
  • Build xv6
  • 
    cd xv6-riscv
    make
    	
  • Start xv6 via QEMU
  • 
    make qemu
    	
  • Stop xv6
    • press Ctrl + A (A is just key a, not the alt key) then release the keys,
    • press X

RISC-V GNU Compiler Toolchain

Getting the sources:
  • Download the latest
  • Visit the official RISC-V GNU Toolchain repository on GitHub.
    Click on the "Code" button and select "Download ZIP" to download the latest version of the toolchain.
    Extract the downloaded ZIP file to a directory of your choice.
  • Git clone
  • 
    $ git clone https://github.com/riscv/riscv-gnu-toolchain
    	
Installing the RISC-V Toolchain: On Ubuntu, executing the following command to install packages:

$ sudo apt-get install autoconf automake autotools-dev curl python3 python3-pip libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev ninja-build git cmake libglib2.0-dev
To build the cross-compiler,

$ ./configure --prefix=/opt/riscv
make

Add /opt/riscv/bin to your PATH.

  
export PATH=/opt/riscv/bin:$PATH 
export LD_LIBRARY_PATH=/opt/riscv/lib:$LD_LIBRARY_PATH    
Verify the installation:
  
riscv32-unknown-elf-gcc --version  
riscv64-unknown-elf-gcc -dumpmachine
riscv64-unknown-elf-gcc -print-search-dirs
riscv64-unknown-elf-gdb --version

Remote Debugging xv6 under QEMU

The easiest way to debug xv6 under QEMU is to use GDB's remote debugging feature and QEMU's remote GDB debugging stub:
  • The GDB debugger and the target environment communicate over some simple communication medium.
  • A small remote debugging stub is typically embedded into the kernel being debugged; the remote debugging stub implements a simple command language that the main debugger uses to inspect and modify the target program's memory, set breakpoints, start and stop execution, etc.
To run xv6 under QEMU and enable remote debugging, type:

$ make qemu-gdb
  
*** Now run 'gdb' in another window.
qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -global virtio-mmio.force-legacy=false -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 -S -gdb tcp::26000
  
Now, QEMU initialized the virtual machine but stopped it before executing the first instruction, and is now waiting for an instance of GDB to connect to its remote debugging stub and supervise the virtual machine's execution.
QEMU is listening for connections on a TCP network socket port 26000. (configured in the makefile)

To start the debugger and connect it to QEMU's waiting remote debugging stub, open a new, separate terminal window, change to the same xv6 directory, and type:


$ riscv64-unknown-elf-gdb kernel/kernel..
Reading symbols from kernel/kernel...
..
https://blog.csdn.net/yihuajack/article/details/116571913

留言

熱門文章