Printf从函数库到OS跟踪流程
首先需要弄清楚:API-用户编程借口与 系统调用的区别,这里有一篇非常好的文章: http://www.tek-life.org/2010/10/12/linux%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8%EF%BC%BBz%EF%BC%BD/ 另外,printf具体内部原理请见: http://www.tek-life.org/2010/10/12/printf%E5%92%8C%E6%A0%87%E5%87%86%E8%BE%93%E5%87%BA%EF%BC%BBz%EF%BC%BD/ 我仅仅是进行了code review arch/x86/boot/printf.c int printf(const char *fmt, ...) { char printf_buf[1024]; va_list args; int printed; va_start(args, fmt); printed = vsprintf(printf_buf, fmt, args); va_end(args); puts(printf_buf); return printed; } void __attribute__((section(".inittext"))) puts(const char *str) { int n = 0; while (*str) { putchar (*str++); n++; } } /* * These functions are in .inittext so they can be used to signal * error during initialization. */ void __attribute__((section(".inittext"))) putchar (int ch) { unsigned char c = ch; if (c == '\n') putchar('\r'); /* \n -> \r\n */ /* int $0x10 is known to have bugs involving touching registers it shouldn't. Be extra c...