看板Programming
标 题Re: [问题] systemcall的问题
发信站政大狂狷年少 (Thu Dec 14 16:32:18 2006)
转信站ptt!ctu-reader!ctu-peer!news.nctu!news.cis.nctu!news.cs.nthu!WHSHS
※ 引述《[email protected] (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:
[email protected]
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"的狂狷不驯;属於年少的轻狂色彩 ◎