Simple program using xv6 OS through Ubuntu version 20
CS 370 – Project #1, Part A Purpose: Become familiar with the xv6 Teaching Operating System, shell organization, and system calls Points: 50 Introduction: The xv6 OS is an educational OS designed by MIT for use as a teaching tool to give students hands-on experience with topics such as shell organization, virtual memory, CPU scheduling, and file systems. Although xv6 lacks the full functionality of a modern OS, it is based on Sixth Edition Unix (also called V6) and is very similar in design and structure. Resources: The following resources provide more in depth information regarding xv6. They include the xv6 reference book, tools for installing, and guidance to better understand xv6. 1. xv6 Reference Book: https://pdos.csail.mit.edu/6.828/2020/xv6/book-riscv-rev1.pdf 2. Lab Tools Guide: https://pdos.csail.mit.edu/6.828/2020/tools.html 3. Lab Guidance: https://pdos.csail.mit.edu/6.828/2020/labs/guidance.html Project: Complete the following steps. • Install an Ubuntu development environment ◦ You may use a virtual machine (VM) from a previous class, install a new VM from scratch, use the UNLV VM image, or install a dual-boot. • Install and become familiar with xv6 Teaching Operating System ◦ See installation instructions ◦ Focus on shell organization Submission When complete, submit: ● A screen shot of the hello world program (PNG file) via the class web page (assignment submission link) by class time. ○ Your hello program output must include your name. Refer to the example submission for an example of what should be submitted. ○ Note, there is a pre-installed program named screenshot that will be useful to capture the terminal window. Submissions received after the due date/time will not be accepted. Q: What five words best describe programming? A: World never says “hello” back. https://pdos.csail.mit.edu/6.828/2020/xv6/book-riscv-rev1.pdf https://pdos.csail.mit.edu/6.828/2020/labs/guidance.html https://pdos.csail.mit.edu/6.828/2020/tools.html Installing xv6 The following instructions walk you through the process of setting up xv6 within Ubuntu. As previously noted, you may choose to use the UNLV Ubuntu image or install a dual-boot environment. If desired, you may also use VMware or Parallels virtualization software (which may cost money) instead of VirtuaBox. You may also attempt to use Windows Subsystem for Linux (WSL), however this has not been fully tested. 1. Download and Install VirtualBox a. Use default/recommended RAM during installation. b. IMPORTANT: Allocate at least 20GB of disk space to the machine during set-up. Set up Ubuntu in VirtualBox. If you use the default 8 GB setting, you are may run out of space at some point. c. IMPORTANT: Allocate as many CPUs as possible, before installing Ubuntu in VirtualBox the amount of CPUs can be changed. d. Under Display settings, increase display memory to 128 MB. e. Use all other recommendations during installation. 2. Download Ubuntu 20.04.1 LTS 64-bit a. Do not install higher or lower version of Ubuntu 3. Open a terminal and execute the following commands: a. sudo apt-get update b. sudo apt-get upgrade c. sudo apt-get install git zip build-essential gdb-multiarch qemu- system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu d. git clone https://github.com/unlv-os/xv6.git xv6 e. chmod 700 -R xv6 Note, these command will install qemu from the repositories which will be version 4.2. Do not install a later version of qemu from other sources as it will not work correctly. You are now ready to run QEMU and xv6. To run xv6 on QEMU execute the following commands in the terminal: 1. cd xv6 (if not already there) 2. make qemu (this is how you start xv6) You should get a $ prompt which is the xv6 prompt. For example, in xv6, the ls command should show: $ ls . 1 1 512 .. 1 1 512 README 2 2 2170 cat 2 3 13604 echo 2 4 12616 forktest 2 5 8044 grep 2 6 15480 init 2 7 13196 kill 2 8 12668 ln 2 9 12564 ls 2 10 14752 mkdir 2 11 12748 rm 2 12 12724 sh 2 13 23212 stressfs 2 14 13396 usertests 2 15 56328 wc 2 16 14144 zombie 2 17 12388 console 3 18 0 $ Note: To close xv6 use ctrl-a x Using GDB: At some point, you may need to run xv6 on QEMU with GDB. Open two terminals as follows. In terminal 1, execute the following commands: 1. cd xv6 (if not already in the xv6 directory) 2. make qemu-gdb In terminal 2, execute the following commands: 1. cd xv6 (if not already in the xv6 directory) 2. gdb-multiarch -iex "set auto-load safe-path /" kernel/kernel Helpful Information: When attempting to exit xv6, use ctrl-a x To quit GDB: q To terminate an action being executed in GDB: ctrl-c If your mouse and/or keyboard becomes trapped in QEMU, typing ctrl-alt will exit the mouse grab. If you are debugging and you make a change to the code, make sure to close both QEMU and GDB. Otherwise they will get out of sync and cause problems. To find the exact path required for the gdb command you can run gdb kernel in the second terminal. The path will be listed in the error provided. Inserting a User Program Within xv6 Overview One of the first steps in navigating xv6 is learning to insert a user level C program into the system. This will eventually allow you to test and implement more advanced features. These features include additional system calls such as time. The following tutorial demonstrates how to add a basic user program and display it at the shell prompt. Tutorial 1. Create a new C program (hello.c) in your chosen text editor. The contents of the program can be as simple as that shown in Figure 1. Figure 1: Sample xv6 User Program (hello.c) 2. Save the program within the xv6/user folder. 3. Open the xv6 Makefile from xv6 directory. The Makefile should be edited to ensure that hello.c is properly added to the existing set of user programs (under UPROGS) to be compiled. This is done as shown in Figure 2. Figure 2: Add hello to the List of User Programs 4. Open the terminal to compile the system and start up xv6 on QEMU. The commands should be the following: cd xv6 (note, your xv6 directory might be different) make clean make qemu If there were no compilation errors xv6 should have been properly launched something like as shown in Figure 4. Figure 4: Compilation and Start-Up of xv6 5. Use the ls command to verify that hello.c was added to the existing list of available user programs as shown in Figure 5. You can then type hello to view the output of the newly created test program. Figure 5: Successful Sample Program Output Committing Changes The files you will need for this and subsequent lab assignments are distributed using the Git version control system. To learn more about Git, take a look at the Git user's manual, or, you may find this CS- oriented overview of Git useful. Git allows you to keep track of the changes you make to the code. For example, if you are finished with one of the project exercises, and want to checkpoint your progress, you can commit your changes by running: $ git add . $ git commit -am 'my solution for hello xv6' Created commit 60d2135: my solution for hello xv6 1 files changed, 1 insertions(+), 0 deletions(-) $ Example Submission The final submission should include a capture of current window (via built-in screenshot utility “Grab current window). As noted, your name should be included in the hello world output. The following is an example of the PNG file that should be submitted. https://eagain.net/articles/git-for-computer-scientists/ https://eagain.net/articles/git-for-computer-scientists/ https://mirrors.edge.kernel.org/pub/software/scm/git/docs/user-manual.html http://www.git-scm.com/