iT邦幫忙

0

[6.1810][lab] Xv6 and Unix utilities (一)

  • 分享至 

  • xImage
  •  

系列文章 : [6.1810] 跟著 MIT 6.1810 學習基礎作業系統觀念

大綱

  • Boot xv6 (easy)
  • sleep (easy)
  • sixfive (moderate)
  • memdump (easy)

在寫作業之前,要注意到寫作業用的 repo 跟 xv6-riscv 官方 repo 是不同的。

寫作業要先 clone 這一份 : git clone git://g.csail.mit.edu/xv6-labs-2025。裡面會有跟作業相關的 utility。

我是把一些 utility 複製回自己 fork 來的 repo,方便我可以 git push 到 github XD。



Boot xv6 (easy)

作業要求

開機 xv6-riscv
使用 ctrl+p 觀察當前 process 的狀態

作業內容

這部份的作業內容,在之前的文章就有做過了,這邊就不贅述。

https://ithelp.ithome.com.tw/articles/10399433



sleep (easy)

作業要求

  • 撰寫一個 user-level 的 sleep 程式。
  • 使用者可以決定要 sleep 多少 ticks
  • A tick is a notion of time defined by the xv6 kernel, namely the time between two interrupts from the timer chip.
  • Your solution should be in the file user/sleep.c.

作業內容

== Test sleep, no arguments == sleep, no arguments: OK (0.6s) 
== Test sleep, returns == sleep, returns: OK (1.0s) 
== Test sleep, makes syscall == sleep, makes syscall: OK (1.0s)


sixfive (moderate)

作業要求

  • 讀取檔案,只要裡面的數值可以被 5 或 6 整除,就 print 出來
  • 數字 的定義是被 " -\r\t\n./," 這幾個字元切開的 sequence of decimal digits
  • 例如 “xv6” 不能 print 6,因為 xv6 是一個 token
  • “/6,” 可以 print 6,因為 6 自己是一個 token

作業提示

  • Read the input file a character at the time
  • You can test if a character matches any of the separators using strchr (see user/ulib.c).
  • Start and end of file are implicit separators.

作業內容

  • strchr 的用法可以參考 user/sh.c
    • 可以使用 strchr 來判斷當前讀取到的字元,是否為 separator
  • 開檔/讀檔的方式可以參考 user/ls.c
    • 用 open 取得 process-file-descriptor
    • 用 read 讀取檔案
    • 可以用 fstat 判斷當前的檔案是否為 regular file ( T_FILE )
    • 用 close 關閉檔案
  • 不知道需不需要處理大數 … 這邊先不處理大數運算
  • sixfive.c
  • 可以使用 ./grade-lab-util sixfive 進行測試
== Test sixfive_test == sixfive_test: OK (1.0s) 
== Test sixfive_readme == sixfive_readme: OK (1.5s) 
    (Old xv6.out.sixfive_readme failure log removed)
== Test sixfive_all == sixfive_all: OK (1.1s)


memdump (easy)

作業要求

  • 在作業的 repo ( git clone git://g.csail.mit.edu/xv6-labs-2025 ) 裡面有 user/memdump.c,* 這個 source file 裡面的 memdump function 沒有實作完,而我們的作業就是要完成 memdump 這個 function。
  • memdump()'s purpose is to print the contents of the memory pointed to by data in the format described by the fmt argument.
  • The format is a C string. Each character of the string indicates how to print successive parts of the data.
  • Your memdump() should handle the following format characters
    • i: print the next 4 bytes of the data as a 32-bit integer, in decimal.
    • p: print the next 8 bytes of the data as a 64-bit integer, in hex.
    • h: print the next 2 bytes of the data as a 16-bit integer, in decimal.
    • c: print the next 1 byte of the data as an 8-bit ASCII character.
    • s: the next 8 bytes of the data contain a 64-bit pointer to a C string; print the string.
    • S: the rest of the data contains the bytes of a null-terminated C string; print the string.
  • 可以使用 printf 實作。
  • The memdump program, if executed with no arguments, calls memdump() with some example format strings and data. If memdump() is correctly implemented, the output will be:
$ memdump
Example 1:
61810
2025
Example 2:
a string
Example 3:
another
Example 4:
BD0
1819438967
100
z
xyzzy
Example 5:
hello
w
o
r
l
d

作業內容

== Test memdump, examples == memdump, examples: OK (1.2s) 
== Test memdump, format ii, S, p == memdump, format ii, S, p: OK (0.9s) 
  • 感覺 grade-lab-util memdump 可能有 bug ?
    • p: print the next 8 bytes of the data as a 64-bit integer, in hex.
    • 但實際上解答只 print 4 bytes。


Reference


圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言