Subversion Repositories HelenOS

Rev

Rev 3065 | Rev 3113 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3065 Rev 3097
Line 33... Line 33...
33
/** @file
33
/** @file
34
 */
34
 */
35
 
35
 
36
#include <console/console.h>
36
#include <console/console.h>
37
#include <console/chardev.h>
37
#include <console/chardev.h>
-
 
38
#include <sysinfo/sysinfo.h>
38
#include <synch/waitq.h>
39
#include <synch/waitq.h>
39
#include <synch/spinlock.h>
40
#include <synch/spinlock.h>
40
#include <arch/types.h>
41
#include <arch/types.h>
-
 
42
#include <ddi/device.h>
-
 
43
#include <ddi/irq.h>
-
 
44
#include <ddi/ddi.h>
-
 
45
#include <ipc/irq.h>
41
#include <arch.h>
46
#include <arch.h>
42
#include <func.h>
47
#include <func.h>
43
#include <print.h>
48
#include <print.h>
44
#include <atomic.h>
49
#include <atomic.h>
45
 
50
 
46
#define KLOG_SIZE 4096
51
#define KLOG_SIZE PAGE_SIZE
47
 
52
 
48
/**< Kernel log cyclic buffer */
53
/**< Kernel log cyclic buffer */
49
static char klog[KLOG_SIZE];
54
static char klog[KLOG_SIZE] __attribute__ ((aligned (PAGE_SIZE)));
50
 
55
 
-
 
56
/**< Kernel log initialized */
-
 
57
static bool klog_inited = false;
51
/**< First kernel log characters */
58
/**< First kernel log characters */
52
static index_t klog_start = 0;
59
static index_t klog_start = 0;
53
/**< Number of valid kernel log characters */
60
/**< Number of valid kernel log characters */
54
static size_t klog_len = 0;
61
static size_t klog_len = 0;
55
/**< Number of stored (not printed) kernel log characters */
62
/**< Number of stored (not printed) kernel log characters */
56
static size_t klog_stored = 0;
63
static size_t klog_stored = 0;
-
 
64
/**< Number of stored kernel log characters for uspace */
-
 
65
static size_t klog_uspace = 0;
-
 
66
 
-
 
67
/**< Kernel log spinlock */
-
 
68
SPINLOCK_INITIALIZE(klog_lock);
-
 
69
 
-
 
70
/** Physical memory area used for klog buffer */
-
 
71
static parea_t klog_parea;
-
 
72
   
-
 
73
/*
-
 
74
 * For now, we use 0 as INR.
-
 
75
 * However, it is therefore desirable to have architecture specific
-
 
76
 * definition of KLOG_VIRT_INR in the future.
-
 
77
 */
-
 
78
#define KLOG_VIRT_INR   0
-
 
79
 
-
 
80
static irq_t klog_irq;
57
 
81
 
