#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);
内核打印函数,该函数调用了tty_write函数,
该函数需要使用fs寄存器,指定为数据段寄存器,
在调用前,需要将其入栈保存。
int printk(const char *fmt, ...)
{
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"
"call _tty_write/n/t"
"addl $8,%%esp/n/t"
将字符串长度从栈中弹出,作为函数返回值
"popl %0/n/t"
"pop %%fs"
::"r" (i):"ax","cx","dx");
return i;
}