Subversion Repositories HelenOS

Rev

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

Rev 4346 Rev 4347
Line 37... Line 37...
37
#include <console/chardev.h>
37
#include <console/chardev.h>
38
#include <sysinfo/sysinfo.h>
38
#include <sysinfo/sysinfo.h>
39
#include <synch/waitq.h>
39
#include <synch/waitq.h>
40
#include <synch/spinlock.h>
40
#include <synch/spinlock.h>
41
#include <arch/types.h>
41
#include <arch/types.h>
42
#include <ddi/device.h>
-
 
43
#include <ddi/irq.h>
42
#include <ddi/irq.h>
44
#include <ddi/ddi.h>
43
#include <ddi/ddi.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>
-
 
51
#include <syscall/copy.h>
-
 
52
#include <errno.h>
50
 
53
 
51
#define KLOG_SIZE PAGE_SIZE
54
#define KLOG_SIZE     PAGE_SIZE
52
#define KLOG_LATENCY 8
55
#define KLOG_LATENCY  8
53
 
56
 
54
/** Kernel log cyclic buffer */
57
/** Kernel log cyclic buffer */
55
static char klog[KLOG_SIZE] __attribute__ ((aligned (PAGE_SIZE)));
58
static wchar_t klog[KLOG_SIZE] __attribute__ ((aligned (PAGE_SIZE)));
56
 
59
 
57
/** Kernel log initialized */
60
/** Kernel log initialized */
58
static bool klog_inited = false;
61
static bool klog_inited = false;
59
/** First kernel log characters */
62
/** First kernel log characters */
60
static index_t klog_start = 0;
63
static index_t klog_start = 0;
Line 91... Line 94...
91
   
94
   
92
    ASSERT((uintptr_t) faddr % FRAME_SIZE == 0);
95
    ASSERT((uintptr_t) faddr % FRAME_SIZE == 0);
93
    ASSERT(KLOG_SIZE % FRAME_SIZE == 0);
96
    ASSERT(KLOG_SIZE % FRAME_SIZE == 0);
94
   
97
   
95
    klog_parea.pbase = (uintptr_t) faddr;
98
    klog_parea.pbase = (uintptr_t) faddr;
96
    klog_parea.frames = SIZE2FRAMES(KLOG_SIZE);
99
    klog_parea.frames = SIZE2FRAMES(sizeof(klog));
97
    ddi_parea_register(&klog_parea);
100
    ddi_parea_register(&klog_parea);
98
   
101
   
99
    sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr);
102
    sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr);
100
    sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(KLOG_SIZE));
103
    sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(sizeof(klog)));
101
   
-
 
102
    //irq_initialize(&klog_irq);
-
 
103
    //klog_irq.devno = devno;
-
 
104
    //klog_irq.inr = KLOG_VIRT_INR;
-
 
105
    //klog_irq.claim = klog_claim;
-
 
106
    //irq_register(&klog_irq);
-
 
107
   
104
   
108
    spinlock_lock(&klog_lock);
105
    spinlock_lock(&klog_lock);
109
    klog_inited = true;
106
    klog_inited = true;
110
    spinlock_unlock(&klog_lock);
107
    spinlock_unlock(&klog_lock);
111
}
108
}
Line 120... Line 117...
120
{
117
{
121
    silent = true;
118
    silent = true;
122
    arch_release_console();
119
    arch_release_console();
123
}
120
}
124
 
121
 
-
 
122
/** Tell kernel to get keyboard/console access again */
-
 
123
unative_t sys_debug_enable_console(void)
-
 
124
{
-
 
125
#ifdef CONFIG_KCONSOLE
-
 
126
    grab_console();
-
 
127
    return true;
-
 
128
#else
-
 
129
    return false;
-
 
130
#endif
-
 
131
}
-
 
132
 
-
 
133
/** Tell kernel to relinquish keyboard/console access */
-
 
134
unative_t sys_debug_disable_console(void)
-
 
135
{
-
 
136
    release_console();
-
 
137
    return true;
-
 
138
}
-
 
139
 
