Re: [問題] start.s在Nachos下的作用

作者: cole945 (躂躂..)   2018-08-22 01:09:50
這個 topic 已經遠超過 c_and_cpp 的範圍了..囧
: → laughingman: 我知道syscall那行是呼叫system call handler,但是 08/21 23:33
: → laughingman: 是誰規定它呼叫誰的system call handler?因為start.s 08/21 23:34
: → laughingman: 看起來就像一般的MIPS組語,為什麼這邊的syscall就是 08/21 23:35
: → laughingman: 連到Nachos中的exception.cc寫的system call handler 08/21 23:36
: → laughingman: ,而不是連到MIPS真正的system call handler?是因為 08/21 23:37
為什麼你會覺得 exception.cc 裡的 syscall handler 不是真正的
syscall handler? 你所謂的 syscall handler 是什麼?
建議先多翻翻書建立背景知識, 有些東西就算是資工系的沒有真的用過也只是背課文
1. 算盤本 Computer Organization and Deisng
看 The Processor 那章的 Exception.
不過這理的解釋很篇 hardware design
2. Understanding the Linux Kernel 和 Linux Kernel Development
兩本都有 System call 章節, 建翻去借書翻一翻
3. 去找 MIPS Architecture For Programmers, 是官發的開發文件,
有很多本, 要找 Privileged Resouce Architecture 那份
Syscall 通常的流程是.. (我也沒做過 MIPS 的, 不過大家大同小異)
1. user mode code 用 syscall 指令觸發 syscall exception (start.s 的Print)
2. CPU 依 exception vector table 查表對應的 handler 位置
vector 位置與 handler 應該是在 boot 時自已設的, 你應該 trace 一開
start code
3. 跳 syscall handler. 這裡通常還會是 assmebly code 寫的,
要保留 user mode code 的所有 context, 例如 general purpose registers
4. 再轉跳到比較好寫的 C code handler, 就是你在改的 exception.cc
如果你在改的那本 exception.cc 就是長這樣,
https://github.com/echoz/NTUSCE/blob/master/CSC205/userprog/exception.cc
那這個做法就是所有 context 存完直接跳 ExceptionHandler, 由這裡判斷是哪
個 exception (syscall 只是其中一個)
建以上提到的東西你都自已 trace 和讀過再來繼續問, 不然你就白問了
: → laughingman: 組譯器不同的關係嗎?抱歉我的問題都很笨orz 08/21 23:38
: → laughingman: 還有照我google mips syscall abi的結果,我知道mips 08/21 23:40
: → laughingman: 會照$v0中的值來決定要呼叫哪個system call handler 08/21 23:41
: → laughingman: 那Nachos是哪邊規定的呢?因為我看Nachos中的1是表示 08/21 23:42
哪邊規定你應該去問老師, 或找 Nachos 的文件, 這些都要明定才能實作
不知道課程和你對自已的要求到什麼層度, 就算沒有文件,
你可以多看看 assembly code 把兩邊串起來
作者: laughingman (笑面男)   2018-08-22 08:17:00
非常感謝原PO願意回答我的蠢問題,看來我需要多建立背景知識和trace code,我會去看您推薦的書和MIPS的官方文件以及Nachos的規定,再次感謝!

Links booklink

Contact Us: admin [ a t ] ucptt.com