Subversion Repositories HelenOS

Rev

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

Rev 4173 Rev 4180
Line 44... Line 44...
44
#include <event/event.h>
44
#include <event/event.h>
45
#include <ipc/irq.h>
45
#include <ipc/irq.h>
46
#include <arch.h>
46
#include <arch.h>
47
#include <func.h>
47
#include <func.h>
48
#include <print.h>
48
#include <print.h>
-
 
49
#include <putchar.h>
49
#include <atomic.h>
50
#include <atomic.h>
50
#include <syscall/copy.h>
51
#include <syscall/copy.h>
51
#include <errno.h>
52
#include <errno.h>
52
 
53
 
53
#define KLOG_SIZE PAGE_SIZE
54
#define KLOG_SIZE     PAGE_SIZE
54
#define KLOG_LATENCY 8
55
#define KLOG_LATENCY  8
55
 
56
 
56
/** Kernel log cyclic buffer */
57
/** Kernel log cyclic buffer */
57
static char klog[KLOG_SIZE] __attribute__ ((aligned (PAGE_SIZE)));
58
static wchar_t klog[KLOG_SIZE] __attribute__ ((aligned (PAGE_SIZE)));
58
 
59
 
59
/** Kernel log initialized */
60
/** Kernel log initialized */
60
static bool klog_inited = false;
61
static bool klog_inited = false;
61
/** First kernel log characters */
62
/** First kernel log characters */
62
static index_t klog_start = 0;
63
static index_t klog_start = 0;
Line 93... Line 94...
93
   
94
   
94
    ASSERT((uintptr_t) faddr % FRAME_SIZE == 0);
95
    ASSERT((uintptr_t) faddr % FRAME_SIZE == 0);
95
    ASSERT(KLOG_SIZE % FRAME_SIZE == 0);
96
    ASSERT(KLOG_SIZE % FRAME_SIZE == 0);
96
   
97
   
97
    klog_parea.pbase = (uintptr_t) faddr;
98
    klog_parea.pbase = (uintptr_t) faddr;
98
    klog_parea.frames = SIZE2FRAMES(KLOG_SIZE);
99
    klog_parea.frames = SIZE2FRAMES(sizeof(klog));
99
    ddi_parea_register(&klog_parea);
100
    ddi_parea_register(&klog_parea);
100
   
101
   
101
    sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr);
102
    sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr);
102
    sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(KLOG_SIZE));
103
    sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(sizeof(klog)));
103
   
104
   
104
    spinlock_lock(&klog_lock);
105
    spinlock_lock(&klog_lock);
105
    klog_inited = true;
106
    klog_inited = true;
106
    spinlock_unlock(&klog_lock);
107
    spinlock_unlock(&klog_lock);
107
}
108
}
Line 243... Line 244...
243
    }
244
    }
244
   
245
   
245
    spinlock_unlock(&klog_lock);
246
    spinlock_unlock(&klog_lock);
246
}
247
}
247
 
248
 
248
void putchar(char c)
249
void putchar(const wchar_t ch)
249
{
250
{
250
    spinlock_lock(&klog_lock);
251
    spinlock_lock(&klog_lock);
251
   
252
   
252
    if ((klog_stored > 0) && (stdout) && (stdout->op->write)) {
253
    if ((klog_stored > 0) && (stdout) && (stdout->op->write)) {
253
        /* Print charaters stored in kernel log */
254
        /* Print charaters stored in kernel log */
Line 256... Line 257...
256
            stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE], silent);
257
            stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE], silent);
257
        klog_stored = 0;
258
        klog_stored = 0;
258
    }
259
    }
259
   
260
   
260
    /* Store character in the cyclic kernel log */
261
    /* Store character in the cyclic kernel log */
261
    klog[(klog_start + klog_len) % KLOG_SIZE] = c;
262
    klog[(klog_start + klog_len) % KLOG_SIZE] = ch;
262
    if (klog_len < KLOG_SIZE)
263
    if (klog_len < KLOG_SIZE)
263
        klog_len++;
264
        klog_len++;
264
    else
265
    else
265
        klog_start = (klog_start + 1) % KLOG_SIZE;
266
        klog_start = (klog_start + 1) % KLOG_SIZE;
266
   
267
   
267
    if ((stdout) && (stdout->op->write))
268
    if ((stdout) && (stdout->op->write))
268
        stdout->op->write(stdout, c, silent);
269
        stdout->op->write(stdout, ch, silent);
269
    else {
270
    else {
270
        /* The character is just in the kernel log */
271
        /* The character is just in the kernel log */
271
        if (klog_stored < klog_len)
272
        if (klog_stored < klog_len)
272
            klog_stored++;
273
            klog_stored++;
273
    }
274
    }
Line 276... Line 277...
276
    if (klog_uspace < klog_len)
277
    if (klog_uspace < klog_len)
277
        klog_uspace++;
278
        klog_uspace++;
278
   
279
   
279
    /* Check notify uspace to update */
280
    /* Check notify uspace to update */
280
    bool update;
281
    bool update;
281
    if ((klog_uspace > KLOG_LATENCY) || (c == '\n'))
282
    if ((klog_uspace > KLOG_LATENCY) || (ch == '\n'))
282
        update = true;
283
        update = true;
283
    else
284
    else
284
        update = false;
285
        update = false;
285
   
286
   
286
    spinlock_unlock(&klog_lock);
287
    spinlock_unlock(&klog_lock);
Line 292... Line 293...
292
/** Print using kernel facility
293
/** Print using kernel facility
293
 *
294
 *
294
 * Print to kernel log.
295
 * Print to kernel log.
295
 *
296
 *
296
 */
297
 */
297
unative_t sys_klog(int fd, const void * buf, size_t count)
298
unative_t sys_klog(int fd, const void * buf, size_t count)
298
{
299
{
299
    char *data;
300
    char *data;
300
    int rc;
301
    int rc;
301
 
302
   
302
    if (count > PAGE_SIZE)
303
    if (count > PAGE_SIZE)
303
        return ELIMIT;
304
        return ELIMIT;
304
   
305
   
305
    if (count > 0) {
306
    if (count > 0) {
306
        data = (char *) malloc(count + 1, 0);
307
        data = (char *) malloc(count + 1, 0);