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