00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <mm/frame.h>
00036 #include <sysinfo/sysinfo.h>
00037 #include <console/klog.h>
00038 #include <print.h>
00039 #include <ipc/irq.h>
00040
00041
00042 #define KLOG_ORDER 0
00043
00044 static char *klog;
00045 static int klogsize;
00046 static int klogpos;
00047
00048 SPINLOCK_INITIALIZE(klog_lock);
00049
00057 void klog_init(void)
00058 {
00059 void *faddr;
00060
00061 faddr = (void *)PFN2ADDR(frame_alloc(KLOG_ORDER, FRAME_ATOMIC));
00062 if (!faddr)
00063 panic("Cannot allocate page for klog");
00064 klog = (char *)PA2KA(faddr);
00065
00066 sysinfo_set_item_val("klog.faddr", NULL, (__native)faddr);
00067 sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER);
00068
00069 klogsize = PAGE_SIZE << KLOG_ORDER;
00070 klogpos = 0;
00071 }
00072
00073 static void klog_vprintf(const char *fmt, va_list args)
00074 {
00075 int ret;
00076 va_list atst;
00077
00078 va_copy(atst, args);
00079 spinlock_lock(&klog_lock);
00080
00081 ret = vsnprintf(klog+klogpos, klogsize-klogpos, fmt, atst);
00082 if (ret >= klogsize-klogpos) {
00083 klogpos = 0;
00084 if (ret >= klogsize)
00085 goto out;
00086 }
00087 ipc_irq_send_msg(IPC_IRQ_KLOG, klogpos, ret, 0);
00088 klogpos += ret;
00089 if (klogpos >= klogsize)
00090 klogpos = 0;
00091 out:
00092 spinlock_unlock(&klog_lock);
00093 va_end(atst);
00094 }
00095
00097 void klog_printf(const char *fmt, ...)
00098 {
00099 va_list args;
00100
00101 va_start(args, fmt);
00102
00103 klog_vprintf(fmt, args);
00104
00105 va_end(args);
00106 }
00107