Changes in kernel/generic/src/console/console.c [91db0280:feeac0d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/console.c
r91db0280 rfeeac0d 52 52 #include <errno.h> 53 53 #include <str.h> 54 #include <abi/k io.h>55 56 #define K IO_PAGES 857 #define K IO_LENGTH (KIO_PAGES * PAGE_SIZE / sizeof(wchar_t))54 #include <abi/klog.h> 55 56 #define KLOG_PAGES 8 57 #define KLOG_LENGTH (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t)) 58 58 59 59 /** Kernel log cyclic buffer */ 60 wchar_t k io[KIO_LENGTH] __attribute__((aligned(PAGE_SIZE)));60 wchar_t klog[KLOG_LENGTH] __attribute__((aligned(PAGE_SIZE))); 61 61 62 62 /** Kernel log initialized */ 63 static atomic_t k io_inited = {false};63 static atomic_t klog_inited = {false}; 64 64 65 65 /** First kernel log characters */ 66 static size_t k io_start = 0;66 static size_t klog_start = 0; 67 67 68 68 /** Number of valid kernel log characters */ 69 static size_t k io_len = 0;69 static size_t klog_len = 0; 70 70 71 71 /** Number of stored (not printed) kernel log characters */ 72 static size_t k io_stored = 0;72 static size_t klog_stored = 0; 73 73 74 74 /** Number of stored kernel log characters for uspace */ 75 static size_t k io_uspace = 0;75 static size_t klog_uspace = 0; 76 76 77 77 /** Kernel log spinlock */ 78 SPINLOCK_ INITIALIZE_NAME(kio_lock, "kio_lock");79 80 /** Physical memory area used for k iobuffer */81 static parea_t k io_parea;78 SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "klog_lock"); 79 80 /** Physical memory area used for klog buffer */ 81 static parea_t klog_parea; 82 82 83 83 static indev_t stdin_sink; … … 146 146 * 147 147 */ 148 void k io_init(void)149 { 150 void *faddr = (void *) KA2PA(k io);148 void klog_init(void) 149 { 150 void *faddr = (void *) KA2PA(klog); 151 151 152 152 ASSERT((uintptr_t) faddr % FRAME_SIZE == 0); 153 153 154 k io_parea.pbase = (uintptr_t) faddr;155 k io_parea.frames = SIZE2FRAMES(sizeof(kio));156 k io_parea.unpriv = false;157 k io_parea.mapped = false;158 ddi_parea_register(&k io_parea);159 160 sysinfo_set_item_val("k io.faddr", NULL, (sysarg_t) faddr);161 sysinfo_set_item_val("k io.pages", NULL, KIO_PAGES);162 163 event_set_unmask_callback(EVENT_K IO, kio_update);164 atomic_set(&k io_inited, true);154 klog_parea.pbase = (uintptr_t) faddr; 155 klog_parea.frames = SIZE2FRAMES(sizeof(klog)); 156 klog_parea.unpriv = false; 157 klog_parea.mapped = false; 158 ddi_parea_register(&klog_parea); 159 160 sysinfo_set_item_val("klog.faddr", NULL, (sysarg_t) faddr); 161 sysinfo_set_item_val("klog.pages", NULL, KLOG_PAGES); 162 163 event_set_unmask_callback(EVENT_KLOG, klog_update); 164 atomic_set(&klog_inited, true); 165 165 } 166 166 … … 247 247 } 248 248 249 void k io_update(void *event)250 { 251 if (!atomic_get(&k io_inited))249 void klog_update(void *event) 250 { 251 if (!atomic_get(&klog_inited)) 252 252 return; 253 253 254 spinlock_lock(&kio_lock); 255 256 if (kio_uspace > 0) { 257 if (event_notify_3(EVENT_KIO, true, kio_start, kio_len, 258 kio_uspace) == EOK) 259 kio_uspace = 0; 260 } 261 262 spinlock_unlock(&kio_lock); 263 } 264 265 /** Flush characters that are stored in the output buffer 266 * 267 */ 268 void kio_flush(void) 254 spinlock_lock(&klog_lock); 255 256 if (klog_uspace > 0) { 257 if (event_notify_3(EVENT_KLOG, true, klog_start, klog_len, 258 klog_uspace) == EOK) 259 klog_uspace = 0; 260 } 261 262 spinlock_unlock(&klog_lock); 263 } 264 265 void putchar(const wchar_t ch) 269 266 { 270 267 bool ordy = ((stdout) && (stdout->op->write)); 271 268 272 if (!ordy) 273 return; 274 275 spinlock_lock(&kio_lock); 276 277 /* Print characters that weren't printed earlier */ 278 while (kio_stored > 0) { 279 wchar_t tmp = kio[(kio_start + kio_len - kio_stored) % KIO_LENGTH]; 280 kio_stored--; 281 269 spinlock_lock(&klog_lock); 270 271 /* Print charaters stored in kernel log */ 272 if (ordy) { 273 while (klog_stored > 0) { 274 wchar_t tmp = klog[(klog_start + klog_len - klog_stored) % KLOG_LENGTH]; 275 klog_stored--; 276 277 /* 278 * We need to give up the spinlock for 279 * the physical operation of writting out 280 * the character. 281 */ 282 spinlock_unlock(&klog_lock); 283 stdout->op->write(stdout, tmp); 284 spinlock_lock(&klog_lock); 285 } 286 } 287 288 /* Store character in the cyclic kernel log */ 289 klog[(klog_start + klog_len) % KLOG_LENGTH] = ch; 290 if (klog_len < KLOG_LENGTH) 291 klog_len++; 292 else 293 klog_start = (klog_start + 1) % KLOG_LENGTH; 294 295 if (!ordy) { 296 if (klog_stored < klog_len) 297 klog_stored++; 298 } 299 300 /* The character is stored for uspace */ 301 if (klog_uspace < klog_len) 302 klog_uspace++; 303 304 spinlock_unlock(&klog_lock); 305 306 if (ordy) { 282 307 /* 283 * We need to give up the spinlock for 284 * the physical operation of writing out 285 * the character. 308 * Output the character. In this case 309 * it should be no longer buffered. 286 310 */ 287 spinlock_unlock(&kio_lock); 288 stdout->op->write(stdout, tmp); 289 spinlock_lock(&kio_lock); 290 } 291 292 spinlock_unlock(&kio_lock); 293 } 294 295 /** Put a character into the output buffer. 296 * 297 * The caller is required to hold kio_lock 298 */ 299 void kio_push_char(const wchar_t ch) 300 { 301 kio[(kio_start + kio_len) % KIO_LENGTH] = ch; 302 if (kio_len < KIO_LENGTH) 303 kio_len++; 304 else 305 kio_start = (kio_start + 1) % KIO_LENGTH; 306 307 if (kio_stored < kio_len) 308 kio_stored++; 309 310 /* The character is stored for uspace */ 311 if (kio_uspace < kio_len) 312 kio_uspace++; 313 } 314 315 void putchar(const wchar_t ch) 316 { 317 bool ordy = ((stdout) && (stdout->op->write)); 318 319 spinlock_lock(&kio_lock); 320 kio_push_char(ch); 321 spinlock_unlock(&kio_lock); 322 323 /* Output stored characters */ 324 kio_flush(); 325 326 if (!ordy) { 311 stdout->op->write(stdout, ch); 312 } else { 327 313 /* 328 314 * No standard output routine defined yet. … … 340 326 /* Force notification on newline */ 341 327 if (ch == '\n') 342 k io_update(NULL);328 klog_update(NULL); 343 329 } 344 330 … … 348 334 * 349 335 */ 350 sysarg_t sys_k io(int cmd, const void *buf, size_t size)336 sysarg_t sys_klog(int cmd, const void *buf, size_t size) 351 337 { 352 338 char *data; … … 354 340 355 341 switch (cmd) { 356 case K IO_UPDATE:357 k io_update(NULL);342 case KLOG_UPDATE: 343 klog_update(NULL); 358 344 return EOK; 359 case K IO_WRITE:360 case K IO_COMMAND:345 case KLOG_WRITE: 346 case KLOG_COMMAND: 361 347 break; 362 348 default: … … 380 366 381 367 switch (cmd) { 382 case K IO_WRITE:368 case KLOG_WRITE: 383 369 printf("%s", data); 384 370 break; 385 case K IO_COMMAND:371 case KLOG_COMMAND: 386 372 if (!stdin) 387 373 break;
Note:
See TracChangeset
for help on using the changeset viewer.