Subversion Repositories HelenOS-historic

Rev

Rev 1595 | Rev 1643 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1595 Rev 1613
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
#include <mm/frame.h>
29
#include <mm/frame.h>
30
#include <sysinfo/sysinfo.h>
30
#include <sysinfo/sysinfo.h>
31
#include <console/klog.h>
31
#include <console/klog.h>
32
#include <print.h>
32
#include <print.h>
33
#include <ipc/irq.h>
33
#include <ipc/irq.h>
34
 
34
 
35
/* Order of frame to be allocated for klog communication */
35
/* Order of frame to be allocated for klog communication */
36
#define KLOG_ORDER 0
36
#define KLOG_ORDER 0
37
 
37
 
38
static char *klog;
38
static char *klog;
39
static int klogsize;
39
static int klogsize;
40
static int klogpos;
40
static int klogpos;
41
 
41
 
42
SPINLOCK_INITIALIZE(klog_lock);
42
SPINLOCK_INITIALIZE(klog_lock);
43
 
43
 
44
/** Initialize kernel loggin facility
44
/** Initialize kernel loggin facility
45
 *
45
 *
46
 * Allocate pages that are to be shared if uspace for console data
46
 * Allocate pages that are to be shared if uspace for console data
47
 */
47
 */
48
void klog_init(void)
48
void klog_init(void)
49
{
49
{
50
    void *faddr;
50
    void *faddr;
51
 
51
 
52
    faddr = (void *)PFN2ADDR(frame_alloc(KLOG_ORDER, FRAME_ATOMIC));
52
    faddr = (void *)PFN2ADDR(frame_alloc(KLOG_ORDER, FRAME_ATOMIC));
53
    if (!faddr)
53
    if (!faddr)
54
        panic("Cannot allocate page for klog");
54
        panic("Cannot allocate page for klog");
55
    klog = (char *)PA2KA(faddr);
55
    klog = (char *)PA2KA(faddr);
56
   
56
   
57
    sysinfo_set_item_val("klog.faddr", NULL, (__native)faddr);
57
    sysinfo_set_item_val("klog.faddr", NULL, (__native)faddr);
58
    sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER);
58
    sysinfo_set_item_val("klog.pages", NULL, 1 << KLOG_ORDER);
59
 
59
 
60
    klogsize = PAGE_SIZE << KLOG_ORDER;
60
    klogsize = PAGE_SIZE << KLOG_ORDER;
61
    klogpos = 0;
61
    klogpos = 0;
62
}
62
}
63
 
63
 
64
static void klog_vprintf(const char *fmt, va_list args)
64
static void klog_vprintf(const char *fmt, va_list args)
65
{
65
{
66
    int ret;
66
    int ret;
67
    va_list atst;
67
    va_list atst;
68
 
68
 
69
    va_copy(atst, args);
69
    va_copy(atst, args);
70
    spinlock_lock(&klog_lock);
70
    spinlock_lock(&klog_lock);
71
 
71
 
72
    ret = vsnprintf(klog+klogpos, klogsize-klogpos, fmt, atst);
72
    ret = vsnprintf(klog+klogpos, klogsize-klogpos, fmt, atst);
73
    // Workaround around bad return value from vsnprintf
-
 
74
    if (ret+klogpos < klogsize)
-
 
75
        ret = 100;
-
 
76
    if (ret == klogsize-klogpos) {
73
    if (ret >= klogsize-klogpos) {
77
        klogpos = 0;
74
        klogpos = 0;
78
        ret = vsnprintf(klog+klogpos, klogsize-klogpos, fmt, args);
-
 
79
        ret = 100;
-
 
80
        if (ret == klogsize)
75
        if (ret >= klogsize)
81
            goto out;
76
            goto out;
82
    }
77
    }
83
    ipc_irq_send_msg(IPC_IRQ_KLOG, klogpos, ret);
78
    ipc_irq_send_msg(IPC_IRQ_KLOG, klogpos, ret);
84
    klogpos += ret;
79
    klogpos += ret;
85
    if (klogpos >= klogsize)
80
    if (klogpos >= klogsize)
86
        klogpos = 0;
81
        klogpos = 0;
87
out:
82
out:
88
    spinlock_unlock(&klog_lock);
83
    spinlock_unlock(&klog_lock);
89
    va_end(atst);
84
    va_end(atst);
90
}
85
}
91
 
86
 
92
/** Printf a message to kernel-uspace log */
87
/** Printf a message to kernel-uspace log */
93
void klog_printf(const char *fmt, ...)
88
void klog_printf(const char *fmt, ...)
94
{
89
{
95
    va_list args;
90
    va_list args;
96
   
91
   
97
    va_start(args, fmt);
92
    va_start(args, fmt);
98
   
93
   
99
    klog_vprintf(fmt, args);
94
    klog_vprintf(fmt, args);
100
 
95
 
101
    va_end(args);
96
    va_end(args);
102
}
97
}
103
 
98