58
static chardev_operations_t null_stdout_ops = {
82
static chardev_operations_t null_stdout_ops = {
59
    .suspend = NULL,
83
    .suspend = NULL,
60
    .resume = NULL,
84
    .resume = NULL,
61
    .write = NULL,
85
    .write = NULL,
Line 65... Line 89...
65
chardev_t null_stdout = {
89
chardev_t null_stdout = {
66
    .name = "null",
90
    .name = "null",
67
    .op = &null_stdout_ops
91
    .op = &null_stdout_ops
68
};
92
};
69
 
93
 
-
 
94
/** Allways refuse IRQ ownership.
-
 
95
 *
-
 
96
 * This is not a real IRQ, so we always decline.
-
 
97
 *
-
 
98
 * @return Always returns IRQ_DECLINE.
-
 
99
 */
-
 
100
static irq_ownership_t klog_claim(void)
-
 
101
{
-
 
102
    return IRQ_DECLINE;
-
 
103
}
-
 
104
 
70
/** Standard input character device. */
105
/** Standard input character device */
71
chardev_t *stdin = NULL;
106
chardev_t *stdin = NULL;
72
chardev_t *stdout = &null_stdout;
107
chardev_t *stdout = &null_stdout;
73
 
108
 
-
 
109
/** Initialize kernel logging facility
-
 
110
 *
-
 
111
 * The shared area contains kernel cyclic buffer. Userspace application may
-
 
112
 * be notified on new data with indication of position and size
-
 
113
 * of the data within the circular buffer.
-
 
114
 */
-
 
115
void klog_init(void)
-
 
116
{
-
 
117
    void *faddr = (void *) KA2PA(klog);
-
 
118
   
-
 
119
    ASSERT((uintptr_t) faddr % FRAME_SIZE == 0);
-
 
120
    ASSERT(KLOG_SIZE % FRAME_SIZE == 0);
-
 
121
 
-
 
122
    devno_t devno = device_assign_devno();
-
 
123
   
-
 
124
    klog_parea.pbase = (uintptr_t) faddr;
-
 
125
    klog_parea.vbase = (uintptr_t) klog;
-
 
126
    klog_parea.frames = SIZE2FRAMES(KLOG_SIZE);
-
 
127
    klog_parea.cacheable = true;
-
 
128
    ddi_parea_register(&klog_parea);
-
 
129
 
-
 
130
    sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr);
-
 
131
    sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(KLOG_SIZE));
-
 
132
    sysinfo_set_item_val("klog.devno", NULL, devno);
-
 
133
    sysinfo_set_item_val("klog.inr", NULL, KLOG_VIRT_INR);
-
 
134
 
-
 
135
    irq_initialize(&klog_irq);
-
 
136
    klog_irq.devno = devno;
-
 
137
    klog_irq.inr = KLOG_VIRT_INR;
-
 
138
    klog_irq.claim = klog_claim;
-
 
139
    irq_register(&klog_irq);
-
 
140
   
-
 
141
    spinlock_lock(&klog_lock);
-
 
142
    klog_inited = true;
-
 
143
    spinlock_unlock(&klog_lock);
-
 
144
}
-
 
145
 
74
/** Get character from character device. Do not echo character.
146
/** Get character from character device. Do not echo character.
75
 *
147
 *
76
 * @param chardev Character device.
148
 * @param chardev Character device.
77
 *
149
 *
78
 * @return Character read.
150
 * @return Character read.
Line 158... Line 230...
158
    ch = _getc(chardev);
230
    ch = _getc(chardev);
159
    putchar(ch);
231
    putchar(ch);
160
    return ch;
232
    return ch;
161
}
233
}
162
 
234
 
-
 
235
void klog_update(void)
-
 
236
{
-
 
237
    spinlock_lock(&klog_lock);
-
 
238
   
-
 
239
    if ((klog_inited) && (klog_irq.notif_cfg.notify) && (klog_uspace > 0)) {
-
 
240
        ipc_irq_send_msg_3(&klog_irq, klog_start, klog_len, klog_uspace);
-
 
241
        klog_uspace = 0;
-
 
242
    }
-
 
243
   
-
 
244
    spinlock_unlock(&klog_lock);
-
 
245
}
-
 
246
 
163
void putchar(char c)
247
void putchar(char c)
164
{
248
{
-
 
249
    spinlock_lock(&klog_lock);
-
 
250
   
165
    if ((klog_stored > 0) && (stdout->op->write)) {
251
    if ((klog_stored > 0) && (stdout->op->write)) {
166
        /* Print charaters stored in kernel log */
252
        /* Print charaters stored in kernel log */
167
        index_t i;
253
        index_t i;
168
        for (i = klog_len - klog_stored; i < klog_len; i++)
254
        for (i = klog_len - klog_stored; i < klog_len; i++)
169
            stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE]);
255
            stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE]);
Line 182... Line 268...
182
    else {
268
    else {
183
        /* The character is just in the kernel log */
269
        /* The character is just in the kernel log */
184
        if (klog_stored < klog_len)
270
        if (klog_stored < klog_len)
185
            klog_stored++;
271
            klog_stored++;
186
    }
272
    }
-
 
273
   
-
 
274
    /* The character is stored for uspace */
-
 
275
    if (klog_uspace < klog_len)
-
 
276
        klog_uspace++;
-
 
277
   
-
 
278
    spinlock_unlock(&klog_lock);
-
 
279
   
-
 
280
    klog_update();
187
}
281
}
188
 
282
 
189
/** @}
283
/** @}
190
 */
284
 */