printk.c
来自「一份精简的linux内核源代码」· C语言 代码 · 共 42 行
C
42 行
/* * linux/kernel/printk.c * * (C) 1991 Linus Torvalds *//* * When in kernel-mode, we cannot use printf, as fs is liable to * point to 'interesting' things. Make a printf with fs-saving, and * all is well. */#include <stdarg.h>#include <stddef.h>#include <linux/kernel.h>static char buf[1024];extern int vsprintf(char * buf, const char * fmt, va_list args);int printk(const char *fmt, ...)/*打印函数(仅仅设了一下FS的值,实际打印操作由tty_write完成)*/{ va_list args;/*?*/ int i; va_start(args, fmt);/*?*/ i=vsprintf(buf,fmt,args); va_end(args);/*?*/ __asm__("push %%fs\n\t" "push %%ds\n\t" "pop %%fs\n\t" "pushl %0\n\t"/*打印长度*/ "pushl $_buf\n\t"/*打印的内容*/ "pushl $0\n\t"/*通道0*/ "call _tty_write\n\t"/*实际的打印操作*/ "addl $8,%%esp\n\t" "popl %0\n\t" "pop %%fs" ::"r" (i):"ax","cx","dx"); return i;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?