klog.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Ondrej Palkovsky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 /* Order of frame to be allocated for klog communication */
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 

Generated on Sun Jun 18 17:37:25 2006 for HelenOS Kernel (sparc64) by  doxygen 1.4.6