106 OS homework 2-2 成果報告書

組長:B10408064、郭建隆
組員:B10401063、洪啟榮
github: https://github.com/TeddyGuo/xv6-public


🙂 使用情境說明(包含流程圖)

當使用者不小心做出除以零的計算時,signal可以即時反應,使用者可以用sigfpe_firstest、sigfpe_timing、sigfpe_secondtest測試。
先開啟終端機,從git hub clone我們的xv6到電腦上,再鍵入cd 存放資料夾指令進入xv6的資料夾,輸入make指令編譯xv6,檢查編譯有沒有錯誤,再鍵入make qemu指令運行xv6,成功開啟xv6的視窗後,就可以鍵入ls指令,查看目前提供的指令;鍵入shutdowm可以離開程式;鍵入sigfpe_firstest、sigfpe_timing、sigfpe_secondtest可以測試signal。


😇 成功畫面


🏃 實作過程(修改哪些檔案[含圖片])

Makefile 修改
Change as a single cpu OS
UPROGS is renewed
It is newly increased

defs.h 修改
Define a new type, which is “sighandler_t”
At mp.c part, increase “mpbcpu” function
At proc.c part, increase “signal” function

halt.h 建立
Define “halt” function

package_patches.sh 建立

proc.h 修改
Define new segments in proc->get, and I included def.h into this file
Increase one-dimension array of sighandler_t for proc struct to realize what kind of state about the process

main.c 修改
Line 34 to 37, increase the following
if (!ismp)
{
timerinit(); // uniprocessor timer
}

mmu.h 修改
Cancel “#define NSEGS 6”
Increase “#define SEG_KCPU 3”

mp.c 修改
Declare “ismp”
Increase “mpbcpu” function
Rebuild “mpinit” function
In “mpinit” function, correct problem about line 123

picirq.c 重建

proc.c 修改
Define SIGFPE as 0
Assign (void*) - 1 to sighandlers array of the process
Implement signal function

restorer.h 建立
Define a function called “restorer”

signal.h 建立
Define three UPROGS in makefile updated
Define the numbers of the signals which I want to implement

sigfpe_firstest, sigfpe_timing, and sigfpe_secondtest 建立

shutdown.c 建立
Shuts down the system by using the halt() system call

syscall.c 修改
Increase a new function called “sys_signal”, which return an integer, and it is decorated by “extern”
Increase a new function called “sys_halt”, which return an integer, and it is decorated by “extern”
Increase the above functions to a static pointer to array called “*syscall[]”, which is an integer array

syscall.h 修改
Define new functions “SYS_halt” and “SYS_signal”, and their numbers are separately 22 and 23

sysproc.c 修改
Implement sys_signal and sys_halt

timer.c 建立

trap.c 修改
Implement a block of code in the switch block for killing a program which is divide by zero

user.h 修改
Define a pointer to function, which is a sighandler_t type and return an integer
Increase two system calls, halt and signal

usys.S 修改
Increase two syscalls, “halt” and “signal”


😎 結論

我們的訴求很簡單,就是作業系統這門課要及格,很重要所以寫在結論第一段。

signal的處理不是很容易,我們在make這個階段卡很久,一個問題處理完了,又會出現另一個問題,最後一直有未定義參考到signal的問題。

作業系統是不容易寫出來的,因為必須要考慮到很多種狀況,要對作業系統內每個程式很熟悉,一個小地方沒注意到,整個系統就會無法運作,必須要熟悉整個xv6才能夠改寫並增加。

xv6我們讀得不是很懂,雖然我們最後成功寫出來了,也只有一隻signal還有halt,但我們仍然很想弄清楚xv6的每個程式片段,但有的程式碼不是很容易找到他的說明,造成我們搜尋相關資料的時間拉十分長,閱讀上也十分的困難,想當然改寫的程式碼也需要參考很多相關資料,在不斷的去嘗試寫出來,看執行的結果如何,就花了很多時間,原因都在我們的基本功不夠扎實,程式碼的知識有許多的不足。

為了提升我們的能力,必須去閱讀別人的程式、嘗試改寫,git hub就是個很好的平台,幸好我們能藉這個機會知道這個網站,讓我們在課餘時間有額外的方式可以學習,希望往後我們能夠持續改進。


📅 組員分工

郭建隆:

查閱資料 構想書編寫 原始碼實作

洪啟榮:

查閱資料 時程甘特圖製作 API實作