source: mainline/generic/src/console/klog.c@ 43752b6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 43752b6 was 43752b6, checked in by Ondrej Palkovsky <ondrap@…>, 19 years ago

Modified ipc/irq to be able to pass up to 3 arguments to userspace.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Copyright (C) 2006 Ondrej Palkovsky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <mm/frame.h>
30#include <sysinfo/sysinfo.h>
31#include <console/klog.h>
32#include <print.h>
33#include <ipc/irq.h>
34
35/* Order of frame to be allocated for klog communication */
36#define KLOG_ORDER 0
37
38static char *klog;
39static int klogsize;
40static int klogpos;
41
42SPINLOCK_INITIALIZE(klog_lock);
43
44/** Initialize kernel logging facility
45 *
46 * Allocate pages that are to be shared with uspace for console data.
47 * The shared area is a circular buffer. Userspace application may
48 * be notified on new data with indication of position and size
49 * of the data within the circular buffer.
50 */
51void klog_init(void)
52{
53 void *faddr;
54
55 faddr = (void *)PFN2ADDR(frame_alloc(KLOG_ORDER, FRAME_ATOMIC));
56 if (!faddr)
57 panic("Cannot allocate page for klog");
58 klog = (char *)PA2KA(faddr);
59
60 sysinfo_set_item_val("klog.faddr", NULL, (__native)faddr);
61 sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER);
62
63 klogsize = PAGE_SIZE << KLOG_ORDER;
64 klogpos = 0;
65}
66
67static void klog_vprintf(const char *fmt, va_list args)
68{
69 int ret;
70 va_list atst;
71
72 va_copy(atst, args);
73 spinlock_lock(&klog_lock);
74
75 ret = vsnprintf(klog+klogpos, klogsize-klogpos, fmt, atst);
76 if (ret >= klogsize-klogpos) {
77 klogpos = 0;
78 if (ret >= klogsize)
79 goto out;
80 }
81 ipc_irq_send_msg(IPC_IRQ_KLOG, klogpos, ret, 0);
82 klogpos += ret;
83 if (klogpos >= klogsize)
84 klogpos = 0;
85out:
86 spinlock_unlock(&klog_lock);
87 va_end(atst);
88}
89
90/** Printf a message to kernel-uspace log */
91void klog_printf(const char *fmt, ...)
92{
93 va_list args;
94
95 va_start(args, fmt);
96
97 klog_vprintf(fmt, args);
98
99 va_end(args);
100}
Note: See TracBrowser for help on using the repository browser.