diff --git a/labs/xv6.html b/labs/xv6.html new file mode 100644 index 0000000..40e1202 --- /dev/null +++ b/labs/xv6.html @@ -0,0 +1,155 @@ + + +Homework: xv6 + + + + +

Lab: xv6

+ +This lab makes you familiar with xv6 and its system calls. + +

Boot xv6

+ +

Login to Athena (e.g., ssh -X athena.dialup.mit.edu) and attach the course +locker: (You must run this command every time you log in; or add it to your +~/.environment file.) + +

+$ add -f 6.828
+
+ +

Fetch the xv6 source: + +

+$ mkdir 6.828
+$ cd 6.828
+$ git clone git://github.com/mit-pdos/xv6-riscv.git
+Cloning into 'xv6-riscv'...
+...
+$
+
+ +

XXX pointer to an update tools page + +

Build xv6 on Athena: +

+$ cd xv6-public
+$ makeriscv64-linux-gnu-gcc    -c -o kernel/entry.o kernel/entry.S
+riscv64-linux-gnu-gcc -Wall -Werror -O -fno-omit-frame-pointer -ggdb -MD -mcmodel=medany -ffreestanding -fno-common -nostdlib -mno-relax -I. -fno-stack-protector -fno-pie -no-pie   -c -o kernel/start.o kernel/start.c
+...
+$ make qemu
+...
+mkfs/mkfs fs.img README user/_cat user/_echo user/_forktest user/_grep user/_init user/_kill user/_ln user/_ls user/_mkdir user/_rm user/_sh user/_stressfs user/_usertests user/_wc user/_zombie user/_cow 
+nmeta 46 (boot, super, log blocks 30 inode blocks 13, bitmap blocks 1) blocks 954 total 1000
+balloc: first 497 blocks have been allocated
+balloc: write bitmap block at sector 45
+qemu-system-riscv64 -machine virt -kernel kernel/kernel -m 3G -smp 3 -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
+hart 0 starting
+hart 2 starting
+hart 1 starting
+init: starting sh
+$
+
+ +

+If you type ls at the prompt, you should output similar to the following: +

+$ ls
+.              1 1 1024
+..             1 1 1024
+README         2 2 2181
+cat            2 3 21024
+echo           2 4 19776
+forktest       2 5 11456
+grep           2 6 24512
+init           2 7 20656
+kill           2 8 19856
+ln             2 9 19832
+ls             2 10 23280
+mkdir          2 11 19952
+rm             2 12 19936
+sh             2 13 38632
+stressfs       2 14 20912
+usertests      2 15 106264
+wc             2 16 22160
+zombie         2 17 19376
+cow            2 18 27152
+console        3 19 0
+
+These are the programs/files that mkfs includes in the +initial file system. You just ran one of them: ls. + +

sleep

+ +

Write a program that sleeps for a user-specified number of seconds, + compile it, and run it. + +

Some hints: +

+ +

Run the program from the xv6 shell: +

+      $ make qemu
+      ...
+      init: starting sh
+      $ sleep 5
+      (waits for a little while)
+      $
+    
+ +

Optional: write an uptime program that prints the uptime in terms + of ticks using the uptime system call. + +

pingpong

+ +

In the previous exercise, if you made an error in sleep, the + program may have exited prematurely, but it didn't affect other + processes because xv6 isolates processes. Sometimes you want + processes to interact with each other. Xv6 provides two ways to do: + either through the file system (one process can create a file and + another process can read that file) or through pipes. In this + exercise you explore interprocess communication through pipes. + +

Write a program that uses UNIX system calls to ``ping-pong'' a + byte between two processes over a pair of pipes, one for each + direction. The parent sends by writing a byte to fd[1] and + the child receives it by reading from fd[0]. After + receiving a byte from parent, the child responds with its own byte + by writing to fd[1], which the parent then reads. + +

Some hints: +

+ +

find

+ +

Optional: modify shell

+ +

Modify the shell to support lists of commands, separated by ";" + +

Modify the shell to support sub-shells by implementing "(" and ")" + + + + +