Re: [問題] systemcall的問題
※ 引述《Qoo2.bbs@ptt.cc (Qoo)》之銘言:
> 請教各位
> 我查資料上是那麼敘述systemcall的
> 他說
> 當我們用C語言寫printf這一條指令時
應該說呼叫 printf() 這個 function。
> C編譯器會把它對照library轉成(例如在Windows)視窗下的systemcall
> 然後再進行編譯
> 不知道我這樣理解對不對?
不全然對,
目前來講 printf() 還是 C 寫出來的,
仍然算是 user space 的 library function,
會呼叫 vsprintf() 將 formatted 的部分代入變數值,
產生好要輸出的字串,
然後呼叫 write() 這個 system call。
簡單來說並不是「轉成」 system call,
而是一路 call 下去 call 到 system call,
C compiler 一般都不會認識 system call,
那是由設計 library 的人負責用 C + asm code 寫出相關動作來的。
> 那麼 也就是說 當我想寫一個全新的os時 除非我自己寫一個新的C compiler
不用寫新的 C compiler,
除非你吃的 executable format 是你新發明的。
> 不然 我就必須仔細寫我的os的systemcall 並改寫現有的c compiler的library
你只要訂好 system call 的 calling convention,
然後去寫 library 裡面跟 system call 有關的部分就好了。
> 使現有的c compiler能辨識並參照我的os的systemcall 否則它就動不了了...
不需要辨識。
> 再請問各位
> 在裝compiler時 compiler怎麼自動辨識我的os類型??
事實上大部分的 compiler,
都要你自己手動去設定,
而不是自動去偵測出來,
但通常可以設的也只有 executable format 和 CPU 架構名稱,
少數例子可以指定 OS。
--
Name: Tseng, Ling-hua E-mail Address: uranus@it.muds.net
School: National Tsing Hua University Department: Computer Science
Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design
Researching: Software pipelining for VLIW architectures
Homepage: https://it.muds.net/~uranus
--
╔═══╗ ┼────────────────────────╮
║狂狷 ║ │* Origin:[ 狂 狷 年 少 ] whshs.cs.nccu.edu.tw ╰─╮
║ 年少║ ┼╮ < IP:140.119.164.252 > ╰─╮
╚╦═╦╝ ╰ * From:61-230-218-43.dynamic.hinet.net
─╨─╨─ KGBBS ─ ◎ 遨翔"BBS"的狂狷不馴;屬於年少的輕狂色彩 ◎
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章