From 723428bebe3105ad3c3406e416402d1831b482c4 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 15 Aug 2021 00:16:45 -0400 Subject: Inital commit --- linux/kernel/printk.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 linux/kernel/printk.c (limited to 'linux/kernel/printk.c') diff --git a/linux/kernel/printk.c b/linux/kernel/printk.c new file mode 100644 index 0000000..7a70dc3 --- /dev/null +++ b/linux/kernel/printk.c @@ -0,0 +1,33 @@ +/* + * 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 +#include + +#include + +static char buf[1024]; + +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; +} -- cgit v1.2.3