125
bool check_poll(indev_t *indev)
140
bool check_poll(indev_t *indev)
126
{
141
{
127
    if (indev == NULL)
142
    if (indev == NULL)
128
        return false;
143
        return false;
129
   
144
   
Line 221... Line 236...
221
 
236
 
222
void klog_update(void)
237
void klog_update(void)
223
{
238
{
224
    spinlock_lock(&klog_lock);
239
    spinlock_lock(&klog_lock);
225
   
240
   
226
//  if ((klog_inited) && (klog_irq.notif_cfg.notify) && (klog_uspace > 0)) {
241
    if ((klog_inited) && (event_is_subscribed(EVENT_KLOG)) && (klog_uspace > 0)) {
227
//      ipc_irq_send_msg_3(&klog_irq, klog_start, klog_len, klog_uspace);
242
        event_notify_3(EVENT_KLOG, klog_start, klog_len, klog_uspace);
228
//      klog_uspace = 0;
243
        klog_uspace = 0;
229
//  }
244
    }
230
   
245
   
231
    spinlock_unlock(&klog_lock);
246
    spinlock_unlock(&klog_lock);
232
}
247
}
233
 
248
 
234
void putchar(char c)
249
void putchar(const wchar_t ch)
235
{
250
{
236
    spinlock_lock(&klog_lock);
251
    spinlock_lock(&klog_lock);
237
   
252
   
238
    if ((klog_stored > 0) && (stdout) && (stdout->op->write)) {
253
    if ((klog_stored > 0) && (stdout) && (stdout->op->write)) {
239
        /* Print charaters stored in kernel log */
254
        /* Print charaters stored in kernel log */
Line 242... Line 257...
242
            stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE], silent);
257
            stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE], silent);
243
        klog_stored = 0;
258
        klog_stored = 0;
244
    }
259
    }
245
   
260
   
246
    /* Store character in the cyclic kernel log */
261
    /* Store character in the cyclic kernel log */
247
    klog[(klog_start + klog_len) % KLOG_SIZE] = c;
262
    klog[(klog_start + klog_len) % KLOG_SIZE] = ch;
248
    if (klog_len < KLOG_SIZE)
263
    if (klog_len < KLOG_SIZE)
249
        klog_len++;
264
        klog_len++;
250
    else
265
    else
251
        klog_start = (klog_start + 1) % KLOG_SIZE;
266
        klog_start = (klog_start + 1) % KLOG_SIZE;
252
   
267
   
253
    if ((stdout) && (stdout->op->write))
268
    if ((stdout) && (stdout->op->write))
254
        stdout->op->write(stdout, c, silent);
269
        stdout->op->write(stdout, ch, silent);
255
    else {
270
    else {
256
        /* The character is just in the kernel log */
271
        /* The character is just in the kernel log */
257
        if (klog_stored < klog_len)
272
        if (klog_stored < klog_len)
258
            klog_stored++;
273
            klog_stored++;
259
    }
274
    }
Line 262... Line 277...
262
    if (klog_uspace < klog_len)
277
    if (klog_uspace < klog_len)
263
        klog_uspace++;
278
        klog_uspace++;
264
   
279
   
265
    /* Check notify uspace to update */
280
    /* Check notify uspace to update */
266
    bool update;
281
    bool update;
267
    if ((klog_uspace > KLOG_LATENCY) || (c == '\n'))
282
    if ((klog_uspace > KLOG_LATENCY) || (ch == '\n'))
268
        update = true;
283
        update = true;
269
    else
284
    else
270
        update = false;
285
        update = false;
271
   
286
   
272
    spinlock_unlock(&klog_lock);
287
    spinlock_unlock(&klog_lock);
273
   
288
   
274
    if (update)
289
    if (update)
275
        klog_update();
290
        klog_update();
276
}
291
}
277
 
292
 
-
 
293
/** Print using kernel facility
-
 
294
 *
-
 
295
 * Print to kernel log.
-
 
296
 *
-
 
297
 */
-
 
298
unative_t sys_klog(int fd, const void * buf, size_t count)
-
 
299
{
-
 
300
    char *data;
-
 
301
    int rc;
-
 
302
   
-
 
303
    if (count > PAGE_SIZE)
-
 
304
        return ELIMIT;
-
 
305
   
-
 
306
    if (count > 0) {
-
 
307
        data = (char *) malloc(count + 1, 0);
-
 
308
        if (!data)
-
 
309
            return ENOMEM;
-
 
310
       
-
 
311
        rc = copy_from_uspace(data, buf, count);
-
 
312
        if (rc) {
-
 
313
            free(data);
-
 
314
            return rc;
-
 
315
        }
-
 
316
        data[count] = 0;
-
 
317
       
-
 
318
        printf("%s", data);
-
 
319
        free(data);
-
 
320
    } else
-
 
321
        klog_update();
-
 
322
   
-
 
323
    return count;
-
 
324
}
-
 
325
 
278
/** @}
326
/** @}
279
 */
327
 */