Rev 4156 | Rev 4296 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4156 | Rev 4201 | ||
---|---|---|---|
Line 39... | Line 39... | ||
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/irq.h> |
42 | #include <ddi/irq.h> |
43 | #include <ddi/ddi.h> |
43 | #include <ddi/ddi.h> |
- | 44 | #include <event/event.h> |
|
44 | #include <ipc/irq.h> |
45 | #include <ipc/irq.h> |
45 | #include <arch.h> |
46 | #include <arch.h> |
46 | #include <func.h> |
47 | #include <func.h> |
47 | #include <print.h> |
48 | #include <print.h> |
- | 49 | #include <putchar.h> |
|
48 | #include <atomic.h> |
50 | #include <atomic.h> |
49 | #include <syscall/copy.h> |
51 | #include <syscall/copy.h> |
50 | #include <errno.h> |
52 | #include <errno.h> |
51 | 53 | ||
52 | #define KLOG_SIZE PAGE_SIZE |
54 | #define KLOG_SIZE PAGE_SIZE |
53 | #define KLOG_LATENCY 8 |
55 | #define KLOG_LATENCY 8 |
54 | 56 | ||
55 | /** Kernel log cyclic buffer */ |
57 | /** Kernel log cyclic buffer */ |
56 | static char klog[KLOG_SIZE] __attribute__ ((aligned (PAGE_SIZE))); |
58 | static wchar_t klog[KLOG_SIZE] __attribute__ ((aligned (PAGE_SIZE))); |
57 | 59 | ||
58 | /** Kernel log initialized */ |
60 | /** Kernel log initialized */ |
59 | static bool klog_inited = false; |
61 | static bool klog_inited = false; |
60 | /** First kernel log characters */ |
62 | /** First kernel log characters */ |
61 | static index_t klog_start = 0; |
63 | static index_t klog_start = 0; |
Line 92... | Line 94... | ||
92 | 94 | ||
93 | ASSERT((uintptr_t) faddr % FRAME_SIZE == 0); |
95 | ASSERT((uintptr_t) faddr % FRAME_SIZE == 0); |
94 | ASSERT(KLOG_SIZE % FRAME_SIZE == 0); |
96 | ASSERT(KLOG_SIZE % FRAME_SIZE == 0); |
95 | 97 | ||
96 | klog_parea.pbase = (uintptr_t) faddr; |
98 | klog_parea.pbase = (uintptr_t) faddr; |
97 | klog_parea.frames = SIZE2FRAMES(KLOG_SIZE); |
99 | klog_parea.frames = SIZE2FRAMES(sizeof(klog)); |
98 | ddi_parea_register(&klog_parea); |
100 | ddi_parea_register(&klog_parea); |
99 | 101 | ||
100 | sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr); |
102 | sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr); |
101 | sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(KLOG_SIZE)); |
103 | sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(sizeof(klog))); |
102 | - | ||
103 | //irq_initialize(&klog_irq); |
- | |
104 | //klog_irq.devno = devno; |
- | |
105 | //klog_irq.inr = KLOG_VIRT_INR; |
- | |
106 | //klog_irq.claim = klog_claim; |
- | |
107 | //irq_register(&klog_irq); |
- | |
108 | 104 | ||
109 | spinlock_lock(&klog_lock); |
105 | spinlock_lock(&klog_lock); |
110 | klog_inited = true; |
106 | klog_inited = true; |
111 | spinlock_unlock(&klog_lock); |
107 | spinlock_unlock(&klog_lock); |
112 | } |
108 | } |
Line 240... | Line 236... | ||
240 | 236 | ||
241 | void klog_update(void) |
237 | void klog_update(void) |
242 | { |
238 | { |
243 | spinlock_lock(&klog_lock); |
239 | spinlock_lock(&klog_lock); |
244 | 240 | ||
245 | // if ((klog_inited) && (klog_irq.notif_cfg.notify) && (klog_uspace > 0)) { |
241 | if ((klog_inited) && (event_is_subscribed(EVENT_KLOG)) && (klog_uspace > 0)) { |
246 | // 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); |
247 | // klog_uspace = 0; |
243 | klog_uspace = 0; |
248 | // } |
244 | } |
249 | 245 | ||
250 | spinlock_unlock(&klog_lock); |
246 | spinlock_unlock(&klog_lock); |
251 | } |
247 | } |
252 | 248 | ||
253 | void putchar(char c) |
249 | void putchar(const wchar_t ch) |
254 | { |
250 | { |
255 | spinlock_lock(&klog_lock); |
251 | spinlock_lock(&klog_lock); |
256 | 252 | ||
257 | if ((klog_stored > 0) && (stdout) && (stdout->op->write)) { |
253 | if ((klog_stored > 0) && (stdout) && (stdout->op->write)) { |
258 | /* Print charaters stored in kernel log */ |
254 | /* Print charaters stored in kernel log */ |
Line 261... | Line 257... | ||
261 | stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE], silent); |
257 | stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE], silent); |
262 | klog_stored = 0; |
258 | klog_stored = 0; |
263 | } |
259 | } |
264 | 260 | ||
265 | /* Store character in the cyclic kernel log */ |
261 | /* Store character in the cyclic kernel log */ |
266 | klog[(klog_start + klog_len) % KLOG_SIZE] = c; |
262 | klog[(klog_start + klog_len) % KLOG_SIZE] = ch; |
267 | if (klog_len < KLOG_SIZE) |
263 | if (klog_len < KLOG_SIZE) |
268 | klog_len++; |
264 | klog_len++; |
269 | else |
265 | else |
270 | klog_start = (klog_start + 1) % KLOG_SIZE; |
266 | klog_start = (klog_start + 1) % KLOG_SIZE; |
271 | 267 | ||
272 | if ((stdout) && (stdout->op->write)) |
268 | if ((stdout) && (stdout->op->write)) |
273 | stdout->op->write(stdout, c, silent); |
269 | stdout->op->write(stdout, ch, silent); |
274 | else { |
270 | else { |
275 | /* The character is just in the kernel log */ |
271 | /* The character is just in the kernel log */ |
276 | if (klog_stored < klog_len) |
272 | if (klog_stored < klog_len) |
277 | klog_stored++; |
273 | klog_stored++; |
278 | } |
274 | } |
Line 281... | Line 277... | ||
281 | if (klog_uspace < klog_len) |
277 | if (klog_uspace < klog_len) |
282 | klog_uspace++; |
278 | klog_uspace++; |
283 | 279 | ||
284 | /* Check notify uspace to update */ |
280 | /* Check notify uspace to update */ |
285 | bool update; |
281 | bool update; |
286 | if ((klog_uspace > KLOG_LATENCY) || (c == '\n')) |
282 | if ((klog_uspace > KLOG_LATENCY) || (ch == '\n')) |
287 | update = true; |
283 | update = true; |
288 | else |
284 | else |
289 | update = false; |
285 | update = false; |
290 | 286 | ||
291 | spinlock_unlock(&klog_lock); |
287 | spinlock_unlock(&klog_lock); |
Line 297... | Line 293... | ||
297 | /** Print using kernel facility |
293 | /** Print using kernel facility |
298 | * |
294 | * |
299 | * Print to kernel log. |
295 | * Print to kernel log. |
300 | * |
296 | * |
301 | */ |
297 | */ |
302 | 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) |
303 | { |
299 | { |
304 | char *data; |
300 | char *data; |
305 | int rc; |
301 | int rc; |
306 | 302 | ||
307 | if (count > PAGE_SIZE) |
303 | if (count > PAGE_SIZE) |
308 | return ELIMIT; |
304 | return ELIMIT; |
309 | 305 | ||
310 | if (count > 0) { |
306 | if (count > 0) { |
311 | data = (char *) malloc(count + 1, 0); |
307 | data = (char *) malloc(count + 1, 0); |